Merge "Have WebView Implementation Dev Setting use DefaultAppPickerFragment."

This commit is contained in:
Gustav Sennton
2017-02-09 17:36:32 +00:00
committed by Android (Google) Code Review
15 changed files with 365 additions and 512 deletions

View File

@@ -91,6 +91,11 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
addPreferencesFromResource(R.xml.app_picker_prefs);
updateCandidates();
}
@VisibleForTesting
public void updateCandidates() {
mCandidates.clear();
final List<DefaultAppInfo> candidateList = getCandidates();
if (candidateList != null) {
@@ -123,6 +128,10 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
pref.setSummary(R.string.system_app);
}
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
pref.setEnabled(false);
pref.setSummary(app.getValue().disabledDescription);
}
pref.setOnClickListener(this);
screen.addPreference(pref);
}
@@ -146,18 +155,23 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
private void onRadioButtonConfirmed(String selectedKey) {
final boolean success = setDefaultAppKey(selectedKey);
if (success) {
final PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
final int count = screen.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference pref = screen.getPreference(i);
if (pref instanceof RadioButtonPreference) {
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
final boolean newCheckedState =
TextUtils.equals(pref.getKey(), selectedKey);
if (radioPref.isChecked() != newCheckedState) {
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
}
updateCheckedState(selectedKey);
}
onSelectionPerformed(success);
}
@VisibleForTesting
public void updateCheckedState(String selectedKey) {
final PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
final int count = screen.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference pref = screen.getPreference(i);
if (pref instanceof RadioButtonPreference) {
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
final boolean newCheckedState = TextUtils.equals(pref.getKey(), selectedKey);
if (radioPref.isChecked() != newCheckedState) {
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
}
}
}
@@ -190,6 +204,9 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
protected abstract boolean setDefaultAppKey(String key);
// Called after the user tries to select an item.
protected void onSelectionPerformed(boolean success) {}
protected String getConfirmationMessage(DefaultAppInfo appInfo) {
return null;
}