Loading res/values/attrs.xml +6 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,12 @@ <attr name="demoModeLayoutId" format="reference" /> <attr name="isScalable" format="boolean" /> <attr name="devicePaddingId" format="reference" /> <attr name="gridEnabled" format="integer" > <!-- Enable on all devices; default value --> <enum name="all_displays" value="0" /> <!-- Enable on single display devices only --> <enum name="single_display" value="1" /> </attr> </declare-styleable> Loading src/com/android/launcher3/InvariantDeviceProfile.java +53 −12 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.Rect; import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; import android.util.TypedValue; import android.util.Xml; Loading Loading @@ -68,6 +69,8 @@ public class InvariantDeviceProfile { private static final int DEFAULT_TRUE = -1; private static final int DEFAULT_SPLIT_DISPLAY = 2; private static final int GRID_ENABLED_ALL_DISPLAYS = 0; private static final int GRID_ENABLED_SINGLE_DISPLAY = 1; private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; Loading Loading @@ -104,6 +107,7 @@ public class InvariantDeviceProfile { public float iconTextSize; public float allAppsIconSize; public float allAppsIconTextSize; public boolean isSplitDisplay; public float minCellHeight; public float minCellWidth; Loading Loading @@ -280,6 +284,7 @@ public class InvariantDeviceProfile { numFolderColumns = closestProfile.numFolderColumns; isScalable = closestProfile.isScalable; devicePaddingId = closestProfile.devicePaddingId; this.isSplitDisplay = isSplitDisplay; mExtraAttrs = closestProfile.extraAttrs; Loading Loading @@ -390,10 +395,12 @@ public class InvariantDeviceProfile { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser)); GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); if (gridOption.isEnabled) { final int displayDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > displayDepth) while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > displayDepth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && "display-option".equals( parser.getName())) { Loading @@ -404,6 +411,7 @@ public class InvariantDeviceProfile { } } } } } catch (IOException|XmlPullParserException e) { throw new RuntimeException(e); } Loading @@ -411,7 +419,7 @@ public class InvariantDeviceProfile { ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); if (!TextUtils.isEmpty(gridName)) { for (DisplayOption option : profiles) { if (gridName.equals(option.grid.name)) { if (gridName.equals(option.grid.name) && option.grid.isEnabled) { filteredProfiles.add(option); } } Loading @@ -430,6 +438,32 @@ public class InvariantDeviceProfile { return filteredProfiles; } /** * @return all the grid options that can be shown on the device */ public List<GridOption> parseAllGridOptions(Context context) { List<GridOption> result = new ArrayList<>(); try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { GridOption option = new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); if (option.isEnabled) { result.add(option); } } } } catch (IOException | XmlPullParserException e) { Log.e(TAG, "Error parsing device profile", e); return Collections.emptyList(); } return result; } private int getLauncherIconDensity(int requiredSize) { // Densities typically defined by an app. int[] densityBuckets = new int[] { Loading Loading @@ -591,6 +625,7 @@ public class InvariantDeviceProfile { public final String name; public final int numRows; public final int numColumns; public final boolean isEnabled; private final int numFolderRows; private final int numFolderColumns; Loading @@ -610,7 +645,7 @@ public class InvariantDeviceProfile { private final SparseArray<TypedValue> extraAttrs; public GridOption(Context context, AttributeSet attrs) { public GridOption(Context context, AttributeSet attrs, boolean isSplitDisplay) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.GridDisplayOption); name = a.getString(R.styleable.GridDisplayOption_name); Loading Loading @@ -643,6 +678,12 @@ public class InvariantDeviceProfile { devicePaddingId = a.getResourceId( R.styleable.GridDisplayOption_devicePaddingId, 0); final int enabledInt = a.getInteger(R.styleable.GridDisplayOption_gridEnabled, GRID_ENABLED_ALL_DISPLAYS); isEnabled = enabledInt == GRID_ENABLED_ALL_DISPLAYS || enabledInt == GRID_ENABLED_SINGLE_DISPLAY && !isSplitDisplay; a.recycle(); extraAttrs = Themes.createValueMap(context, attrs, IntArray.wrap(R.styleable.GridDisplayOption)); Loading src/com/android/launcher3/graphics/GridCustomizationsProvider.java +4 −34 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import android.annotation.TargetApi; import android.content.ContentProvider; import android.content.ContentValues; import android.content.pm.PackageManager; import android.content.res.XmlResourceParser; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; Loading @@ -23,23 +22,13 @@ import android.os.Message; import android.os.Messenger; import android.util.ArrayMap; import android.util.Log; import android.util.Xml; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.GridOption; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.Executors; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Exposes various launcher grid options and allows the caller to change them. * APIs: Loading Loading @@ -94,7 +83,7 @@ public class GridCustomizationsProvider extends ContentProvider { MatrixCursor cursor = new MatrixCursor(new String[] { KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT}); InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); for (GridOption gridOption : parseAllGridOptions()) { for (GridOption gridOption : idp.parseAllGridOptions(getContext())) { cursor.newRow() .add(KEY_NAME, gridOption.name) .add(KEY_ROWS, gridOption.numRows) Loading @@ -116,25 +105,6 @@ public class GridCustomizationsProvider extends ContentProvider { } } private List<GridOption> parseAllGridOptions() { List<GridOption> result = new ArrayList<>(); try (XmlResourceParser parser = getContext().getResources().getXml(R.xml.device_profiles)) { final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { result.add(new GridOption(getContext(), Xml.asAttributeSet(parser))); } } } catch (IOException | XmlPullParserException e) { Log.e(TAG, "Error parsing device profile", e); return Collections.emptyList(); } return result; } @Override public String getType(Uri uri) { return "vnd.android.cursor.dir/launcher_grid"; Loading @@ -155,9 +125,10 @@ public class GridCustomizationsProvider extends ContentProvider { switch (uri.getPath()) { case KEY_DEFAULT_GRID: { String gridName = values.getAsString(KEY_NAME); InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); // Verify that this is a valid grid option GridOption match = null; for (GridOption option : parseAllGridOptions()) { for (GridOption option : idp.parseAllGridOptions(getContext())) { if (option.name.equals(gridName)) { match = option; break; Loading @@ -167,8 +138,7 @@ public class GridCustomizationsProvider extends ContentProvider { return 0; } InvariantDeviceProfile.INSTANCE.get(getContext()) .setCurrentGrid(getContext(), gridName); idp.setCurrentGrid(getContext(), gridName); return 1; } case ICON_THEMED: Loading Loading
res/values/attrs.xml +6 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,12 @@ <attr name="demoModeLayoutId" format="reference" /> <attr name="isScalable" format="boolean" /> <attr name="devicePaddingId" format="reference" /> <attr name="gridEnabled" format="integer" > <!-- Enable on all devices; default value --> <enum name="all_displays" value="0" /> <!-- Enable on single display devices only --> <enum name="single_display" value="1" /> </attr> </declare-styleable> Loading
src/com/android/launcher3/InvariantDeviceProfile.java +53 −12 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.Rect; import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; import android.util.TypedValue; import android.util.Xml; Loading Loading @@ -68,6 +69,8 @@ public class InvariantDeviceProfile { private static final int DEFAULT_TRUE = -1; private static final int DEFAULT_SPLIT_DISPLAY = 2; private static final int GRID_ENABLED_ALL_DISPLAYS = 0; private static final int GRID_ENABLED_SINGLE_DISPLAY = 1; private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; Loading Loading @@ -104,6 +107,7 @@ public class InvariantDeviceProfile { public float iconTextSize; public float allAppsIconSize; public float allAppsIconTextSize; public boolean isSplitDisplay; public float minCellHeight; public float minCellWidth; Loading Loading @@ -280,6 +284,7 @@ public class InvariantDeviceProfile { numFolderColumns = closestProfile.numFolderColumns; isScalable = closestProfile.isScalable; devicePaddingId = closestProfile.devicePaddingId; this.isSplitDisplay = isSplitDisplay; mExtraAttrs = closestProfile.extraAttrs; Loading Loading @@ -390,10 +395,12 @@ public class InvariantDeviceProfile { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser)); GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); if (gridOption.isEnabled) { final int displayDepth = parser.getDepth(); while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > displayDepth) while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > displayDepth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && "display-option".equals( parser.getName())) { Loading @@ -404,6 +411,7 @@ public class InvariantDeviceProfile { } } } } } catch (IOException|XmlPullParserException e) { throw new RuntimeException(e); } Loading @@ -411,7 +419,7 @@ public class InvariantDeviceProfile { ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); if (!TextUtils.isEmpty(gridName)) { for (DisplayOption option : profiles) { if (gridName.equals(option.grid.name)) { if (gridName.equals(option.grid.name) && option.grid.isEnabled) { filteredProfiles.add(option); } } Loading @@ -430,6 +438,32 @@ public class InvariantDeviceProfile { return filteredProfiles; } /** * @return all the grid options that can be shown on the device */ public List<GridOption> parseAllGridOptions(Context context) { List<GridOption> result = new ArrayList<>(); try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { GridOption option = new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); if (option.isEnabled) { result.add(option); } } } } catch (IOException | XmlPullParserException e) { Log.e(TAG, "Error parsing device profile", e); return Collections.emptyList(); } return result; } private int getLauncherIconDensity(int requiredSize) { // Densities typically defined by an app. int[] densityBuckets = new int[] { Loading Loading @@ -591,6 +625,7 @@ public class InvariantDeviceProfile { public final String name; public final int numRows; public final int numColumns; public final boolean isEnabled; private final int numFolderRows; private final int numFolderColumns; Loading @@ -610,7 +645,7 @@ public class InvariantDeviceProfile { private final SparseArray<TypedValue> extraAttrs; public GridOption(Context context, AttributeSet attrs) { public GridOption(Context context, AttributeSet attrs, boolean isSplitDisplay) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.GridDisplayOption); name = a.getString(R.styleable.GridDisplayOption_name); Loading Loading @@ -643,6 +678,12 @@ public class InvariantDeviceProfile { devicePaddingId = a.getResourceId( R.styleable.GridDisplayOption_devicePaddingId, 0); final int enabledInt = a.getInteger(R.styleable.GridDisplayOption_gridEnabled, GRID_ENABLED_ALL_DISPLAYS); isEnabled = enabledInt == GRID_ENABLED_ALL_DISPLAYS || enabledInt == GRID_ENABLED_SINGLE_DISPLAY && !isSplitDisplay; a.recycle(); extraAttrs = Themes.createValueMap(context, attrs, IntArray.wrap(R.styleable.GridDisplayOption)); Loading
src/com/android/launcher3/graphics/GridCustomizationsProvider.java +4 −34 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ import android.annotation.TargetApi; import android.content.ContentProvider; import android.content.ContentValues; import android.content.pm.PackageManager; import android.content.res.XmlResourceParser; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; Loading @@ -23,23 +22,13 @@ import android.os.Message; import android.os.Messenger; import android.util.ArrayMap; import android.util.Log; import android.util.Xml; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.GridOption; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.Executors; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Exposes various launcher grid options and allows the caller to change them. * APIs: Loading Loading @@ -94,7 +83,7 @@ public class GridCustomizationsProvider extends ContentProvider { MatrixCursor cursor = new MatrixCursor(new String[] { KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT}); InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); for (GridOption gridOption : parseAllGridOptions()) { for (GridOption gridOption : idp.parseAllGridOptions(getContext())) { cursor.newRow() .add(KEY_NAME, gridOption.name) .add(KEY_ROWS, gridOption.numRows) Loading @@ -116,25 +105,6 @@ public class GridCustomizationsProvider extends ContentProvider { } } private List<GridOption> parseAllGridOptions() { List<GridOption> result = new ArrayList<>(); try (XmlResourceParser parser = getContext().getResources().getXml(R.xml.device_profiles)) { final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) && GridOption.TAG_NAME.equals(parser.getName())) { result.add(new GridOption(getContext(), Xml.asAttributeSet(parser))); } } } catch (IOException | XmlPullParserException e) { Log.e(TAG, "Error parsing device profile", e); return Collections.emptyList(); } return result; } @Override public String getType(Uri uri) { return "vnd.android.cursor.dir/launcher_grid"; Loading @@ -155,9 +125,10 @@ public class GridCustomizationsProvider extends ContentProvider { switch (uri.getPath()) { case KEY_DEFAULT_GRID: { String gridName = values.getAsString(KEY_NAME); InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext()); // Verify that this is a valid grid option GridOption match = null; for (GridOption option : parseAllGridOptions()) { for (GridOption option : idp.parseAllGridOptions(getContext())) { if (option.name.equals(gridName)) { match = option; break; Loading @@ -167,8 +138,7 @@ public class GridCustomizationsProvider extends ContentProvider { return 0; } InvariantDeviceProfile.INSTANCE.get(getContext()) .setCurrentGrid(getContext(), gridName); idp.setCurrentGrid(getContext(), gridName); return 1; } case ICON_THEMED: Loading