summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/app/ChooserActivity.java21
-rw-r--r--core/java/com/android/internal/app/ResolverActivity.java103
2 files changed, 97 insertions, 27 deletions
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 00c1e2977c03..3b82f186d80e 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -2505,9 +2505,7 @@ public class ChooserActivity extends ResolverActivity {
ri.noResourceId = true;
ri.icon = 0;
}
- ResolveInfoPresentationGetter getter = makePresentationGetter(ri);
- mCallerTargets.add(new DisplayResolveInfo(ii, ri,
- getter.getLabel(), getter.getSubLabel(), ii));
+ mCallerTargets.add(new DisplayResolveInfo(ii, ri, ii));
}
}
}
@@ -2606,7 +2604,22 @@ public class ChooserActivity extends ResolverActivity {
@Override
public void onListRebuilt() {
- updateAlphabeticalList();
+ if (getDisplayList() == null || getDisplayList().isEmpty()) {
+ notifyDataSetChanged();
+ } else {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... voids) {
+ updateAlphabeticalList();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ notifyDataSetChanged();
+ }
+ }.execute();
+ }
// don't support direct share on low ram devices
if (ActivityManager.isLowRamDeviceStatic()) {
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index 7f18ae35b00c..74996e9fc212 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -1406,14 +1406,18 @@ public class ResolverActivity extends Activity {
public final class DisplayResolveInfo implements TargetInfo {
private final ResolveInfo mResolveInfo;
- private final CharSequence mDisplayLabel;
+ private CharSequence mDisplayLabel;
private Drawable mDisplayIcon;
private Drawable mBadge;
- private final CharSequence mExtendedInfo;
+ private CharSequence mExtendedInfo;
private final Intent mResolvedIntent;
private final List<Intent> mSourceIntents = new ArrayList<>();
private boolean mIsSuspended;
+ public DisplayResolveInfo(Intent originalIntent, ResolveInfo pri, Intent pOrigIntent) {
+ this(originalIntent, pri, null /*mDisplayLabel*/, null /*mExtendedInfo*/, pOrigIntent);
+ }
+
public DisplayResolveInfo(Intent originalIntent, ResolveInfo pri, CharSequence pLabel,
CharSequence pInfo, Intent pOrigIntent) {
mSourceIntents.add(originalIntent);
@@ -1448,9 +1452,26 @@ public class ResolverActivity extends Activity {
}
public CharSequence getDisplayLabel() {
+ if (mDisplayLabel == null) {
+ ResolveInfoPresentationGetter pg = makePresentationGetter(mResolveInfo);
+ mDisplayLabel = pg.getLabel();
+ mExtendedInfo = pg.getSubLabel();
+ }
return mDisplayLabel;
}
+ public boolean hasDisplayLabel() {
+ return mDisplayLabel != null;
+ }
+
+ public void setDisplayLabel(CharSequence displayLabel) {
+ mDisplayLabel = displayLabel;
+ }
+
+ public void setExtendedInfo(CharSequence extendedInfo) {
+ mExtendedInfo = extendedInfo;
+ }
+
public Drawable getDisplayIcon() {
return mDisplayIcon;
}
@@ -1866,9 +1887,7 @@ public class ResolverActivity extends Activity {
final ResolveInfo ri = rci.getResolveInfoAt(0);
if (ri != null) {
mAllTargetsAreBrowsers &= ri.handleAllWebDataURI;
-
- ResolveInfoPresentationGetter pg = makePresentationGetter(ri);
- addResolveInfoWithAlternates(rci, pg.getSubLabel(), pg.getLabel());
+ addResolveInfoWithAlternates(rci);
}
}
}
@@ -1915,14 +1934,12 @@ public class ResolverActivity extends Activity {
return mFilterLastUsed;
}
- private void addResolveInfoWithAlternates(ResolvedComponentInfo rci,
- CharSequence extraInfo, CharSequence roLabel) {
+ private void addResolveInfoWithAlternates(ResolvedComponentInfo rci) {
final int count = rci.getCount();
final Intent intent = rci.getIntentAt(0);
final ResolveInfo add = rci.getResolveInfoAt(0);
final Intent replaceIntent = getReplacementIntent(add.activityInfo, intent);
- final DisplayResolveInfo dri = new DisplayResolveInfo(intent, add, roLabel,
- extraInfo, replaceIntent);
+ final DisplayResolveInfo dri = new DisplayResolveInfo(intent, add, replaceIntent);
addResolveInfo(dri);
if (replaceIntent == intent) {
// Only add alternates if we didn't get a specific replacement from
@@ -2054,20 +2071,11 @@ public class ResolverActivity extends Activity {
return;
}
- final CharSequence label = info.getDisplayLabel();
- if (!TextUtils.equals(holder.text.getText(), label)) {
- holder.text.setText(info.getDisplayLabel());
- }
-
- // Always show a subLabel for visual consistency across list items. Show an empty
- // subLabel if the subLabel is the same as the label
- CharSequence subLabel = info.getExtendedInfo();
- if (TextUtils.equals(label, subLabel)) subLabel = null;
-
- if (!TextUtils.equals(holder.text2.getText(), subLabel)
- && !TextUtils.isEmpty(subLabel)) {
- holder.text2.setVisibility(View.VISIBLE);
- holder.text2.setText(subLabel);
+ if (info instanceof DisplayResolveInfo
+ && !((DisplayResolveInfo) info).hasDisplayLabel()) {
+ getLoadLabelTask((DisplayResolveInfo) info, holder).execute();
+ } else {
+ holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo());
}
if (info.isSuspended()) {
@@ -2085,6 +2093,9 @@ public class ResolverActivity extends Activity {
}
}
+ protected LoadLabelTask getLoadLabelTask(DisplayResolveInfo info, ViewHolder holder) {
+ return new LoadLabelTask(info, holder);
+ }
@VisibleForTesting
public static final class ResolvedComponentInfo {
@@ -2148,6 +2159,24 @@ public class ResolverActivity extends Activity {
text2 = (TextView) view.findViewById(com.android.internal.R.id.text2);
icon = (ImageView) view.findViewById(R.id.icon);
}
+
+ public void bindLabel(CharSequence label, CharSequence subLabel) {
+ if (!TextUtils.equals(text.getText(), label)) {
+ text.setText(label);
+ }
+
+ // Always show a subLabel for visual consistency across list items. Show an empty
+ // subLabel if the subLabel is the same as the label
+ if (TextUtils.equals(label, subLabel)) {
+ subLabel = null;
+ }
+
+ if (!TextUtils.equals(text2.getText(), subLabel)
+ && !TextUtils.isEmpty(subLabel)) {
+ text2.setVisibility(View.VISIBLE);
+ text2.setText(subLabel);
+ }
+ }
}
class ItemClickListener implements AdapterView.OnItemClickListener,
@@ -2200,6 +2229,34 @@ public class ResolverActivity extends Activity {
}
+ protected class LoadLabelTask extends AsyncTask<Void, Void, CharSequence[]> {
+ private final DisplayResolveInfo mDisplayResolveInfo;
+ private final ViewHolder mHolder;
+
+ protected LoadLabelTask(DisplayResolveInfo dri, ViewHolder holder) {
+ mDisplayResolveInfo = dri;
+ mHolder = holder;
+ }
+
+
+ @Override
+ protected CharSequence[] doInBackground(Void... voids) {
+ ResolveInfoPresentationGetter pg =
+ makePresentationGetter(mDisplayResolveInfo.mResolveInfo);
+ return new CharSequence[] {
+ pg.getLabel(),
+ pg.getSubLabel()
+ };
+ }
+
+ @Override
+ protected void onPostExecute(CharSequence[] result) {
+ mDisplayResolveInfo.setDisplayLabel(result[0]);
+ mDisplayResolveInfo.setExtendedInfo(result[1]);
+ mHolder.bindLabel(result[0], result[1]);
+ }
+ }
+
class LoadIconTask extends AsyncTask<Void, Void, Drawable> {
protected final DisplayResolveInfo mDisplayResolveInfo;
private final ResolveInfo mResolveInfo;