From 0fabfb68943fc833153d89454220fa638a8b9fb6 Mon Sep 17 00:00:00 2001 From: fkloft Date: Sun, 30 Apr 2017 14:29:19 +0200 Subject: [PATCH] [iitcm] workaround for Samsung devices --- .../iitc_mobile/share/IntentAdapter.java | 9 ++------- .../iitc_mobile/share/IntentComparator.java | 10 +++------- .../iitc_mobile/share/IntentGenerator.java | 20 ++++++++++++++----- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java b/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java index fe6c26c1..4361a2a1 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java @@ -36,12 +36,7 @@ class IntentAdapter extends ArrayAdapter { final Intent item = getItem(position); - try { - view.setText(IntentGenerator.getTitle(item)); - } catch (IllegalArgumentException e) { - view.setText("unknown"); - Log.w(e); - } + view.setText(IntentGenerator.getTitle(item)); view.setCompoundDrawablePadding((int) getContext().getResources().getDimension(R.dimen.icon_margin)); // get icon and scale it manually to ensure that all have the same size @@ -70,4 +65,4 @@ class IntentAdapter extends ArrayAdapter { addAll(intents); notifyDataSetChanged(); } -} \ No newline at end of file +} diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java index 34b5560f..533c27a6 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java @@ -78,12 +78,8 @@ public class IntentComparator implements Comparator { if (lCount < rCount) return 1; // still no order. fall back to alphabetical order - try { - order = IntentGenerator.getTitle(lhs).compareTo(IntentGenerator.getTitle(rhs)); - if (order != 0) return order; - } catch(IllegalArgumentException e) { - Log.w(e); - } + order = IntentGenerator.getTitle(lhs).compareTo(IntentGenerator.getTitle(rhs)); + if (order != 0) return order; order = lComponent.getPackageName().compareTo(rComponent.getPackageName()); if (order != 0) return order; @@ -197,4 +193,4 @@ public class IntentComparator implements Comparator { : name); } } -} \ No newline at end of file +} diff --git a/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java b/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java index c62b0c18..c9de0f03 100644 --- a/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java +++ b/mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java @@ -36,12 +36,22 @@ public class IntentGenerator { } } - public static String getTitle(final Intent intent) throws IllegalArgumentException { - if (intent.hasExtra(EXTRA_FLAG_TITLE)) return intent.getStringExtra(EXTRA_FLAG_TITLE); + public static String getTitle(final Intent intent) { + String title = ""; + if (intent.hasExtra(EXTRA_FLAG_TITLE)) + title = intent.getStringExtra(EXTRA_FLAG_TITLE); - throw new IllegalArgumentException("Got an intent not generated by IntentGenerator!\n" - + "Intent:\n" + intent.toString() + "\n" - + "Extras:\n" + intent.getExtras().toString()); + // Samsung WiFi Direct Sharing seems to not provide a title. + // Not directly reproducible without having a Samsung device. + + if (title == null || "".equals(title)) { + Log.w("Intent has no title!\n" + + "Intent:\n" + intent.toUri(Intent.URI_INTENT_SCHEME) + "\n" + + "Extras:\n" + intent.getExtras().toString()); + return "unknown"; + } + + return title; } public static boolean isDefault(final Intent intent) {