diff options
author | Joey <joey@lineageos.org> | 2015-06-20 15:37:04 +0000 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2019-11-16 22:14:37 +0000 |
commit | f1bbf242b0839d9c4e3ff54737dc32315d3e379c (patch) | |
tree | 45283c026e662ab070bcab9d0d3009634ceb5e47 /packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java | |
parent | e7f3c30e243b8eb4d689a902867c469b6b9044cf (diff) | |
download | android_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.tar.gz android_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.tar.bz2 android_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.zip |
SystemUI: Advanced location tile
Includes the following:
* base: LocationTile detail (I968e26b6e5e4ad0acdb347c4acc03994b73ca74b)
* LocationTile: Behave like other tiles (I9767b9f2e812f85c664ff7721ff3d8dc9ba54aca)
* UI improvements for Oreo changes
* LocationTile: Improve strings
* SystemUI: Improve location tile descriptions
Change-Id: I8ce53f535a8d52fead2e518316b4bbb716a06d75
Signed-off-by: Joey <joey@lineageos.org>
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java | 212 |
1 files changed, 199 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java index 837ea9fc5f4..497b4f3c182 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java @@ -1,5 +1,7 @@ /* * Copyright (C) 2014 The Android Open Source Project + * Copyright (C) 2016 The ParanoidAndroid Project + * Copyright (C) 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,21 +18,32 @@ package com.android.systemui.qs.tiles; +import android.content.Context; import android.content.Intent; import android.os.UserManager; import android.provider.Settings; import android.service.quicksettings.Tile; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.Switch; +import android.widget.TextView; +import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.systemui.R; import com.android.systemui.plugins.ActivityStarter; +import com.android.systemui.plugins.qs.DetailAdapter; import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.qs.QSHost; import com.android.systemui.qs.tileimpl.QSTileImpl; import com.android.systemui.statusbar.policy.KeyguardMonitor; import com.android.systemui.statusbar.policy.LocationController; import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback; +import com.android.systemui.volume.SegmentedButtons; + +import org.lineageos.internal.logging.LineageMetricsLogger; import javax.inject.Inject; @@ -39,10 +52,15 @@ public class LocationTile extends QSTileImpl<BooleanState> { private final Icon mIcon = ResourceIcon.get(R.drawable.ic_location); + private static final Intent LOCATION_SETTINGS_INTENT = + new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + private final LocationController mController; + private final LocationDetailAdapter mDetailAdapter; private final KeyguardMonitor mKeyguard; private final ActivityStarter mActivityStarter; private final Callback mCallback = new Callback(); + private int mLastState; @Inject public LocationTile(QSHost host, LocationController locationController, @@ -53,6 +71,7 @@ public class LocationTile extends QSTileImpl<BooleanState> { mActivityStarter = activityStarter; mController.observe(this, mCallback); mKeyguard.observe(this, mCallback); + mDetailAdapter = (LocationDetailAdapter) createDetailAdapter(); } @Override @@ -61,6 +80,17 @@ public class LocationTile extends QSTileImpl<BooleanState> { } @Override + public DetailAdapter getDetailAdapter() { + return mDetailAdapter; + } + + @Override + protected DetailAdapter createDetailAdapter() { + return new LocationDetailAdapter(); + } + + + @Override public void handleSetListening(boolean listening) { } @@ -71,6 +101,13 @@ public class LocationTile extends QSTileImpl<BooleanState> { @Override protected void handleClick() { + final boolean wasEnabled = mState.value; + MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); + mController.setLocationEnabled(!wasEnabled); + } + + @Override + protected void handleSecondaryClick() { if (mKeyguard.isSecure() && mKeyguard.isShowing()) { mActivityStarter.postQSRunnableDismissingKeyguard(() -> { final boolean wasEnabled = mState.value; @@ -80,7 +117,10 @@ public class LocationTile extends QSTileImpl<BooleanState> { return; } final boolean wasEnabled = mState.value; - mController.setLocationEnabled(!wasEnabled); + if (!wasEnabled) { + mController.setLocationEnabled(!wasEnabled); + } + showDetail(true); } @Override @@ -93,31 +133,70 @@ public class LocationTile extends QSTileImpl<BooleanState> { if (state.slash == null) { state.slash = new SlashState(); } - final boolean locationEnabled = mController.isLocationEnabled(); + int currentState = arg instanceof Integer ? (Integer) arg : + mController.getLocationCurrentState(); + final boolean newValue = currentState != Settings.Secure.LOCATION_MODE_OFF; + final boolean valueChanged = state.value != newValue; // Work around for bug 15916487: don't show location tile on top of lock screen. After the // bug is fixed, this should be reverted to only hiding it on secure lock screens: // state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing()); - state.value = locationEnabled; + state.value = newValue; + state.dualTarget = true; checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION); if (state.disabledByPolicy == false) { checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_LOCATION); } - state.icon = mIcon; - state.slash.isSlashed = !state.value; - if (locationEnabled) { - state.label = mContext.getString(R.string.quick_settings_location_label); - state.contentDescription = mContext.getString( - R.string.accessibility_quick_settings_location_on); - } else { - state.label = mContext.getString(R.string.quick_settings_location_label); - state.contentDescription = mContext.getString( - R.string.accessibility_quick_settings_location_off); + state.label = mContext.getString(getStateLabelRes(currentState)); + state.slash.isSlashed = currentState == Settings.Secure.LOCATION_MODE_OFF; + switch (currentState) { + case Settings.Secure.LOCATION_MODE_OFF: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_off); + state.icon = mIcon; + break; + case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_high_accuracy); + state.icon = mIcon; + break; + case Settings.Secure.LOCATION_MODE_BATTERY_SAVING: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_battery_saving); + state.icon = ResourceIcon.get(R.drawable.ic_qs_location_battery_saving); + break; + case Settings.Secure.LOCATION_MODE_SENSORS_ONLY: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_gps_only); + state.icon = ResourceIcon.get(R.drawable.ic_qs_location_sensors_only); + break; + default: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_on); + state.icon = mIcon; + } + if (valueChanged) { + fireToggleStateChanged(state.value); } state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; state.expandedAccessibilityClassName = Switch.class.getName(); } + 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_HIGH_ACCURACY: + return R.string.quick_settings_location_high_accuracy_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; + default: + return R.string.quick_settings_location_label; + } + } + @Override public int getMetricsCategory() { return MetricsEvent.QS_LOCATION; @@ -144,4 +223,111 @@ public class LocationTile extends QSTileImpl<BooleanState> { refreshState(); } }; + + private class LocationDetailAdapter implements DetailAdapter { + + private SegmentedButtons mButtons; + private ViewGroup mMessageContainer; + private TextView mMessageText; + + @Override + public int getMetricsCategory() { + return LineageMetricsLogger.TILE_LOCATION_DETAIL; + } + + @Override + public CharSequence getTitle() { + return mContext.getString(R.string.quick_settings_location_detail_title); + } + + @Override + public Boolean getToggleState() { + return mState.value; + } + + @Override + public Intent getSettingsIntent() { + return LOCATION_SETTINGS_INTENT; + } + + @Override + public void setToggleState(boolean state) { + MetricsLogger.action(mContext, MetricsEvent.QS_DND_TOGGLE, state); + if (!state) { + mController.setLocationEnabled(state); + showDetail(false); + } + } + + @Override + public View createDetailView(Context context, View convertView, ViewGroup parent) { + final LinearLayout details = convertView != null ? (LinearLayout) convertView + : (LinearLayout) LayoutInflater.from(context).inflate( + R.layout.location_mode_panel, parent, false); + + mLastState = mController.getLocationCurrentState(); + + if (convertView == null) { + mButtons = (SegmentedButtons) details.findViewById(R.id.location_buttons); + mButtons.addButton(R.string.quick_settings_location_high_accuracy_label_twoline, + R.string.quick_settings_location_high_accuracy_label, + Settings.Secure.LOCATION_MODE_HIGH_ACCURACY); + mButtons.addButton(R.string.quick_settings_location_battery_saving_label_twoline, + R.string.quick_settings_location_battery_saving_label, + Settings.Secure.LOCATION_MODE_BATTERY_SAVING); + mButtons.addButton(R.string.quick_settings_location_gps_only_label_twoline, + R.string.quick_settings_location_gps_only_label, + Settings.Secure.LOCATION_MODE_SENSORS_ONLY); + mButtons.setCallback(mButtonsCallback); + mMessageContainer = (ViewGroup) details.findViewById(R.id.location_introduction); + mMessageText = (TextView) details.findViewById(R.id.location_introduction_message); + } + + mButtons.setSelectedValue(mLastState, false /* fromClick */); + refresh(mLastState); + + return details; + } + + private void refresh(int state) { + switch (state) { + case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY: + mMessageText.setText(mContext.getString( + R.string.quick_settings_location_detail_mode_high_accuracy_description)); + mMessageContainer.setVisibility(View.VISIBLE); + break; + case Settings.Secure.LOCATION_MODE_BATTERY_SAVING: + mMessageText.setText(mContext.getString( + R.string.quick_settings_location_detail_mode_battery_saving_description)); + mMessageContainer.setVisibility(View.VISIBLE); + break; + case Settings.Secure.LOCATION_MODE_SENSORS_ONLY: + mMessageText.setText(mContext.getString( + R.string.quick_settings_location_detail_mode_sensors_only_description)); + mMessageContainer.setVisibility(View.VISIBLE); + break; + default: + mMessageContainer.setVisibility(View.GONE); + break; + } + } + + private final SegmentedButtons.Callback mButtonsCallback = new SegmentedButtons.Callback() { + @Override + public void onSelected(final Object value, boolean fromClick) { + if (value != null && mButtons.isShown()) { + mLastState = (Integer) value; + if (fromClick) { + MetricsLogger.action(mContext, MetricsEvent.QS_LOCATION, mLastState); + mController.setLocationMode(mLastState); + refresh(mLastState); + } + } + } + + @Override + public void onInteraction() { + } + }; + } } |