Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 138ff8c0 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

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
parent 601aad20
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -167,7 +167,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private WifiManager mWifiManager;

    private SwitchBar mSwitchBar;
    private Switch mEnabledSwitch;
    private boolean mLastEnabledState;
    private boolean mHaveDebugSettings;
    private boolean mDontPokeProperties;
@@ -386,11 +385,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        final SettingsActivity activity = (SettingsActivity) getActivity();

        mSwitchBar = activity.getSwitchBar();
        mEnabledSwitch = mSwitchBar.getSwitch();
       if (mUnavailable) {
            mEnabledSwitch.setEnabled(false);
            mSwitchBar.setEnabled(false);
            return;
        }

        mSwitchBar.addOnSwitchChangeListener(this);
    }

    private boolean removePreferenceForProduction(Preference preference) {
@@ -441,7 +441,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.setChecked(mLastEnabledState);
        setPrefsEnabledState(mLastEnabledState);

        if (mHaveDebugSettings && !mLastEnabledState) {
@@ -452,17 +452,15 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            Settings.Global.putInt(getActivity().getContentResolver(),
                    Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
            mLastEnabledState = true;
            mEnabledSwitch.setChecked(mLastEnabledState);
            mSwitchBar.setChecked(mLastEnabledState);
            setPrefsEnabledState(mLastEnabledState);
        }

        mSwitchBar.addOnSwitchChangeListener(this);
        mSwitchBar.show();
    }

    @Override
    public void onPause() {
        super.onPause();
    public void onDestroyView() {
        super.onDestroyView();

        mSwitchBar.removeOnSwitchChangeListener(this);
        mSwitchBar.hide();
@@ -1210,7 +1208,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment

    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        if (switchView != mEnabledSwitch) {
        if (switchView != mSwitchBar.getSwitch()) {
            return;
        }
        if (isChecked != mLastEnabledState) {
@@ -1463,7 +1461,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                setPrefsEnabledState(mLastEnabledState);
            } else {
                // Reset the toggle
                mEnabledSwitch.setChecked(false);
                mSwitchBar.setChecked(false);
            }
        }
    }
@@ -1477,7 +1475,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            mAdbDialog = null;
        } else if (dialog == mEnableDialog) {
            if (!mDialogClicked) {
                mEnabledSwitch.setChecked(false);
                mSwitchBar.setChecked(false);
            }
            mEnableDialog = null;
        }
+7 −10
Original line number Diff line number Diff line
@@ -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;

@@ -105,6 +104,9 @@ public class DreamSettings extends SettingsPreferenceFragment implements
    public void onDestroyView() {
        logd("onDestroyView()");
        super.onDestroyView();

        mSwitchBar.removeOnSwitchChangeListener(this);
        mSwitchBar.hide();
    }

    @Override
@@ -124,7 +126,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements

        final SettingsActivity sa = (SettingsActivity) getActivity();
        mSwitchBar = sa.getSwitchBar();
        mSwitch = mSwitchBar.getSwitch();
        mSwitchBar.addOnSwitchChangeListener(this);
        mSwitchBar.show();
    }

    @Override
@@ -212,9 +215,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
        super.onPause();

        mContext.unregisterReceiver(mPackageReceiver);

        mSwitchBar.removeOnSwitchChangeListener(this);
        mSwitchBar.hide();
    }

    @Override
@@ -231,9 +231,6 @@ public class DreamSettings extends SettingsPreferenceFragment implements
        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
        filter.addDataScheme(PACKAGE_SCHEME);
        mContext.registerReceiver(mPackageReceiver , filter);

        mSwitchBar.addOnSwitchChangeListener(this);
        mSwitchBar.show();
    }

    public static int getSummaryResource(Context context) {
@@ -263,8 +260,8 @@ public class DreamSettings extends SettingsPreferenceFragment implements
        logd("refreshFromBackend()");
        mRefreshing = true;
        boolean dreamsEnabled = mBackend.isEnabled();
        if (mSwitch.isChecked() != dreamsEnabled)
            mSwitch.setChecked(dreamsEnabled);
        if (mSwitchBar.isChecked() != dreamsEnabled)
            mSwitchBar.setChecked(dreamsEnabled);

        mAdapter.clear();
        if (dreamsEnabled) {
+9 −6
Original line number Diff line number Diff line
@@ -142,27 +142,30 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
                refreshPreviewText();
            }
        });
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        final boolean enabled = mCaptioningManager.isEnabled();
        SettingsActivity activity = (SettingsActivity) getActivity();
        mSwitchBar = activity.getSwitchBar();
        mSwitchBar.setTextViewLabel(enabled);
        mToggleSwitch = mSwitchBar.getSwitch();
        mToggleSwitch.setCheckedInternal(enabled);

        getPreferenceScreen().setEnabled(enabled);

        refreshPreviewText();
    }

    @Override
    public void onResume() {
        super.onResume();
        installSwitchBarToggleSwitch();
    }

    @Override
    public void onPause() {
    public void onDestroyView() {
        super.onDestroyView();
        removeSwitchBarToggleSwitch();
        super.onPause();
    }

    private void refreshPreviewText() {
+5 −5
Original line number Diff line number Diff line
@@ -95,17 +95,17 @@ public abstract class ToggleFeaturePreferenceFragment
    }

    @Override
    public void onResume() {
        super.onResume();
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        installActionBarToggleSwitch();
    }

    @Override
    public void onPause() {
        removeActionBarToggleSwitch();
    public void onDestroyView() {
        super.onDestroyView();

        super.onPause();
        removeActionBarToggleSwitch();
    }

    protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
+10 −4
Original line number Diff line number Diff line
@@ -89,6 +89,16 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
        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) {
        if (mLocalAdapter == null) {
            mSwitch.setEnabled(false);
@@ -103,8 +113,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
        handleStateChanged(mLocalAdapter.getBluetoothState());

        mContext.registerReceiver(mReceiver, mIntentFilter);
        mSwitchBar.addOnSwitchChangeListener(this);
        mSwitchBar.show();
        mValidListener = true;
    }

@@ -114,8 +122,6 @@ public final class BluetoothEnabler implements SwitchBar.OnSwitchChangeListener
        }

        mContext.unregisterReceiver(mReceiver);
        mSwitchBar.removeOnSwitchChangeListener(this);
        mSwitchBar.hide();
        mValidListener = false;
    }

Loading