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 | |
parent | 5160536df91bb9daa6cac9a878ce406deda791c6 (diff) | |
download | packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.zip packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.tar.gz packages_apps_Settings-6220275d6dec8ffc6f1df2cbfbf42934d09d41f0.tar.bz2 |
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
10 files changed, 86 insertions, 80 deletions
diff --git a/res/layout/switch_bar.xml b/res/layout/switch_bar.xml index f9a887f..40f7aa8 100644 --- a/res/layout/switch_bar.xml +++ b/res/layout/switch_bar.xml @@ -28,7 +28,7 @@ android:textAppearance="@style/TextAppearance.Switch" android:textAlignment="viewStart" /> - <Switch android:id="@+id/switch_widget" + <com.android.settings.widget.ToggleSwitch android:id="@+id/switch_widget" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index 43306f2..5dcf121 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 7f0bb41..a446f49 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 6da81b0..b910f79 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 55e3199..331c0e3 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 56680b8..782e7a5 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 88c6caf..b6d5569 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 0e8926a..8202a2a 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) { diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index e871671..40c8481 100644 --- a/src/com/android/settings/widget/SwitchBar.java +++ b/src/com/android/settings/widget/SwitchBar.java @@ -33,7 +33,7 @@ import java.util.ArrayList; public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener { - private Switch mSwitch; + private ToggleSwitch mSwitch; private TextView mTextView; private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners = @@ -69,7 +69,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC mTextView = (TextView) findViewById(R.id.switch_text); mTextView.setText(R.string.switch_off_text); - mSwitch = (Switch) findViewById(R.id.switch_widget); + mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget); mSwitch.setOnCheckedChangeListener(this); addOnSwitchChangeListener(new OnSwitchChangeListener() { @@ -86,7 +86,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC setVisibility(View.GONE); } - public Switch getSwitch() { + public ToggleSwitch getSwitch() { return mSwitch; } diff --git a/src/com/android/settings/widget/ToggleSwitch.java b/src/com/android/settings/widget/ToggleSwitch.java index 41abf8a..8232ff1 100644 --- a/src/com/android/settings/widget/ToggleSwitch.java +++ b/src/com/android/settings/widget/ToggleSwitch.java @@ -17,9 +17,11 @@ package com.android.settings.widget; import android.content.Context; +import android.util.AttributeSet; import android.widget.Switch; public class ToggleSwitch extends Switch { + private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener; public static interface OnBeforeCheckedChangeListener { @@ -30,6 +32,18 @@ public class ToggleSwitch extends Switch { super(context); } + public ToggleSwitch(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ToggleSwitch(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public ToggleSwitch(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + public void setOnBeforeCheckedChangeListener(OnBeforeCheckedChangeListener listener) { mOnBeforeListener = listener; } |