Adding switch to toggle Memory Overlay

-> The overlay causes performance regressions so it's hard to evaluate
   performance with it on.
-> Also, the WeightWatcher is still running regardless, so you can
   always check it
-> Saved as a shared pref

Change-Id: Iad5ccbeca2c2b4e0ec86294879f3eb09caa594e9
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 09a94ae..b9f75cf 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -96,6 +96,17 @@
         </activity>
 
         <activity
+            android:name="com.android.launcher3.ToggleWeightWatcher"
+            android:label="@string/toggle_weight_watcher"
+            android:icon="@mipmap/ic_launcher_home">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
             android:name="com.android.launcher3.WallpaperChooser"
             android:theme="@style/Theme.WallpaperPicker"
             android:label="@string/pick_wallpaper"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b57ae74..052e13b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -41,6 +41,8 @@
 
     <string name="widget_adder">Widgets</string>
 
+    <string name="toggle_weight_watcher">Show Mem</string>
+
     <!-- AppsCustomize pane -->
     <!-- Message to tell the user to press and hold on a widget to add it [CHAR_LIMIT=50] -->
     <string name="long_press_widget_to_add">Touch &amp; hold to pick up a widget.</string>
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index bf9773a..2881a91 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -191,6 +191,8 @@
     private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
             "com.android.launcher.toolbar_voice_search_icon";
 
+    public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
+
     /** The different states that Launcher can be in. */
     private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
     private State mState = State.WORKSPACE;
@@ -221,6 +223,7 @@
     private View mLauncherView;
     private DragLayer mDragLayer;
     private DragController mDragController;
+    private View mWeightWatcher;
 
     private AppWidgetManager mAppWidgetManager;
     private LauncherAppWidgetHost mAppWidgetHost;
@@ -1040,14 +1043,17 @@
 
         if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
             Log.v(TAG, "adding WeightWatcher");
-            final View ww = new WeightWatcher(this);
-            ww.setAlpha(0.5f);
-            ((FrameLayout) mLauncherView).addView(ww,
+            mWeightWatcher = new WeightWatcher(this);
+            mWeightWatcher.setAlpha(0.5f);
+            ((FrameLayout) mLauncherView).addView(mWeightWatcher,
                     new FrameLayout.LayoutParams(
                             FrameLayout.LayoutParams.MATCH_PARENT,
                             FrameLayout.LayoutParams.WRAP_CONTENT,
                             Gravity.BOTTOM)
             );
+
+            boolean show = shouldShowWeightWatcher();
+            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
         }
     }
 
@@ -2051,6 +2057,9 @@
                 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
                     MemoryDumpActivity.startDump(this);
                     return;
+                } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
+                    toggleShowWeightWatcher();
+                    return;
                 }
             }
 
@@ -3460,6 +3469,30 @@
         }
     }
 
+    private boolean shouldShowWeightWatcher() {
+        String spKey = LauncherAppState.getSharedPreferencesKey();
+        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
+        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
+
+        return show;
+    }
+
+    private void toggleShowWeightWatcher() {
+        String spKey = LauncherAppState.getSharedPreferencesKey();
+        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
+        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
+
+        show = !show;
+
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
+        editor.commit();
+
+        if (mWeightWatcher != null) {
+            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
+        }
+    }
+
     /**
      * Bind the items start-end from the list.
      *
diff --git a/src/com/android/launcher3/ToggleWeightWatcher.java b/src/com/android/launcher3/ToggleWeightWatcher.java
new file mode 100644
index 0000000..33701a2
--- /dev/null
+++ b/src/com/android/launcher3/ToggleWeightWatcher.java
@@ -0,0 +1,7 @@
+package com.android.launcher3;
+
+import android.app.Activity;
+
+public class ToggleWeightWatcher extends Activity {
+
+}