summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-07-17 17:06:20 (GMT)
committerStephen Bird <sbird@cyngn.com>2015-08-14 00:18:54 (GMT)
commite709bdd23575be9c951910ed2bea892f013afcc8 (patch)
treefaf715ff2fe2576135c042e84dfa6961ecbd7439
parent6fcb1c4bd0f44986a214c5714552c854d974a0dc (diff)
downloadandroid_packages_apps_Trebuchet-e709bdd23575be9c951910ed2bea892f013afcc8.zip
android_packages_apps_Trebuchet-e709bdd23575be9c951910ed2bea892f013afcc8.tar.gz
android_packages_apps_Trebuchet-e709bdd23575be9c951910ed2bea892f013afcc8.tar.bz2
Show apps as unavailable when on unmounted storage
This patch allows shortcuts to apps that are currently unavailable due to being on unmounted external storage to remain on the workspace and in folders. The icons will be disabled and grayed out until the external storage is mounted. Conflicts: res/values/cm_strings.xml Ticket: QRDL-991 Change-Id: I971483806b27e3a75ef0d5bb89d8dfb86f97511e
-rw-r--r--res/values/cm_strings.xml3
-rw-r--r--src/com/android/launcher3/Launcher.java40
-rw-r--r--src/com/android/launcher3/LauncherModel.java65
-rw-r--r--src/com/android/launcher3/Workspace.java84
4 files changed, 171 insertions, 21 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 6f1899a..73ac3b1 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -85,4 +85,7 @@
<string name="drawer_type_pager">Paged</string>
<string name="setting_state_disabled">DISABLED</string>
+
+ <!-- App not available toast text -->
+ <string name="app_not_available">App not available</string>
</resources>
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 87a3d24..b7a2c94 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3076,11 +3076,15 @@ public class Launcher extends Activity
final Intent intent;
if (tag instanceof ShortcutInfo) {
shortcut = (ShortcutInfo) tag;
+ if (shortcut.isDisabled) {
+ Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_SHORT).show();
+ return;
+ }
intent = shortcut.intent;
int[] pos = new int[2];
v.getLocationOnScreen(pos);
- intent.setSourceBounds(new Rect(pos[0], pos[1],
- pos[0] + v.getWidth(), pos[1] + v.getHeight()));
+ intent.setSourceBounds(
+ new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()));
} else if (tag instanceof AppInfo) {
shortcut = null;
@@ -5474,6 +5478,38 @@ public class Launcher extends Activity
}
/**
+ * A package has become unavailable.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindComponentsUnavailable(final ArrayList<String> packageNames,
+ final ArrayList<AppInfo> appInfos) {
+ if (!packageNames.isEmpty()) {
+ mWorkspace.updateUnavailableItemsByPackageName(packageNames);
+ }
+ // Notify the drag controller
+ mDragController.onAppsRemoved(packageNames, appInfos);
+
+ // Update AllApps
+ if (!LauncherAppState.isDisableAllApps() &&
+ mAppsCustomizeContent != null) {
+ mAppsCustomizeContent.removeApps(appInfos);
+ mAppDrawerAdapter.removeApps(appInfos);
+ }
+ }
+
+ /**
+ * A package has become unavailable.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindComponentsAvailable(final ArrayList<ItemInfo> itemInfos) {
+ if (!itemInfos.isEmpty()) {
+ mWorkspace.updateAvailableItems(itemInfos);
+ }
+ }
+
+ /**
* A number of packages were updated.
*/
private ArrayList<Object> mWidgetsAndShortcuts;
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index abe96b2..d5672d5 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -209,6 +209,9 @@ public class LauncherModel extends BroadcastReceiver
public void updatePackageBadge(String packageName);
public void bindComponentsRemoved(ArrayList<String> packageNames,
ArrayList<AppInfo> appInfos, UserHandleCompat user);
+ public void bindComponentsUnavailable(ArrayList<String> packageNames,
+ ArrayList<AppInfo> appInfos);
+ public void bindComponentsAvailable(ArrayList<ItemInfo> itemInfos);
public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts);
public void bindSearchablesChanged();
public boolean isAllAppsButtonRank(int rank);
@@ -3299,6 +3302,7 @@ public class LauncherModel extends BroadcastReceiver
final String[] packages = mPackages;
final int N = packages.length;
+ final ArrayList<String> unavailable = new ArrayList<String>();
switch (mOp) {
case OP_ADD:
for (int i=0; i<N; i++) {
@@ -3322,6 +3326,9 @@ public class LauncherModel extends BroadcastReceiver
mBgAllAppsList.removePackage(packages[i], mUser);
WidgetPreviewLoader.removePackageFromDb(
mApp.getWidgetPreviewCacheDb(), packages[i]);
+ if (mOp == OP_UNAVAILABLE) {
+ unavailable.add(packages[i]);
+ }
}
break;
}
@@ -3350,12 +3357,21 @@ public class LauncherModel extends BroadcastReceiver
}
if (added != null) {
+ final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
// Ensure that we add all the workspace applications to the db
if (LauncherAppState.isDisableAllApps()) {
- final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
addAndBindAddedWorkspaceApps(context, addedInfos);
} else {
addAppsToAllApps(context, added);
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == cb && cb != null) {
+ Log.d(TAG, "bindComponentsAvailable: " + addedInfos.size());
+ callbacks.bindComponentsAvailable(addedInfos);
+ }
+ }
+ });
}
}
@@ -3391,6 +3407,32 @@ public class LauncherModel extends BroadcastReceiver
if (mOp == OP_REMOVE) {
// Mark all packages in the broadcast to be removed
removedPackageNames.addAll(Arrays.asList(packages));
+ // Remove all the components associated with this package
+ for (String pn : removedPackageNames) {
+ deletePackageFromDatabase(context, pn, mUser);
+ }
+ // Remove all the specific components
+ for (AppInfo a : removedApps) {
+ ArrayList<ItemInfo> infos = getItemInfoForComponentName(a.componentName, mUser);
+ deleteItemsFromDatabase(context, infos);
+ }
+ if (!removedPackageNames.isEmpty() || !removedApps.isEmpty()) {
+ // Remove any queued items from the install queue
+ String spKey = LauncherAppState.getSharedPreferencesKey();
+ SharedPreferences sp =
+ context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+ InstallShortcutReceiver.removeFromInstallQueue(sp, removedPackageNames);
+ // Call the components-removed callback
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == cb && cb != null) {
+ callbacks.bindComponentsRemoved(removedPackageNames, removedApps,
+ mUser);
+ }
+ }
+ });
+ }
} else if (mOp == OP_UPDATE) {
// Mark disabled packages in the broadcast to be removed
final PackageManager pm = context.getPackageManager();
@@ -3399,28 +3441,13 @@ public class LauncherModel extends BroadcastReceiver
removedPackageNames.add(packages[i]);
}
}
- }
- // Remove all the components associated with this package
- for (String pn : removedPackageNames) {
- deletePackageFromDatabase(context, pn, mUser);
- }
- // Remove all the specific components
- for (AppInfo a : removedApps) {
- ArrayList<ItemInfo> infos = getItemInfoForComponentName(a.componentName, mUser);
- deleteItemsFromDatabase(context, infos);
- }
- if (!removedPackageNames.isEmpty() || !removedApps.isEmpty()) {
- // Remove any queued items from the install queue
- String spKey = LauncherAppState.getSharedPreferencesKey();
- SharedPreferences sp =
- context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
- InstallShortcutReceiver.removeFromInstallQueue(sp, removedPackageNames);
- // Call the components-removed callback
+ } else if (mOp == OP_UNAVAILABLE) {
+ // Call the packages-unavailable callback
mHandler.post(new Runnable() {
public void run() {
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
if (callbacks == cb && cb != null) {
- callbacks.bindComponentsRemoved(removedPackageNames, removedApps, mUser);
+ callbacks.bindComponentsUnavailable(unavailable, removedApps);
}
}
});
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 1cfa685..8e5f868 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -4948,6 +4948,90 @@ public class Workspace extends SmoothPagedView
stripEmptyScreens();
}
+ void updateUnvailableItemsInCellLayout(CellLayout parent, ArrayList<String> packages) {
+ final HashSet<String> packageNames = new HashSet<String>();
+ packageNames.addAll(packages);
+
+ ViewGroup layout = parent.getShortcutsAndWidgets();
+ int childCount = layout.getChildCount();
+ for (int i = 0; i < childCount; ++i) {
+ View view = layout.getChildAt(i);
+ if (view instanceof BubbleTextView) {
+ ItemInfo info = (ItemInfo) view.getTag();
+ if (info instanceof ShortcutInfo) {
+ Intent intent = info.getIntent();
+ ComponentName cn = intent != null ? intent.getComponent() : null;
+ if (cn != null && packageNames.contains(cn.getPackageName())) {
+ ShortcutInfo shortcut = (ShortcutInfo) info;
+ if (!shortcut.isDisabled) {
+ shortcut.isDisabled = true;
+ ((BubbleTextView) view)
+ .applyFromShortcutInfo(shortcut, mIconCache, true);
+ }
+ }
+ }
+ } else if (view instanceof FolderIcon) {
+ final Folder folder = ((FolderIcon)view).getFolder();
+ updateUnvailableItemsInCellLayout(folder.getContent(), packages);
+ folder.invalidate();
+ }
+ }
+ }
+
+ void updateUnavailableItemsByPackageName(final ArrayList<String> packages) {
+ ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
+ for (CellLayout layoutParent : cellLayouts) {
+ updateUnvailableItemsInCellLayout(layoutParent, packages);
+ }
+ }
+
+ /**
+ * Updates shortcuts to an app that was previously unavailable in the given cell layout
+ * @param parent CellLayout to check childen for shortcuts to the available app
+ * @param appInfos List of item infos. Items are assumed to be of type AppInfo
+ */
+ void updateAvailabeItemsInCellLayout(CellLayout parent, final ArrayList<ItemInfo> appInfos) {
+ ViewGroup layout = parent.getShortcutsAndWidgets();
+ int childCount = layout.getChildCount();
+ for (int i = 0; i < childCount; ++i) {
+ View view = layout.getChildAt(i);
+ if (view instanceof BubbleTextView) {
+ ItemInfo info = (ItemInfo) view.getTag();
+ if (info instanceof ShortcutInfo) {
+ Intent intent = info.getIntent();
+ ComponentName cn = intent != null ? intent.getComponent() : null;
+ for (ItemInfo itemInfo : appInfos) {
+ AppInfo appInfo = (AppInfo) itemInfo;
+ if (cn != null && cn.getPackageName().equals(
+ appInfo.componentName.getPackageName())) {
+ ShortcutInfo shortcut = (ShortcutInfo) info;
+ if (shortcut.isDisabled) {
+ shortcut.isDisabled = false;
+ ((BubbleTextView) view)
+ .applyFromShortcutInfo(shortcut, mIconCache, true);
+ }
+ }
+ }
+ }
+ } else if (view instanceof FolderIcon) {
+ final Folder folder = ((FolderIcon)view).getFolder();
+ updateAvailabeItemsInCellLayout(folder.getContent(), appInfos);
+ folder.invalidate();
+ }
+ }
+ }
+
+ /**
+ * Updates shortcuts to an app that was previously unavailable
+ * @param appInfos List of item infos. Items are assumed to be of type AppInfo
+ */
+ void updateAvailableItems(final ArrayList<ItemInfo> appInfos) {
+ ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
+ for (CellLayout layoutParent : cellLayouts) {
+ updateAvailabeItemsInCellLayout(layoutParent, appInfos);
+ }
+ }
+
interface ItemOperator {
/**
* Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}.