Merge "Load icons and labels only once" into tm-qpr-dev
This commit is contained in:
@@ -86,7 +86,6 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
private final ChooserActivityLogger mChooserActivityLogger;
|
private final ChooserActivityLogger mChooserActivityLogger;
|
||||||
|
|
||||||
private int mNumShortcutResults = 0;
|
private int mNumShortcutResults = 0;
|
||||||
private Map<DisplayResolveInfo, LoadIconTask> mIconLoaders = new HashMap<>();
|
|
||||||
private boolean mApplySharingAppLimits;
|
private boolean mApplySharingAppLimits;
|
||||||
|
|
||||||
// Reserve spots for incoming direct share targets by adding placeholders
|
// Reserve spots for incoming direct share targets by adding placeholders
|
||||||
@@ -265,31 +264,20 @@ public class ChooserListAdapter extends ResolverListAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(info instanceof DisplayResolveInfo)) {
|
holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo(), alwaysShowSubLabel());
|
||||||
holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo(), alwaysShowSubLabel());
|
holder.bindIcon(info);
|
||||||
holder.bindIcon(info);
|
if (info instanceof SelectableTargetInfo) {
|
||||||
|
// direct share targets should append the application name for a better readout
|
||||||
if (info instanceof SelectableTargetInfo) {
|
DisplayResolveInfo rInfo = ((SelectableTargetInfo) info).getDisplayResolveInfo();
|
||||||
// direct share targets should append the application name for a better readout
|
CharSequence appName = rInfo != null ? rInfo.getDisplayLabel() : "";
|
||||||
DisplayResolveInfo rInfo = ((SelectableTargetInfo) info).getDisplayResolveInfo();
|
CharSequence extendedInfo = info.getExtendedInfo();
|
||||||
CharSequence appName = rInfo != null ? rInfo.getDisplayLabel() : "";
|
String contentDescription = String.join(" ", info.getDisplayLabel(),
|
||||||
CharSequence extendedInfo = info.getExtendedInfo();
|
extendedInfo != null ? extendedInfo : "", appName);
|
||||||
String contentDescription = String.join(" ", info.getDisplayLabel(),
|
holder.updateContentDescription(contentDescription);
|
||||||
extendedInfo != null ? extendedInfo : "", appName);
|
} else if (info instanceof DisplayResolveInfo) {
|
||||||
holder.updateContentDescription(contentDescription);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DisplayResolveInfo dri = (DisplayResolveInfo) info;
|
DisplayResolveInfo dri = (DisplayResolveInfo) info;
|
||||||
holder.bindLabel(dri.getDisplayLabel(), dri.getExtendedInfo(), alwaysShowSubLabel());
|
if (!dri.hasDisplayIcon()) {
|
||||||
LoadIconTask task = mIconLoaders.get(dri);
|
loadIcon(dri);
|
||||||
if (task == null) {
|
|
||||||
task = new LoadIconTask(dri, holder);
|
|
||||||
mIconLoaders.put(dri, task);
|
|
||||||
task.execute();
|
|
||||||
} else {
|
|
||||||
// The holder was potentially changed as the underlying items were
|
|
||||||
// reshuffled, so reset the target holder
|
|
||||||
task.setViewHolder(holder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import android.content.pm.UserInfo;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Insets;
|
import android.graphics.Insets;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -1475,14 +1476,21 @@ public class ResolverActivity extends Activity implements
|
|||||||
mMultiProfilePagerAdapter.getActiveListAdapter().mDisplayList.get(0);
|
mMultiProfilePagerAdapter.getActiveListAdapter().mDisplayList.get(0);
|
||||||
boolean inWorkProfile = getCurrentProfile() == PROFILE_WORK;
|
boolean inWorkProfile = getCurrentProfile() == PROFILE_WORK;
|
||||||
|
|
||||||
ResolverListAdapter inactiveAdapter = mMultiProfilePagerAdapter.getInactiveListAdapter();
|
final ResolverListAdapter inactiveAdapter =
|
||||||
DisplayResolveInfo otherProfileResolveInfo = inactiveAdapter.mDisplayList.get(0);
|
mMultiProfilePagerAdapter.getInactiveListAdapter();
|
||||||
|
final DisplayResolveInfo otherProfileResolveInfo = inactiveAdapter.mDisplayList.get(0);
|
||||||
|
|
||||||
// Load the icon asynchronously
|
// Load the icon asynchronously
|
||||||
ImageView icon = findViewById(R.id.icon);
|
ImageView icon = findViewById(R.id.icon);
|
||||||
ResolverListAdapter.LoadIconTask iconTask = inactiveAdapter.new LoadIconTask(
|
inactiveAdapter.new LoadIconTask(otherProfileResolveInfo) {
|
||||||
otherProfileResolveInfo, new ResolverListAdapter.ViewHolder(icon));
|
@Override
|
||||||
iconTask.execute();
|
protected void onPostExecute(Drawable drawable) {
|
||||||
|
if (!isDestroyed()) {
|
||||||
|
otherProfileResolveInfo.setDisplayIcon(drawable);
|
||||||
|
new ResolverListAdapter.ViewHolder(icon).bindIcon(otherProfileResolveInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
|
||||||
((TextView) findViewById(R.id.open_cross_profile)).setText(
|
((TextView) findViewById(R.id.open_cross_profile)).setText(
|
||||||
getResources().getString(
|
getResources().getString(
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ import com.android.internal.app.chooser.DisplayResolveInfo;
|
|||||||
import com.android.internal.app.chooser.TargetInfo;
|
import com.android.internal.app.chooser.TargetInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ResolverListAdapter extends BaseAdapter {
|
public class ResolverListAdapter extends BaseAdapter {
|
||||||
private static final String TAG = "ResolverListAdapter";
|
private static final String TAG = "ResolverListAdapter";
|
||||||
@@ -87,6 +90,8 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
private Runnable mPostListReadyRunnable;
|
private Runnable mPostListReadyRunnable;
|
||||||
private final boolean mIsAudioCaptureDevice;
|
private final boolean mIsAudioCaptureDevice;
|
||||||
private boolean mIsTabLoaded;
|
private boolean mIsTabLoaded;
|
||||||
|
private final Map<DisplayResolveInfo, LoadIconTask> mIconLoaders = new HashMap<>();
|
||||||
|
private final Map<DisplayResolveInfo, LoadLabelTask> mLabelLoaders = new HashMap<>();
|
||||||
|
|
||||||
public ResolverListAdapter(Context context, List<Intent> payloadIntents,
|
public ResolverListAdapter(Context context, List<Intent> payloadIntents,
|
||||||
Intent[] initialIntents, List<ResolveInfo> rList,
|
Intent[] initialIntents, List<ResolveInfo> rList,
|
||||||
@@ -636,26 +641,47 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
if (info == null) {
|
if (info == null) {
|
||||||
holder.icon.setImageDrawable(
|
holder.icon.setImageDrawable(
|
||||||
mContext.getDrawable(R.drawable.resolver_icon_placeholder));
|
mContext.getDrawable(R.drawable.resolver_icon_placeholder));
|
||||||
|
holder.bindLabel("", "", false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info instanceof DisplayResolveInfo
|
if (info instanceof DisplayResolveInfo) {
|
||||||
&& !((DisplayResolveInfo) info).hasDisplayLabel()) {
|
DisplayResolveInfo dri = (DisplayResolveInfo) info;
|
||||||
getLoadLabelTask((DisplayResolveInfo) info, holder).execute();
|
boolean hasLabel = dri.hasDisplayLabel();
|
||||||
} else {
|
holder.bindLabel(
|
||||||
holder.bindLabel(info.getDisplayLabel(), info.getExtendedInfo(), alwaysShowSubLabel());
|
dri.getDisplayLabel(),
|
||||||
}
|
dri.getExtendedInfo(),
|
||||||
|
hasLabel && alwaysShowSubLabel());
|
||||||
if (info instanceof DisplayResolveInfo
|
|
||||||
&& !((DisplayResolveInfo) info).hasDisplayIcon()) {
|
|
||||||
new LoadIconTask((DisplayResolveInfo) info, holder).execute();
|
|
||||||
} else {
|
|
||||||
holder.bindIcon(info);
|
holder.bindIcon(info);
|
||||||
|
if (!hasLabel) {
|
||||||
|
loadLabel(dri);
|
||||||
|
}
|
||||||
|
if (!dri.hasDisplayIcon()) {
|
||||||
|
loadIcon(dri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LoadLabelTask getLoadLabelTask(DisplayResolveInfo info, ViewHolder holder) {
|
protected final void loadIcon(DisplayResolveInfo info) {
|
||||||
return new LoadLabelTask(info, holder);
|
LoadIconTask task = mIconLoaders.get(info);
|
||||||
|
if (task == null) {
|
||||||
|
task = new LoadIconTask((DisplayResolveInfo) info);
|
||||||
|
mIconLoaders.put(info, task);
|
||||||
|
task.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLabel(DisplayResolveInfo info) {
|
||||||
|
LoadLabelTask task = mLabelLoaders.get(info);
|
||||||
|
if (task == null) {
|
||||||
|
task = createLoadLabelTask(info);
|
||||||
|
mLabelLoaders.put(info, task);
|
||||||
|
task.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected LoadLabelTask createLoadLabelTask(DisplayResolveInfo info) {
|
||||||
|
return new LoadLabelTask(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
@@ -666,6 +692,16 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
if (mResolverListController != null) {
|
if (mResolverListController != null) {
|
||||||
mResolverListController.destroy();
|
mResolverListController.destroy();
|
||||||
}
|
}
|
||||||
|
cancelTasks(mIconLoaders.values());
|
||||||
|
cancelTasks(mLabelLoaders.values());
|
||||||
|
mIconLoaders.clear();
|
||||||
|
mLabelLoaders.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends AsyncTask> void cancelTasks(Collection<T> tasks) {
|
||||||
|
for (T task: tasks) {
|
||||||
|
task.cancel(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ColorMatrixColorFilter getSuspendedColorMatrix() {
|
private static ColorMatrixColorFilter getSuspendedColorMatrix() {
|
||||||
@@ -883,11 +919,9 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
protected class LoadLabelTask extends AsyncTask<Void, Void, CharSequence[]> {
|
protected class LoadLabelTask extends AsyncTask<Void, Void, CharSequence[]> {
|
||||||
private final DisplayResolveInfo mDisplayResolveInfo;
|
private final DisplayResolveInfo mDisplayResolveInfo;
|
||||||
private final ViewHolder mHolder;
|
|
||||||
|
|
||||||
protected LoadLabelTask(DisplayResolveInfo dri, ViewHolder holder) {
|
protected LoadLabelTask(DisplayResolveInfo dri) {
|
||||||
mDisplayResolveInfo = dri;
|
mDisplayResolveInfo = dri;
|
||||||
mHolder = holder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -925,21 +959,22 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(CharSequence[] result) {
|
protected void onPostExecute(CharSequence[] result) {
|
||||||
|
if (mDisplayResolveInfo.hasDisplayLabel()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mDisplayResolveInfo.setDisplayLabel(result[0]);
|
mDisplayResolveInfo.setDisplayLabel(result[0]);
|
||||||
mDisplayResolveInfo.setExtendedInfo(result[1]);
|
mDisplayResolveInfo.setExtendedInfo(result[1]);
|
||||||
mHolder.bindLabel(result[0], result[1], alwaysShowSubLabel());
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadIconTask extends AsyncTask<Void, Void, Drawable> {
|
class LoadIconTask extends AsyncTask<Void, Void, Drawable> {
|
||||||
protected final DisplayResolveInfo mDisplayResolveInfo;
|
protected final DisplayResolveInfo mDisplayResolveInfo;
|
||||||
private final ResolveInfo mResolveInfo;
|
private final ResolveInfo mResolveInfo;
|
||||||
private ViewHolder mHolder;
|
|
||||||
|
|
||||||
LoadIconTask(DisplayResolveInfo dri, ViewHolder holder) {
|
LoadIconTask(DisplayResolveInfo dri) {
|
||||||
mDisplayResolveInfo = dri;
|
mDisplayResolveInfo = dri;
|
||||||
mResolveInfo = dri.getResolveInfo();
|
mResolveInfo = dri.getResolveInfo();
|
||||||
mHolder = holder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -953,17 +988,9 @@ public class ResolverListAdapter extends BaseAdapter {
|
|||||||
mResolverListCommunicator.updateProfileViewButton();
|
mResolverListCommunicator.updateProfileViewButton();
|
||||||
} else if (!mDisplayResolveInfo.hasDisplayIcon()) {
|
} else if (!mDisplayResolveInfo.hasDisplayIcon()) {
|
||||||
mDisplayResolveInfo.setDisplayIcon(d);
|
mDisplayResolveInfo.setDisplayIcon(d);
|
||||||
mHolder.bindIcon(mDisplayResolveInfo);
|
|
||||||
// Notify in case view is already bound to resolve the race conditions on
|
|
||||||
// low end devices
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setViewHolder(ViewHolder holder) {
|
|
||||||
mHolder = holder;
|
|
||||||
mHolder.bindIcon(mDisplayResolveInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,14 +46,14 @@ public class ResolverWrapperAdapter extends ResolverListAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LoadLabelTask getLoadLabelTask(DisplayResolveInfo info, ViewHolder holder) {
|
protected LoadLabelTask createLoadLabelTask(DisplayResolveInfo info) {
|
||||||
return new LoadLabelWrapperTask(info, holder);
|
return new LoadLabelWrapperTask(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadLabelWrapperTask extends LoadLabelTask {
|
class LoadLabelWrapperTask extends LoadLabelTask {
|
||||||
|
|
||||||
protected LoadLabelWrapperTask(DisplayResolveInfo dri, ViewHolder holder) {
|
protected LoadLabelWrapperTask(DisplayResolveInfo dri) {
|
||||||
super(dri, holder);
|
super(dri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user