Make the SwitchBar appear immediately
- change the way the SwitchBar is shown and hidden - save its state - remove the delay transition code Change-Id: I07260430e6709b42517ca011f6d3c3446a626731
This commit is contained in:
@@ -167,7 +167,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mEnabledSwitch;
|
|
||||||
private boolean mLastEnabledState;
|
private boolean mLastEnabledState;
|
||||||
private boolean mHaveDebugSettings;
|
private boolean mHaveDebugSettings;
|
||||||
private boolean mDontPokeProperties;
|
private boolean mDontPokeProperties;
|
||||||
@@ -386,11 +385,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
mEnabledSwitch = mSwitchBar.getSwitch();
|
|
||||||
if (mUnavailable) {
|
if (mUnavailable) {
|
||||||
mEnabledSwitch.setEnabled(false);
|
mSwitchBar.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removePreferenceForProduction(Preference preference) {
|
private boolean removePreferenceForProduction(Preference preference) {
|
||||||
@@ -441,7 +441,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
final ContentResolver cr = getActivity().getContentResolver();
|
final ContentResolver cr = getActivity().getContentResolver();
|
||||||
mLastEnabledState = Settings.Global.getInt(cr,
|
mLastEnabledState = Settings.Global.getInt(cr,
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
|
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
|
||||||
mEnabledSwitch.setChecked(mLastEnabledState);
|
mSwitchBar.setChecked(mLastEnabledState);
|
||||||
setPrefsEnabledState(mLastEnabledState);
|
setPrefsEnabledState(mLastEnabledState);
|
||||||
|
|
||||||
if (mHaveDebugSettings && !mLastEnabledState) {
|
if (mHaveDebugSettings && !mLastEnabledState) {
|
||||||
@@ -452,17 +452,15 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
Settings.Global.putInt(getActivity().getContentResolver(),
|
Settings.Global.putInt(getActivity().getContentResolver(),
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
|
||||||
mLastEnabledState = true;
|
mLastEnabledState = true;
|
||||||
mEnabledSwitch.setChecked(mLastEnabledState);
|
mSwitchBar.setChecked(mLastEnabledState);
|
||||||
setPrefsEnabledState(mLastEnabledState);
|
setPrefsEnabledState(mLastEnabledState);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onDestroyView() {
|
||||||
super.onPause();
|
super.onDestroyView();
|
||||||
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
mSwitchBar.hide();
|
mSwitchBar.hide();
|
||||||
@@ -1210,7 +1208,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
if (switchView != mEnabledSwitch) {
|
if (switchView != mSwitchBar.getSwitch()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isChecked != mLastEnabledState) {
|
if (isChecked != mLastEnabledState) {
|
||||||
@@ -1463,7 +1461,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
setPrefsEnabledState(mLastEnabledState);
|
setPrefsEnabledState(mLastEnabledState);
|
||||||
} else {
|
} else {
|
||||||
// Reset the toggle
|
// Reset the toggle
|
||||||
mEnabledSwitch.setChecked(false);
|
mSwitchBar.setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1477,7 +1475,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
mAdbDialog = null;
|
mAdbDialog = null;
|
||||||
} else if (dialog == mEnableDialog) {
|
} else if (dialog == mEnableDialog) {
|
||||||
if (!mDialogClicked) {
|
if (!mDialogClicked) {
|
||||||
mEnabledSwitch.setChecked(false);
|
mSwitchBar.setChecked(false);
|
||||||
}
|
}
|
||||||
mEnableDialog = null;
|
mEnableDialog = null;
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
private DreamBackend mBackend;
|
private DreamBackend mBackend;
|
||||||
private DreamInfoAdapter mAdapter;
|
private DreamInfoAdapter mAdapter;
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mSwitch;
|
|
||||||
private MenuItem[] mMenuItemsWhenEnabled;
|
private MenuItem[] mMenuItemsWhenEnabled;
|
||||||
private boolean mRefreshing;
|
private boolean mRefreshing;
|
||||||
|
|
||||||
@@ -105,6 +104,9 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
logd("onDestroyView()");
|
logd("onDestroyView()");
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +126,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
final SettingsActivity sa = (SettingsActivity) getActivity();
|
final SettingsActivity sa = (SettingsActivity) getActivity();
|
||||||
mSwitchBar = sa.getSwitchBar();
|
mSwitchBar = sa.getSwitchBar();
|
||||||
mSwitch = mSwitchBar.getSwitch();
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -212,9 +215,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
mContext.unregisterReceiver(mPackageReceiver);
|
mContext.unregisterReceiver(mPackageReceiver);
|
||||||
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -231,9 +231,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||||
filter.addDataScheme(PACKAGE_SCHEME);
|
filter.addDataScheme(PACKAGE_SCHEME);
|
||||||
mContext.registerReceiver(mPackageReceiver , filter);
|
mContext.registerReceiver(mPackageReceiver , filter);
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSummaryResource(Context context) {
|
public static int getSummaryResource(Context context) {
|
||||||
@@ -263,8 +260,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements
|
|||||||
logd("refreshFromBackend()");
|
logd("refreshFromBackend()");
|
||||||
mRefreshing = true;
|
mRefreshing = true;
|
||||||
boolean dreamsEnabled = mBackend.isEnabled();
|
boolean dreamsEnabled = mBackend.isEnabled();
|
||||||
if (mSwitch.isChecked() != dreamsEnabled)
|
if (mSwitchBar.isChecked() != dreamsEnabled)
|
||||||
mSwitch.setChecked(dreamsEnabled);
|
mSwitchBar.setChecked(dreamsEnabled);
|
||||||
|
|
||||||
mAdapter.clear();
|
mAdapter.clear();
|
||||||
if (dreamsEnabled) {
|
if (dreamsEnabled) {
|
||||||
|
@@ -142,27 +142,30 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
refreshPreviewText();
|
refreshPreviewText();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
final boolean enabled = mCaptioningManager.isEnabled();
|
||||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
|
mSwitchBar.setTextViewLabel(enabled);
|
||||||
mToggleSwitch = mSwitchBar.getSwitch();
|
mToggleSwitch = mSwitchBar.getSwitch();
|
||||||
mToggleSwitch.setCheckedInternal(enabled);
|
mToggleSwitch.setCheckedInternal(enabled);
|
||||||
|
|
||||||
getPreferenceScreen().setEnabled(enabled);
|
getPreferenceScreen().setEnabled(enabled);
|
||||||
|
|
||||||
refreshPreviewText();
|
refreshPreviewText();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
installSwitchBarToggleSwitch();
|
installSwitchBarToggleSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
removeSwitchBarToggleSwitch();
|
removeSwitchBarToggleSwitch();
|
||||||
super.onPause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshPreviewText() {
|
private void refreshPreviewText() {
|
||||||
|
@@ -95,17 +95,17 @@ public abstract class ToggleFeaturePreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onResume();
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
installActionBarToggleSwitch();
|
installActionBarToggleSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onDestroyView() {
|
||||||
removeActionBarToggleSwitch();
|
super.onDestroyView();
|
||||||
|
|
||||||
super.onPause();
|
removeActionBarToggleSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
||||||
|
@@ -89,6 +89,16 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
|||||||
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupSwitchBar() {
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teardownSwitchBar() {
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
|
}
|
||||||
|
|
||||||
public void resume(Context context) {
|
public void resume(Context context) {
|
||||||
if (mLocalAdapter == null) {
|
if (mLocalAdapter == null) {
|
||||||
mSwitch.setEnabled(false);
|
mSwitch.setEnabled(false);
|
||||||
@@ -103,8 +113,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
|||||||
handleStateChanged(mLocalAdapter.getBluetoothState());
|
handleStateChanged(mLocalAdapter.getBluetoothState());
|
||||||
|
|
||||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
|
||||||
mValidListener = true;
|
mValidListener = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +122,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
mValidListener = false;
|
mValidListener = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -119,6 +119,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
|
|
||||||
mBluetoothEnabler = new BluetoothEnabler(activity, mSwitchBar);
|
mBluetoothEnabler = new BluetoothEnabler(activity, mSwitchBar);
|
||||||
|
mBluetoothEnabler.setupSwitchBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
|
||||||
|
mBluetoothEnabler.teardownSwitchBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -73,6 +73,16 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
mSwitch = mSwitchBar.getSwitch();
|
mSwitch = mSwitchBar.getSwitch();
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,8 +94,6 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
|
||||||
mValidListener = true;
|
mValidListener = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +105,6 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
// Ignore exceptions caused by race condition
|
// Ignore exceptions caused by race condition
|
||||||
}
|
}
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
mValidListener = false;
|
mValidListener = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,7 +33,6 @@ public class AndroidBeam extends Fragment
|
|||||||
private View mView;
|
private View mView;
|
||||||
private NfcAdapter mNfcAdapter;
|
private NfcAdapter mNfcAdapter;
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mSwitch;
|
|
||||||
private CharSequence mOldActivityTitle;
|
private CharSequence mOldActivityTitle;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,46 +62,33 @@ public class AndroidBeam extends Fragment
|
|||||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
mSwitch = mSwitchBar.getSwitch();
|
mSwitchBar.setChecked(mNfcAdapter.isNdefPushEnabled());
|
||||||
mSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
if (mOldActivityTitle != null) {
|
if (mOldActivityTitle != null) {
|
||||||
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
||||||
}
|
}
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSwitchChanged(Switch switchView, boolean desiredState) {
|
public void onSwitchChanged(Switch switchView, boolean desiredState) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
mSwitch.setEnabled(false);
|
mSwitchBar.setEnabled(false);
|
||||||
if (desiredState) {
|
if (desiredState) {
|
||||||
success = mNfcAdapter.enableNdefPush();
|
success = mNfcAdapter.enableNdefPush();
|
||||||
} else {
|
} else {
|
||||||
success = mNfcAdapter.disableNdefPush();
|
success = mNfcAdapter.disableNdefPush();
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
mSwitch.setChecked(desiredState);
|
mSwitchBar.setChecked(desiredState);
|
||||||
}
|
}
|
||||||
mSwitch.setEnabled(true);
|
mSwitchBar.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
private final SettingsObserver mSettingsObserver = new SettingsObserver();
|
private final SettingsObserver mSettingsObserver = new SettingsObserver();
|
||||||
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mSwitch;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PackageManager mPM;
|
private PackageManager mPM;
|
||||||
private ZenModeConfig mConfig;
|
private ZenModeConfig mConfig;
|
||||||
@@ -159,7 +158,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
||||||
|
|
||||||
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
|
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
|
||||||
mSwitch = mSwitchBar.getSwitch();
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
|
|
||||||
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
|
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
|
||||||
|
|
||||||
@@ -400,14 +400,17 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
updateControls();
|
updateControls();
|
||||||
updateZenMode();
|
updateZenMode();
|
||||||
mSettingsObserver.register();
|
mSettingsObserver.register();
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSettingsObserver.unregister();
|
mSettingsObserver.unregister();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
mSwitchBar.hide();
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
@@ -415,8 +418,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
private void updateZenMode() {
|
private void updateZenMode() {
|
||||||
final boolean zenMode = Global.getInt(getContentResolver(),
|
final boolean zenMode = Global.getInt(getContentResolver(),
|
||||||
Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF;
|
Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF;
|
||||||
if (mSwitch.isChecked() != zenMode) {
|
if (mSwitchBar.isChecked() != zenMode) {
|
||||||
mSwitch.setChecked(zenMode);
|
mSwitchBar.setChecked(zenMode);
|
||||||
mIgnoreNext = true;
|
mIgnoreNext = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -143,16 +143,12 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
mSettingsContentObserver.register(getContentResolver());
|
mSettingsContentObserver.register(getContentResolver());
|
||||||
updateEmptyView();
|
updateEmptyView();
|
||||||
updateUiForServiceState();
|
updateUiForServiceState();
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mSettingsContentObserver.unregister(getContentResolver());
|
mSettingsContentObserver.unregister(getContentResolver());
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,6 +164,8 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
||||||
}
|
}
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
private void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||||
@@ -292,6 +290,8 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
|
|
||||||
mToggleSwitch = mSwitchBar.getSwitch();
|
mToggleSwitch = mSwitchBar.getSwitch();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() {
|
||||||
|
@@ -17,10 +17,11 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.transition.TransitionManager;
|
import android.transition.TransitionManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
@@ -72,12 +73,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
mTextView.setText(R.string.switch_off_text);
|
mTextView.setText(R.string.switch_off_text);
|
||||||
|
|
||||||
mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
|
mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
|
||||||
mSwitch.setOnCheckedChangeListener(this);
|
|
||||||
|
|
||||||
addOnSwitchChangeListener(new OnSwitchChangeListener() {
|
addOnSwitchChangeListener(new OnSwitchChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
setTextViewLabel(isChecked);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,18 +90,41 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
setVisibility(View.GONE);
|
setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToggleSwitch getSwitch() {
|
public void setTextViewLabel(boolean isChecked) {
|
||||||
|
mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChecked(boolean checked) {
|
||||||
|
setTextViewLabel(checked);
|
||||||
|
mSwitch.setChecked(checked);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChecked() {
|
||||||
|
return mSwitch.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
mTextView.setEnabled(enabled);
|
||||||
|
mSwitch.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final ToggleSwitch getSwitch() {
|
||||||
return mSwitch;
|
return mSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
TransitionManager.beginDelayedTransition((ViewGroup) getParent());
|
if (!isShowing()) {
|
||||||
setVisibility(View.VISIBLE);
|
setVisibility(View.VISIBLE);
|
||||||
|
mSwitch.setOnCheckedChangeListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
public void hide() {
|
||||||
TransitionManager.beginDelayedTransition((ViewGroup) getParent());
|
if (isShowing()) {
|
||||||
setVisibility(View.GONE);
|
setVisibility(View.GONE);
|
||||||
|
mSwitch.setOnCheckedChangeListener(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowing() {
|
public boolean isShowing() {
|
||||||
@@ -139,4 +162,69 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
}
|
}
|
||||||
mSwitchChangeListeners.remove(listener);
|
mSwitchChangeListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class SavedState extends BaseSavedState {
|
||||||
|
boolean checked;
|
||||||
|
boolean visible;
|
||||||
|
|
||||||
|
SavedState(Parcelable superState) {
|
||||||
|
super(superState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor called from {@link #CREATOR}
|
||||||
|
*/
|
||||||
|
private SavedState(Parcel in) {
|
||||||
|
super(in);
|
||||||
|
checked = (Boolean)in.readValue(null);
|
||||||
|
visible = (Boolean)in.readValue(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
|
super.writeToParcel(out, flags);
|
||||||
|
out.writeValue(checked);
|
||||||
|
out.writeValue(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SwitchBar.SavedState{"
|
||||||
|
+ Integer.toHexString(System.identityHashCode(this))
|
||||||
|
+ " checked=" + checked
|
||||||
|
+ " visible=" + visible + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR
|
||||||
|
= new Parcelable.Creator<SavedState>() {
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Parcelable onSaveInstanceState() {
|
||||||
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
|
|
||||||
|
SavedState ss = new SavedState(superState);
|
||||||
|
ss.checked = mSwitch.isChecked();
|
||||||
|
ss.visible = isShowing();
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRestoreInstanceState(Parcelable state) {
|
||||||
|
SavedState ss = (SavedState) state;
|
||||||
|
|
||||||
|
super.onRestoreInstanceState(ss.getSuperState());
|
||||||
|
mSwitch.setChecked(ss.checked);
|
||||||
|
setTextViewLabel(ss.checked);
|
||||||
|
setVisibility(ss.visible ? View.VISIBLE : View.GONE);
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -96,20 +96,26 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
|||||||
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume(Context context) {
|
public void setupSwitchBar() {
|
||||||
mContext = context;
|
|
||||||
// Wi-Fi state is sticky, so just let the receiver update UI
|
|
||||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
mSwitchBar.show();
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void teardownSwitchBar() {
|
||||||
mContext.unregisterReceiver(mReceiver);
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
mSwitchBar.hide();
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resume(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
// Wi-Fi state is sticky, so just let the receiver update UI
|
||||||
|
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
mContext.unregisterReceiver(mReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleWifiStateChanged(int state) {
|
private void handleWifiStateChanged(int state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WifiManager.WIFI_STATE_ENABLING:
|
case WifiManager.WIFI_STATE_ENABLING:
|
||||||
|
@@ -404,6 +404,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
|
||||||
|
if (mWifiEnabler != null) {
|
||||||
|
mWifiEnabler.teardownSwitchBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@@ -414,6 +423,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
mSwitchBar = activity.getSwitchBar();
|
||||||
mWifiEnabler = new WifiEnabler(activity, mSwitchBar);
|
mWifiEnabler = new WifiEnabler(activity, mSwitchBar);
|
||||||
|
mWifiEnabler.setupSwitchBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user