diff options
17 files changed, 101 insertions, 90 deletions
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 1cd08f399..94d8a3682 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -168,7 +168,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment private WifiManager mWifiManager; private SwitchBar mSwitchBar; - private Switch mEnabledSwitch; private boolean mLastEnabledState; private boolean mHaveDebugSettings; private boolean mDontPokeProperties; @@ -389,9 +388,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment final SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - mEnabledSwitch = mSwitchBar.getSwitch(); if (mUnavailable) { - mEnabledSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); return; } } @@ -444,7 +442,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment final ContentResolver cr = getActivity().getContentResolver(); mLastEnabledState = Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; - mEnabledSwitch.setChecked(mLastEnabledState); + mSwitchBar.setSwitchChecked(mLastEnabledState); setPrefsEnabledState(mLastEnabledState); if (mHaveDebugSettings && !mLastEnabledState) { @@ -455,7 +453,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); mLastEnabledState = true; - mEnabledSwitch.setChecked(mLastEnabledState); + mSwitchBar.setSwitchChecked(mLastEnabledState); setPrefsEnabledState(mLastEnabledState); } @@ -1225,9 +1223,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment @Override public void onSwitchChanged(Switch switchView, boolean isChecked) { - if (switchView != mEnabledSwitch) { - return; - } if (isChecked != mLastEnabledState) { if (isChecked) { mDialogClicked = false; @@ -1482,7 +1477,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment setPrefsEnabledState(mLastEnabledState); } else { // Reset the toggle - mEnabledSwitch.setChecked(false); + mSwitchBar.setSwitchChecked(false); } } } @@ -1496,7 +1491,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mAdbDialog = null; } else if (dialog == mEnableDialog) { if (!mDialogClicked) { - mEnabledSwitch.setChecked(false); + mSwitchBar.setSwitchChecked(false); } mEnableDialog = null; } diff --git a/src/com/android/settings/DreamSettings.java b/src/com/android/settings/DreamSettings.java index 1175639de..d97e616e1 100644 --- a/src/com/android/settings/DreamSettings.java +++ b/src/com/android/settings/DreamSettings.java @@ -61,7 +61,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements private DreamBackend mBackend; private DreamInfoAdapter mAdapter; private SwitchBar mSwitchBar; - private Switch mSwitch; private MenuItem[] mMenuItemsWhenEnabled; private boolean mRefreshing; @@ -124,7 +123,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements final SettingsActivity sa = (SettingsActivity) getActivity(); mSwitchBar = sa.getSwitchBar(); - mSwitch = mSwitchBar.getSwitch(); } @Override @@ -263,8 +261,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements logd("refreshFromBackend()"); mRefreshing = true; boolean dreamsEnabled = mBackend.isEnabled(); - if (mSwitch.isChecked() != dreamsEnabled) - mSwitch.setChecked(dreamsEnabled); + if (mSwitchBar.isSwitchChecked() != dreamsEnabled) + mSwitchBar.setSwitchChecked(dreamsEnabled); mAdapter.clear(); if (dreamsEnabled) { diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index 5dcf121eb..937f3b799 100644 --- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java +++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java @@ -70,7 +70,6 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment private SubtitleView mPreviewText; private View mPreviewWindow; private SwitchBar mSwitchBar; - private ToggleSwitch mToggleSwitch; // Standard options. private LocalePreference mLocale; @@ -132,8 +131,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - mToggleSwitch = mSwitchBar.getSwitch(); - mToggleSwitch.setCheckedInternal(enabled); + mSwitchBar.setSwitchChecked(enabled); mPreviewWindow = view.findViewById(R.id.preview_window); @@ -200,10 +198,10 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment } protected void onInstallSwitchBarToggleSwitch() { - mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { - toggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0); getPreferenceScreen().setEnabled(checked); @@ -222,7 +220,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment private void removeSwitchBarToggleSwitch() { mSwitchBar.hide(); - mToggleSwitch.setOnBeforeCheckedChangeListener(null); + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(null); } private void initializeAllPreferences() { diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java index a446f4925..d18c7f370 100644 --- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java @@ -58,7 +58,7 @@ public class ToggleAccessibilityServicePreferenceFragment String settingValue = Settings.Secure.getString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); final boolean enabled = settingValue.contains(mComponentName.flattenToString()); - mToggleSwitch.setCheckedInternal(enabled); + mSwitchBar.setSwitchChecked(enabled); } }; @@ -265,13 +265,13 @@ public class ToggleAccessibilityServicePreferenceFragment switch (which) { case DialogInterface.BUTTON_POSITIVE: checked = (mShownDialogId == DIALOG_ID_ENABLE_WARNING); - mToggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); break; case DialogInterface.BUTTON_NEGATIVE: checked = (mShownDialogId == DIALOG_ID_DISABLE_WARNING); - mToggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); break; @@ -283,15 +283,15 @@ public class ToggleAccessibilityServicePreferenceFragment @Override protected void onInstallSwitchBarToggleSwitch() { super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { if (checked) { - toggleSwitch.setCheckedInternal(false); + mSwitchBar.setSwitchChecked(false); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false); showDialog(DIALOG_ID_ENABLE_WARNING); } else { - toggleSwitch.setCheckedInternal(true); + mSwitchBar.setSwitchChecked(true); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, true); showDialog(DIALOG_ID_DISABLE_WARNING); } diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java index b910f796a..a39c5d8f1 100644 --- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java @@ -80,7 +80,7 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF protected void onInstallSwitchBarToggleSwitch() { super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setCheckedInternal( + mSwitchBar.setSwitchChecked( Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1); mSwitchBar.addOnSwitchChangeListener(this); } diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java index 331c0e340..cc8128911 100644 --- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java @@ -40,7 +40,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment { protected SwitchBar mSwitchBar; - protected ToggleSwitch mToggleSwitch; protected String mPreferenceKey; protected Preference mSummaryPreference; @@ -89,7 +88,6 @@ public abstract class ToggleFeaturePreferenceFragment SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - mToggleSwitch = mSwitchBar.getSwitch(); onProcessArguments(getArguments()); } @@ -132,7 +130,7 @@ public abstract class ToggleFeaturePreferenceFragment } private void removeActionBarToggleSwitch() { - mToggleSwitch.setOnBeforeCheckedChangeListener(null); + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(null); onRemoveSwitchBarToggleSwitch(); mSwitchBar.hide(); } @@ -153,7 +151,7 @@ public abstract class ToggleFeaturePreferenceFragment // Enabled. if (arguments.containsKey(AccessibilitySettings.EXTRA_CHECKED)) { final boolean enabled = arguments.getBoolean(AccessibilitySettings.EXTRA_CHECKED); - mToggleSwitch.setCheckedInternal(enabled); + mSwitchBar.setSwitchChecked(enabled); } // Title. diff --git a/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java index 782e7a5b2..d815e5038 100644 --- a/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleGlobalGesturePreferenceFragment.java @@ -32,10 +32,10 @@ public class ToggleGlobalGesturePreferenceFragment @Override protected void onInstallSwitchBarToggleSwitch() { super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { - toggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); return false; diff --git a/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java index b6d5569b6..594ed2239 100644 --- a/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleInversionPreferenceFragment.java @@ -71,7 +71,7 @@ public class ToggleInversionPreferenceFragment extends ToggleFeaturePreferenceFr protected void onInstallSwitchBarToggleSwitch() { super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setCheckedInternal( + mSwitchBar.setSwitchChecked( Settings.Secure.getInt(getContentResolver(), ENABLED, 0) == 1); mSwitchBar.addOnSwitchChangeListener(this); } diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 8202a2a25..7c01d0e5f 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -32,10 +32,10 @@ public class ToggleScreenMagnificationPreferenceFragment @Override protected void onInstallSwitchBarToggleSwitch() { super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { - toggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); return false; diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java index be03b6380..4626ed4c3 100644 --- a/src/com/android/settings/bluetooth/BluetoothEnabler.java +++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java @@ -40,7 +40,6 @@ import com.android.settings.widget.SwitchBar; */ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener { private Context mContext; - private Switch mSwitch; private SwitchBar mSwitchBar; private boolean mValidListener; private final LocalBluetoothAdapter mLocalAdapter; @@ -75,14 +74,13 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener public BluetoothEnabler(Context context, SwitchBar switchBar) { mContext = context; mSwitchBar = switchBar; - mSwitch = switchBar.getSwitch(); mValidListener = false; LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context); if (manager == null) { // Bluetooth is not supported mLocalAdapter = null; - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); } else { mLocalAdapter = manager.getBluetoothAdapter(); } @@ -91,7 +89,7 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener public void resume(Context context) { if (mLocalAdapter == null) { - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); return; } @@ -122,36 +120,36 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener void handleStateChanged(int state) { switch (state) { case BluetoothAdapter.STATE_TURNING_ON: - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); break; case BluetoothAdapter.STATE_ON: setChecked(true); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(true); break; case BluetoothAdapter.STATE_TURNING_OFF: - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); break; case BluetoothAdapter.STATE_OFF: setChecked(false); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(false); break; default: setChecked(false); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(false); } } private void setChecked(boolean isChecked) { - if (isChecked != mSwitch.isChecked()) { + if (isChecked != mSwitchBar.isSwitchChecked()) { // set listener to null, so onCheckedChanged won't be called // if the checked status on Switch isn't changed by user click if (mValidListener) { mSwitchBar.removeOnSwitchChangeListener(this); } - mSwitch.setChecked(isChecked); + mSwitchBar.setSwitchChecked(isChecked); if (mValidListener) { mSwitchBar.addOnSwitchChangeListener(this); } @@ -180,6 +178,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener if (mLocalAdapter != null) { mLocalAdapter.setBluetoothEnabled(isChecked); } - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); } } diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 8794a8dca..6eabf36da 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -53,7 +53,6 @@ public class LocationSettings extends LocationSettingsBase private static final String KEY_LOCATION_SERVICES = "location_services"; private SwitchBar mSwitchBar; - private Switch mSwitch; private boolean mValidListener; private Preference mLocationMode; private PreferenceCategory mCategoryRecentLocationRequests; @@ -72,7 +71,6 @@ public class LocationSettings extends LocationSettingsBase final SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - mSwitch = mSwitchBar.getSwitch(); } @Override @@ -221,16 +219,16 @@ public class LocationSettings extends LocationSettingsBase // corner cases, the location might still be enabled. In such case the master switch should // be disabled but checked. boolean enabled = (mode != android.provider.Settings.Secure.LOCATION_MODE_OFF); - mSwitch.setEnabled(!restricted); + mSwitchBar.setSwitchEnabled(!restricted); mLocationMode.setEnabled(enabled && !restricted); mCategoryRecentLocationRequests.setEnabled(enabled); - if (enabled != mSwitch.isChecked()) { + if (enabled != mSwitchBar.isSwitchChecked()) { // set listener to null so that that code below doesn't trigger onCheckedChanged() if (mValidListener) { mSwitchBar.removeOnSwitchChangeListener(this); } - mSwitch.setChecked(enabled); + mSwitchBar.setSwitchChecked(enabled); if (mValidListener) { mSwitchBar.addOnSwitchChangeListener(this); } diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java index eb3ff9bbc..b63a97525 100644 --- a/src/com/android/settings/nfc/AndroidBeam.java +++ b/src/com/android/settings/nfc/AndroidBeam.java @@ -33,7 +33,6 @@ public class AndroidBeam extends Fragment private View mView; private NfcAdapter mNfcAdapter; private SwitchBar mSwitchBar; - private Switch mSwitch; private CharSequence mOldActivityTitle; @Override @@ -63,8 +62,7 @@ public class AndroidBeam extends Fragment SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - mSwitch = mSwitchBar.getSwitch(); - mSwitch.setChecked(mNfcAdapter.isNdefPushEnabled()); + mSwitchBar.setSwitchChecked(mNfcAdapter.isNdefPushEnabled()); } @Override @@ -94,15 +92,15 @@ public class AndroidBeam extends Fragment @Override public void onSwitchChanged(Switch switchView, boolean desiredState) { boolean success = false; - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); if (desiredState) { success = mNfcAdapter.enableNdefPush(); } else { success = mNfcAdapter.disableNdefPush(); } if (success) { - mSwitch.setChecked(desiredState); + mSwitchBar.setSwitchChecked(desiredState); } - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); } } diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index 8a66d1b29..7b7c9eed4 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -104,7 +104,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index private final SettingsObserver mSettingsObserver = new SettingsObserver(); private SwitchBar mSwitchBar; - private Switch mSwitch; private Context mContext; private PackageManager mPM; private ZenModeConfig mConfig; @@ -156,7 +155,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig); mSwitchBar = ((SettingsActivity) mContext).getSwitchBar(); - mSwitch = mSwitchBar.getSwitch(); final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL); @@ -392,8 +390,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index private void updateZenMode() { final boolean zenMode = Global.getInt(getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF; - if (mSwitch.isChecked() != zenMode) { - mSwitch.setChecked(zenMode); + if (mSwitchBar.isSwitchChecked() != zenMode) { + mSwitchBar.setSwitchChecked(zenMode); mIgnoreNext = true; } } diff --git a/src/com/android/settings/print/PrintServiceSettingsFragment.java b/src/com/android/settings/print/PrintServiceSettingsFragment.java index f104a06d8..c1ebcb9d3 100644 --- a/src/com/android/settings/print/PrintServiceSettingsFragment.java +++ b/src/com/android/settings/print/PrintServiceSettingsFragment.java @@ -112,7 +112,6 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment }; private SwitchBar mSwitchBar; - private ToggleSwitch mToggleSwitch; private String mPreferenceKey; @@ -209,13 +208,13 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment switch (which) { case DialogInterface.BUTTON_POSITIVE: checked = true; - mToggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(PrintSettingsFragment.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); break; case DialogInterface.BUTTON_NEGATIVE: checked = false; - mToggleSwitch.setCheckedInternal(checked); + mSwitchBar.setSwitchChecked(checked); getArguments().putBoolean(PrintSettingsFragment.EXTRA_CHECKED, checked); onPreferenceToggled(mPreferenceKey, checked); break; @@ -228,7 +227,7 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment ListView listView = getListView(); ViewGroup contentRoot = (ViewGroup) listView.getParent(); View emptyView = listView.getEmptyView(); - if (!mToggleSwitch.isChecked()) { + if (!mSwitchBar.isSwitchChecked()) { if (emptyView != null && emptyView.getId() != R.id.empty_print_state) { contentRoot.removeView(emptyView); emptyView = null; @@ -277,10 +276,10 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment List<ComponentName> services = PrintSettingsUtils.readEnabledPrintServices(getActivity()); mServiceEnabled = services.contains(mComponentName); if (mServiceEnabled) { - mToggleSwitch.setCheckedInternal(true); + mSwitchBar.setSwitchChecked(true); mPrintersAdapter.enable(); } else { - mToggleSwitch.setCheckedInternal(false); + mSwitchBar.setSwitchChecked(false); mPrintersAdapter.disable(); } getActivity().invalidateOptionsMenu(); @@ -293,14 +292,12 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment final SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - - mToggleSwitch = mSwitchBar.getSwitch(); - mToggleSwitch.setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() { + mSwitchBar.setSwitchOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() { @Override public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { if (checked) { if (!TextUtils.isEmpty(mEnableWarningMessage)) { - toggleSwitch.setCheckedInternal(false); + mSwitchBar.setSwitchChecked(false); getArguments().putBoolean(PrintSettingsFragment.EXTRA_CHECKED, false); showDialog(DIALOG_ID_ENABLE_WARNING); return true; @@ -331,7 +328,7 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment // Enabled. final boolean enabled = arguments.getBoolean(PrintSettingsFragment.EXTRA_CHECKED); - mToggleSwitch.setCheckedInternal(enabled); + mSwitchBar.setSwitchChecked(enabled); // Settings title and intent. String settingsTitle = arguments.getString(PrintSettingsFragment.EXTRA_SETTINGS_TITLE); diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index 40c848103..1675f2a48 100644 --- a/src/com/android/settings/widget/SwitchBar.java +++ b/src/com/android/settings/widget/SwitchBar.java @@ -84,10 +84,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC // Default is hide setVisibility(View.GONE); - } - - public ToggleSwitch getSwitch() { - return mSwitch; + mSwitch.setVisibility(View.GONE); } public void show() { @@ -125,4 +122,39 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC } mSwitchChangeListeners.remove(listener); } + + public void setSwitchOnBeforeCheckedChangeListener( + ToggleSwitch.OnBeforeCheckedChangeListener listener) { + mSwitch.setOnBeforeCheckedChangeListener(listener); + } + + public void setSwitchChecked(boolean checked) { + setSwitchChecked(checked, false); + } + + public void setSwitchChecked(boolean checked, boolean checkBefore) { + if (checkBefore) { + ToggleSwitch.OnBeforeCheckedChangeListener listener = + mSwitch.getOnBeforeCheckedChangeListener(); + if (listener != null && listener.onBeforeCheckedChanged(mSwitch, checked)) { + return; + } + + } + mSwitch.setCheckedInternal(checked); + if (mSwitch.getVisibility() == View.GONE) { + mSwitch.setVisibility(View.VISIBLE); + } + } + + public void setSwitchEnabled(boolean enabled) { + mSwitch.setEnabled(enabled); + if (mSwitch.getVisibility() == View.GONE) { + mSwitch.setVisibility(View.VISIBLE); + } + } + + public boolean isSwitchChecked() { + return mSwitch.isChecked(); + } } diff --git a/src/com/android/settings/widget/ToggleSwitch.java b/src/com/android/settings/widget/ToggleSwitch.java index 8232ff1c2..ab0c37e03 100644 --- a/src/com/android/settings/widget/ToggleSwitch.java +++ b/src/com/android/settings/widget/ToggleSwitch.java @@ -48,6 +48,10 @@ public class ToggleSwitch extends Switch { mOnBeforeListener = listener; } + public OnBeforeCheckedChangeListener getOnBeforeCheckedChangeListener() { + return mOnBeforeListener; + } + @Override public void setChecked(boolean checked) { if (mOnBeforeListener != null diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index 9f0b6fa53..1e86761f9 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -27,7 +27,6 @@ import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Message; import android.provider.Settings; -import android.widget.CompoundButton; import android.widget.Switch; import android.widget.Toast; @@ -40,7 +39,6 @@ import java.util.concurrent.atomic.AtomicBoolean; public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { private Context mContext; - private Switch mSwitch; private SwitchBar mSwitchBar; private AtomicBoolean mConnected = new AtomicBoolean(false); @@ -87,7 +85,6 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { public WifiEnabler(Context context, SwitchBar switchBar) { mContext = context; mSwitchBar = switchBar; - mSwitch = switchBar.getSwitch(); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION); @@ -113,24 +110,24 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { private void handleWifiStateChanged(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); break; case WifiManager.WIFI_STATE_ENABLED: setSwitchChecked(true); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(true); break; case WifiManager.WIFI_STATE_DISABLING: - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); break; case WifiManager.WIFI_STATE_DISABLED: setSwitchChecked(false); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(false); break; default: setSwitchChecked(false); - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); updateSearchIndex(false); } } @@ -145,9 +142,9 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { } private void setSwitchChecked(boolean checked) { - if (checked != mSwitch.isChecked()) { + if (checked != mSwitchBar.isSwitchChecked()) { mStateMachineEvent = true; - mSwitch.setChecked(checked); + mSwitchBar.setSwitchChecked(checked); mStateMachineEvent = false; } } @@ -189,10 +186,10 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener { mWifiManager.setWifiApEnabled(null, false); } - mSwitch.setEnabled(false); + mSwitchBar.setSwitchEnabled(false); if (!mWifiManager.setWifiEnabled(isChecked)) { // Error - mSwitch.setEnabled(true); + mSwitchBar.setSwitchEnabled(true); Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show(); } } |