Skip to content

Commit

Permalink
[iitcm] workaround for Samsung devices
Browse files Browse the repository at this point in the history
  • Loading branch information
fkloft committed Apr 30, 2017
1 parent dfab0d1 commit 0fabfb6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 2 additions & 7 deletions mobile/src/com/cradle/iitc_mobile/share/IntentAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ public View getView(final int position, final View convertView, final ViewGroup

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
Expand Down Expand Up @@ -70,4 +65,4 @@ public void setIntents(final List<Intent> intents) {
addAll(intents);
notifyDataSetChanged();
}
}
}
10 changes: 3 additions & 7 deletions mobile/src/com/cradle/iitc_mobile/share/IntentComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ public int compare(final Intent lhs, final Intent rhs) {
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;

Expand Down Expand Up @@ -197,4 +193,4 @@ public String toString() {
: name);
}
}
}
}
20 changes: 15 additions & 5 deletions mobile/src/com/cradle/iitc_mobile/share/IntentGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 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";
}

throw new IllegalArgumentException("Got an intent not generated by IntentGenerator!\n"
+ "Intent:\n" + intent.toString() + "\n"
+ "Extras:\n" + intent.getExtras().toString());
return title;
}

public static boolean isDefault(final Intent intent) {
Expand Down

0 comments on commit 0fabfb6

Please sign in to comment.