summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/AppsCustomizePagedView.java
diff options
context:
space:
mode:
authorFlamefire <alex@grundis.de>2014-04-01 11:40:55 +0200
committerFlamefire <alex@grundis.de>2014-04-22 19:40:20 +0200
commit6a43e660cce2cda206f4fecf3ed4ecf9dce8f326 (patch)
tree49ec4b23b7065fa18aa730a38afb952b8f13fe71 /src/com/android/launcher3/AppsCustomizePagedView.java
parent16310323d9c820ae98691fc5f0c459cb18524ca6 (diff)
downloadandroid_packages_apps_Trebuchet-6a43e660cce2cda206f4fecf3ed4ecf9dce8f326.tar.gz
android_packages_apps_Trebuchet-6a43e660cce2cda206f4fecf3ed4ecf9dce8f326.tar.bz2
android_packages_apps_Trebuchet-6a43e660cce2cda206f4fecf3ed4ecf9dce8f326.zip
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
Diffstat (limited to 'src/com/android/launcher3/AppsCustomizePagedView.java')
-rw-r--r--src/com/android/launcher3/AppsCustomizePagedView.java150
1 files changed, 136 insertions, 14 deletions
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<AppInfo> mApps;
private ArrayList<Object> mWidgets;
+ private ArrayList<AppInfo> mFilteredApps;
+ private ArrayList<Object> mFilteredWidgets;
+ private ArrayList<ComponentName> mHiddenApps;
+ private ArrayList<String> 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<AppInfo>();
+ mFilteredApps = new ArrayList<AppInfo>();
mWidgets = new ArrayList<Object>();
+ mFilteredWidgets = new ArrayList<Object>();
mIconCache = (LauncherAppState.getInstance()).getIconCache();
mCanvas = new Canvas();
mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>();
@@ -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<ComponentName>(flattened.length);
+ mHiddenPackages = new ArrayList<String>(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<Object> items = new ArrayList<Object>();
ArrayList<Bitmap> images = new ArrayList<Bitmap>();
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<AppInfo> list) {
if (!DISABLE_ALL_APPS) {
mApps = list;
- Collections.sort(mApps, getComparatorForSortMode());
+ filterAppsWithoutInvalidate();
updatePageCountsAndInvalidateData();
}
}
+
private void addAppsWithoutInvalidate(ArrayList<AppInfo> 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<AppInfo> list) {
if (!DISABLE_ALL_APPS) {
addAppsWithoutInvalidate(list);
+ filterAppsWithoutInvalidate();
updatePageCountsAndInvalidateData();
}
}
+
private int findAppByComponent(List<AppInfo> 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<AppInfo> 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<AppInfo> appInfos) {
if (!DISABLE_ALL_APPS) {
removeAppsWithoutInvalidate(appInfos);
+ filterAppsWithoutInvalidate();
updatePageCountsAndInvalidateData();
}
}
+
public void updateApps(ArrayList<AppInfo> 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<AppInfo>(mApps);
+ Iterator<AppInfo> 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<Object>(mWidgets);
+
+ Iterator<Object> 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;