Use SwitchBar for Location Settings
- follow up CL to 4193776698
Related to bug #14898161 On/Off switches must move down from Action Bar
Change-Id: Ic46768d97fef3abbec3f46f90037d366c123a6e8
This commit is contained in:
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -29,12 +27,11 @@ import android.preference.PreferenceCategory;
|
|||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -44,7 +41,7 @@ import java.util.List;
|
|||||||
* Location access settings.
|
* Location access settings.
|
||||||
*/
|
*/
|
||||||
public class LocationSettings extends LocationSettingsBase
|
public class LocationSettings extends LocationSettingsBase
|
||||||
implements CompoundButton.OnCheckedChangeListener {
|
implements SwitchBar.OnSwitchChangeListener {
|
||||||
|
|
||||||
private static final String TAG = "LocationSettings";
|
private static final String TAG = "LocationSettings";
|
||||||
|
|
||||||
@@ -55,6 +52,7 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
/** Key for preference category "Location services" */
|
/** Key for preference category "Location services" */
|
||||||
private static final String KEY_LOCATION_SERVICES = "location_services";
|
private static final String KEY_LOCATION_SERVICES = "location_services";
|
||||||
|
|
||||||
|
private SwitchBar mSwitchBar;
|
||||||
private Switch mSwitch;
|
private Switch mSwitch;
|
||||||
private boolean mValidListener;
|
private boolean mValidListener;
|
||||||
private Preference mLocationMode;
|
private Preference mLocationMode;
|
||||||
@@ -71,43 +69,24 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
|
|
||||||
mSwitch = new Switch(activity.getActionBar().getThemedContext());
|
|
||||||
final int padding = activity.getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.action_bar_switch_padding);
|
|
||||||
mSwitch.setPaddingRelative(0, 0, padding, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
|
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
|
||||||
// Only show the master switch when we're not being used as Setup Wizard.
|
mSwitchBar = activity.getSwitchBar();
|
||||||
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
mSwitch = mSwitchBar.getSwitch();
|
||||||
ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
activity.getActionBar().setCustomView(mSwitch, 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 SettingsActivity activity = (SettingsActivity) getActivity();
|
|
||||||
activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
activity.getActionBar().setCustomView(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mValidListener = true;
|
|
||||||
createPreferenceHierarchy();
|
createPreferenceHierarchy();
|
||||||
mSwitch.setOnCheckedChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
|
mValidListener = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -118,8 +97,9 @@ 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;
|
||||||
mSwitch.setOnCheckedChangeListener(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
|
private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
|
||||||
@@ -248,11 +228,11 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
if (enabled != mSwitch.isChecked()) {
|
if (enabled != mSwitch.isChecked()) {
|
||||||
// set listener to null so that that code below doesn't trigger onCheckedChanged()
|
// set listener to null so that that code below doesn't trigger onCheckedChanged()
|
||||||
if (mValidListener) {
|
if (mValidListener) {
|
||||||
mSwitch.setOnCheckedChangeListener(null);
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
mSwitch.setChecked(enabled);
|
mSwitch.setChecked(enabled);
|
||||||
if (mValidListener) {
|
if (mValidListener) {
|
||||||
mSwitch.setOnCheckedChangeListener(this);
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// As a safety measure, also reloads on location mode change to ensure the settings are
|
// As a safety measure, also reloads on location mode change to ensure the settings are
|
||||||
@@ -264,7 +244,7 @@ public class LocationSettings extends LocationSettingsBase
|
|||||||
* Listens to the state change of the location master switch.
|
* Listens to the state change of the location master switch.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
|
setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user