Use SwitchBar for Development Settings
- follow up CL to 4193776698
Related to bug #14898161 On/Off switches must move down from Action Bar
Change-Id: I2db49f9d982e4d759f7eeb3623c95cbe53a5ff53
This commit is contained in:
@@ -66,6 +66,7 @@ import android.widget.CompoundButton;
|
|||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
import dalvik.system.VMRuntime;
|
import dalvik.system.VMRuntime;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -78,7 +79,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class DevelopmentSettings extends SettingsPreferenceFragment
|
public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||||
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
|
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
|
||||||
OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
|
OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener {
|
||||||
private static final String TAG = "DevelopmentSettings";
|
private static final String TAG = "DevelopmentSettings";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,6 +164,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
private DevicePolicyManager mDpm;
|
private DevicePolicyManager mDpm;
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
|
||||||
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mEnabledSwitch;
|
private Switch mEnabledSwitch;
|
||||||
private boolean mLastEnabledState;
|
private boolean mLastEnabledState;
|
||||||
private boolean mHaveDebugSettings;
|
private boolean mHaveDebugSettings;
|
||||||
@@ -377,37 +379,27 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
mEnabledSwitch = new Switch(activity.getActionBar().getThemedContext());
|
|
||||||
|
|
||||||
final int padding = activity.getResources().getDimensionPixelSize(
|
mSwitchBar = activity.getSwitchBar();
|
||||||
R.dimen.action_bar_switch_padding);
|
mEnabledSwitch = mSwitchBar.getSwitch();
|
||||||
mEnabledSwitch.setPaddingRelative(0, 0, padding, 0);
|
|
||||||
if (mUnavailable) {
|
if (mUnavailable) {
|
||||||
mEnabledSwitch.setEnabled(false);
|
mEnabledSwitch.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mEnabledSwitch.setOnCheckedChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
final Activity activity = getActivity();
|
mSwitchBar.show();
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
final Activity activity = getActivity();
|
mSwitchBar.hide();
|
||||||
activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
activity.getActionBar().setCustomView(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removePreferenceForProduction(Preference preference) {
|
private boolean removePreferenceForProduction(Preference preference) {
|
||||||
@@ -1217,28 +1209,29 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
if (buttonView == mEnabledSwitch) {
|
if (switchView != mEnabledSwitch) {
|
||||||
if (isChecked != mLastEnabledState) {
|
return;
|
||||||
if (isChecked) {
|
}
|
||||||
mDialogClicked = false;
|
if (isChecked != mLastEnabledState) {
|
||||||
if (mEnableDialog != null) dismissDialogs();
|
if (isChecked) {
|
||||||
mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
|
mDialogClicked = false;
|
||||||
getActivity().getResources().getString(
|
if (mEnableDialog != null) dismissDialogs();
|
||||||
R.string.dev_settings_warning_message))
|
mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
|
||||||
.setTitle(R.string.dev_settings_warning_title)
|
getActivity().getResources().getString(
|
||||||
.setIconAttribute(android.R.attr.alertDialogIcon)
|
R.string.dev_settings_warning_message))
|
||||||
.setPositiveButton(android.R.string.yes, this)
|
.setTitle(R.string.dev_settings_warning_title)
|
||||||
.setNegativeButton(android.R.string.no, this)
|
.setIconAttribute(android.R.attr.alertDialogIcon)
|
||||||
.show();
|
.setPositiveButton(android.R.string.yes, this)
|
||||||
mEnableDialog.setOnDismissListener(this);
|
.setNegativeButton(android.R.string.no, this)
|
||||||
} else {
|
.show();
|
||||||
resetDangerousOptions();
|
mEnableDialog.setOnDismissListener(this);
|
||||||
Settings.Global.putInt(getActivity().getContentResolver(),
|
} else {
|
||||||
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
resetDangerousOptions();
|
||||||
mLastEnabledState = isChecked;
|
Settings.Global.putInt(getActivity().getContentResolver(),
|
||||||
setPrefsEnabledState(mLastEnabledState);
|
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
|
||||||
}
|
mLastEnabledState = isChecked;
|
||||||
|
setPrefsEnabledState(mLastEnabledState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user