From 3d605d5bbef35e3b8aded44c5ef7fe3948f8f7d5 Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Thu, 29 Jul 2010 13:59:29 -0700 Subject: Make tabs in all apps actually filter the list of apps. --- src/com/android/launcher2/AllApps2D.java | 48 +++++++++++++++++++++----- src/com/android/launcher2/AllAppsList.java | 4 +-- src/com/android/launcher2/AllAppsTabbed.java | 45 +++++++++++++++++++----- src/com/android/launcher2/ApplicationInfo.java | 36 +++++++++++++++---- src/com/android/launcher2/LauncherModel.java | 2 +- 5 files changed, 109 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher2/AllApps2D.java b/src/com/android/launcher2/AllApps2D.java index 7d0970b0a..9764f2338 100644 --- a/src/com/android/launcher2/AllApps2D.java +++ b/src/com/android/launcher2/AllApps2D.java @@ -22,9 +22,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; -import android.graphics.PixelFormat; import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -58,8 +56,16 @@ public class AllApps2D private GridView mGrid; + /** All applications in the system (we might only be showing a subset) */ private ArrayList mAllAppsList = new ArrayList(); + /** Currently visible applications in the grid */ + private ArrayList mVisibleAppsList = new ArrayList(); + + public enum AppType { APP, GAME, DOWNLOADED, ALL }; + + private AppType mCurrentFilter = AppType.ALL; + // preserve compatibility with 3D all apps: // 0.0 -> hidden // 1.0 -> shown and opaque @@ -120,8 +126,7 @@ public class AllApps2D setVisibility(View.GONE); setSoundEffectsEnabled(false); - mAppsAdapter = new AppsAdapter(getContext(), mAllAppsList); - mAppsAdapter.setNotifyOnChange(false); + mAppsAdapter = new AppsAdapter(getContext(), mVisibleAppsList); } @Override @@ -255,11 +260,10 @@ public class AllApps2D public void setApps(ArrayList list) { mAllAppsList.clear(); addApps(list); + filterApps(mCurrentFilter); } public void addApps(ArrayList list) { -// Log.d(TAG, "addApps: " + list.size() + " apps: " + list.toString()); - final int N = list.size(); for (int i=0; i list) { final int N = list.size(); + for (int i=0; i list) { @@ -295,6 +300,33 @@ public class AllApps2D addApps(list); } + public void filterApps(AppType appType) { + mCurrentFilter = appType; + + mAppsAdapter.setNotifyOnChange(false); + mVisibleAppsList.clear(); + if (appType == AppType.ALL) { + mVisibleAppsList.addAll(mAllAppsList); + } else { + int searchFlags = 0; + + if (appType == AppType.APP) { + searchFlags = ApplicationInfo.APP_FLAG; + } else if (appType == AppType.GAME) { + searchFlags = ApplicationInfo.GAME_FLAG; + } else if (appType == AppType.DOWNLOADED) { + searchFlags = ApplicationInfo.DOWNLOADED_FLAG; + } + + for (ApplicationInfo info : mAllAppsList) { + if ((info.flags & searchFlags) != 0) { + mVisibleAppsList.add(info); + } + } + } + mAppsAdapter.notifyDataSetChanged(); + } + private static int findAppByComponent(ArrayList list, ApplicationInfo item) { ComponentName component = item.intent.getComponent(); final int N = list.size(); diff --git a/src/com/android/launcher2/AllAppsList.java b/src/com/android/launcher2/AllAppsList.java index e5d878226..4c9bc5eca 100644 --- a/src/com/android/launcher2/AllAppsList.java +++ b/src/com/android/launcher2/AllAppsList.java @@ -91,7 +91,7 @@ class AllAppsList { if (matches.size() > 0) { for (ResolveInfo info : matches) { - add(new ApplicationInfo(info, mIconCache)); + add(new ApplicationInfo(context.getPackageManager(), info, mIconCache)); } } } @@ -142,7 +142,7 @@ class AllAppsList { info.activityInfo.applicationInfo.packageName, info.activityInfo.name); if (applicationInfo == null) { - add(new ApplicationInfo(info, mIconCache)); + add(new ApplicationInfo(context.getPackageManager(), info, mIconCache)); } else { mIconCache.remove(applicationInfo.componentName); mIconCache.getTitleAndIcon(applicationInfo, info); diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java index 7f6f63f97..20027032c 100644 --- a/src/com/android/launcher2/AllAppsTabbed.java +++ b/src/com/android/launcher2/AllAppsTabbed.java @@ -34,16 +34,23 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { private static final String TAG = "Launcher.AllAppsTabbed"; - private AllAppsView mAllApps2D; + private static final String TAG_ALL = "ALL"; + private static final String TAG_APPS = "APPS"; + private static final String TAG_GAMES = "GAMES"; + private static final String TAG_DOWNLOADED = "DOWNLOADED"; + + private AllApps2D mAllApps2D; + private Context mContext; public AllAppsTabbed(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; } @Override protected void onFinishInflate() { try { - mAllApps2D = (AllAppsView)findViewById(R.id.all_apps_2d); + mAllApps2D = (AllApps2D)findViewById(R.id.all_apps_2d); if (mAllApps2D == null) throw new Resources.NotFoundException(); } catch (Resources.NotFoundException e) { Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); @@ -53,15 +60,36 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { // This lets us share the same view between all tabs TabContentFactory contentFactory = new TabContentFactory() { public View createTabContent(String tag) { - return (View)mAllApps2D; + return mAllApps2D; } }; - // TODO: Make these tabs show the appropriate content (they're no-ops for now) - addTab(newTabSpec("apps").setIndicator("All").setContent(contentFactory)); - addTab(newTabSpec("apps").setIndicator("Apps").setContent(contentFactory)); - addTab(newTabSpec("apps").setIndicator("Games").setContent(contentFactory)); - addTab(newTabSpec("apps").setIndicator("Downloaded").setContent(contentFactory)); + String label = mContext.getString(R.string.all_apps_tab_all); + addTab(newTabSpec(TAG_ALL).setIndicator(label).setContent(contentFactory)); + + label = mContext.getString(R.string.all_apps_tab_apps); + addTab(newTabSpec(TAG_APPS).setIndicator(label).setContent(contentFactory)); + + label = mContext.getString(R.string.all_apps_tab_games); + addTab(newTabSpec(TAG_GAMES).setIndicator(label).setContent(contentFactory)); + + label = mContext.getString(R.string.all_apps_tab_downloaded); + addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(label).setContent(contentFactory)); + + setOnTabChangedListener(new OnTabChangeListener() { + public void onTabChanged(String tabId) { + String tag = getCurrentTabTag(); + if (tag == TAG_ALL) { + mAllApps2D.filterApps(AllApps2D.AppType.ALL); + } else if (tag == TAG_APPS) { + mAllApps2D.filterApps(AllApps2D.AppType.APP); + } else if (tag == TAG_GAMES) { + mAllApps2D.filterApps(AllApps2D.AppType.GAME); + } else if (tag == TAG_DOWNLOADED) { + mAllApps2D.filterApps(AllApps2D.AppType.DOWNLOADED); + } + } + }); setCurrentTab(0); setVisibility(GONE); @@ -125,5 +153,4 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { public void surrender() { mAllApps2D.surrender(); } - } diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java index 7b00f4fb1..6d78a4404 100644 --- a/src/com/android/launcher2/ApplicationInfo.java +++ b/src/com/android/launcher2/ApplicationInfo.java @@ -16,18 +16,21 @@ package com.android.launcher2; -import java.util.ArrayList; - import android.content.ComponentName; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; import android.util.Log; +import java.util.ArrayList; + /** * Represents an app in AllAppsView. */ class ApplicationInfo extends ItemInfo { + private static final String TAG = "Launcher2.ApplicationInfo"; /** * The application name. @@ -51,6 +54,10 @@ class ApplicationInfo extends ItemInfo { ComponentName componentName; + static final int APP_FLAG = 1; + static final int GAME_FLAG = 2; + static final int DOWNLOADED_FLAG = 4; + int flags = 0; ApplicationInfo() { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; @@ -59,15 +66,32 @@ class ApplicationInfo extends ItemInfo { /** * Must not hold the Context. */ - public ApplicationInfo(ResolveInfo info, IconCache iconCache) { - this.componentName = new ComponentName( - info.activityInfo.applicationInfo.packageName, - info.activityInfo.name); + public ApplicationInfo(PackageManager pm, ResolveInfo info, IconCache iconCache) { + final String packageName = info.activityInfo.applicationInfo.packageName; + this.componentName = new ComponentName(packageName, info.activityInfo.name); this.container = ItemInfo.NO_ID; this.setActivity(componentName, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + try { + int appFlags = pm.getApplicationInfo(packageName, 0).flags; + if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { + flags |= DOWNLOADED_FLAG; + } + if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { + flags |= DOWNLOADED_FLAG; + } + // TODO: Figure out how to determine what is a game + + // If it's not a game, it's an app + if ((flags & GAME_FLAG) == 0) { + flags |= APP_FLAG; + } + } catch (NameNotFoundException e) { + Log.d(TAG, "PackageManager.getApplicationInfo failed for " + packageName); + } + iconCache.getTitleAndIcon(this, info); } diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 238fbdfe7..45cef437c 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -1213,7 +1213,7 @@ public class LauncherModel extends BroadcastReceiver { startIndex = i; for (int j=0; i