Use SwitchBar for Accessibility Settings
Deals with Talkback / Captions / Magnification Gestures
- follow up CL to 4193776698
Related to bug #14898161 On/Off switches must move down from Action Bar
Change-Id: Ibda0ed05b399f1b2b4464c5b22a3e9fd3d378867
This commit is contained in:
@@ -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"
|
||||
|
@@ -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() {
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user