From 6a43e660cce2cda206f4fecf3ed4ecf9dce8f326 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Tue, 1 Apr 2014 11:40:55 +0200 Subject: Re-Add hidden-apps setting Forward port from CM 10.2 PS3: Don't rename and incorporate changes from Devkota PS4: Update German translation PS5: Remove translations PS7: Hide widgets from widget list PS9: Remove debug output PS11: Rebase Change-Id: Ie06b288e22c2678fb09da1bf42d46922b8319e01 --- .../android/launcher3/AppsCustomizePagedView.java | 150 +++++++++++++++++++-- 1 file changed, 136 insertions(+), 14 deletions(-) (limited to 'src/com/android/launcher3/AppsCustomizePagedView.java') diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index 28bc4e477..0cc540436 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -27,6 +27,7 @@ import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.content.res.TypedArray; @@ -175,6 +176,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } private SortMode mSortMode = SortMode.Title; + private int mFilterApps = FILTER_APPS_SYSTEM_FLAG | FILTER_APPS_DOWNLOADED_FLAG; + + private static final int FILTER_APPS_SYSTEM_FLAG = 1; + private static final int FILTER_APPS_DOWNLOADED_FLAG = 2; + // Refs private Launcher mLauncher; private DragController mDragController; @@ -189,6 +195,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private ArrayList mApps; private ArrayList mWidgets; + private ArrayList mFilteredApps; + private ArrayList mFilteredWidgets; + private ArrayList mHiddenApps; + private ArrayList mHiddenPackages; + // Cling private boolean mHasShownAllAppsCling; private int mClingFocusedX; @@ -279,7 +290,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mLayoutInflater = LayoutInflater.from(context); mPackageManager = context.getPackageManager(); mApps = new ArrayList(); + mFilteredApps = new ArrayList(); mWidgets = new ArrayList(); + mFilteredWidgets = new ArrayList(); mIconCache = (LauncherAppState.getInstance()).getIconCache(); mCanvas = new Canvas(); mRunningTasks = new ArrayList(); @@ -309,6 +322,18 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); } + + String[] flattened = SettingsProvider.getStringCustomDefault(context, + SettingsProvider.SETTINGS_UI_DRAWER_HIDDEN_APPS, "").split("\\|"); + mHiddenApps = new ArrayList(flattened.length); + mHiddenPackages = new ArrayList(flattened.length); + for (String flat : flattened) { + ComponentName cmp = ComponentName.unflattenFromString(flat); + if (cmp != null) { + mHiddenApps.add(cmp); + mHiddenPackages.add(cmp.getPackageName()); + } + } } @Override @@ -351,7 +376,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen i = (currentPage * numItemsPerPage) + (childCount / 2); } } else if (mContentType == ContentType.Widgets) { - int numApps = mApps.size(); + int numApps = mFilteredApps.size(); PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage); int numItemsPerPage = mWidgetCountX * mWidgetCountY; int childCount = layout.getChildCount(); @@ -379,12 +404,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int getPageForComponent(int index) { if (index < 0) return 0; - if (index < mApps.size()) { + if (index < mFilteredApps.size()) { int numItemsPerPage = mCellCountX * mCellCountY; return (index / numItemsPerPage); } else { int numItemsPerPage = mWidgetCountX * mWidgetCountY; - return (index - mApps.size()) / numItemsPerPage; + return (index - mFilteredApps.size()) / numItemsPerPage; } } @@ -395,9 +420,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } private void updatePageCounts() { - mNumWidgetPages = (int) Math.ceil(mWidgets.size() / - (float) (mWidgetCountX * mWidgetCountY)); - mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + mNumWidgetPages = (int) Math.ceil((float) mFilteredWidgets.size() + / (mWidgetCountX * mWidgetCountY)); + mNumAppsPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)); } protected void onDataReady(int width, int height) { @@ -462,7 +487,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); if (!isDataReady()) { - if ((DISABLE_ALL_APPS || !mApps.isEmpty()) && !mWidgets.isEmpty()) { + if ((DISABLE_ALL_APPS || !mFilteredApps.isEmpty()) && !mFilteredWidgets.isEmpty()) { setDataIsReady(); setMeasuredDimension(width, height); onDataReady(width, height); @@ -507,7 +532,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgets.add(o); } } - updatePageCountsAndInvalidateData(); + filterWidgets(); } public void setBulkBind(boolean bulkBind) { @@ -1083,14 +1108,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen final boolean isRtl = isLayoutRtl(); int numCells = mCellCountX * mCellCountY; int startIndex = page * numCells; - int endIndex = Math.min(startIndex + numCells, mApps.size()); + int endIndex = Math.min(startIndex + numCells, mFilteredApps.size()); AppsCustomizeCellLayout layout = (AppsCustomizeCellLayout) getPageAt(page); layout.removeAllViewsOnPage(); ArrayList items = new ArrayList(); ArrayList images = new ArrayList(); for (int i = startIndex; i < endIndex; ++i) { - AppInfo info = mApps.get(i); + AppInfo info = mFilteredApps.get(i); PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate( R.layout.apps_customize_application, layout, false); icon.applyFromApplicationInfo(info, true, this); @@ -1239,8 +1264,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen // Prepare the set of widgets to load previews for in the background int offset = page * numItemsPerPage; - for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { - items.add(mWidgets.get(i)); + for (int i = offset; i < Math.min(offset + numItemsPerPage, mFilteredWidgets.size()); ++i) { + items.add(mFilteredWidgets.get(i)); } // Prepopulate the pages with the other widget info, and fill in the previews later @@ -1865,7 +1890,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mSortMode = sortMode; - Collections.sort(mApps, getComparatorForSortMode()); + Collections.sort(mFilteredApps, getComparatorForSortMode()); if (mContentType == ContentType.Applications) { for (int i = 0; i < getChildCount(); i++) { @@ -1903,13 +1928,40 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } + public void setShowSystemApps(boolean show) { + if (show) { + mFilterApps |= FILTER_APPS_SYSTEM_FLAG; + } else { + mFilterApps &= ~FILTER_APPS_SYSTEM_FLAG; + } + filterApps(); + } + + public void setShowDownloadedApps(boolean show) { + if (show) { + mFilterApps |= FILTER_APPS_DOWNLOADED_FLAG; + } else { + mFilterApps &= ~FILTER_APPS_DOWNLOADED_FLAG; + } + filterApps(); + } + + public boolean getShowSystemApps() { + return (mFilterApps & FILTER_APPS_SYSTEM_FLAG) != 0; + } + + public boolean getShowDownloadedApps() { + return (mFilterApps & FILTER_APPS_DOWNLOADED_FLAG) != 0; + } + public void setApps(ArrayList list) { if (!DISABLE_ALL_APPS) { mApps = list; - Collections.sort(mApps, getComparatorForSortMode()); + filterAppsWithoutInvalidate(); updatePageCountsAndInvalidateData(); } } + private void addAppsWithoutInvalidate(ArrayList list) { // We add it in place, in alphabetical order int count = list.size(); @@ -1921,12 +1973,15 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } } + public void addApps(ArrayList list) { if (!DISABLE_ALL_APPS) { addAppsWithoutInvalidate(list); + filterAppsWithoutInvalidate(); updatePageCountsAndInvalidateData(); } } + private int findAppByComponent(List list, AppInfo item) { ComponentName removeComponent = item.intent.getComponent(); int length = list.size(); @@ -1938,6 +1993,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } return -1; } + private void removeAppsWithoutInvalidate(ArrayList list) { // loop through all the apps and remove apps that have the same component int length = list.size(); @@ -1949,12 +2005,15 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } } + public void removeApps(ArrayList appInfos) { if (!DISABLE_ALL_APPS) { removeAppsWithoutInvalidate(appInfos); + filterAppsWithoutInvalidate(); updatePageCountsAndInvalidateData(); } } + public void updateApps(ArrayList list) { // We remove and re-add the updated applications list because it's properties may have // changed (ie. the title), and this will ensure that the items will be in their proper @@ -1962,10 +2021,73 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen if (!DISABLE_ALL_APPS) { removeAppsWithoutInvalidate(list); addAppsWithoutInvalidate(list); + filterAppsWithoutInvalidate(); updatePageCountsAndInvalidateData(); } } + public void filterAppsWithoutInvalidate() { + mFilteredApps = new ArrayList(mApps); + Iterator iterator = mFilteredApps.iterator(); + while (iterator.hasNext()) { + AppInfo appInfo = iterator.next(); + boolean system = (appInfo.flags & AppInfo.DOWNLOADED_FLAG) == 0; + if (mHiddenApps.contains(appInfo.componentName) || + (system && !getShowSystemApps()) || + (!system && !getShowDownloadedApps())) { + iterator.remove(); + } + } + Collections.sort(mFilteredApps, getComparatorForSortMode()); + } + + public void filterApps() { + filterAppsWithoutInvalidate(); + updatePageCountsAndInvalidateData(); + } + + public void filterWidgetsWithoutInvalidate() { + mFilteredWidgets = new ArrayList(mWidgets); + + Iterator iterator = mFilteredWidgets.iterator(); + while (iterator.hasNext()) { + Object o = iterator.next(); + + String packageName; + if (o instanceof AppWidgetProviderInfo) { + AppWidgetProviderInfo widgetInfo = (AppWidgetProviderInfo) o; + if (widgetInfo.provider == null) { + continue; + } + packageName = widgetInfo.provider.getPackageName(); + } else if (o instanceof ResolveInfo) { + ResolveInfo shortcut = (ResolveInfo) o; + packageName = shortcut.activityInfo.applicationInfo.packageName; + } else { + Log.w(TAG, "Unknown class in widgets list: " + o.getClass()); + continue; + } + + int flags; + try { + flags = AppInfo.initFlags(mPackageManager.getPackageInfo(packageName, 0)); + } catch (NameNotFoundException e) { + flags = 0; + } + boolean system = (flags & AppInfo.DOWNLOADED_FLAG) == 0; + if (mHiddenPackages.contains(packageName) || + (system && !getShowSystemApps()) || + (!system && !getShowDownloadedApps())) { + iterator.remove(); + } + } + } + + public void filterWidgets() { + filterWidgetsWithoutInvalidate(); + updatePageCountsAndInvalidateData(); + } + public void reset() { // If we have reset, then we should not continue to restore the previous state mSaveInstanceStateItemIndex = -1; -- cgit v1.2.3