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

Commit f02db01b authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Use SwitchBar for Development Settings

- follow up CL to 41937766

Related to bug #14898161 On/Off switches must move down from Action Bar

Change-Id: I2db49f9d982e4d759f7eeb3623c95cbe53a5ff53
parent 30410035
Loading
Loading
Loading
Loading
+32 −39
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import com.android.settings.widget.SwitchBar;
import dalvik.system.VMRuntime;

import java.io.File;
@@ -78,7 +79,7 @@ import java.util.List;
 */
public class DevelopmentSettings extends SettingsPreferenceFragment
        implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
                OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
                OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener {
    private static final String TAG = "DevelopmentSettings";

    /**
@@ -163,6 +164,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private DevicePolicyManager mDpm;
    private UserManager mUm;

    private SwitchBar mSwitchBar;
    private Switch mEnabledSwitch;
    private boolean mLastEnabledState;
    private boolean mHaveDebugSettings;
@@ -377,37 +379,27 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        final Activity activity = getActivity();
        mEnabledSwitch = new Switch(activity.getActionBar().getThemedContext());
        final SettingsActivity activity = (SettingsActivity) getActivity();

        final int padding = activity.getResources().getDimensionPixelSize(
                R.dimen.action_bar_switch_padding);
        mEnabledSwitch.setPaddingRelative(0, 0, padding, 0);
        mSwitchBar = activity.getSwitchBar();
        mEnabledSwitch = mSwitchBar.getSwitch();
        if (mUnavailable) {
            mEnabledSwitch.setEnabled(false);
            return;
        }
        mEnabledSwitch.setOnCheckedChangeListener(this);
        mSwitchBar.addOnSwitchChangeListener(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        final Activity activity = getActivity();
        activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                ActionBar.DISPLAY_SHOW_CUSTOM);
        activity.getActionBar().setCustomView(mEnabledSwitch, new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_VERTICAL | Gravity.END));
        mSwitchBar.show();
    }

    @Override
    public void onStop() {
        super.onStop();
        final Activity activity = getActivity();
        activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
        activity.getActionBar().setCustomView(null);
        mSwitchBar.hide();
    }

    private boolean removePreferenceForProduction(Preference preference) {
@@ -1217,8 +1209,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView == mEnabledSwitch) {
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        if (switchView != mEnabledSwitch) {
            return;
        }
        if (isChecked != mLastEnabledState) {
            if (isChecked) {
                mDialogClicked = false;
@@ -1241,7 +1235,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            }
        }
    }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {