catch exception of IntentGenerator.getTitle(...)
This commit is contained in:
@ -36,7 +36,12 @@ class IntentAdapter extends ArrayAdapter<Intent> {
|
||||
|
||||
final Intent item = getItem(position);
|
||||
|
||||
view.setText(IntentGenerator.getTitle(item));
|
||||
try {
|
||||
view.setText(IntentGenerator.getTitle(item));
|
||||
} catch (IllegalArgumentException e) {
|
||||
view.setText("unknown");
|
||||
Log.w(e);
|
||||
}
|
||||
view.setCompoundDrawablePadding((int) getContext().getResources().getDimension(R.dimen.icon_margin));
|
||||
|
||||
// get icon and scale it manually to ensure that all have the same size
|
||||
|
@ -78,9 +78,12 @@ public class IntentComparator implements Comparator<Intent> {
|
||||
if (lCount < rCount) return 1;
|
||||
|
||||
// still no order. fall back to alphabetical order
|
||||
order = IntentGenerator.getTitle(lhs).compareTo(IntentGenerator.getTitle(rhs));
|
||||
if (order != 0) return order;
|
||||
|
||||
try {
|
||||
order = IntentGenerator.getTitle(lhs).compareTo(IntentGenerator.getTitle(rhs));
|
||||
if (order != 0) return order;
|
||||
} catch(IllegalArgumentException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
order = lComponent.getPackageName().compareTo(rComponent.getPackageName());
|
||||
if (order != 0) return order;
|
||||
|
||||
|
@ -34,9 +34,8 @@ public class IntentGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTitle(final Intent intent) {
|
||||
if (intent.hasExtra(EXTRA_FLAG_TITLE))
|
||||
return intent.getStringExtra(EXTRA_FLAG_TITLE);
|
||||
public static String getTitle(final Intent intent) throws IllegalArgumentException {
|
||||
if (intent.hasExtra(EXTRA_FLAG_TITLE)) return intent.getStringExtra(EXTRA_FLAG_TITLE);
|
||||
|
||||
throw new IllegalArgumentException("Got an intent not generated by IntentGenerator");
|
||||
}
|
||||
|
Reference in New Issue
Block a user