Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Optimizations for ResolverActivity
Browse files Browse the repository at this point in the history
Load app icons using AsyncTask instead of during list item binding.

Make sorting resolved components by display name case insensitive.

Change-Id: I8e69781ed021035b9f0dac349791b3d8a674cf60
  • Loading branch information
adamp committed May 30, 2013
1 parent 579c00e commit 0256c6f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
5 changes: 3 additions & 2 deletions core/java/android/content/pm/ResolveInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ public static class DisplayNameComparator
implements Comparator<ResolveInfo> {
public DisplayNameComparator(PackageManager pm) {
mPM = pm;
mCollator.setStrength(Collator.PRIMARY);
}

public final int compare(ResolveInfo a, ResolveInfo b) {
Expand All @@ -336,10 +337,10 @@ public final int compare(ResolveInfo a, ResolveInfo b) {
CharSequence sb = b.loadLabel(mPM);
if (sb == null) sb = b.activityInfo.name;

return sCollator.compare(sa.toString(), sb.toString());
return mCollator.compare(sa.toString(), sb.toString());
}

private final Collator sCollator = Collator.getInstance();
private final Collator mCollator = Collator.getInstance();
private PackageManager mPM;
}
}
51 changes: 40 additions & 11 deletions core/java/com/android/internal/app/ResolverActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.android.internal.app;

import android.os.AsyncTask;
import com.android.internal.R;
import com.android.internal.content.PackageMonitor;

Expand Down Expand Up @@ -621,9 +622,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
view = mInflater.inflate(
com.android.internal.R.layout.resolve_list_item, parent, false);

final ViewHolder holder = new ViewHolder(view);
view.setTag(holder);

// Fix the icon size even if we have different sized resources
ImageView icon = (ImageView)view.findViewById(R.id.icon);
ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) icon.getLayoutParams();
ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();
lp.width = lp.height = mIconSize;
} else {
view = convertView;
Expand All @@ -633,20 +636,30 @@ public View getView(int position, View convertView, ViewGroup parent) {
}

private final void bindView(View view, DisplayResolveInfo info) {
TextView text = (TextView)view.findViewById(com.android.internal.R.id.text1);
TextView text2 = (TextView)view.findViewById(com.android.internal.R.id.text2);
ImageView icon = (ImageView)view.findViewById(R.id.icon);
text.setText(info.displayLabel);
final ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(info.displayLabel);
if (mShowExtended) {
text2.setVisibility(View.VISIBLE);
text2.setText(info.extendedInfo);
holder.text2.setVisibility(View.VISIBLE);
holder.text2.setText(info.extendedInfo);
} else {
text2.setVisibility(View.GONE);
holder.text2.setVisibility(View.GONE);
}
if (info.displayIcon == null) {
info.displayIcon = loadIconForResolveInfo(info.ri);
new LoadIconTask().execute(info);
}
icon.setImageDrawable(info.displayIcon);
holder.icon.setImageDrawable(info.displayIcon);
}
}

static class ViewHolder {
public TextView text;
public TextView text2;
public ImageView icon;

public ViewHolder(View view) {
text = (TextView) view.findViewById(com.android.internal.R.id.text1);
text2 = (TextView) view.findViewById(com.android.internal.R.id.text2);
icon = (ImageView) view.findViewById(R.id.icon);
}
}

Expand All @@ -660,5 +673,21 @@ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, l
}

}

class LoadIconTask extends AsyncTask<DisplayResolveInfo, Void, DisplayResolveInfo> {
@Override
protected DisplayResolveInfo doInBackground(DisplayResolveInfo... params) {
final DisplayResolveInfo info = params[0];
if (info.displayIcon == null) {
info.displayIcon = loadIconForResolveInfo(info.ri);
}
return info;
}

@Override
protected void onPostExecute(DisplayResolveInfo info) {
mAdapter.notifyDataSetChanged();
}
}
}

0 comments on commit 0256c6f

Please sign in to comment.