am 7fa28cdf: am ed60ba1e: Merge "Add a better app filtering mechanism and filter widgets" into jb-ub-now-indigo-rose

* commit '7fa28cdf92a1c4c60686b832ec01e88c94971c61':
  Add a better app filtering mechanism and filter widgets
This commit is contained in:
Bjorn Bringert
2013-10-03 16:26:17 -07:00
committed by Android Git Automerger
7 changed files with 64 additions and 16 deletions
+5
View File
@@ -81,4 +81,9 @@
<!-- Memory debugging, including a memory dump icon --> <!-- Memory debugging, including a memory dump icon -->
<bool name="debug_memory_enabled">false</bool> <bool name="debug_memory_enabled">false</bool>
<!-- Name of a subclass of com.android.launcher3.AppFilter used to
filter the activities shown in the launcher. Can be empty. -->
<string name="app_filter_class" translatable="false"></string>
</resources> </resources>
+8 -2
View File
@@ -46,11 +46,14 @@ class AllAppsList {
private IconCache mIconCache; private IconCache mIconCache;
private AppFilter mAppFilter;
/** /**
* Boring constructor. * Boring constructor.
*/ */
public AllAppsList(IconCache iconCache) { public AllAppsList(IconCache iconCache, AppFilter appFilter) {
mIconCache = iconCache; mIconCache = iconCache;
mAppFilter = appFilter;
} }
/** /**
@@ -60,13 +63,16 @@ class AllAppsList {
* If the app is already in the list, doesn't add it. * If the app is already in the list, doesn't add it.
*/ */
public void add(AppInfo info) { public void add(AppInfo info) {
if (mAppFilter != null && !mAppFilter.shouldShowApp(info.componentName)) {
return;
}
if (findActivity(data, info.componentName)) { if (findActivity(data, info.componentName)) {
return; return;
} }
data.add(info); data.add(info);
added.add(info); added.add(info);
} }
public void clear() { public void clear() {
data.clear(); data.clear();
// TODO: do we clear these too? // TODO: do we clear these too?
+35
View File
@@ -0,0 +1,35 @@
package com.android.launcher3;
import android.content.ComponentName;
import android.text.TextUtils;
import android.util.Log;
public abstract class AppFilter {
private static final boolean DBG = false;
private static final String TAG = "AppFilter";
public abstract boolean shouldShowApp(ComponentName app);
public static AppFilter loadByName(String className) {
if (TextUtils.isEmpty(className)) return null;
if (DBG) Log.d(TAG, "Loading AppFilter: " + className);
try {
Class<?> cls = Class.forName(className);
return (AppFilter) cls.newInstance();
} catch (ClassNotFoundException e) {
Log.e(TAG, "Bad AppFilter class", e);
return null;
} catch (InstantiationException e) {
Log.e(TAG, "Bad AppFilter class", e);
return null;
} catch (IllegalAccessException e) {
Log.e(TAG, "Bad AppFilter class", e);
return null;
} catch (ClassCastException e) {
Log.e(TAG, "Bad AppFilter class", e);
return null;
}
}
}
@@ -438,6 +438,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
for (Object o : widgetsAndShortcuts) { for (Object o : widgetsAndShortcuts) {
if (o instanceof AppWidgetProviderInfo) { if (o instanceof AppWidgetProviderInfo) {
AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o; AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o;
if (!app.shouldShowAppOrWidgetProvider(widget.provider)) {
continue;
}
widget.label = widget.label.trim(); widget.label = widget.label.trim();
if (widget.minWidth > 0 && widget.minHeight > 0) { if (widget.minWidth > 0 && widget.minHeight > 0) {
// Ensure that all widgets we show can be added on a workspace of this size // Ensure that all widgets we show can be added on a workspace of this size
-5
View File
@@ -3937,11 +3937,6 @@ public class Launcher extends Activity
} }
} }
@Override
public boolean shouldShowApp(ResolveInfo app) {
return true;
}
/** /**
* A package was updated. * A package was updated.
* *
@@ -34,6 +34,7 @@ public class LauncherAppState {
private LauncherModel mModel; private LauncherModel mModel;
private IconCache mIconCache; private IconCache mIconCache;
private AppFilter mAppFilter;
private WidgetPreviewLoader.CacheDb mWidgetPreviewCacheDb; private WidgetPreviewLoader.CacheDb mWidgetPreviewCacheDb;
private boolean mIsScreenLarge; private boolean mIsScreenLarge;
private float mScreenDensity; private float mScreenDensity;
@@ -81,7 +82,9 @@ public class LauncherAppState {
mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext); mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext);
mIconCache = new IconCache(sContext); mIconCache = new IconCache(sContext);
mModel = new LauncherModel(this, mIconCache);
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
mModel = new LauncherModel(this, mIconCache, mAppFilter);
// Register intent receivers // Register intent receivers
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
@@ -147,6 +150,10 @@ public class LauncherAppState {
return mModel; return mModel;
} }
boolean shouldShowAppOrWidgetProvider(ComponentName componentName) {
return mAppFilter == null || mAppFilter.shouldShowApp(componentName);
}
WidgetPreviewLoader.CacheDb getWidgetPreviewCacheDb() { WidgetPreviewLoader.CacheDb getWidgetPreviewCacheDb() {
return mWidgetPreviewCacheDb; return mWidgetPreviewCacheDb;
} }
+5 -8
View File
@@ -158,7 +158,6 @@ public class LauncherModel extends BroadcastReceiver {
public void bindFolders(HashMap<Long,FolderInfo> folders); public void bindFolders(HashMap<Long,FolderInfo> folders);
public void finishBindingItems(boolean upgradePath); public void finishBindingItems(boolean upgradePath);
public void bindAppWidget(LauncherAppWidgetInfo info); public void bindAppWidget(LauncherAppWidgetInfo info);
public boolean shouldShowApp(ResolveInfo app);
public void bindAllApplications(ArrayList<AppInfo> apps); public void bindAllApplications(ArrayList<AppInfo> apps);
public void bindAppsAdded(ArrayList<Long> newScreens, public void bindAppsAdded(ArrayList<Long> newScreens,
ArrayList<ItemInfo> addNotAnimated, ArrayList<ItemInfo> addNotAnimated,
@@ -179,12 +178,12 @@ public class LauncherModel extends BroadcastReceiver {
public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn); public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn);
} }
LauncherModel(LauncherAppState app, IconCache iconCache) { LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
final Context context = app.getContext(); final Context context = app.getContext();
mAppsCanBeOnRemoveableStorage = Environment.isExternalStorageRemovable(); mAppsCanBeOnRemoveableStorage = Environment.isExternalStorageRemovable();
mApp = app; mApp = app;
mBgAllAppsList = new AllAppsList(iconCache); mBgAllAppsList = new AllAppsList(iconCache, appFilter);
mIconCache = iconCache; mIconCache = iconCache;
mDefaultIcon = Utilities.createIconBitmap( mDefaultIcon = Utilities.createIconBitmap(
@@ -2397,11 +2396,9 @@ public class LauncherModel extends BroadcastReceiver {
// Create the ApplicationInfos // Create the ApplicationInfos
for (int i = 0; i < apps.size(); i++) { for (int i = 0; i < apps.size(); i++) {
ResolveInfo app = apps.get(i); ResolveInfo app = apps.get(i);
if (oldCallbacks.shouldShowApp(app)) { // This builds the icon bitmaps.
// This builds the icon bitmaps. mBgAllAppsList.add(new AppInfo(packageManager, app,
mBgAllAppsList.add(new AppInfo(packageManager, app, mIconCache, mLabelCache));
mIconCache, mLabelCache));
}
} }
// Huh? Shouldn't this be inside the Runnable below? // Huh? Shouldn't this be inside the Runnable below?