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

Commit e6314232 authored by Lifu Tang's avatar Lifu Tang
Browse files

Finished the location settings

Change-Id: I333fcc74ad387ef6edaa558656d3eaa91feb8fe9
parent 2500f7a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -818,6 +818,7 @@
        </activity>

        <activity android:name="Settings$LocationSettingsActivity"
                android:uiOptions="splitActionBarWhenNarrow"
                android:label="@string/location_settings_title"
                android:configChanges="orientation|keyboardHidden|screenSize"
                android:taskAffinity=""
+5 −3
Original line number Diff line number Diff line
@@ -2362,17 +2362,19 @@
    <string name="location_mode_battery_saving_title">Battery saving</string>
    <!-- [CHAR LIMIT=30] Location settings screen, device sensors only location mode -->
    <string name="location_mode_sensors_only_title">Device sensors only</string>
    <!-- [CHAR LIMIT=30] Location settings screen, location off mode -->
    <string name="location_mode_location_off_title">Location off</string>
    <!-- [CHAR LIMIT=30] Location settings screen, sub category for recent location requests -->
    <string name="location_category_recent_location_requests">Recent location requests</string>
    <!-- [CHAR LIMIT=30] Location settings screen, sub category for location services -->
    <string name="location_category_location_services">Location services</string>
    <!-- [CHAR LIMIT=30] Location mode screen, screen title -->
    <string name="location_mode_screen_title">Location mode</string>
    <!-- [CHAR LIMIT=30] Location mode screen, description for high accuracy mode -->
    <!-- [CHAR LIMIT=130] Location mode screen, description for high accuracy mode -->
    <string name="location_mode_high_accuracy_description">Use GPS, Wi\u2011Fi and mobile networks to estimate location </string>
    <!-- [CHAR LIMIT=30] Location mode screen, description for battery saving mode -->
    <!-- [CHAR LIMIT=130] Location mode screen, description for battery saving mode -->
    <string name="location_mode_battery_saving_description">Use Wi\u2011Fi and mobile networks to estimate location</string>
    <!-- [CHAR LIMIT=30] Location mode screen, description for sensors only mode -->
    <!-- [CHAR LIMIT=130] Location mode screen, description for sensors only mode -->
    <string name="location_mode_sensors_only_description">Use GPS to pinpoint your location</string>

    <!-- [CHAR LIMIT=30] Security & location settings screen, setting check box label for Google location service (cell ID, wifi, etc.) -->
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
        <PreferenceScreen
            android:key="location_mode"
            android:title="@string/location_mode_title"
            android:summary="@string/location_mode_high_accuracy_title" />
            android:summary="@string/location_mode_location_off_title" />

        <PreferenceCategory
            android:key="recent_location_requests"
+0 −76
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.location;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.CompoundButton;
import android.widget.Switch;

/**
 * LocationEnabler is a helper to manage the Location on/off master switch
 * preference. It turns on/off Location master switch and ensures the summary
 * of the preference reflects the current state.
 */
public final class LocationEnabler implements CompoundButton.OnCheckedChangeListener {
    private final Context mContext;
    private Switch mSwitch;
    private boolean mValidListener;

    // TODO(lifu): listens to the system configuration change, and modify the switch state whenever
    // necessary.
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
        }
    };

    public LocationEnabler(Context context, Switch switch_) {
        mContext = context;
        mSwitch = switch_;
        mValidListener = false;
    }

    public void resume() {
        mSwitch.setOnCheckedChangeListener(this);
        mValidListener = true;
    }

    public void pause() {
        mSwitch.setOnCheckedChangeListener(null);
        mValidListener = false;
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // TODO(lifu): modify the actual location settings when the user flip the master switch.
    }

    private void setChecked(boolean isChecked) {
        if (isChecked != mSwitch.isChecked()) {
            // set listener to null so that that code below doesn't trigger onCheckedChanged()
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(null);
            }
            mSwitch.setChecked(isChecked);
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(this);
            }
        }
    }
}
+84 −11
Original line number Diff line number Diff line
@@ -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 int getHelpResource() {
        return R.string.help_url_location_access;
    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 boolean onPreferenceChange(Preference preference, Object newValue) {
      return true;
    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;
    }
}
Loading