Add the settings content observer for shortcut preference.
Root cause: Didn't update the UI when settings value chagned. Next: Add the settings content observer. Bug: 155837154 Test: manual test Change-Id: Icee0bb50f88987ea6c8a0be59bd936628a32ca1e
This commit is contained in:
@@ -30,6 +30,7 @@ import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
@@ -96,6 +97,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
private int mUserShortcutTypes = UserShortcutType.EMPTY;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
private SettingsContentObserver mSettingsContentObserver;
|
||||
|
||||
// For html description of accessibility service, must follow the rule, such as
|
||||
// <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
|
||||
@@ -133,6 +135,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
removeDialog(DialogEnums.EDIT_SHORTCUT);
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
};
|
||||
|
||||
final List<String> shortcutFeatureKeys = new ArrayList<>();
|
||||
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
|
||||
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
|
||||
mSettingsContentObserver = new SettingsContentObserver(new Handler(), shortcutFeatureKeys) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
};
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -229,6 +242,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
final AccessibilityManager am = getPrefContext().getSystemService(
|
||||
AccessibilityManager.class);
|
||||
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
|
||||
mSettingsContentObserver.register(getContentResolver());
|
||||
updateShortcutPreferenceData();
|
||||
updateShortcutPreference();
|
||||
}
|
||||
@@ -238,6 +252,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
final AccessibilityManager am = getPrefContext().getSystemService(
|
||||
AccessibilityManager.class);
|
||||
am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
|
||||
mSettingsContentObserver.unregister(getContentResolver());
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -618,7 +633,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
private void updateShortcutPreferenceData() {
|
||||
protected void updateShortcutPreferenceData() {
|
||||
if (mComponentName == null) {
|
||||
return;
|
||||
}
|
||||
@@ -651,7 +666,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
mShortcutPreference.setTitle(title);
|
||||
}
|
||||
|
||||
private void updateShortcutPreference() {
|
||||
protected void updateShortcutPreference() {
|
||||
if (mComponentName == null) {
|
||||
return;
|
||||
}
|
||||
|
@@ -467,7 +467,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
|
||||
}
|
||||
|
||||
private void updateShortcutPreferenceData() {
|
||||
@Override
|
||||
protected void updateShortcutPreferenceData() {
|
||||
// Get the user shortcut type from settings provider.
|
||||
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
|
||||
if (mUserShortcutType != UserShortcutType.EMPTY) {
|
||||
@@ -489,7 +490,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
mShortcutPreference.setTitle(title);
|
||||
}
|
||||
|
||||
private void updateShortcutPreference() {
|
||||
@Override
|
||||
protected void updateShortcutPreference() {
|
||||
final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
mShortcutPreference.setChecked(
|
||||
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
|
||||
|
Reference in New Issue
Block a user