Various icon size changes

1) Setting different icon and text size for workspace and all apps
2) Setting padding during BubbleTextView inflation

Change-Id: I59da6986b0d98e8e2aa6065743bb799a6bf06a37
diff --git a/res/layout/apps_customize_application.xml b/res/layout/apps_customize_application.xml
deleted file mode 100644
index c56cdf3..0000000
--- a/res/layout/apps_customize_application.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 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.
--->
-
-<com.android.launcher3.BubbleTextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    style="@style/WorkspaceIcon.AppsCustomize"
-    android:id="@+id/application_icon"
-    android:focusable="true" />
diff --git a/res/layout/apps_grid_row_icon_view.xml b/res/layout/apps_grid_row_icon_view.xml
index 81e74b9..286deb4 100644
--- a/res/layout/apps_grid_row_icon_view.xml
+++ b/res/layout/apps_grid_row_icon_view.xml
@@ -25,5 +25,6 @@
     android:paddingBottom="8dp"
     android:focusable="true"
     android:background="@drawable/focusable_view_bg"
-    launcher:deferShadowGeneration="true" />
+    launcher:deferShadowGeneration="true"
+    launcher:iconDisplay="all_apps" />
 
diff --git a/res/layout/apps_list_row_icon_view.xml b/res/layout/apps_list_row_icon_view.xml
deleted file mode 100644
index 867dbdc..0000000
--- a/res/layout/apps_list_row_icon_view.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?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.
--->
-
-<com.android.launcher3.BubbleTextView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:launcher="http://schemas.android.com/apk/res-auto"
-    style="@style/WorkspaceIcon.AppsCustomize"
-    android:id="@+id/application_icon"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:focusable="true"
-    android:background="@drawable/focusable_view_bg"
-    launcher:iconPaddingOverride="24dp"
-    launcher:textSizeOverride="16dp"
-    launcher:layoutHorizontal="true"
-    launcher:deferShadowGeneration="true" />
diff --git a/res/layout/apps_list_row_view.xml b/res/layout/apps_list_row_view.xml
deleted file mode 100644
index e80285b..0000000
--- a/res/layout/apps_list_row_view.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?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.
--->
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="@dimen/apps_view_row_height"
-    android:orientation="horizontal"
-    android:focusable="true"
-    android:background="@drawable/focusable_view_bg"
-    android:descendantFocusability="afterDescendants">
-    <TextView
-        android:id="@+id/section"
-        android:layout_width="64dp"
-        android:layout_height="match_parent"
-        android:paddingLeft="16dp"
-        android:gravity="start|center_vertical"
-        android:textColor="@color/apps_view_section_text_color"
-        android:textSize="@dimen/apps_view_section_text_size"
-        android:focusable="false" />
-</LinearLayout>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index a1f2845..fee3417 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -22,8 +22,10 @@
     <declare-styleable name="BubbleTextView">
         <attr name="layoutHorizontal" format="boolean" />
         <attr name="iconSizeOverride" format="dimension" />
-        <attr name="iconPaddingOverride" format="dimension" />
-        <attr name="textSizeOverride" format="dimension" />
+        <attr name="iconDisplay" format="integer">
+            <enum name="workspace" value="0" />
+            <enum name="all_apps" value="1" />
+        </attr>
         <attr name="deferShadowGeneration" format="boolean" />
         <attr name="customShadows" format="boolean" />
     </declare-styleable>
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index ae6ebba..009cc2b 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -52,13 +52,14 @@
     private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
     static final float PADDING_V = 3.0f;
 
+    private static final int DISPLAY_WORKSPACE = 0;
+    private static final int DISPLAY_ALL_APPS = 1;
+
     private Drawable mIcon;
     private final Drawable mBackground;
     private final CheckLongPressHelper mLongPressHelper;
     private final HolographicOutlineHelper mOutlineHelper;
 
-    // TODO: Remove custom background handling code, as no instance of BubbleTextView use any
-    // background.
     private boolean mBackgroundSizeChanged;
 
     private Bitmap mPressedBackground;
@@ -69,8 +70,6 @@
     private final boolean mCustomShadowsEnabled;
     private final boolean mLayoutHorizontal;
     private final int mIconSize;
-    private final int mIconPaddingSize;
-    private final int mTextSize;
     private int mTextColor;
 
     private boolean mStayPressed;
@@ -95,14 +94,21 @@
                 R.styleable.BubbleTextView, defStyle, 0);
         mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
         mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
-        mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
-                grid.allAppsIconSizePx);
-        mIconPaddingSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconPaddingOverride,
-                grid.iconDrawablePaddingPx);
-        mTextSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_textSizeOverride,
-                grid.allAppsIconTextSizePx);
         mDeferShadowGenerationOnTouch =
                 a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);
+
+        int display = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
+        int defaultIconSize = grid.iconSizePx;
+        if (display == DISPLAY_WORKSPACE) {
+            setTextSize(grid.iconTextSizePx);
+        } else if (display == DISPLAY_ALL_APPS) {
+            setTextSize(grid.allAppsIconTextSizePx);
+            defaultIconSize = grid.allAppsIconSizePx;
+        }
+
+        mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
+                defaultIconSize);
+
         a.recycle();
 
         if (mCustomShadowsEnabled) {
@@ -128,26 +134,18 @@
         setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate());
     }
 
-    public void onFinishInflate() {
-        super.onFinishInflate();
-
-        // Ensure we are using the right text size
-        setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
+    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
+        applyFromShortcutInfo(info, iconCache, false);
     }
 
     public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
-            boolean setDefaultPadding) {
-        applyFromShortcutInfo(info, iconCache, setDefaultPadding, false);
-    }
-
-    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
-            boolean setDefaultPadding, boolean promiseStateChanged) {
+            boolean promiseStateChanged) {
         Bitmap b = info.getIcon(iconCache);
 
         FastBitmapDrawable iconDrawable = Utilities.createIconDrawable(b);
         iconDrawable.setGhostModeEnabled(info.isDisabled != 0);
 
-        setIcon(iconDrawable, mIconSize, setDefaultPadding ? mIconPaddingSize : -1);
+        setIcon(iconDrawable, mIconSize);
         if (info.contentDescription != null) {
             setContentDescription(info.contentDescription);
         }
@@ -160,7 +158,7 @@
     }
 
     public void applyFromApplicationInfo(AppInfo info) {
-        setIcon(Utilities.createIconDrawable(info.iconBitmap), mIconSize, mIconPaddingSize);
+        setIcon(Utilities.createIconDrawable(info.iconBitmap), mIconSize);
         setText(info.title);
         if (info.contentDescription != null) {
             setContentDescription(info.contentDescription);
@@ -409,7 +407,7 @@
                     preloadDrawable = (PreloadIconDrawable) mIcon;
                 } else {
                     preloadDrawable = new PreloadIconDrawable(mIcon, getPreloaderTheme());
-                    setIcon(preloadDrawable, mIconSize, -1);
+                    setIcon(preloadDrawable, mIconSize);
                 }
 
                 preloadDrawable.setLevel(progressLevel);
@@ -437,7 +435,7 @@
     /**
      * Sets the icon for this view based on the layout direction.
      */
-    private Drawable setIcon(Drawable icon, int iconSize, int drawablePadding) {
+    private Drawable setIcon(Drawable icon, int iconSize) {
         mIcon = icon;
         if (iconSize != -1) {
             mIcon.setBounds(0, 0, iconSize, iconSize);
@@ -447,9 +445,6 @@
         } else {
             setCompoundDrawablesRelative(null, mIcon, null, null);
         }
-        if (drawablePadding != -1) {
-            setCompoundDrawablePadding(drawablePadding);
-        }
         return icon;
     }
 
@@ -463,7 +458,7 @@
                 applyFromApplicationInfo((AppInfo) info);
             } else if (info instanceof ShortcutInfo) {
                 applyFromShortcutInfo((ShortcutInfo) info,
-                        LauncherAppState.getInstance().getIconCache(), false);
+                        LauncherAppState.getInstance().getIconCache());
             }
         }
     }
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 6ca4888..a955b27 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -1076,8 +1076,7 @@
                 // Move the item from the folder to the workspace, in the position of the folder
                 if (getItemCount() == 1) {
                     ShortcutInfo finalItem = mInfo.contents.get(0);
-                    child = mLauncher.createShortcut(R.layout.application, cellLayout,
-                            finalItem);
+                    child = mLauncher.createShortcut(cellLayout, finalItem);
                     LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
                             mInfo.screenId, mInfo.cellX, mInfo.cellY);
                 }
diff --git a/src/com/android/launcher3/FolderPagedView.java b/src/com/android/launcher3/FolderPagedView.java
index 211bbfe..6355082 100644
--- a/src/com/android/launcher3/FolderPagedView.java
+++ b/src/com/android/launcher3/FolderPagedView.java
@@ -206,7 +206,7 @@
     public View createNewView(ShortcutInfo item) {
         final BubbleTextView textView = (BubbleTextView) mInflater.inflate(
                 R.layout.folder_application, null, false);
-        textView.applyFromShortcutInfo(item, mIconCache, false);
+        textView.applyFromShortcutInfo(item, mIconCache);
         textView.setOnClickListener(mFolder);
         textView.setOnLongClickListener(mFolder);
         textView.setOnFocusChangeListener(mFocusIndicatorView);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 5645759..b17a92f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -347,6 +347,8 @@
     private Canvas mFolderIconCanvas;
     private Rect mRectForFolderAnimation = new Rect();
 
+    private DeviceProfile mDeviceProfile;
+
     private BubbleTextView mWaitingForResume;
 
     protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
@@ -423,7 +425,7 @@
         LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
 
         // Lazy-initialize the dynamic grid
-        DeviceProfile grid = app.initDynamicGrid(this);
+        mDeviceProfile = app.initDynamicGrid(this);
 
         // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
         mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
@@ -431,7 +433,7 @@
         mIsSafeModeEnabled = getPackageManager().isSafeMode();
         mModel = app.setLauncher(this);
         mIconCache = app.getIconCache();
-        mIconCache.flushInvalidIcons(grid);
+        mIconCache.flushInvalidIcons(mDeviceProfile);
         mDragController = new DragController(this);
         mInflater = getLayoutInflater();
         mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
@@ -457,7 +459,7 @@
         setContentView(R.layout.launcher);
 
         setupViews();
-        grid.layout(this);
+        mDeviceProfile.layout(this);
 
         registerContentObservers();
 
@@ -1511,22 +1513,22 @@
      * @return A View inflated from R.layout.application.
      */
     View createShortcut(ShortcutInfo info) {
-        return createShortcut(R.layout.application,
-                (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
+        return createShortcut((ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
     }
 
     /**
      * Creates a view representing a shortcut inflated from the specified resource.
      *
-     * @param layoutResId The id of the XML layout used to create the shortcut.
      * @param parent The group the shortcut belongs to.
      * @param info The data structure describing the shortcut.
      *
      * @return A View inflated from layoutResId.
      */
-    public View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
-        BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
-        favorite.applyFromShortcutInfo(info, mIconCache, true);
+    public View createShortcut(ViewGroup parent, ShortcutInfo info) {
+        BubbleTextView favorite = (BubbleTextView) mInflater.inflate(R.layout.application,
+                parent, false);
+        favorite.applyFromShortcutInfo(info, mIconCache);
+        favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
         favorite.setOnClickListener(this);
         favorite.setOnFocusChangeListener(mFocusHandler);
         return favorite;
@@ -4157,13 +4159,11 @@
     }
 
     public boolean useVerticalBarLayout() {
-        return LauncherAppState.getInstance().getDynamicGrid().
-                getDeviceProfile().isVerticalBarLayout();
+        return mDeviceProfile.isVerticalBarLayout();
     }
 
     protected Rect getSearchBarBounds() {
-        return LauncherAppState.getInstance().getDynamicGrid().
-                getDeviceProfile().getSearchBarBounds();
+        return mDeviceProfile.getSearchBarBounds();
     }
 
     public void bindSearchablesChanged() {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 55deb85..4004b1d 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -3558,8 +3558,7 @@
                     // Came from all apps -- make a copy
                     info = ((AppInfo) info).makeShortcut();
                 }
-                view = mLauncher.createShortcut(R.layout.application, cellLayout,
-                        (ShortcutInfo) info);
+                view = mLauncher.createShortcut(cellLayout, (ShortcutInfo) info);
                 break;
             case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                 view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout,
@@ -4185,7 +4184,7 @@
                             && packageNames.contains(cn.getPackageName())) {
                         shortcutInfo.isDisabled |= reason;
                         BubbleTextView shortcut = (BubbleTextView) v;
-                        shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, false);
+                        shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache);
 
                         if (parent != null) {
                             parent.invalidate();
@@ -4371,7 +4370,7 @@
                     BubbleTextView shortcut = (BubbleTextView) v;
                     boolean oldPromiseState = getTextViewIcon(shortcut)
                             instanceof PreloadIconDrawable;
-                    shortcut.applyFromShortcutInfo(si, mIconCache, false,
+                    shortcut.applyFromShortcutInfo(si, mIconCache,
                             si.isPromise() != oldPromiseState);
 
                     if (parent != null) {