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:textAppearance="@style/TextAppearance.Switch"
|
||||||
android:textAlignment="viewStart" />
|
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_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -28,7 +27,6 @@ import android.preference.PreferenceCategory;
|
|||||||
import android.preference.PreferenceFrameLayout;
|
import android.preference.PreferenceFrameLayout;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -38,8 +36,10 @@ import android.view.accessibility.CaptioningManager.CaptionStyle;
|
|||||||
|
|
||||||
import com.android.internal.widget.SubtitleView;
|
import com.android.internal.widget.SubtitleView;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
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;
|
||||||
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
|
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
|
||||||
|
|
||||||
@@ -69,6 +69,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
private CaptioningManager mCaptioningManager;
|
private CaptioningManager mCaptioningManager;
|
||||||
private SubtitleView mPreviewText;
|
private SubtitleView mPreviewText;
|
||||||
private View mPreviewWindow;
|
private View mPreviewWindow;
|
||||||
|
private SwitchBar mSwitchBar;
|
||||||
private ToggleSwitch mToggleSwitch;
|
private ToggleSwitch mToggleSwitch;
|
||||||
|
|
||||||
// Standard options.
|
// Standard options.
|
||||||
@@ -129,14 +130,9 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
|
mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
|
||||||
mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
|
mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
final Context context = getActivity().getActionBar().getThemedContext();
|
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
final int padding = context.getResources().getDimensionPixelSize(
|
mSwitchBar = activity.getSwitchBar();
|
||||||
R.dimen.action_bar_switch_padding);
|
mToggleSwitch = mSwitchBar.getSwitch();
|
||||||
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));
|
|
||||||
mToggleSwitch.setCheckedInternal(enabled);
|
mToggleSwitch.setCheckedInternal(enabled);
|
||||||
|
|
||||||
mPreviewWindow = view.findViewById(R.id.preview_window);
|
mPreviewWindow = view.findViewById(R.id.preview_window);
|
||||||
@@ -149,14 +145,12 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
installSwitchBarToggleSwitch();
|
||||||
installActionBarToggleSwitch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
removeActionBarToggleSwitch();
|
removeSwitchBarToggleSwitch();
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +199,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
@@ -221,20 +215,14 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installActionBarToggleSwitch() {
|
private void installSwitchBarToggleSwitch() {
|
||||||
final ActionBar ab = getActivity().getActionBar();
|
onInstallSwitchBarToggleSwitch();
|
||||||
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
|
mSwitchBar.show();
|
||||||
ab.setCustomView(mToggleSwitch);
|
|
||||||
|
|
||||||
onInstallActionBarToggleSwitch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeActionBarToggleSwitch() {
|
private void removeSwitchBarToggleSwitch() {
|
||||||
|
mSwitchBar.hide();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||||
|
|
||||||
final ActionBar ab = getActivity().getActionBar();
|
|
||||||
ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
ab.setCustomView(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAllPreferences() {
|
private void initializeAllPreferences() {
|
||||||
|
@@ -281,8 +281,8 @@ public class ToggleAccessibilityServicePreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallActionBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
|
@@ -23,13 +23,13 @@ import android.preference.Preference;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
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.R;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment
|
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 ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
|
||||||
private static final String TYPE = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER;
|
private static final String TYPE = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER;
|
||||||
private static final String QUICK_SETTING_ENABLED =
|
private static final String QUICK_SETTING_ENABLED =
|
||||||
@@ -77,17 +77,18 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallActionBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
|
|
||||||
mToggleSwitch.setCheckedInternal(
|
mToggleSwitch.setCheckedInternal(
|
||||||
Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1);
|
Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1);
|
||||||
mToggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
@Override
|
}
|
||||||
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
|
||||||
onPreferenceToggled(mPreferenceKey, checked);
|
@Override
|
||||||
}
|
protected void onRemoveSwitchBarToggleSwitch() {
|
||||||
});
|
super.onRemoveSwitchBarToggleSwitch();
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPreferences() {
|
private void initPreferences() {
|
||||||
@@ -106,4 +107,9 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
|
|||||||
getString(R.string.simulate_color_space)));
|
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;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -36,11 +33,13 @@ import android.widget.TextView;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settings.widget.ToggleSwitch;
|
import com.android.settings.widget.ToggleSwitch;
|
||||||
|
|
||||||
public abstract class ToggleFeaturePreferenceFragment
|
public abstract class ToggleFeaturePreferenceFragment
|
||||||
extends SettingsPreferenceFragment {
|
extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
|
protected SwitchBar mSwitchBar;
|
||||||
protected ToggleSwitch mToggleSwitch;
|
protected ToggleSwitch mToggleSwitch;
|
||||||
|
|
||||||
protected String mPreferenceKey;
|
protected String mPreferenceKey;
|
||||||
@@ -88,14 +87,9 @@ public abstract class ToggleFeaturePreferenceFragment
|
|||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
final Context context = getActivity().getActionBar().getThemedContext();
|
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
final int padding = context.getResources().getDimensionPixelSize(
|
mSwitchBar = activity.getSwitchBar();
|
||||||
R.dimen.action_bar_switch_padding);
|
mToggleSwitch = mSwitchBar.getSwitch();
|
||||||
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));
|
|
||||||
|
|
||||||
onProcessArguments(getArguments());
|
onProcessArguments(getArguments());
|
||||||
}
|
}
|
||||||
@@ -124,28 +118,26 @@ public abstract class ToggleFeaturePreferenceFragment
|
|||||||
menuItem.setIntent(mSettingsIntent);
|
menuItem.setIntent(mSettingsIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
// Implement this to set a checked listener.
|
// Implement this to set a checked listener.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installActionBarToggleSwitch() {
|
protected void onRemoveSwitchBarToggleSwitch() {
|
||||||
final ActionBar ab = getActivity().getActionBar();
|
// Implement this to reset a checked listener.
|
||||||
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
|
}
|
||||||
ab.setCustomView(mToggleSwitch);
|
|
||||||
|
|
||||||
onInstallActionBarToggleSwitch();
|
private void installActionBarToggleSwitch() {
|
||||||
|
mSwitchBar.show();
|
||||||
|
onInstallSwitchBarToggleSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeActionBarToggleSwitch() {
|
private void removeActionBarToggleSwitch() {
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||||
|
onRemoveSwitchBarToggleSwitch();
|
||||||
final ActionBar ab = getActivity().getActionBar();
|
mSwitchBar.hide();
|
||||||
ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
ab.setCustomView(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
|
||||||
getActivity().setTitle(title);
|
getActivity().setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,8 +30,8 @@ public class ToggleGlobalGesturePreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallActionBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
|
@@ -21,13 +21,13 @@ import android.preference.CheckBoxPreference;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
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.R;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFragment
|
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 ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
|
||||||
private static final String QUICK_SETTING_ENABLED =
|
private static final String QUICK_SETTING_ENABLED =
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_QUICK_SETTING_ENABLED;
|
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_QUICK_SETTING_ENABLED;
|
||||||
@@ -68,17 +68,18 @@ public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallActionBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
|
|
||||||
mToggleSwitch.setCheckedInternal(
|
mToggleSwitch.setCheckedInternal(
|
||||||
Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1);
|
Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1);
|
||||||
mToggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
@Override
|
}
|
||||||
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
|
||||||
onPreferenceToggled(mPreferenceKey, checked);
|
@Override
|
||||||
}
|
protected void onRemoveSwitchBarToggleSwitch() {
|
||||||
});
|
super.onRemoveSwitchBarToggleSwitch();
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPreferences() {
|
private void initPreferences() {
|
||||||
@@ -86,4 +87,9 @@ public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFr
|
|||||||
Settings.Secure.getInt(getContentResolver(), QUICK_SETTING_ENABLED, 0) == 1);
|
Settings.Secure.getInt(getContentResolver(), QUICK_SETTING_ENABLED, 0) == 1);
|
||||||
mEnableQuickSetting.setOnPreferenceChangeListener(this);
|
mEnableQuickSetting.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
onPreferenceToggled(mPreferenceKey, isChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,8 +30,8 @@ public class ToggleScreenMagnificationPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallActionBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
|
@@ -33,7 +33,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener {
|
public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener {
|
||||||
|
|
||||||
private Switch mSwitch;
|
private ToggleSwitch mSwitch;
|
||||||
private TextView mTextView;
|
private TextView mTextView;
|
||||||
|
|
||||||
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
|
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
|
||||||
@@ -69,7 +69,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
mTextView = (TextView) findViewById(R.id.switch_text);
|
mTextView = (TextView) findViewById(R.id.switch_text);
|
||||||
mTextView.setText(R.string.switch_off_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);
|
mSwitch.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
addOnSwitchChangeListener(new OnSwitchChangeListener() {
|
addOnSwitchChangeListener(new OnSwitchChangeListener() {
|
||||||
@@ -86,7 +86,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
setVisibility(View.GONE);
|
setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Switch getSwitch() {
|
public ToggleSwitch getSwitch() {
|
||||||
return mSwitch;
|
return mSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,9 +17,11 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
|
||||||
public class ToggleSwitch extends Switch {
|
public class ToggleSwitch extends Switch {
|
||||||
|
|
||||||
private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener;
|
private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener;
|
||||||
|
|
||||||
public static interface OnBeforeCheckedChangeListener {
|
public static interface OnBeforeCheckedChangeListener {
|
||||||
@@ -30,6 +32,18 @@ public class ToggleSwitch extends Switch {
|
|||||||
super(context);
|
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) {
|
public void setOnBeforeCheckedChangeListener(OnBeforeCheckedChangeListener listener) {
|
||||||
mOnBeforeListener = listener;
|
mOnBeforeListener = listener;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user