mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-09-08 10:32:42 +00:00
232 lines
9.8 KiB
Diff
232 lines
9.8 KiB
Diff
From 0eb8f3eb492844954cdbfa44b660cc5a278ebcd5 Mon Sep 17 00:00:00 2001
|
|
From: Tad <tad@spotco.us>
|
|
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 @@
|
|
+<?xml version="1.0" encoding="utf-8"?>
|
|
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
+ android:width="64dp"
|
|
+ android:height="64dp"
|
|
+ android:viewportWidth="24"
|
|
+ android:viewportHeight="24">
|
|
+ <path
|
|
+ android:fillColor="#4DFFFFFF"
|
|
+ android:pathData="M12,5c-3.87,0 -7,3.13 -7,7h2c0,-2.76 2.24,-5 5,-5s5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM13,14.29c0.88,-0.39 1.5,-1.26 1.5,-2.29 0,-1.38 -1.12,-2.5 -2.5,-2.5S9.5,10.62 9.5,12c0,1.02 0.62,1.9 1.5,2.29v3.3L7.59,21 9,22.41l3,-3 3,3L16.41,21 13,17.59v-3.3zM12,1C5.93,1 1,5.93 1,12h2c0,-4.97 4.03,-9 9,-9s9,4.03 9,9h2c0,-6.07 -4.93,-11 -11,-11z" />
|
|
+</vector>
|
|
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 @@
|
|
+<?xml version="1.0" encoding="utf-8"?>
|
|
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
+ android:width="64dp"
|
|
+ android:height="64dp"
|
|
+ android:viewportWidth="24"
|
|
+ android:viewportHeight="24">
|
|
+ <path
|
|
+ android:fillColor="#FFFFFFFF"
|
|
+ android:pathData="M12,5c-3.87,0 -7,3.13 -7,7h2c0,-2.76 2.24,-5 5,-5s5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM13,14.29c0.88,-0.39 1.5,-1.26 1.5,-2.29 0,-1.38 -1.12,-2.5 -2.5,-2.5S9.5,10.62 9.5,12c0,1.02 0.62,1.9 1.5,2.29v3.3L7.59,21 9,22.41l3,-3 3,3L16.41,21 13,17.59v-3.3zM12,1C5.93,1 1,5.93 1,12h2c0,-4.97 4.03,-9 9,-9s9,4.03 9,9h2c0,-6.07 -4.93,-11 -11,-11z" />
|
|
+</vector>
|
|
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 @@
|
|
<string name="accessibility_lock_task">Prevent <xliff:g id="task">%1$s</xliff:g> from being dismissed</string>
|
|
<!-- Content description for Accessibility on locked tasks in recents -->
|
|
<string name="accessibility_unlock_task">Allow <xliff:g id="task">%1$s</xliff:g> to be dismissed</string>
|
|
+
|
|
+ <!-- Radio Power QS tile -->
|
|
+ <string name="quick_settings_radio_power_label">Radio power</string>
|
|
</resources>
|
|
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 @@
|
|
|
|
<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
|
|
<string name="quick_settings_tiles_stock" translatable="false">
|
|
- 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
|
|
</string>
|
|
|
|
<!-- The tiles to display in QuickSettings -->
|
|
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<QSTile.BooleanState> {
|
|
+
|
|
+ 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
|
|
|