Merge "Add the settings content observer for shortcut preference." into rvc-dev am: a85f5dc80b am: 99f1a37582 am: a0953560f8 am: 7fcf167362

Change-Id: I7df7b79bc75d61130bf45bdf3763c10d8933115f
This commit is contained in:
PETER LIANG
2020-05-12 12:34:47 +00:00
committed by Automerger Merge Worker
2 changed files with 21 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.text.Html; import android.text.Html;
@@ -96,6 +97,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private int mUserShortcutTypes = UserShortcutType.EMPTY; private int mUserShortcutTypes = UserShortcutType.EMPTY;
private CheckBox mSoftwareTypeCheckBox; private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox; private CheckBox mHardwareTypeCheckBox;
private SettingsContentObserver mSettingsContentObserver;
// For html description of accessibility service, must follow the rule, such as // For html description of accessibility service, must follow the rule, such as
// <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully. // <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); removeDialog(DialogEnums.EDIT_SHORTCUT);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext())); 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); return super.onCreateView(inflater, container, savedInstanceState);
} }
@@ -229,6 +242,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final AccessibilityManager am = getPrefContext().getSystemService( final AccessibilityManager am = getPrefContext().getSystemService(
AccessibilityManager.class); AccessibilityManager.class);
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener); am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
mSettingsContentObserver.register(getContentResolver());
updateShortcutPreferenceData(); updateShortcutPreferenceData();
updateShortcutPreference(); updateShortcutPreference();
} }
@@ -238,6 +252,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final AccessibilityManager am = getPrefContext().getSystemService( final AccessibilityManager am = getPrefContext().getSystemService(
AccessibilityManager.class); AccessibilityManager.class);
am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener); am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
mSettingsContentObserver.unregister(getContentResolver());
super.onPause(); super.onPause();
} }
@@ -618,7 +633,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
getShortcutTypeSummary(getPrefContext())); getShortcutTypeSummary(getPrefContext()));
} }
private void updateShortcutPreferenceData() { protected void updateShortcutPreferenceData() {
if (mComponentName == null) { if (mComponentName == null) {
return; return;
} }
@@ -651,7 +666,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
mShortcutPreference.setTitle(title); mShortcutPreference.setTitle(title);
} }
private void updateShortcutPreference() { protected void updateShortcutPreference() {
if (mComponentName == null) { if (mComponentName == null) {
return; return;
} }

View File

@@ -472,7 +472,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT); showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
} }
private void updateShortcutPreferenceData() { @Override
protected void updateShortcutPreferenceData() {
// Get the user shortcut type from settings provider. // Get the user shortcut type from settings provider.
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext()); mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
if (mUserShortcutType != UserShortcutType.EMPTY) { if (mUserShortcutType != UserShortcutType.EMPTY) {
@@ -494,7 +495,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mShortcutPreference.setTitle(title); mShortcutPreference.setTitle(title);
} }
private void updateShortcutPreference() { @Override
protected void updateShortcutPreference() {
final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE); final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
mShortcutPreference.setChecked( mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes)); hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));