summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-09-21 20:35:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-09-21 20:35:29 +0000
commite04febbf8ec8326edb095d023e494911381cee66 (patch)
tree5ac674f93f7128f414c4537400c8ef898cbd40a3 /src/com/android/launcher3/util
parent3c9c7263dcd06cba449597104db039a4019e15ff (diff)
parent322d55622031985c75f7e5db07964b7730a97dac (diff)
downloadandroid_packages_apps_Trebuchet-e04febbf8ec8326edb095d023e494911381cee66.tar.gz
android_packages_apps_Trebuchet-e04febbf8ec8326edb095d023e494911381cee66.tar.bz2
android_packages_apps_Trebuchet-e04febbf8ec8326edb095d023e494911381cee66.zip
Merge "Moving a few testing classes to a separate package" into ub-launcher3-master
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r--src/com/android/launcher3/util/TestingUtils.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/com/android/launcher3/util/TestingUtils.java b/src/com/android/launcher3/util/TestingUtils.java
new file mode 100644
index 000000000..39b80463d
--- /dev/null
+++ b/src/com/android/launcher3/util/TestingUtils.java
@@ -0,0 +1,73 @@
+package com.android.launcher3.util;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import com.android.launcher3.CustomAppWidget;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.R;
+
+import java.util.HashMap;
+
+public class TestingUtils {
+
+ public static final String MEMORY_TRACKER = "com.android.launcher3.testing.MemoryTracker";
+ public static final String ACTION_START_TRACKING = "com.android.launcher3.action.START_TRACKING";
+
+ public static final boolean MEMORY_DUMP_ENABLED = false;
+ public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
+
+ public static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
+ public static final String DUMMY_WIDGET = "com.android.launcher3.testing.DummyWidget";
+
+ public static void startTrackingMemory(Context context) {
+ if (MEMORY_DUMP_ENABLED) {
+ context.startService(new Intent()
+ .setComponent(new ComponentName(context.getPackageName(), MEMORY_TRACKER))
+ .setAction(ACTION_START_TRACKING)
+ .putExtra("pid", android.os.Process.myPid())
+ .putExtra("name", "L"));
+ }
+ }
+
+ public static void addWeightWatcher(Launcher launcher) {
+ if (MEMORY_DUMP_ENABLED) {
+ String spKey = LauncherAppState.getSharedPreferencesKey();
+ SharedPreferences sp = launcher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+ boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
+
+ int id = launcher.getResources().getIdentifier("zzz_weight_watcher", "layout",
+ launcher.getPackageName());
+ View watcher = launcher.getLayoutInflater().inflate(id, null);
+ watcher.setAlpha(0.5f);
+ ((FrameLayout) launcher.findViewById(R.id.launcher)).addView(watcher,
+ new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.WRAP_CONTENT,
+ Gravity.BOTTOM)
+ );
+
+ watcher.setVisibility(show ? View.VISIBLE : View.GONE);
+ launcher.mWeightWatcher = watcher;
+ }
+ }
+
+ public static void addDummyWidget(HashMap<String, CustomAppWidget> set) {
+ if (ENABLE_CUSTOM_WIDGET_TEST) {
+ try {
+ Class<?> clazz = Class.forName(DUMMY_WIDGET);
+ CustomAppWidget widget = (CustomAppWidget) clazz.newInstance();
+ set.put(widget.getClass().getName(), widget);
+ } catch (Exception e) {
+ Log.e("TestingUtils", "Error adding dummy widget", e);
+ }
+ }
+ }
+}