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