OSDN Git Service

Adding support for negative x and y in layout xml.
authorSunny Goyal <sunnygoyal@google.com>
Wed, 16 Dec 2015 19:32:54 +0000 (11:32 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Sat, 19 Dec 2015 01:17:08 +0000 (17:17 -0800)
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

res/xml/default_workspace_3x3.xml [new file with mode: 0644]
res/xml/default_workspace_4x4.xml
res/xml/default_workspace_5x5.xml
res/xml/default_workspace_5x6.xml
src/com/android/launcher3/AutoInstallsLayout.java
src/com/android/launcher3/CommonAppTypeParser.java
src/com/android/launcher3/DefaultLayoutParser.java
src/com/android/launcher3/InvariantDeviceProfile.java

diff --git a/res/xml/default_workspace_3x3.xml b/res/xml/default_workspace_3x3.xml
new file mode 100644 (file)
index 0000000..8d99404
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3">
+
+    <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
+    <!-- Messaging, [All Apps], Dialer -->
+
+    <resolve
+        launcher:container="-101"
+        launcher:screen="0"
+        launcher:x="0"
+        launcher:y="0" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MESSAGING;end" />
+        <favorite launcher:uri="sms:" />
+        <favorite launcher:uri="smsto:" />
+        <favorite launcher:uri="mms:" />
+        <favorite launcher:uri="mmsto:" />
+    </resolve>
+
+    <!-- All Apps -->
+
+    <resolve
+        launcher:container="-101"
+        launcher:screen="2"
+        launcher:x="2"
+        launcher:y="0" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.DIAL;end" />
+        <favorite launcher:uri="tel:123" />
+        <favorite launcher:uri="#Intent;action=android.intent.action.CALL_BUTTON;end" />
+    </resolve>
+
+    <!-- Bottom row -->
+    <resolve
+        launcher:screen="0"
+        launcher:x="0"
+        launcher:y="-1" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_EMAIL;end" />
+        <favorite launcher:uri="mailto:" />
+    </resolve>
+
+    <resolve
+        launcher:screen="0"
+        launcher:x="1"
+        launcher:y="-1" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_GALLERY;end" />
+        <favorite launcher:uri="#Intent;type=images/*;end" />
+    </resolve>
+
+    <resolve
+        launcher:screen="0"
+        launcher:x="2"
+        launcher:y="-1" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
+        <favorite launcher:uri="market://details?id=com.android.launcher" />
+    </resolve>
+
+    <!-- Second last row -->
+    <resolve
+        launcher:screen="0"
+        launcher:x="0"
+        launcher:y="-2" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_BROWSER;end" />
+        <favorite launcher:uri="http://www.example.com/" />
+    </resolve>
+
+    <resolve
+        launcher:screen="0"
+        launcher:x="2"
+        launcher:y="-2" >
+        <favorite launcher:uri="#Intent;action=android.media.action.STILL_IMAGE_CAMERA;end" />
+        <favorite launcher:uri="#Intent;action=android.intent.action.CAMERA_BUTTON;end" />
+    </resolve>
+
+</favorites>
index 060a1f8..979a1b4 100644 (file)
@@ -23,7 +23,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="0"
-        launcher:y="3" >
+        launcher:y="-1" >
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_EMAIL;end" />
         <favorite launcher:uri="mailto:" />
     </resolve>
@@ -31,7 +31,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="1"
-        launcher:y="3" >
+        launcher:y="-1" >
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_GALLERY;end" />
         <favorite launcher:uri="#Intent;type=images/*;end" />
     </resolve>
@@ -39,7 +39,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="3"
-        launcher:y="3" >
+        launcher:y="-1" >
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
         <favorite launcher:uri="market://details?id=com.android.launcher" />
     </resolve>
index 3226617..f9cc0e7 100644 (file)
@@ -23,7 +23,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="0"
-        launcher:y="4" >
+        launcher:y="-1" >
            <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_EMAIL;end" />
            <favorite launcher:uri="mailto:" />
 
@@ -32,7 +32,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="1"
-        launcher:y="4" >
+        launcher:y="-1" >
            <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_GALLERY;end" />
            <favorite launcher:uri="#Intent;type=images/*;end" />
 
@@ -41,7 +41,7 @@
     <resolve
         launcher:screen="0"
         launcher:x="4"
-        launcher:y="4" >
+        launcher:y="-1" >
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
         <favorite launcher:uri="market://details?id=com.android.launcher" />
     </resolve>
index bc236fb..8493c26 100644 (file)
     <favorite
         launcher:screen="0"
         launcher:x="0"
-        launcher:y="4"
+        launcher:y="-1"
         launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_CONTACTS;end" />
 
     <resolve
         launcher:screen="0"
-        launcher:x="5"
-        launcher:y="4" >
+        launcher:x="-1"
+        launcher:y="-1" >
         <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
         <favorite launcher:uri="market://details?id=com.android.launcher" />
     </resolve>
index 440e4e7..151048c 100644 (file)
@@ -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.
index 5314ecf..5ea4726 100644 (file)
@@ -93,7 +93,7 @@ public class CommonAppTypeParser implements LayoutParserCallback {
 
         public MyLayoutParser() {
             super(CommonAppTypeParser.this.mContext, null, CommonAppTypeParser.this,
-                    CommonAppTypeParser.this.mContext.getResources(), mResId, TAG_RESOLVE, 0);
+                    CommonAppTypeParser.this.mContext.getResources(), mResId, TAG_RESOLVE);
         }
 
         @Override
index 7b91c67..2bba380 100644 (file)
@@ -48,9 +48,8 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
     }
 
     public DefaultLayoutParser(Context context, AppWidgetHost appWidgetHost,
-            LayoutParserCallback callback, Resources sourceRes, int layoutId, String rootTag,
-            int hotseatAllAppsRank) {
-        super(context, appWidgetHost, callback, sourceRes, layoutId, rootTag, hotseatAllAppsRank);
+            LayoutParserCallback callback, Resources sourceRes, int layoutId, String rootTag) {
+        super(context, appWidgetHost, callback, sourceRes, layoutId, rootTag);
     }
 
     @Override
index a91181d..b3a8bbc 100644 (file)
@@ -173,9 +173,9 @@ public class InvariantDeviceProfile {
         // width, height, #rows, #columns, #folder rows, #folder columns,
         // iconSize, iconTextSize, #hotseat, #hotseatIconSize, defaultLayoutId.
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Super Short Stubby",
-                255, 300,     2, 3, 2, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
+                255, 300,     2, 3, 2, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_3x3));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Shorter Stubby",
-                255, 400,     3, 3, 3, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
+                255, 400,     3, 3, 3, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_3x3));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Short Stubby",
                 275, 420,     3, 4, 3, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Stubby",
@@ -196,7 +196,7 @@ public class InvariantDeviceProfile {
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 10",
                 727, 1207,    5, 6, 4, 5, 4, 76, 14.4f,  7, 76, R.xml.default_workspace_5x6));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("20-inch Tablet",
-                1527, 2527,   7, 7, 6, 6, 4, 100, 20,  7, 72, R.xml.default_workspace_4x4));
+                1527, 2527,   7, 7, 6, 6, 4, 100, 20,  7, 72, R.xml.default_workspace_5x6));
         return predefinedDeviceProfiles;
     }