Merge "Using state to update voice button proxy visibility instead of view flags. (Bug 10915381)" into jb-ub-now-indigo-rose
diff --git a/res/layout/all_apps_button.xml b/res/layout/all_apps_button.xml
new file mode 100644
index 0000000..1b9ea08
--- /dev/null
+++ b/res/layout/all_apps_button.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+   style="@style/WorkspaceIcon"
+   android:focusable="true"
+   android:background="@drawable/focusable_view_bg" />
diff --git a/res/values/config.xml b/res/values/config.xml
index 97408cc..8718f15 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -12,7 +12,7 @@
 
 <!-- AllApps/Customize/AppsCustomize -->
     <!-- The alpha of the AppsCustomize bg in spring loaded mode -->
-    <integer name="config_appsCustomizeSpringLoadedBgAlpha">45</integer>
+    <integer name="config_appsCustomizeSpringLoadedBgAlpha">65</integer>
     <integer name="config_workspaceUnshrinkTime">300</integer>
     <!-- Out of 100, the percent to shrink the workspace during spring loaded mode. -->
     <integer name="config_workspaceSpringLoadShrinkPercentage">80</integer>
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index fbbb09f..986a89b 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -28,6 +28,7 @@
 import android.view.MotionEvent;
 import android.view.View;
 import android.widget.FrameLayout;
+import android.widget.TextView;
 
 import java.util.ArrayList;
 
@@ -126,27 +127,17 @@
             // Add the Apps button
             Context context = getContext();
 
-            Drawable rawIcon =
-                    context.getResources().getDrawable(R.drawable.all_apps_button_icon);
-            Bitmap icon = Utilities.createIconBitmap(rawIcon, context);
-
             LayoutInflater inflater = LayoutInflater.from(context);
-            BubbleTextView allAppsButton = (BubbleTextView)
-                    inflater.inflate(R.layout.application, mContent, false);
-            allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null,
-                    new FastBitmapDrawable(icon), null, null);
-            allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
-            allAppsButton.setOnTouchListener(new View.OnTouchListener() {
-                @Override
-                public boolean onTouch(View v, MotionEvent event) {
-                    if (mLauncher != null &&
-                            (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
-                        mLauncher.onTouchDownAllAppsButton(v);
-                    }
-                    return false;
-                }
-            });
+            TextView allAppsButton = (TextView)
+                    inflater.inflate(R.layout.all_apps_button, mContent, false);
+            Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
+            d.setBounds(0, 0, Utilities.sIconTextureWidth, Utilities.sIconTextureHeight);
+            allAppsButton.setCompoundDrawables(null, d, null, null);
 
+            allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
+            if (mLauncher != null) {
+                allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
+            }
             allAppsButton.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(android.view.View v) {
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 71b98dd..7ae429d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -281,7 +281,7 @@
 
     private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
 
-    private Intent mAppMarketIntent = null;
+    private View.OnTouchListener mHapticFeedbackTouchListener;
 
     // Related to the auto-advancing of widgets
     private final int ADVANCE_MSG = 1;
@@ -301,6 +301,9 @@
     private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
     private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
 
+    private Intent mAppMarketIntent = null;
+    private static final boolean DISABLE_MARKET_BUTTON = true;
+
     private Drawable mWorkspaceBackgroundDrawable;
 
     private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
@@ -513,7 +516,9 @@
         int coi = getCurrentOrientationIndexForGlobalIcons();
         if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
                 sAppMarketIcon[coi] == null) {
-            updateAppMarketIcon();
+            if (!DISABLE_MARKET_BUTTON) {
+                updateAppMarketIcon();
+            }
             searchVisible = updateGlobalSearchIcon();
             voiceVisible = updateVoiceSearchIcon(searchVisible);
         }
@@ -525,7 +530,7 @@
             updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
             voiceVisible = true;
         }
-        if (sAppMarketIcon[coi] != null) {
+        if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
             updateAppMarketIcon(sAppMarketIcon[coi]);
         }
         if (mSearchDropTargetBar != null) {
@@ -1148,24 +1153,32 @@
         }
 
         mOverviewPanel = findViewById(R.id.overview_panel);
-        findViewById(R.id.widget_button).setOnClickListener(new OnClickListener() {
+        View widgetButton = findViewById(R.id.widget_button);
+        widgetButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View arg0) {
                 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
             }
         });
-        findViewById(R.id.wallpaper_button).setOnClickListener(new OnClickListener() {
+        widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
+
+        View wallpaperButton = findViewById(R.id.wallpaper_button);
+        wallpaperButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View arg0) {
                 startWallpaper();
             }
         });
-        findViewById(R.id.settings_button).setOnClickListener(new OnClickListener() {
+        wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
+
+        View settingsButton = findViewById(R.id.settings_button);
+        settingsButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View arg0) {
                 startSettings();
             }
         });
+        settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
         mOverviewPanel.setAlpha(0f);
 
         // Setup the workspace
@@ -1530,7 +1543,9 @@
             }
             // When Launcher comes back to foreground, a different Activity might be responsible for
             // the app market intent, so refresh the icon
-            updateAppMarketIcon();
+            if (!DISABLE_MARKET_BUTTON) {
+                updateAppMarketIcon();
+            }
             clearTypedText();
         }
     }
@@ -2272,11 +2287,33 @@
         v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
     }
 
+    public void performHapticFeedbackOnTouchDown(View v) {
+        // Provide the same haptic feedback that the system offers for virtual keys.
+        v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
+    }
+
+    public View.OnTouchListener getHapticFeedbackTouchListener() {
+        if (mHapticFeedbackTouchListener == null) {
+            mHapticFeedbackTouchListener = new View.OnTouchListener() {
+                @Override
+                public boolean onTouch(View v, MotionEvent event) {
+                    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
+                        v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
+                    }
+                    return false;
+                }
+            };
+        }
+        return mHapticFeedbackTouchListener;
+    }
+
     public void onClickAppMarketButton(View v) {
-        if (mAppMarketIntent != null) {
-            startActivitySafely(v, mAppMarketIntent, "app market");
-        } else {
-            Log.e(TAG, "Invalid app market intent.");
+        if (!DISABLE_MARKET_BUTTON) {
+            if (mAppMarketIntent != null) {
+                startActivitySafely(v, mAppMarketIntent, "app market");
+            } else {
+                Log.e(TAG, "Invalid app market intent.");
+            }
         }
     }
 
@@ -3390,35 +3427,39 @@
      * Sets the app market icon
      */
     private void updateAppMarketIcon() {
-        final View marketButton = findViewById(R.id.market_button);
-        Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
-        // Find the app market activity by resolving an intent.
-        // (If multiple app markets are installed, it will return the ResolverActivity.)
-        ComponentName activityName = intent.resolveActivity(getPackageManager());
-        if (activityName != null) {
-            int coi = getCurrentOrientationIndexForGlobalIcons();
-            mAppMarketIntent = intent;
-            sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
-                    R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
-                    TOOLBAR_ICON_METADATA_NAME);
-            marketButton.setVisibility(View.VISIBLE);
-        } else {
-            // We should hide and disable the view so that we don't try and restore the visibility
-            // of it when we swap between drag & normal states from IconDropTarget subclasses.
-            marketButton.setVisibility(View.GONE);
-            marketButton.setEnabled(false);
+        if (!DISABLE_MARKET_BUTTON) {
+            final View marketButton = findViewById(R.id.market_button);
+            Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
+            // Find the app market activity by resolving an intent.
+            // (If multiple app markets are installed, it will return the ResolverActivity.)
+            ComponentName activityName = intent.resolveActivity(getPackageManager());
+            if (activityName != null) {
+                int coi = getCurrentOrientationIndexForGlobalIcons();
+                mAppMarketIntent = intent;
+                sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
+                        R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
+                        TOOLBAR_ICON_METADATA_NAME);
+                marketButton.setVisibility(View.VISIBLE);
+            } else {
+                // We should hide and disable the view so that we don't try and restore the visibility
+                // of it when we swap between drag & normal states from IconDropTarget subclasses.
+                marketButton.setVisibility(View.GONE);
+                marketButton.setEnabled(false);
+            }
         }
     }
 
     private void updateAppMarketIcon(Drawable.ConstantState d) {
-        // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
-        Resources r = getResources();
-        Drawable marketIconDrawable = d.newDrawable(r);
-        int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
-        int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
-        marketIconDrawable.setBounds(0, 0, w, h);
+        if (!DISABLE_MARKET_BUTTON) {
+            // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
+            Resources r = getResources();
+            Drawable marketIconDrawable = d.newDrawable(r);
+            int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
+            int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
+            marketIconDrawable.setBounds(0, 0, w, h);
 
-        updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
+            updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
+        }
     }
 
     @Override
@@ -3840,7 +3881,9 @@
 
         // Update the market app icon as necessary (the other icons will be managed in response to
         // package changes in bindSearchablesChanged()
-        updateAppMarketIcon();
+        if (!DISABLE_MARKET_BUTTON) {
+            updateAppMarketIcon();
+        }
 
         mWorkspaceLoading = false;
         if (upgradePath) {
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 4a8a237..b6900fe 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -48,8 +48,8 @@
 
     private static int sIconWidth = -1;
     private static int sIconHeight = -1;
-    private static int sIconTextureWidth = -1;
-    private static int sIconTextureHeight = -1;
+    public static int sIconTextureWidth = -1;
+    public static int sIconTextureHeight = -1;
 
     private static final Paint sBlurPaint = new Paint();
     private static final Paint sGlowColorPressedPaint = new Paint();