diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-12-16 11:32:54 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-12-18 17:17:08 -0800 |
commit | 96a0963c4a05c6ef9b1fc9d76e6431c510d48e69 (patch) | |
tree | 8204318122f979e798624fbf8efb7ecc376036eb /src/com/android/launcher3/AutoInstallsLayout.java | |
parent | ffa123769807675869819037676717585d3fe647 (diff) | |
download | android_packages_apps_Trebuchet-96a0963c4a05c6ef9b1fc9d76e6431c510d48e69.tar.gz android_packages_apps_Trebuchet-96a0963c4a05c6ef9b1fc9d76e6431c510d48e69.tar.bz2 android_packages_apps_Trebuchet-96a0963c4a05c6ef9b1fc9d76e6431c510d48e69.zip |
Adding support for negative x and y in layout xml.
Fixing default configurations for some screen sizes.
> Negative values for x and y are parsed as distance from end
column and row respectively. e.g. (-1, -2) => (3, 2) in a
4x4 grid
Bug: 26110981
Change-Id: I4ca30e225ed6e2a31610ab23235d2cd10e8d317c
Diffstat (limited to 'src/com/android/launcher3/AutoInstallsLayout.java')
-rw-r--r-- | src/com/android/launcher3/AutoInstallsLayout.java | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java index 440e4e7b9..151048c7c 100644 --- a/src/com/android/launcher3/AutoInstallsLayout.java +++ b/src/com/android/launcher3/AutoInstallsLayout.java @@ -125,8 +125,12 @@ public class AutoInstallsLayout { private static final String ATTR_CLASS_NAME = "className"; private static final String ATTR_TITLE = "title"; private static final String ATTR_SCREEN = "screen"; + + // x and y can be specified as negative integers, in which case -1 represents the + // last row / column, -2 represents the second last, and so on. private static final String ATTR_X = "x"; private static final String ATTR_Y = "y"; + private static final String ATTR_SPAN_X = "spanX"; private static final String ATTR_SPAN_Y = "spanY"; private static final String ATTR_ICON = "icon"; @@ -154,6 +158,8 @@ public class AutoInstallsLayout { protected final int mLayoutId; private final int mHotseatAllAppsRank; + private final int mRowCount; + private final int mColumnCount; private final long[] mTemp = new long[2]; @Thunk final ContentValues mValues; @@ -164,13 +170,6 @@ public class AutoInstallsLayout { public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, LayoutParserCallback callback, Resources res, int layoutId, String rootTag) { - this(context, appWidgetHost, callback, res, layoutId, rootTag, - LauncherAppState.getInstance().getInvariantDeviceProfile().hotseatAllAppsRank); - } - - public AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost, - LayoutParserCallback callback, Resources res, - int layoutId, String rootTag, int hotseatAllAppsRank) { mContext = context; mAppWidgetHost = appWidgetHost; mCallback = callback; @@ -181,7 +180,11 @@ public class AutoInstallsLayout { mSourceRes = res; mLayoutId = layoutId; - mHotseatAllAppsRank = hotseatAllAppsRank; + + InvariantDeviceProfile idp = LauncherAppState.getInstance().getInvariantDeviceProfile(); + mHotseatAllAppsRank = idp.hotseatAllAppsRank; + mRowCount = idp.numRows; + mColumnCount = idp.numColumns; } /** @@ -261,8 +264,11 @@ public class AutoInstallsLayout { mValues.put(Favorites.CONTAINER, container); mValues.put(Favorites.SCREEN, screenId); - mValues.put(Favorites.CELLX, getAttributeValue(parser, ATTR_X)); - mValues.put(Favorites.CELLY, getAttributeValue(parser, ATTR_Y)); + + mValues.put(Favorites.CELLX, + convertToDistanceFromEnd(getAttributeValue(parser, ATTR_X), mColumnCount); + mValues.put(Favorites.CELLY, + convertToDistanceFromEnd(getAttributeValue(parser, ATTR_Y), mRowCount); TagParser tagParser = tagParserMap.get(parser.getName()); if (tagParser == null) { @@ -648,6 +654,16 @@ public class AutoInstallsLayout { } } + private static String convertToDistanceFromEnd(String value, int endValue) { + if (!TextUtils.isEmpty(value)) { + int x = Integer.parseInt(value); + if (x < 0) { + return Integer.toString(endValue + x); + } + } + return value; + } + /** * Return attribute value, attempting launcher-specific namespace first * before falling back to anonymous attribute. |