From 58c68edb81c736b78590aa592ac2bb229b211246 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sun, 23 Feb 2014 12:47:16 +0100 Subject: [PATCH] catch exception of IntentGenerator.getTitle(...) --- mobile/.idea/misc.xml | 7 ------- .../src/com/cradle/iitc_mobile/share/IntentAdapter.java | 7 ++++++- .../com/cradle/iitc_mobile/share/IntentComparator.java | 9 ++++++--- .../com/cradle/iitc_mobile/share/IntentGenerator.java | 5 ++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mobile/.idea/misc.xml b/mobile/.idea/misc.xml index 062c409c..4742f8a1 100644 --- a/mobile/.idea/misc.xml +++ b/mobile/.idea/misc.xml @@ -3,13 +3,6 @@ - - - diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java b/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java index 3c3cde4a..fe6c26c1 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java @@ -36,7 +36,12 @@ class IntentAdapter extends ArrayAdapter { 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 diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java index 8e0dead9..34b5560f 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java @@ -78,9 +78,12 @@ public class IntentComparator implements Comparator { 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; diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java b/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java index 218ae7a3..8d331712 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java @@ -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"); }