Remove redundant spaces in ActivityPicker

Bug: 182438726
Test: compile
Change-Id: I8f0440530fcd95cc352dbef7e2bbcc7cdce495b9
This commit is contained in:
Arc Wang
2021-07-05 11:02:49 +08:00
parent e8a80850c1
commit 9e7d132ab8

View File

@@ -57,23 +57,23 @@ import java.util.List;
*/
public class ActivityPicker extends AlertActivity implements
DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
/**
* Adapter of items that are displayed in this dialog.
*/
private PickAdapter mAdapter;
/**
* Base {@link Intent} used when building list.
*/
private Intent mBaseIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
// Read base intent from extras, otherwise assume default
Parcelable parcel = intent.getParcelableExtra(Intent.EXTRA_INTENT);
if (parcel instanceof Intent) {
@@ -91,14 +91,14 @@ public class ActivityPicker extends AlertActivity implements
AlertController.AlertParams params = mAlertParams;
params.mOnClickListener = this;
params.mOnCancelListener = this;
// Use custom title if provided, otherwise default window title
if (intent.hasExtra(Intent.EXTRA_TITLE)) {
params.mTitle = intent.getStringExtra(Intent.EXTRA_TITLE);
} else {
params.mTitle = getTitle();
}
// Build list adapter of pickable items
List<PickAdapter.Item> items = getItems();
mAdapter = new PickAdapter(this, items);
@@ -106,7 +106,7 @@ public class ActivityPicker extends AlertActivity implements
setupAlert();
}
/**
* Handle clicking of dialog item by passing back
* {@link #getIntentForPosition(int)} in {@link #setResult(int, Intent)}.
@@ -116,7 +116,7 @@ public class ActivityPicker extends AlertActivity implements
setResult(Activity.RESULT_OK, intent);
finish();
}
/**
* Handle canceled dialog by passing back {@link Activity#RESULT_CANCELED}.
*/
@@ -144,19 +144,19 @@ public class ActivityPicker extends AlertActivity implements
protected List<PickAdapter.Item> getItems() {
PackageManager packageManager = getPackageManager();
List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>();
// Add any injected pick items
final Intent intent = getIntent();
ArrayList<String> labels =
intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME);
ArrayList<ShortcutIconResource> icons =
intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (labels != null && icons != null && labels.size() == icons.size()) {
for (int i = 0; i < labels.size(); i++) {
String label = labels.get(i);
Drawable icon = null;
try {
// Try loading icon from requested package
ShortcutIconResource iconResource = icons.get(i);
@@ -167,7 +167,7 @@ public class ActivityPicker extends AlertActivity implements
} catch (NameNotFoundException e) {
// Ignore
}
items.add(new PickAdapter.Item(this, label, icon));
}
}
@@ -176,38 +176,38 @@ public class ActivityPicker extends AlertActivity implements
if (mBaseIntent != null) {
putIntentItems(mBaseIntent, items);
}
return items;
}
/**
* Fill the given list with any activities matching the base {@link Intent}.
* Fill the given list with any activities matching the base {@link Intent}.
*/
protected void putIntentItems(Intent baseIntent, List<PickAdapter.Item> items) {
PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(baseIntent,
0 /* no flags */);
Collections.sort(list, new ResolveInfo.DisplayNameComparator(packageManager));
final int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
items.add(new PickAdapter.Item(this, packageManager, resolveInfo));
}
}
/**
* Adapter which shows the set of activities that can be performed for a
* given {@link Intent}.
*/
protected static class PickAdapter extends BaseAdapter {
/**
* Item that appears in a {@link PickAdapter} list.
*/
public static class Item implements AppWidgetLoader.LabelledItem {
protected static IconResizer sResizer;
protected IconResizer getResizer(Context context) {
if (sResizer == null) {
final Resources resources = context.getResources();
@@ -216,13 +216,13 @@ public class ActivityPicker extends AlertActivity implements
}
return sResizer;
}
CharSequence label;
Drawable icon;
String packageName;
String className;
Bundle extras;
/**
* Create a list item from given label and icon.
*/
@@ -271,10 +271,10 @@ public class ActivityPicker extends AlertActivity implements
return label;
}
}
private final LayoutInflater mInflater;
private final List<Item> mItems;
/**
* Create an adapter for the given items.
*/
@@ -311,16 +311,16 @@ public class ActivityPicker extends AlertActivity implements
if (convertView == null) {
convertView = mInflater.inflate(R.layout.pick_item, parent, false);
}
Item item = (Item) getItem(position);
TextView textView = (TextView) convertView;
textView.setText(item.label);
textView.setCompoundDrawablesWithIntrinsicBounds(item.icon, null, null, null);
return convertView;
}
}
/**
* Utility class to resize icons to match default icon size. Code is mostly
* borrowed from Launcher.
@@ -332,14 +332,14 @@ public class ActivityPicker extends AlertActivity implements
private final DisplayMetrics mMetrics;
private final Rect mOldBounds = new Rect();
private final Canvas mCanvas = new Canvas();
public IconResizer(int width, int height, DisplayMetrics metrics) {
mCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
Paint.FILTER_BITMAP_FLAG));
mMetrics = metrics;
mIconWidth = width;
mIconHeight = height;
mIconHeight = height;
}
/**
@@ -352,7 +352,7 @@ public class ActivityPicker extends AlertActivity implements
* @param icon The icon to get a thumbnail of.
*
* @return A thumbnail for the specified icon or the icon itself if the
* thumbnail could not be created.
* thumbnail could not be created.
*/
public Drawable createIconThumbnail(Drawable icon) {
int width = mIconWidth;
@@ -361,7 +361,7 @@ public class ActivityPicker extends AlertActivity implements
if (icon == null) {
return new EmptyDrawable(width, height);
}
try {
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
@@ -377,17 +377,17 @@ public class ActivityPicker extends AlertActivity implements
}
int iconWidth = icon.getIntrinsicWidth();
int iconHeight = icon.getIntrinsicHeight();
if (iconWidth > 0 && iconHeight > 0) {
if (width < iconWidth || height < iconHeight) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
height = (int) (width / ratio);
} else if (iconHeight > iconWidth) {
width = (int) (height * ratio);
}
final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
final Bitmap thumb = Bitmap.createBitmap(mIconWidth, mIconHeight, c);
@@ -425,7 +425,7 @@ public class ActivityPicker extends AlertActivity implements
canvas.setBitmap(null);
}
}
} catch (Throwable t) {
icon = new EmptyDrawable(width, height);
}