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:
Fabrice Di Meglio
2014-05-14 20:14:27 -07:00
parent 3041003503
commit f02db01ba6

View File

@@ -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) {