summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-03-01 17:30:53 -0800
committerDianne Hackborn <hackbod@google.com>2012-03-01 19:14:36 -0800
commite8f2c7ff5abe339061f1823362e12b912c430c1a (patch)
tree82e7ab4f3c9a800272fad83c20e356065f840e44
parentee329930956c88d3c2cbcbb6da01abde4b40b2e8 (diff)
downloadframeworks_base-e8f2c7ff5abe339061f1823362e12b912c430c1a.zip
frameworks_base-e8f2c7ff5abe339061f1823362e12b912c430c1a.tar.gz
frameworks_base-e8f2c7ff5abe339061f1823362e12b912c430c1a.tar.bz2
Make ResolverActivity update dynamically.
Watches for package changes so it can dynamically adjust to reflect the actual list of available activities. Change-Id: I3a2fef3dac4d13d1b2a7ed6fc117a7b814679669
-rw-r--r--core/java/com/android/internal/app/ResolverActivity.java72
1 files changed, 57 insertions, 15 deletions
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index 3fba1be..0563846 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -17,6 +17,8 @@
package com.android.internal.app;
import com.android.internal.R;
+import com.android.internal.content.PackageMonitor;
+
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -58,6 +60,12 @@ public class ResolverActivity extends AlertActivity implements
private TextView mClearDefaultHint;
private PackageManager mPm;
+ private final PackageMonitor mPackageMonitor = new PackageMonitor() {
+ @Override public void onSomePackagesChanged() {
+ mAdapter.handlePackagesChanged();
+ }
+ };
+
private Intent makeMyIntent() {
Intent intent = new Intent(getIntent());
// The resolver activity is set to be hidden from recent tasks.
@@ -88,6 +96,8 @@ public class ResolverActivity extends AlertActivity implements
ap.mTitle = title;
ap.mOnClickListener = this;
+ mPackageMonitor.register(this, false);
+
if (alwaysUseOption) {
LayoutInflater inflater = (LayoutInflater) getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
@@ -114,6 +124,19 @@ public class ResolverActivity extends AlertActivity implements
setupAlert();
}
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ mPackageMonitor.register(this, false);
+ mAdapter.handlePackagesChanged();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mPackageMonitor.unregister();
+ }
+
public void onClick(DialogInterface dialog, int which) {
ResolveInfo ri = mAdapter.resolveInfoForPosition(which);
Intent intent = mAdapter.intentForPosition(which);
@@ -225,29 +248,48 @@ public class ResolverActivity extends AlertActivity implements
}
private final class ResolveListAdapter extends BaseAdapter {
+ private final Intent[] mInitialIntents;
+ private final List<ResolveInfo> mBaseResolveList;
private final Intent mIntent;
private final LayoutInflater mInflater;
+ private List<ResolveInfo> mCurrentResolveList;
private List<DisplayResolveInfo> mList;
public ResolveListAdapter(Context context, Intent intent,
Intent[] initialIntents, List<ResolveInfo> rList) {
mIntent = new Intent(intent);
mIntent.setComponent(null);
+ mInitialIntents = initialIntents;
+ mBaseResolveList = rList;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ rebuildList();
+ }
- if (rList == null) {
- rList = mPm.queryIntentActivities(
- intent, PackageManager.MATCH_DEFAULT_ONLY
+ public void handlePackagesChanged() {
+ rebuildList();
+ notifyDataSetChanged();
+ if (mList.size() <= 0) {
+ // We no longer have any items... just finish the activity.
+ finish();
+ }
+ }
+
+ private void rebuildList() {
+ if (mBaseResolveList != null) {
+ mCurrentResolveList = mBaseResolveList;
+ } else {
+ mCurrentResolveList = mPm.queryIntentActivities(
+ mIntent, PackageManager.MATCH_DEFAULT_ONLY
| (mAlwaysCheck != null ? PackageManager.GET_RESOLVED_FILTER : 0));
}
int N;
- if ((rList != null) && ((N = rList.size()) > 0)) {
+ if ((mCurrentResolveList != null) && ((N = mCurrentResolveList.size()) > 0)) {
// Only display the first matches that are either of equal
// priority or have asked to be default options.
- ResolveInfo r0 = rList.get(0);
+ ResolveInfo r0 = mCurrentResolveList.get(0);
for (int i=1; i<N; i++) {
- ResolveInfo ri = rList.get(i);
+ ResolveInfo ri = mCurrentResolveList.get(i);
if (false) Log.v(
"ResolveListActivity",
r0.activityInfo.name + "=" +
@@ -257,7 +299,7 @@ public class ResolverActivity extends AlertActivity implements
if (r0.priority != ri.priority ||
r0.isDefault != ri.isDefault) {
while (i < N) {
- rList.remove(i);
+ mCurrentResolveList.remove(i);
N--;
}
}
@@ -265,15 +307,15 @@ public class ResolverActivity extends AlertActivity implements
if (N > 1) {
ResolveInfo.DisplayNameComparator rComparator =
new ResolveInfo.DisplayNameComparator(mPm);
- Collections.sort(rList, rComparator);
+ Collections.sort(mCurrentResolveList, rComparator);
}
mList = new ArrayList<DisplayResolveInfo>();
// First put the initial items at the top.
- if (initialIntents != null) {
- for (int i=0; i<initialIntents.length; i++) {
- Intent ii = initialIntents[i];
+ if (mInitialIntents != null) {
+ for (int i=0; i<mInitialIntents.length; i++) {
+ Intent ii = mInitialIntents[i];
if (ii == null) {
continue;
}
@@ -300,14 +342,14 @@ public class ResolverActivity extends AlertActivity implements
// Check for applications with same name and use application name or
// package name if necessary
- r0 = rList.get(0);
+ r0 = mCurrentResolveList.get(0);
int start = 0;
CharSequence r0Label = r0.loadLabel(mPm);
for (int i = 1; i < N; i++) {
if (r0Label == null) {
r0Label = r0.activityInfo.packageName;
}
- ResolveInfo ri = rList.get(i);
+ ResolveInfo ri = mCurrentResolveList.get(i);
CharSequence riLabel = ri.loadLabel(mPm);
if (riLabel == null) {
riLabel = ri.activityInfo.packageName;
@@ -315,13 +357,13 @@ public class ResolverActivity extends AlertActivity implements
if (riLabel.equals(r0Label)) {
continue;
}
- processGroup(rList, start, (i-1), r0, r0Label);
+ processGroup(mCurrentResolveList, start, (i-1), r0, r0Label);
r0 = ri;
r0Label = riLabel;
start = i;
}
// Process last group
- processGroup(rList, start, (N-1), r0, r0Label);
+ processGroup(mCurrentResolveList, start, (N-1), r0, r0Label);
}
}