summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Papageorgiou <root.expert.xda@gmail.com>2020-04-21 14:07:10 +0300
committerChristos Papageorgiou <root.expert.xda@gmail.com>2020-04-22 14:01:35 +0300
commitea5868bf10fb8343d1acb6b68cb1948e630fd1d3 (patch)
tree1b88c5644f1c1d002aa8fbb88f687a4d78624b49
parent89b2c81a0a32c4dc51e20b47d4f293f7afa976d4 (diff)
JamesDSPManager: Add QS Tile.
Signed-off-by: Christos Papageorgiou <root.expert.xda@gmail.com> Change-Id: Idad2b5aaec6dadf82d6195dff1d87378d598eefd
-rw-r--r--app/src/main/AndroidManifest.xml14
-rw-r--r--app/src/main/java/james/dsp/tile/JamesTile.java78
2 files changed, 92 insertions, 0 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index de3a89e..d2c2995 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -31,6 +31,10 @@
<action android:name="android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+
+ <intent-filter>
+ <action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
+ </intent-filter>
</activity>
<service
android:exported="false"
@@ -45,5 +49,15 @@
</receiver>
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true">
</meta-data>
+ <service
+ android:name=".tile.JamesTile"
+ android:icon="@drawable/notification_icon"
+ android:label="JamesDSP"
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
+ <intent-filter>
+ <action
+ android:name="android.service.quicksettings.action.QS_TILE"/>
+ </intent-filter>
+ </service>
</application>
</manifest> \ No newline at end of file
diff --git a/app/src/main/java/james/dsp/tile/JamesTile.java b/app/src/main/java/james/dsp/tile/JamesTile.java
new file mode 100644
index 0000000..e5983ce
--- /dev/null
+++ b/app/src/main/java/james/dsp/tile/JamesTile.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2020 The Android Ice Cold Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package james.dsp.tile;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+
+import james.dsp.activity.DSPManager;
+
+import static james.dsp.service.HeadsetService.getAudioOutputRouting;
+
+public class JamesTile extends TileService {
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ boolean active = isActive();
+
+ getQsTile().setState(active ? Tile.STATE_INACTIVE : Tile.STATE_ACTIVE);
+ }
+
+ @Override
+ public void onTileRemoved() {
+ super.onTileRemoved();
+ }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ boolean active = isActive();
+
+ getQsTile().setState(active ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
+ getQsTile().updateTile();
+ }
+
+ @Override
+ public void onStopListening() {
+ super.onStopListening();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ String mode = getAudioOutputRouting();
+ SharedPreferences sharedPrefs = getSharedPreferences(DSPManager.SHARED_PREFERENCES_BASENAME + "." + mode, 0);
+
+ boolean active = isActive();
+
+ sharedPrefs.edit().putBoolean("dsp.masterswitch.enable", !active).apply();
+ sendBroadcast(new Intent(DSPManager.ACTION_UPDATE_PREFERENCES));
+
+ getQsTile().setState(active ? Tile.STATE_INACTIVE : Tile.STATE_ACTIVE);
+ getQsTile().updateTile();
+ }
+
+ private boolean isActive() {
+ String mode = getAudioOutputRouting();
+ SharedPreferences sharedPrefs = getSharedPreferences(DSPManager.SHARED_PREFERENCES_BASENAME + "." + mode, 0);
+
+ return sharedPrefs.getBoolean("dsp.masterswitch.enable", false);
+ }
+}