Finished the location settings
Change-Id: I333fcc74ad387ef6edaa558656d3eaa91feb8fe9
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.settings.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
/**
|
||||
* A page with 3 radio buttons to choose the location mode.
|
||||
@@ -34,8 +34,15 @@ import com.android.settings.SettingsPreferenceFragment;
|
||||
*
|
||||
* Sensors only: use GPS location only.
|
||||
*/
|
||||
public class LocationMode extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
public class LocationMode extends LocationSettingsBase
|
||||
implements RadioButtonPreference.OnClickListener {
|
||||
private static final String KEY_HIGH_ACCURACY = "high_accuracy";
|
||||
private RadioButtonPreference mHighAccuracy;
|
||||
private static final String KEY_BATTERY_SAVING = "battery_saving";
|
||||
private RadioButtonPreference mBatterySaving;
|
||||
private static final String KEY_SENSORS_ONLY = "sensors_only";
|
||||
private RadioButtonPreference mSensorsOnly;
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -45,10 +52,18 @@ public class LocationMode extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// Make sure we reload the preference hierarchy since some of these settings
|
||||
// depend on others...
|
||||
createPreferenceHierarchy();
|
||||
mHighAccuracy.resume();
|
||||
mBatterySaving.resume();
|
||||
mSensorsOnly.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mHighAccuracy.pause();
|
||||
mBatterySaving.pause();
|
||||
mSensorsOnly.pause();
|
||||
}
|
||||
|
||||
private PreferenceScreen createPreferenceHierarchy() {
|
||||
@@ -59,16 +74,74 @@ public class LocationMode extends SettingsPreferenceFragment
|
||||
addPreferencesFromResource(R.xml.location_mode);
|
||||
root = getPreferenceScreen();
|
||||
|
||||
mHighAccuracy = (RadioButtonPreference) root.findPreference(KEY_HIGH_ACCURACY);
|
||||
mBatterySaving = (RadioButtonPreference) root.findPreference(KEY_BATTERY_SAVING);
|
||||
mSensorsOnly = (RadioButtonPreference) root.findPreference(KEY_SENSORS_ONLY);
|
||||
mHighAccuracy.setOnClickListener(this);
|
||||
mBatterySaving.setOnClickListener(this);
|
||||
mSensorsOnly.setOnClickListener(this);
|
||||
|
||||
refreshLocationMode();
|
||||
return root;
|
||||
}
|
||||
|
||||
private void updateRadioButtons(RadioButtonPreference activated) {
|
||||
if (activated == mHighAccuracy) {
|
||||
mHighAccuracy.setChecked(true);
|
||||
mBatterySaving.setChecked(false);
|
||||
mSensorsOnly.setChecked(false);
|
||||
} else if (activated == mBatterySaving) {
|
||||
mHighAccuracy.setChecked(false);
|
||||
mBatterySaving.setChecked(true);
|
||||
mSensorsOnly.setChecked(false);
|
||||
} else if (activated == mSensorsOnly) {
|
||||
mHighAccuracy.setChecked(false);
|
||||
mBatterySaving.setChecked(false);
|
||||
mSensorsOnly.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(RadioButtonPreference emiter) {
|
||||
int mode = LocationSettingsBase.MODE_LOCATION_OFF;
|
||||
if (emiter == mHighAccuracy) {
|
||||
mode = LocationSettingsBase.MODE_HIGH_ACCURACY;
|
||||
} else if (emiter == mBatterySaving) {
|
||||
mode = LocationSettingsBase.MODE_BATTERY_SAVING;
|
||||
} else if (emiter == mSensorsOnly) {
|
||||
mode = LocationSettingsBase.MODE_SENSORS_ONLY;
|
||||
}
|
||||
setLocationMode(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModeChanged(int mode) {
|
||||
switch (mode) {
|
||||
case MODE_LOCATION_OFF:
|
||||
Intent intent = new Intent();
|
||||
PreferenceActivity pa = (PreferenceActivity) getActivity();
|
||||
pa.finishPreferencePanel(LocationMode.this, Activity.RESULT_OK, intent);
|
||||
break;
|
||||
case MODE_SENSORS_ONLY:
|
||||
updateRadioButtons(mSensorsOnly);
|
||||
break;
|
||||
case MODE_BATTERY_SAVING:
|
||||
updateRadioButtons(mBatterySaving);
|
||||
break;
|
||||
case MODE_HIGH_ACCURACY:
|
||||
updateRadioButtons(mHighAccuracy);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
boolean enabled = (mode != MODE_LOCATION_OFF);
|
||||
mHighAccuracy.setEnabled(enabled);
|
||||
mBatterySaving.setEnabled(enabled);
|
||||
mSensorsOnly.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_location_access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user