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/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.
      *