diff options
author | Danesh M <daneshm90@gmail.com> | 2015-12-15 13:50:48 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-12-15 17:43:58 -0800 |
commit | acfc22ef98d862000664757c800995d2670350a2 (patch) | |
tree | 4b7b94b8f0438393a7ab2ecc8d4a998ac68e0991 /packages/SystemUI/src/com/android/systemui/qs/tiles | |
parent | 45c058ad105c5c512c2a88b542eb3ace20ee939a (diff) | |
download | frameworks_base-acfc22ef98d862000664757c800995d2670350a2.zip frameworks_base-acfc22ef98d862000664757c800995d2670350a2.tar.gz frameworks_base-acfc22ef98d862000664757c800995d2670350a2.tar.bz2 |
SystemUI : Add location tile from 12.1
Change-Id: I93fd420550d21161e14a817c29103cbdb358f63b
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/qs/tiles')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java | 210 |
1 files changed, 188 insertions, 22 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 347d079..3598bba 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java @@ -17,21 +17,44 @@ package com.android.systemui.qs.tiles; +import com.android.internal.logging.MetricsConstants; import com.android.internal.logging.MetricsLogger; +import android.content.Context; import android.content.Intent; import android.provider.Settings; +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; + +import cyanogenmod.app.StatusBarPanelCustomTile; + /** 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 AnimationIcon mEnable = new AnimationIcon(R.drawable.ic_signal_location_enable_animation); @@ -39,16 +62,24 @@ public class LocationTile extends QSTile<QSTile.BooleanState> { new AnimationIcon(R.drawable.ic_signal_location_disable_animation); private final LocationController mController; + private final LocationDetailAdapter mDetailAdapter; private final KeyguardMonitor mKeyguard; private final Callback mCallback = new Callback(); + private final List<Integer> mLocationList = new ArrayList<Integer>(); public LocationTile(Host host) { super(host); mController = host.getLocationController(); + mDetailAdapter = new LocationDetailAdapter(); mKeyguard = host.getKeyguardMonitor(); } @Override + public DetailAdapter getDetailAdapter() { + return mDetailAdapter; + } + + @Override protected BooleanState newTileState() { return new BooleanState(); } @@ -66,37 +97,74 @@ public class LocationTile extends QSTile<QSTile.BooleanState> { @Override protected void handleClick() { - final boolean wasEnabled = (Boolean) mState.value; - MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); - mController.setLocationEnabled(!wasEnabled); + if(mController.isAdvancedSettingsEnabled()) { + showDetail(true); + } else { + boolean wasEnabled = mController.isLocationEnabled(); + mController.setLocationEnabled(!wasEnabled); + MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled); + refreshState(); + } + mEnable.setAllowAnimation(true); mDisable.setAllowAnimation(true); } @Override protected void handleLongClick() { - mHost.startActivityDismissingKeyguard(LOCATION_SETTINGS); + mHost.startActivityDismissingKeyguard(LOCATION_SETTINGS_INTENT); } @Override protected void handleUpdateState(BooleanState state, Object arg) { - final boolean locationEnabled = mController.isLocationEnabled(); + final int currentState = mController.getLocationCurrentState(); // 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.visible = !mKeyguard.isShowing(); - state.value = locationEnabled; - if (locationEnabled) { - state.icon = mEnable; - state.label = mContext.getString(R.string.quick_settings_location_label); - state.contentDescription = mContext.getString( - R.string.accessibility_quick_settings_location_on); - } else { - state.icon = mDisable; - 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)); + + switch (currentState) { + case Settings.Secure.LOCATION_MODE_OFF: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_off); + state.icon = mDisable; + 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 = mEnable; + break; + case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_high_accuracy); + state.icon = mEnable; + break; + default: + state.contentDescription = mContext.getString( + R.string.accessibility_quick_settings_location_on); + state.icon = mEnable; + } + } + + 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; } } @@ -107,10 +175,22 @@ public class LocationTile extends QSTile<QSTile.BooleanState> { @Override protected String composeChangeAnnouncement() { - if (mState.value) { - return mContext.getString(R.string.accessibility_quick_settings_location_changed_on); - } else { - return mContext.getString(R.string.accessibility_quick_settings_location_changed_off); + switch (mController.getLocationCurrentState()) { + case Settings.Secure.LOCATION_MODE_OFF: + return mContext.getString( + R.string.accessibility_quick_settings_location_changed_off); + case Settings.Secure.LOCATION_MODE_BATTERY_SAVING: + return mContext.getString( + R.string.accessibility_quick_settings_location_changed_battery_saving); + case Settings.Secure.LOCATION_MODE_SENSORS_ONLY: + return mContext.getString( + R.string.accessibility_quick_settings_location_changed_gps_only); + case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY: + return mContext.getString( + R.string.accessibility_quick_settings_location_changed_high_accuracy); + default: + return mContext.getString( + R.string.accessibility_quick_settings_location_changed_on); } } @@ -126,4 +206,90 @@ public class LocationTile extends QSTile<QSTile.BooleanState> { refreshState(); } }; + + 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 class LocationDetailAdapter implements DetailAdapter, AdapterView.OnItemClickListener { + + private AdvancedLocationAdapter mAdapter; + private QSDetailItemsList mDetails; + + @Override + public int getTitle() { + return R.string.quick_settings_location_detail_title; + } + + @Override + public Boolean getToggleState() { + boolean state = mController.getLocationCurrentState() + != Settings.Secure.LOCATION_MODE_OFF; + rebuildLocationList(state); + return state; + } + + @Override + public Intent getSettingsIntent() { + return LOCATION_SETTINGS_INTENT; + } + + @Override + public StatusBarPanelCustomTile getCustomTile() { + return null; + } + + @Override + public void setToggleState(boolean state) { + mController.setLocationEnabled(state); + rebuildLocationList(state); + fireToggleStateChanged(state); + } + + @Override + public int getMetricsCategory() { + return MetricsLogger.QS_LOCATION; + } + + @Override + public View createDetailView(Context context, View convertView, ViewGroup parent) { + 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; + } + + 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(); + } + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + mController.setLocationMode((Integer) parent.getItemAtPosition(position)); + } + } } |