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.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class IntentBuilderView extends FrameLayout implements View.OnClickListener,
|
public class IntentBuilderView extends FrameLayout implements View.OnClickListener,
|
||||||
CompoundButton.OnCheckedChangeListener {
|
CompoundButton.OnCheckedChangeListener {
|
||||||
|
private static final String TAG = "IntentBuilderView";
|
||||||
protected final int TAG_FLAG = R.id.tag_flag;
|
protected final int TAG_FLAG = R.id.tag_flag;
|
||||||
protected final int TAG_SUGGESTED = R.id.tag_suggested;
|
protected final int TAG_SUGGESTED = R.id.tag_suggested;
|
||||||
protected ComponentName mActivityToLaunch;
|
protected ComponentName mActivityToLaunch;
|
||||||
@@ -241,12 +243,22 @@ public class IntentBuilderView extends FrameLayout implements View.OnClickListen
|
|||||||
clearSuggestions();
|
clearSuggestions();
|
||||||
List<String> suggestions = flag.getComplements().stream().map(IntentFlag::getName)
|
List<String> suggestions = flag.getComplements().stream().map(IntentFlag::getName)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
getAllCheckBoxes().stream().filter(box ->
|
getAllCheckBoxes().stream()
|
||||||
suggestions.contains(((IntentFlag) box.getTag(TAG_FLAG)).getName()))
|
.filter(box -> hasSuggestion(suggestions, box))
|
||||||
.forEach(box -> {
|
.forEach(box -> {
|
||||||
box.setButtonTintList(mSuggestTint);
|
box.setButtonTintList(mSuggestTint);
|
||||||
box.setTag(TAG_SUGGESTED, true);
|
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() {
|
private void clearSuggestions() {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ enum IntentFlag {
|
|||||||
NEW_TASK ("FLAG_ACTIVITY_NEW_TASK", emptySet(), emptySet(), emptySet()),
|
NEW_TASK ("FLAG_ACTIVITY_NEW_TASK", emptySet(), emptySet(), emptySet()),
|
||||||
CLEAR_TASK ("FLAG_ACTIVITY_CLEAR_TASK", emptySet(), emptySet(), setOf(NEW_TASK)),
|
CLEAR_TASK ("FLAG_ACTIVITY_CLEAR_TASK", emptySet(), emptySet(), setOf(NEW_TASK)),
|
||||||
CLEAR_TOP ("FLAG_ACTIVITY_CLEAR_TOP", setOf(SINGLE_TOP, NEW_TASK), emptySet(), emptySet()),
|
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)),
|
MULTIPLE_TASK ("FLAG_ACTIVITY_MULTIPLE_TASK", emptySet(), emptySet(), setOf(NEW_TASK)),
|
||||||
NEW_DOCUMENT ("FLAG_ACTIVITY_NEW_DOCUMENT", setOf(MULTIPLE_TASK), emptySet(),
|
NEW_DOCUMENT ("FLAG_ACTIVITY_NEW_DOCUMENT", setOf(MULTIPLE_TASK), emptySet(),
|
||||||
emptySet()),
|
emptySet()),
|
||||||
|
|||||||
Reference in New Issue
Block a user