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

Commit ca271ea6 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: clean up Location tile



* Match logic in other list-bearing toggles for consistency

Change-Id: Ibd9913160ec1034085cab4af5d7dccd529946040
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 5b4f5a5a
Loading
Loading
Loading
Loading
+0 −68
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2014 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.
-->
<com.android.systemui.qs.tiles.LocationDetailView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="16dp"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:orientation="vertical" >

        <RadioGroup
            android:id="@+id/radiogroup_location"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        <RadioButton android:id="@+id/radio_high_accuracy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/detail_radio_group_padding"
            android:paddingLeft="@dimen/detail_radio_group_padding_left"
            android:paddingRight="@dimen/detail_radio_group_padding"
            android:paddingBottom="@dimen/detail_radio_group_padding"
            android:textAppearance="@style/TextAppearance.QS.DetailItemPrimary"
            android:text="@string/quick_settings_location_high_accuracy_label" />
        <RadioButton android:id="@+id/radio_battery_saving"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/detail_radio_group_padding"
            android:paddingLeft="@dimen/detail_radio_group_padding_left"
            android:paddingRight="@dimen/detail_radio_group_padding"
            android:paddingBottom="@dimen/detail_radio_group_padding"
            android:textAppearance="@style/TextAppearance.QS.DetailItemPrimary"
            android:text="@string/quick_settings_location_battery_saving_label" />
        <RadioButton android:id="@+id/radio_sensors_only"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/detail_radio_group_padding"
            android:paddingLeft="@dimen/detail_radio_group_padding_left"
            android:paddingRight="@dimen/detail_radio_group_padding"
            android:paddingBottom="@dimen/detail_radio_group_padding"
            android:textAppearance="@style/TextAppearance.QS.DetailItemPrimary"
            android:text="@string/quick_settings_location_gps_only_label" />
        </RadioGroup>
    </LinearLayout>

</com.android.systemui.qs.tiles.LocationDetailView>
+4 −3
Original line number Diff line number Diff line
@@ -25,16 +25,17 @@

    <ListView
        android:id="@android:id/list"
        android:divider="@null"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" />

    <LinearLayout
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center_horizontal"
            android:gravity="center"
            android:orientation="vertical" >

        <ImageView
+0 −106
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.systemui.qs.tiles;

import android.content.Context;
import android.provider.Settings;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.android.systemui.R;
import com.android.systemui.statusbar.policy.LocationController;

/**
 * Layout for the location detail in quick settings.
 */
public class LocationDetailView extends LinearLayout {

    private RadioGroup mRadioGroup;
    private RadioButton mHighAccuracy;
    private RadioButton mBatterySaving;
    private RadioButton mSensorsOnly;

    //private Context mContext;
    private LocationController mController;

    public LocationDetailView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_location);
        mHighAccuracy = (RadioButton) findViewById(R.id.radio_high_accuracy);
        mBatterySaving = (RadioButton) findViewById(R.id.radio_battery_saving);
        mSensorsOnly = (RadioButton) findViewById(R.id.radio_sensors_only);
        
        mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                onRadioButtonClicked(checkedId);
            }
        });
    }

    public void setLocationController(LocationController controller) {
        mController = controller;
    }

    public void onRadioButtonClicked(int checkedId) {
        switch(checkedId) {
            case R.id.radio_high_accuracy:
                mController.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
                break;
            case R.id.radio_battery_saving:
                mController.setLocationMode(Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
                break;
            case R.id.radio_sensors_only:
                mController.setLocationMode(Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
                break;
            default: break;
        }
    }

    public void setLocationMode(int mode) {
        boolean enabled = mode != Settings.Secure.LOCATION_MODE_OFF;

        switch(mode) {
            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
                mRadioGroup.check(mHighAccuracy.getId());
                break;
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                mRadioGroup.check(mBatterySaving.getId());
                break;
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                mRadioGroup.check(mSensorsOnly.getId());
                break;
            default: break;
        }

        mHighAccuracy.setEnabled(enabled);
        mBatterySaving.setEnabled(enabled);
        mSensorsOnly.setEnabled(enabled);
    }
}
+92 −29
Original line number Diff line number Diff line
@@ -23,17 +23,33 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ListView;
import com.android.systemui.R;
import com.android.systemui.qs.QSDetailItems;
import com.android.systemui.qs.QSDetailItemsList;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.LocationController.LocationSettingsChangeCallback;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/** Quick settings tile: Location **/
public class LocationTile extends QSTile<QSTile.BooleanState> {
    private static final Intent LOCATION_SETTINGS = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    private static final Intent LOCATION_SETTINGS_INTENT
            = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    public static final Integer[] LOCATION_SETTINGS = new Integer[]{
            Settings.Secure.LOCATION_MODE_BATTERY_SAVING,
            Settings.Secure.LOCATION_MODE_SENSORS_ONLY,
            Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
    };

    private final List<Integer> mLocationList = new ArrayList<>();
    private final LocationController mController;
    private final LocationDetailAdapter mDetailAdapter;
    private final KeyguardMonitor mKeyguard;
@@ -78,7 +94,7 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {

    @Override
    protected void handleLongClick() {
        mHost.startSettingsActivity(LOCATION_SETTINGS);
        mHost.startSettingsActivity(LOCATION_SETTINGS_INTENT);
    }

    @Override
@@ -91,31 +107,47 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
        // state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing());
        state.visible = !mKeyguard.isShowing();
        state.value = locationEnabled;
        state.label = mContext.getString(getStateLabelRes(currentState));

        switch (currentState) {
            case Settings.Secure.LOCATION_MODE_OFF:
                state.label = mContext.getString(R.string.quick_settings_location_off_label);
                state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_location_off);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_location_off);
                state.iconId = R.drawable.ic_qs_location_off;
                break;
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                state.label = mContext.getString(R.string.quick_settings_location_battery_saving_label);
                state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_location_battery_saving);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_location_battery_saving);
                state.iconId = R.drawable.ic_qs_location_battery_saving;
                break;
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                state.label = mContext.getString(R.string.quick_settings_location_gps_only_label);
                state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_location_gps_only);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_location_gps_only);
                state.iconId = R.drawable.ic_qs_location_on;
                break;
            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
                state.label = mContext.getString(R.string.quick_settings_location_high_accuracy_label);
                state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_location_high_accuracy);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_location_high_accuracy);
                state.iconId = R.drawable.ic_qs_location_on;
                break;
            default:
                state.label = mContext.getString(R.string.quick_settings_location_label);
                state.contentDescription = mContext.getString(R.string.accessibility_quick_settings_location_on);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_location_on);
        }
    }

    private int getStateLabelRes(int currentState) {
        switch (currentState) {
            case Settings.Secure.LOCATION_MODE_OFF:
                return R.string.quick_settings_location_off_label;
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
                return R.string.quick_settings_location_battery_saving_label;
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                return R.string.quick_settings_location_gps_only_label;
            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
                return R.string.quick_settings_location_high_accuracy_label;
            default:
                return R.string.quick_settings_location_label;
        }
    }

@@ -132,8 +164,6 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
            KeyguardMonitor.Callback {
        @Override
        public void onLocationSettingsChanged(boolean enabled) {
            mDetailAdapter.setLocationEnabled(enabled);
            mDetailAdapter.setLocationMode(mController.getLocationCurrentState());
            refreshState();
        }

@@ -143,9 +173,25 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
        }
    };

    private class LocationDetailAdapter implements DetailAdapter {
    private class AdvancedLocationAdapter extends ArrayAdapter<Integer> {
        public AdvancedLocationAdapter(Context context) {
            super(context, android.R.layout.simple_list_item_single_choice, mLocationList);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            CheckedTextView label = (CheckedTextView) inflater.inflate(
                    android.R.layout.simple_list_item_single_choice, parent, false);
            label.setText(getStateLabelRes(getItem(position)));
            return label;
        }
    }

        private LocationDetailView mLocationDetailView;
    private class LocationDetailAdapter implements DetailAdapter, AdapterView.OnItemClickListener {

        private AdvancedLocationAdapter mAdapter;
        private QSDetailItemsList mDetails;

        @Override
        public int getTitle() {
@@ -154,35 +200,52 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {

        @Override
        public Boolean getToggleState() {
            return mController.getLocationCurrentState() != Settings.Secure.LOCATION_MODE_OFF;
            boolean state = mController.getLocationCurrentState()
                    != Settings.Secure.LOCATION_MODE_OFF;
            rebuildLocationList(state);
            return state;
        }

        @Override
        public Intent getSettingsIntent() {
            return LOCATION_SETTINGS;
            return LOCATION_SETTINGS_INTENT;
        }

        @Override
        public void setToggleState(boolean state) {
            mController.setLocationEnabled(state);
            rebuildLocationList(state);
            fireToggleStateChanged(state);
        }

        @Override
        public View createDetailView(Context context, View convertView, ViewGroup parent) {
            final LocationDetailView v = (LocationDetailView) (LayoutInflater.from(mContext).inflate(R.layout.location, parent, false));
            mLocationDetailView = v;
            mLocationDetailView.setLocationController(mController);
            setLocationMode(mController.getLocationCurrentState());
            return v;
            mDetails = QSDetailItemsList.convertOrInflate(context, convertView, parent);
            mDetails.setEmptyState(R.drawable.ic_qs_location_off,
                    R.string.accessibility_quick_settings_location_off);
            mAdapter = new LocationTile.AdvancedLocationAdapter(context);
            mDetails.setAdapter(mAdapter);

            final ListView list = mDetails.getListView();
            list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
            list.setOnItemClickListener(this);

            return mDetails;
        }

        public void setLocationEnabled(boolean enabled) {
            fireToggleStateChanged(enabled);
        private void rebuildLocationList(boolean populate) {
            mLocationList.clear();
            if (populate) {
                mLocationList.addAll(Arrays.asList(LOCATION_SETTINGS));
                mDetails.getListView().setItemChecked(mAdapter.getPosition(
                        mController.getLocationCurrentState()), true);
            }
            mAdapter.notifyDataSetChanged();
        }

        public void setLocationMode(int mode) {
            if(mLocationDetailView != null)
                mLocationDetailView.setLocationMode(mode);
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mController.setLocationMode((Integer) parent.getItemAtPosition(position));
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ public class ProfilesTile extends QSTile<QSTile.State> {

            final ListView list = mDetails.getListView();
            list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
            list.setDivider(null);
            list.setOnItemClickListener(this);

            mDetails.setEmptyState(R.drawable.ic_qs_system_profiles,