diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-05-15 17:34:14 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2014-05-15 17:44:26 -0700 |
commit | 6220275d6dec8ffc6f1df2cbfbf42934d09d41f0 (patch) | |
tree | ba632c7b6defa71c15f7901ae3134bc94c2553d4 /src/com/android/settings/accessibility | |
parent | 5160536df91bb9daa6cac9a878ce406deda791c6 (diff) | |
download | packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.tar.gz packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.tar.bz2 packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.zip |
Use SwitchBar for Accessibility Settings
Deals with Talkback / Captions / Magnification Gestures
- follow up CL to 41937766981423c9252e12e3319b2e7532739627
Related to bug #14898161 On/Off switches must move down from Action Bar
Change-Id: Ibda0ed05b399f1b2b4464c5b22a3e9fd3d378867
Diffstat (limited to 'src/com/android/settings/accessibility')
7 files changed, 68 insertions, 76 deletions
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index 43306f2d8..5dcf121eb 100644 --- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java +++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java @@ -16,7 +16,6 @@ package com.android.settings.accessibility; -import android.app.ActionBar; import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; @@ -28,7 +27,6 @@ import android.preference.PreferenceCategory; import android.preference.PreferenceFrameLayout; import android.preference.Preference.OnPreferenceChangeListener; import android.provider.Settings; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,8 +36,10 @@ import android.view.accessibility.CaptioningManager.CaptionStyle; import com.android.internal.widget.SubtitleView; import com.android.settings.R; +import com.android.settings.SettingsActivity; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener; +import com.android.settings.widget.SwitchBar; import com.android.settings.widget.ToggleSwitch; import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener; @@ -69,6 +69,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment private CaptioningManager mCaptioningManager; private SubtitleView mPreviewText; private View mPreviewWindow; + private SwitchBar mSwitchBar; private ToggleSwitch mToggleSwitch; // Standard options. @@ -129,14 +130,9 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); - final Context context = getActivity().getActionBar().getThemedContext(); - final int padding = context.getResources().getDimensionPixelSize( - R.dimen.action_bar_switch_padding); - mToggleSwitch = new ToggleSwitch(context); - mToggleSwitch.setPaddingRelative(0, 0, padding, 0); - mToggleSwitch.setLayoutParams(new ActionBar.LayoutParams( - ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, - Gravity.CENTER_VERTICAL | Gravity.END)); + SettingsActivity activity = (SettingsActivity) getActivity(); + mSwitchBar = activity.getSwitchBar(); + mToggleSwitch = mSwitchBar.getSwitch(); mToggleSwitch.setCheckedInternal(enabled); mPreviewWindow = view.findViewById(R.id.preview_window); @@ -149,14 +145,12 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment @Override public void onResume() { super.onResume(); - - installActionBarToggleSwitch(); + installSwitchBarToggleSwitch(); } @Override public void onPause() { - removeActionBarToggleSwitch(); - + removeSwitchBarToggleSwitch(); super.onPause(); } @@ -205,7 +199,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment } } - protected void onInstallActionBarToggleSwitch() { + protected void onInstallSwitchBarToggleSwitch() { mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { @@ -221,20 +215,14 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment }); } - private void installActionBarToggleSwitch() { - final ActionBar ab = getActivity().getActionBar(); - ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); - ab.setCustomView(mToggleSwitch); - - onInstallActionBarToggleSwitch(); + private void installSwitchBarToggleSwitch() { + onInstallSwitchBarToggleSwitch(); + mSwitchBar.show(); } - private void removeActionBarToggleSwitch() { + private void removeSwitchBarToggleSwitch() { + mSwitchBar.hide(); mToggleSwitch.setOnBeforeCheckedChangeListener(null); - - final ActionBar ab = getActivity().getActionBar(); - ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM); - ab.setCustomView(null); } private void initializeAllPreferences() { diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java index 7f0bb41bb..a446f4925 100644 --- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java @@ -281,8 +281,8 @@ public class ToggleAccessibilityServicePreferenceFragment } @Override - protected void onInstallActionBarToggleSwitch() { - super.onInstallActionBarToggleSwitch(); + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java index 6da81b01b..b910f796a 100644 --- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java @@ -23,13 +23,13 @@ import android.preference.Preference; import android.provider.Settings; import android.view.View; import android.view.accessibility.AccessibilityManager; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.Switch; import com.android.settings.R; +import com.android.settings.widget.SwitchBar; public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment - implements Preference.OnPreferenceChangeListener { + implements Preference.OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener { private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED; private static final String TYPE = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER; private static final String QUICK_SETTING_ENABLED = @@ -77,17 +77,18 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF } @Override - protected void onInstallActionBarToggleSwitch() { - super.onInstallActionBarToggleSwitch(); + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); mToggleSwitch.setCheckedInternal( Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1); - mToggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean checked) { - onPreferenceToggled(mPreferenceKey, checked); - } - }); + mSwitchBar.addOnSwitchChangeListener(this); + } + + @Override + protected void onRemoveSwitchBarToggleSwitch() { + super.onRemoveSwitchBarToggleSwitch(); + mSwitchBar.removeOnSwitchChangeListener(this); } private void initPreferences() { @@ -106,4 +107,9 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF getString(R.string.simulate_color_space))); } } + + @Override + public void onSwitchChanged(Switch switchView, boolean isChecked) { + onPreferenceToggled(mPreferenceKey, isChecked); + } } diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java index 55e3199b8..331c0e340 100644 --- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java @@ -16,15 +16,12 @@ package com.android.settings.accessibility; -import android.app.ActionBar; -import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceScreen; -import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -36,11 +33,13 @@ import android.widget.TextView; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.widget.SwitchBar; import com.android.settings.widget.ToggleSwitch; public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment { + protected SwitchBar mSwitchBar; protected ToggleSwitch mToggleSwitch; protected String mPreferenceKey; @@ -88,14 +87,9 @@ public abstract class ToggleFeaturePreferenceFragment public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - final Context context = getActivity().getActionBar().getThemedContext(); - final int padding = context.getResources().getDimensionPixelSize( - R.dimen.action_bar_switch_padding); - mToggleSwitch = new ToggleSwitch(context); - mToggleSwitch.setPaddingRelative(0, 0, padding, 0); - mToggleSwitch.setLayoutParams(new ActionBar.LayoutParams( - ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, - Gravity.CENTER_VERTICAL | Gravity.END)); + SettingsActivity activity = (SettingsActivity) getActivity(); + mSwitchBar = activity.getSwitchBar(); + mToggleSwitch = mSwitchBar.getSwitch(); onProcessArguments(getArguments()); } @@ -124,28 +118,26 @@ public abstract class ToggleFeaturePreferenceFragment menuItem.setIntent(mSettingsIntent); } - protected void onInstallActionBarToggleSwitch() { + protected void onInstallSwitchBarToggleSwitch() { // Implement this to set a checked listener. } - private void installActionBarToggleSwitch() { - final ActionBar ab = getActivity().getActionBar(); - ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); - ab.setCustomView(mToggleSwitch); + protected void onRemoveSwitchBarToggleSwitch() { + // Implement this to reset a checked listener. + } - onInstallActionBarToggleSwitch(); + private void installActionBarToggleSwitch() { + mSwitchBar.show(); + onInstallSwitchBarToggleSwitch(); } private void removeActionBarToggleSwitch() { mToggleSwitch.setOnBeforeCheckedChangeListener(null); - - final ActionBar ab = getActivity().getActionBar(); - ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM); - ab.setCustomView(null); + onRemoveSwitchBarToggleSwitch(); + mSwitchBar.hide(); } public void setTitle(String title) { - final SettingsActivity activity = (SettingsActivity) getActivity(); getActivity().setTitle(title); } diff --git a/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java index 56680b8d3..782e7a5b2 100644 --- a/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java @@ -30,8 +30,8 @@ public class ToggleGlobalGesturePreferenceFragment } @Override - protected void onInstallActionBarToggleSwitch() { - super.onInstallActionBarToggleSwitch(); + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { diff --git a/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java index 88c6cafab..b6d5569b6 100644 --- a/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java @@ -21,13 +21,13 @@ import android.preference.CheckBoxPreference; import android.preference.Preference; import android.provider.Settings; import android.view.View; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.Switch; import com.android.settings.R; +import com.android.settings.widget.SwitchBar; public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFragment - implements Preference.OnPreferenceChangeListener { + implements Preference.OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener { private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED; private static final String QUICK_SETTING_ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_QUICK_SETTING_ENABLED; @@ -68,17 +68,18 @@ public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFr } @Override - protected void onInstallActionBarToggleSwitch() { - super.onInstallActionBarToggleSwitch(); + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); mToggleSwitch.setCheckedInternal( Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1); - mToggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton button, boolean checked) { - onPreferenceToggled(mPreferenceKey, checked); - } - }); + mSwitchBar.addOnSwitchChangeListener(this); + } + + @Override + protected void onRemoveSwitchBarToggleSwitch() { + super.onRemoveSwitchBarToggleSwitch(); + mSwitchBar.removeOnSwitchChangeListener(this); } private void initPreferences() { @@ -86,4 +87,9 @@ public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFr Settings.Secure.getInt(getContentResolver(), QUICK_SETTING_ENABLED, 0) == 1); mEnableQuickSetting.setOnPreferenceChangeListener(this); } + + @Override + public void onSwitchChanged(Switch switchView, boolean isChecked) { + onPreferenceToggled(mPreferenceKey, isChecked); + } } diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 0e8926ae3..8202a2a25 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -30,8 +30,8 @@ public class ToggleScreenMagnificationPreferenceFragment } @Override - protected void onInstallActionBarToggleSwitch() { - super.onInstallActionBarToggleSwitch(); + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { |