From 0eb8f3eb492844954cdbfa44b660cc5a278ebcd5 Mon Sep 17 00:00:00 2001 From: Tad Date: Fri, 10 Nov 2017 17:28:06 -0500 Subject: [PATCH] Add radio power tile (1/2) Change-Id: Icec0f52b43d6bf319befa855a2dd753e9c99b98d --- packages/SystemUI/res/drawable/ic_qs_radio_off.xml | 10 ++ packages/SystemUI/res/drawable/ic_qs_radio_on.xml | 10 ++ packages/SystemUI/res/values/cm_strings.xml | 3 + packages/SystemUI/res/values/config.xml | 2 +- .../android/systemui/qs/tiles/RadioPowerTile.java | 127 +++++++++++++++++++++ .../systemui/statusbar/phone/QSTileHost.java | 2 + 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 packages/SystemUI/res/drawable/ic_qs_radio_off.xml create mode 100644 packages/SystemUI/res/drawable/ic_qs_radio_on.xml create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java diff --git a/packages/SystemUI/res/drawable/ic_qs_radio_off.xml b/packages/SystemUI/res/drawable/ic_qs_radio_off.xml new file mode 100644 index 00000000000..1cb49181faa --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_radio_off.xml @@ -0,0 +1,10 @@ + + + + diff --git a/packages/SystemUI/res/drawable/ic_qs_radio_on.xml b/packages/SystemUI/res/drawable/ic_qs_radio_on.xml new file mode 100644 index 00000000000..d446debdfc6 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_radio_on.xml @@ -0,0 +1,10 @@ + + + + diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml index b429946bd93..89e3210a21f 100644 --- a/packages/SystemUI/res/values/cm_strings.xml +++ b/packages/SystemUI/res/values/cm_strings.xml @@ -230,4 +230,7 @@ Prevent %1$s from being dismissed Allow %1$s to be dismissed + + + Radio power diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 47aacddfbd3..fe98a33d00c 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -105,7 +105,7 @@ - wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,work,cast,night,adb_network,ambient_display,caffeine,heads_up,sync,usb_tether,volume_panel,profiles + wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,nfc,location,hotspot,inversion,saver,work,cast,night,adb_network,ambient_display,caffeine,heads_up,sync,usb_tether,volume_panel,profiles,radio_power diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java new file mode 100644 index 00000000000..b907205025c --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RadioPowerTile.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015 The CyanogenMod 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. + * 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.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.database.ContentObserver; +import android.os.UserHandle; +import android.provider.Settings; + +import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.MetricsProto.MetricsEvent; +import com.android.internal.telephony.Phone; +import com.android.internal.telephony.PhoneFactory; + +import com.android.systemui.R; +import com.android.systemui.qs.QSTile; + +import android.telephony.ServiceState; + + +/** Quick settings tile: RadioPower **/ +public class RadioPowerTile extends QSTile { + + private boolean mListening; + + public RadioPowerTile(Host host) { + super(host); + } + + @Override + public boolean isAvailable() { + return PhoneFactory.getDefaultPhone() != null; + } + + @Override + public BooleanState newTileState() { + return new BooleanState(); + } + + @Override + protected void handleClick() { + refreshState(!getRadioState()); + } + + @Override + public Intent getLongClickIntent() { + return new Intent().setClassName("com.android.settings", "com.android.settings.RadioInfo"); + } + + @Override + protected void handleLongClick() { + mHost.startActivityDismissingKeyguard(getLongClickIntent()); + } + + @Override + protected void handleUpdateState(BooleanState state, Object arg) { + state.visible = true; + final boolean radioPower = arg instanceof Boolean ? (boolean) arg : getRadioState(); + state.value = radioPower; + state.label = mContext.getString(R.string.quick_settings_radio_power_label); + if(state.value) { + state.icon = ResourceIcon.get(R.drawable.ic_qs_radio_on); + } else { + state.icon = ResourceIcon.get(R.drawable.ic_qs_radio_off); + } + } + + @Override + public CharSequence getTileLabel() { + return mContext.getString(R.string.quick_settings_radio_power_label); + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.QS_AIRPLANEMODE; + } + + private boolean getRadioState() { + final Phone phone = PhoneFactory.getDefaultPhone(); + return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; + } + + private void setRadioState(boolean enabled) { + final Phone phone = PhoneFactory.getDefaultPhone(); + phone.setRadioPower(enabled); + } + + public void setListening(boolean listening) { + if (mListening == listening) return; + mListening = listening; + if (listening) { + final IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); + mContext.registerReceiver(mReceiver, filter); + } else { + mContext.unregisterReceiver(mReceiver); + } + } + + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) { + refreshState(); + } + } + }; + +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index 7f8ef210b52..ac7fa6ab96c 100755 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -59,6 +59,7 @@ import com.android.systemui.qs.tiles.IntentTile; import com.android.systemui.qs.tiles.LocationTile; import com.android.systemui.qs.tiles.NfcTile; import com.android.systemui.qs.tiles.NightDisplayTile; +import com.android.systemui.qs.tiles.RadioPowerTile; import com.android.systemui.qs.tiles.RotationLockTile; import com.android.systemui.qs.tiles.SyncTile; import com.android.systemui.qs.tiles.UsbTetherTile; @@ -441,6 +442,7 @@ public class QSTileHost implements QSTile.Host, Tunable { else if (tileSpec.equals("dnd")) return new DndTile(this); else if (tileSpec.equals("inversion")) return new ColorInversionTile(this); else if (tileSpec.equals("airplane")) return new AirplaneModeTile(this); + else if (tileSpec.equals("radio_power")) return new RadioPowerTile(this); else if (tileSpec.equals("work")) return new WorkModeTile(this); else if (tileSpec.equals("rotation")) return new RotationLockTile(this); else if (tileSpec.equals("flashlight")) return new FlashlightTile(this); -- 2.15.0