Update IntentFlags to include MATCH_EXTERNAL
MATCH_EXTERNAL was introduced in api level 28, which was after the initial version of this application. This caused a bug for suggestions which assumed the enumeration was total. This also includes a defensive check + log warning for unkown flags. Test: Build and Run Change-Id: I153985b5fd576baf80545b4737648745b421f11e
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class IntentBuilderView extends FrameLayout implements View.OnClickListener,
|
||||
CompoundButton.OnCheckedChangeListener {
|
||||
private static final String TAG = "IntentBuilderView";
|
||||
protected final int TAG_FLAG = R.id.tag_flag;
|
||||
protected final int TAG_SUGGESTED = R.id.tag_suggested;
|
||||
protected ComponentName mActivityToLaunch;
|
||||
@@ -241,14 +243,24 @@ public class IntentBuilderView extends FrameLayout implements View.OnClickListen
|
||||
clearSuggestions();
|
||||
List<String> suggestions = flag.getComplements().stream().map(IntentFlag::getName)
|
||||
.collect(Collectors.toList());
|
||||
getAllCheckBoxes().stream().filter(box ->
|
||||
suggestions.contains(((IntentFlag) box.getTag(TAG_FLAG)).getName()))
|
||||
getAllCheckBoxes().stream()
|
||||
.filter(box -> hasSuggestion(suggestions, box))
|
||||
.forEach(box -> {
|
||||
box.setButtonTintList(mSuggestTint);
|
||||
box.setTag(TAG_SUGGESTED, true);
|
||||
});
|
||||
}
|
||||
|
||||
private boolean hasSuggestion(List<String> suggestions, CheckBox box) {
|
||||
IntentFlag flag = (IntentFlag) box.getTag(TAG_FLAG);
|
||||
if (flag != null) {
|
||||
return suggestions.contains(flag.getName());
|
||||
} else {
|
||||
Log.w(TAG, "Unknown flag: " + box.getText());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void clearSuggestions() {
|
||||
getAllCheckBoxes().forEach(box -> box.setButtonTintList(mDefaultTint));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ enum IntentFlag {
|
||||
NEW_TASK ("FLAG_ACTIVITY_NEW_TASK", emptySet(), emptySet(), emptySet()),
|
||||
CLEAR_TASK ("FLAG_ACTIVITY_CLEAR_TASK", emptySet(), emptySet(), setOf(NEW_TASK)),
|
||||
CLEAR_TOP ("FLAG_ACTIVITY_CLEAR_TOP", setOf(SINGLE_TOP, NEW_TASK), emptySet(), emptySet()),
|
||||
MATCH_EXTERNAL("FLAG_ACTIVITY_MATCH_EXTERNAL", emptySet(), emptySet(), emptySet()),
|
||||
MULTIPLE_TASK ("FLAG_ACTIVITY_MULTIPLE_TASK", emptySet(), emptySet(), setOf(NEW_TASK)),
|
||||
NEW_DOCUMENT ("FLAG_ACTIVITY_NEW_DOCUMENT", setOf(MULTIPLE_TASK), emptySet(),
|
||||
emptySet()),
|
||||
|
||||
Reference in New Issue
Block a user