Refine and migrate the functions that related to update preference into the specific lifecycle.
Goal: Avoid the screen to be scrolled or moved by itself after changing theme. Bug: 148785841 Test: make RunSettingsRoboTests ROBOTEST_FILTER=ToggleFeaturePreferenceFragment && make RunSettingsRoboTests ROBOTEST_FILTER=ToggleScreenMagnificationPreferenceFragmentTest Change-Id: I35a41a920194d6de01b635ce4c8461df2635ce1a
This commit is contained in:
@@ -144,6 +144,21 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
// Need to be called as early as possible. Protected variables will be assigned here.
|
||||||
|
onProcessArguments(getArguments());
|
||||||
|
|
||||||
|
initAnimatedImagePreference();
|
||||||
|
initToggleServiceDividerSwitchPreference();
|
||||||
|
initGeneralCategory();
|
||||||
|
initShortcutPreference(savedInstanceState);
|
||||||
|
initSettingsPreference();
|
||||||
|
initHtmlTextPreference();
|
||||||
|
initFooterPreference();
|
||||||
|
|
||||||
|
installActionBarToggleSwitch();
|
||||||
|
|
||||||
|
updateToggleServiceTitle(mToggleServiceDividerSwitchPreference);
|
||||||
|
|
||||||
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
|
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
|
||||||
removeDialog(DialogEnums.EDIT_SHORTCUT);
|
removeDialog(DialogEnums.EDIT_SHORTCUT);
|
||||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||||
@@ -158,84 +173,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
final SwitchBar switchBar = activity.getSwitchBar();
|
final SwitchBar switchBar = activity.getSwitchBar();
|
||||||
switchBar.hide();
|
switchBar.hide();
|
||||||
|
|
||||||
// Need to be called as early as possible. Protected variables will be assigned here.
|
|
||||||
onProcessArguments(getArguments());
|
|
||||||
|
|
||||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
|
||||||
if (mImageUri != null) {
|
|
||||||
final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
|
|
||||||
final AnimatedImagePreference animatedImagePreference = new AnimatedImagePreference(
|
|
||||||
getPrefContext());
|
|
||||||
animatedImagePreference.setImageUri(mImageUri);
|
|
||||||
animatedImagePreference.setSelectable(false);
|
|
||||||
animatedImagePreference.setMaxHeight(screenHalfHeight);
|
|
||||||
preferenceScreen.addPreference(animatedImagePreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext());
|
|
||||||
mToggleServiceDividerSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
|
|
||||||
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
|
|
||||||
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
|
|
||||||
mToggleServiceDividerSwitchPreference.setChecked(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
preferenceScreen.addPreference(mToggleServiceDividerSwitchPreference);
|
|
||||||
|
|
||||||
updateToggleServiceTitle(mToggleServiceDividerSwitchPreference);
|
|
||||||
|
|
||||||
final PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
|
||||||
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
|
||||||
groupCategory.setTitle(R.string.accessibility_screen_option);
|
|
||||||
preferenceScreen.addPreference(groupCategory);
|
|
||||||
|
|
||||||
initShortcutPreference(savedInstanceState);
|
|
||||||
groupCategory.addPreference(mShortcutPreference);
|
|
||||||
|
|
||||||
// Show the "Settings" menu as if it were a preference screen.
|
|
||||||
if (mSettingsTitle != null && mSettingsIntent != null) {
|
|
||||||
mSettingsPreference = new Preference(getPrefContext());
|
|
||||||
mSettingsPreference.setTitle(mSettingsTitle);
|
|
||||||
mSettingsPreference.setIconSpaceReserved(true);
|
|
||||||
mSettingsPreference.setIntent(mSettingsIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The downloaded app may not show Settings. The framework app has Settings.
|
|
||||||
if (mSettingsPreference != null) {
|
|
||||||
groupCategory.addPreference(mSettingsPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(mHtmlDescription)) {
|
|
||||||
final PreferenceCategory introductionCategory = new PreferenceCategory(
|
|
||||||
getPrefContext());
|
|
||||||
final CharSequence title = getString(R.string.accessibility_introduction_title,
|
|
||||||
mPackageName);
|
|
||||||
introductionCategory.setKey(KEY_INTRODUCTION_CATEGORY);
|
|
||||||
introductionCategory.setTitle(title);
|
|
||||||
preferenceScreen.addPreference(introductionCategory);
|
|
||||||
|
|
||||||
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(getPrefContext());
|
|
||||||
htmlTextPreference.setSummary(mHtmlDescription);
|
|
||||||
htmlTextPreference.setImageGetter(mImageGetter);
|
|
||||||
htmlTextPreference.setSelectable(false);
|
|
||||||
introductionCategory.addPreference(htmlTextPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(mDescription)) {
|
|
||||||
createFooterPreference(mDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(mHtmlDescription) && TextUtils.isEmpty(mDescription)) {
|
|
||||||
final CharSequence defaultDescription = getText(
|
|
||||||
R.string.accessibility_service_default_description);
|
|
||||||
createFooterPreference(defaultDescription);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
installActionBarToggleSwitch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -444,6 +381,93 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
return drawable;
|
return drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initAnimatedImagePreference() {
|
||||||
|
if (mImageUri == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int screenHalfHeight = getScreenHeightPixels(getPrefContext()) / /* half */ 2;
|
||||||
|
final AnimatedImagePreference animatedImagePreference =
|
||||||
|
new AnimatedImagePreference(getPrefContext());
|
||||||
|
animatedImagePreference.setImageUri(mImageUri);
|
||||||
|
animatedImagePreference.setSelectable(false);
|
||||||
|
animatedImagePreference.setMaxHeight(screenHalfHeight);
|
||||||
|
|
||||||
|
getPreferenceScreen().addPreference(animatedImagePreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initToggleServiceDividerSwitchPreference() {
|
||||||
|
mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext());
|
||||||
|
mToggleServiceDividerSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
|
||||||
|
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||||
|
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
|
||||||
|
mToggleServiceDividerSwitchPreference.setChecked(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPreferenceScreen().addPreference(mToggleServiceDividerSwitchPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initGeneralCategory() {
|
||||||
|
final PreferenceCategory generalCategory = new PreferenceCategory(getPrefContext());
|
||||||
|
generalCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||||
|
generalCategory.setTitle(R.string.accessibility_screen_option);
|
||||||
|
|
||||||
|
getPreferenceScreen().addPreference(generalCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initSettingsPreference() {
|
||||||
|
if (mSettingsTitle == null || mSettingsIntent == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the "Settings" menu as if it were a preference screen.
|
||||||
|
mSettingsPreference = new Preference(getPrefContext());
|
||||||
|
mSettingsPreference.setTitle(mSettingsTitle);
|
||||||
|
mSettingsPreference.setIconSpaceReserved(true);
|
||||||
|
mSettingsPreference.setIntent(mSettingsIntent);
|
||||||
|
|
||||||
|
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
|
||||||
|
generalCategory.addPreference(mSettingsPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initIntroductionCategory() {
|
||||||
|
final PreferenceCategory introductionCategory = new PreferenceCategory(getPrefContext());
|
||||||
|
final CharSequence title =
|
||||||
|
getString(R.string.accessibility_introduction_title, mPackageName);
|
||||||
|
introductionCategory.setKey(KEY_INTRODUCTION_CATEGORY);
|
||||||
|
introductionCategory.setTitle(title);
|
||||||
|
|
||||||
|
getPreferenceScreen().addPreference(introductionCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initHtmlTextPreference() {
|
||||||
|
if (TextUtils.isEmpty(mHtmlDescription)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
initIntroductionCategory();
|
||||||
|
|
||||||
|
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(getPrefContext());
|
||||||
|
htmlTextPreference.setSummary(mHtmlDescription);
|
||||||
|
htmlTextPreference.setImageGetter(mImageGetter);
|
||||||
|
htmlTextPreference.setSelectable(false);
|
||||||
|
|
||||||
|
final PreferenceCategory introductionCategory = findPreference(KEY_INTRODUCTION_CATEGORY);
|
||||||
|
introductionCategory.addPreference(htmlTextPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFooterPreference() {
|
||||||
|
if (!TextUtils.isEmpty(mDescription)) {
|
||||||
|
createFooterPreference(mDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(mHtmlDescription) && TextUtils.isEmpty(mDescription)) {
|
||||||
|
final CharSequence defaultDescription =
|
||||||
|
getText(R.string.accessibility_service_default_description);
|
||||||
|
createFooterPreference(defaultDescription);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static final class AccessibilityUserShortcutType {
|
static final class AccessibilityUserShortcutType {
|
||||||
private static final char COMPONENT_NAME_SEPARATOR = ':';
|
private static final char COMPONENT_NAME_SEPARATOR = ':';
|
||||||
private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
|
private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
|
||||||
@@ -653,7 +677,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initShortcutPreference(Bundle savedInstanceState) {
|
protected void initShortcutPreference(Bundle savedInstanceState) {
|
||||||
// Restore the user shortcut type.
|
// Restore the user shortcut type.
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_SHORTCUT_TYPE)) {
|
||||||
mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
mUserShortcutTypesCache = savedInstanceState.getInt(EXTRA_SHORTCUT_TYPE,
|
||||||
@@ -668,6 +692,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
|
|
||||||
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
|
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
|
||||||
mShortcutPreference.setTitle(title);
|
mShortcutPreference.setTitle(title);
|
||||||
|
|
||||||
|
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
|
||||||
|
generalCategory.addPreference(mShortcutPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateShortcutPreference() {
|
protected void updateShortcutPreference() {
|
||||||
@@ -682,7 +709,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getShortcutPreferenceKey() {
|
protected String getShortcutPreferenceKey() {
|
||||||
return KEY_SHORTCUT_PREFERENCE;
|
return KEY_SHORTCUT_PREFERENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ import android.widget.CheckBox;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -60,7 +61,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
ToggleFeaturePreferenceFragment {
|
ToggleFeaturePreferenceFragment {
|
||||||
|
|
||||||
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
|
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
|
||||||
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
|
|
||||||
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
|
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
|
||||||
private int mUserShortcutType = UserShortcutType.EMPTY;
|
private int mUserShortcutType = UserShortcutType.EMPTY;
|
||||||
private CheckBox mSoftwareTypeCheckBox;
|
private CheckBox mSoftwareTypeCheckBox;
|
||||||
@@ -95,18 +95,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
||||||
initShortcutPreference();
|
|
||||||
|
|
||||||
mSettingsPreference = new Preference(getPrefContext());
|
|
||||||
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
|
|
||||||
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
|
|
||||||
mSettingsPreference.setPersistent(false);
|
|
||||||
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
|
outState.putInt(EXTRA_SHORTCUT_TYPE, mUserShortcutTypesCache);
|
||||||
@@ -120,9 +108,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
final AccessibilityManager am = getPrefContext().getSystemService(
|
final AccessibilityManager am = getPrefContext().getSystemService(
|
||||||
AccessibilityManager.class);
|
AccessibilityManager.class);
|
||||||
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
|
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
|
||||||
|
|
||||||
updateShortcutPreferenceData();
|
|
||||||
updateShortcutPreference();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -162,6 +147,14 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initSettingsPreference() {
|
||||||
|
mSettingsPreference = new Preference(getPrefContext());
|
||||||
|
mSettingsPreference.setTitle(R.string.accessibility_menu_item_settings);
|
||||||
|
mSettingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
|
||||||
|
mSettingsPreference.setPersistent(false);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeDialogCheckBox(AlertDialog dialog) {
|
private void initializeDialogCheckBox(AlertDialog dialog) {
|
||||||
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
||||||
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
||||||
@@ -374,15 +367,19 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initShortcutPreference() {
|
@Override
|
||||||
|
protected void initShortcutPreference(Bundle savedInstanceState) {
|
||||||
mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
|
mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
|
||||||
mShortcutPreference.setPersistent(false);
|
mShortcutPreference.setPersistent(false);
|
||||||
mShortcutPreference.setKey(KEY_SHORTCUT_PREFERENCE);
|
mShortcutPreference.setKey(getShortcutPreferenceKey());
|
||||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||||
mShortcutPreference.setOnClickCallback(this);
|
mShortcutPreference.setOnClickCallback(this);
|
||||||
|
|
||||||
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
|
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
|
||||||
mShortcutPreference.setTitle(title);
|
mShortcutPreference.setTitle(title);
|
||||||
|
|
||||||
|
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
|
||||||
|
generalCategory.addPreference(mShortcutPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user