mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2025-08-14 09:06:00 -04:00
Fix Silence replacement, RIP CustomTiles
This commit is contained in:
parent
1ef1ada003
commit
73d0b61dba
3 changed files with 3 additions and 259 deletions
|
@ -1,253 +0,0 @@
|
|||
From a42004f47da3d2f8128f77b7170bf84dd86d7e19 Mon Sep 17 00:00:00 2001
|
||||
From: Gabriele M <moto.falcon.git@gmail.com>
|
||||
Date: Mon, 27 Mar 2017 17:23:04 +0200
|
||||
Subject: [PATCH] CustomTiles: Add system profiles tile
|
||||
|
||||
This tile opens a dialog to change the current profile. If system
|
||||
profiles are disabled, they'll be enabled as soon as a profile is
|
||||
selected. Disabling system profiles from the tile is not possible.
|
||||
|
||||
Change-Id: I38b28be8fcf1eb7998d7d18df204802ea66554f6
|
||||
---
|
||||
AndroidManifest.xml | 11 ++
|
||||
res/drawable/ic_profiles.xml | 28 +++++
|
||||
res/values/strings.xml | 4 +
|
||||
src/org/lineageos/customtiles/MainActivity.java | 1 +
|
||||
src/org/lineageos/customtiles/ProfileTile.java | 139 ++++++++++++++++++++++++
|
||||
5 files changed, 183 insertions(+)
|
||||
create mode 100644 res/drawable/ic_profiles.xml
|
||||
create mode 100644 src/org/lineageos/customtiles/ProfileTile.java
|
||||
|
||||
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
|
||||
index 6bef3c7..09f2de9 100644
|
||||
--- a/AndroidManifest.xml
|
||||
+++ b/AndroidManifest.xml
|
||||
@@ -129,6 +129,17 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
+ <!-- Profiles -->
|
||||
+ <service
|
||||
+ android:name=".ProfileTile"
|
||||
+ android:icon="@drawable/ic_profiles"
|
||||
+ android:label="@string/system_profile_label"
|
||||
+ android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
+ <intent-filter>
|
||||
+ <action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
+ </intent-filter>
|
||||
+ </service>
|
||||
+
|
||||
<!-- WakeLock Service -->
|
||||
<service
|
||||
android:name=".WakelockService"
|
||||
diff --git a/res/drawable/ic_profiles.xml b/res/drawable/ic_profiles.xml
|
||||
new file mode 100644
|
||||
index 0000000..79f7725
|
||||
--- /dev/null
|
||||
+++ b/res/drawable/ic_profiles.xml
|
||||
@@ -0,0 +1,28 @@
|
||||
+<?xml version="1.0" encoding="utf-8"?>
|
||||
+<!--
|
||||
+ Copyright (c) 2015 The CyanogenMod 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.
|
||||
+-->
|
||||
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
+ android:width="24dp"
|
||||
+ android:height="24dp"
|
||||
+ android:viewportWidth="24"
|
||||
+ android:viewportHeight="24">
|
||||
+
|
||||
+ <path
|
||||
+ android:fillColor="?android:attr/colorAccent"
|
||||
+ android:pathData="M19,5v14H5V5H19
|
||||
+M19,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2V5C21,3.9,20.1,3,19,3L19,3z
|
||||
+M17,8 c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1s0.4,1,1,1C16.6,9,17,8.6,17,8z
|
||||
+M13,8c0-0.6-0.4-1-1-1c-0.6,0-1,0.4-1,1s0.4,1,1,1 C12.6,9,13,8.6,13,8z
|
||||
+M9,8c0-0.6-0.4-1-1-1S7,7.4,7,8s0.4,1,1,1S9,8.6,9,8z
|
||||
+M17,13h-6v-2H9v2H7v2h2v2h2v-2h6V13z" />
|
||||
+</vector>
|
||||
diff --git a/res/values/strings.xml b/res/values/strings.xml
|
||||
index 60cb829..e0dd75e 100644
|
||||
--- a/res/values/strings.xml
|
||||
+++ b/res/values/strings.xml
|
||||
@@ -24,8 +24,12 @@
|
||||
<string name="sync_label">Sync</string>
|
||||
<string name="volume_panel_label">Volume panel</string>
|
||||
<string name="usb_tether_label">USB tethering</string>
|
||||
+ <string name="system_profile_label">System Profile</string>
|
||||
|
||||
<!-- Caffeine -->
|
||||
<string name="caffeine_label">Caffeine</string>
|
||||
|
||||
+ <string name="dialog_system_profile_title">Select profile</string>
|
||||
+ <string name="dialog_system_profile_message">No system profile found</string>
|
||||
+
|
||||
</resources>
|
||||
diff --git a/src/org/lineageos/customtiles/MainActivity.java b/src/org/lineageos/customtiles/MainActivity.java
|
||||
index 95d3015..4f9f3ba 100644
|
||||
--- a/src/org/lineageos/customtiles/MainActivity.java
|
||||
+++ b/src/org/lineageos/customtiles/MainActivity.java
|
||||
@@ -33,6 +33,7 @@ public class MainActivity extends Activity {
|
||||
put(".SyncTile", new Intent(Settings.ACTION_SYNC_SETTINGS));
|
||||
put(".UsbTetherTile", new Intent(Settings.ACTION_WIRELESS_SETTINGS));
|
||||
put(".VolumePanelTile", new Intent(Settings.ACTION_SOUND_SETTINGS));
|
||||
+ put(".ProfileTile", new Intent("org.cyanogenmod.cmparts.PROFILES_SETTINGS"));
|
||||
}};
|
||||
|
||||
@Override
|
||||
diff --git a/src/org/lineageos/customtiles/ProfileTile.java b/src/org/lineageos/customtiles/ProfileTile.java
|
||||
new file mode 100644
|
||||
index 0000000..ed3caab
|
||||
--- /dev/null
|
||||
+++ b/src/org/lineageos/customtiles/ProfileTile.java
|
||||
@@ -0,0 +1,139 @@
|
||||
+/*
|
||||
+ * 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 org.lineageos.customtiles;
|
||||
+
|
||||
+import android.app.AlertDialog;
|
||||
+import android.app.Dialog;
|
||||
+import android.content.BroadcastReceiver;
|
||||
+import android.content.Context;
|
||||
+import android.content.DialogInterface;
|
||||
+import android.content.Intent;
|
||||
+import android.content.IntentFilter;
|
||||
+import android.service.quicksettings.Tile;
|
||||
+import android.service.quicksettings.TileService;
|
||||
+
|
||||
+import java.util.UUID;
|
||||
+
|
||||
+import cyanogenmod.app.Profile;
|
||||
+import cyanogenmod.app.ProfileManager;
|
||||
+import cyanogenmod.providers.CMSettings;
|
||||
+
|
||||
+public class ProfileTile extends TileService {
|
||||
+
|
||||
+ private ProfileManager mProfileManager;
|
||||
+
|
||||
+ private Profile mCurrentProfile;
|
||||
+
|
||||
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
+ @Override
|
||||
+ public void onReceive(Context context, Intent intent) {
|
||||
+ refresh();
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
+ @Override
|
||||
+ public void onStartListening() {
|
||||
+ super.onStartListening();
|
||||
+
|
||||
+ mProfileManager = ProfileManager.getInstance(getBaseContext());
|
||||
+
|
||||
+ IntentFilter filter = new IntentFilter();
|
||||
+ filter.addAction(ProfileManager.INTENT_ACTION_PROFILE_SELECTED);
|
||||
+ filter.addAction(ProfileManager.INTENT_ACTION_PROFILE_UPDATED);
|
||||
+ filter.addAction(ProfileManager.PROFILES_STATE_CHANGED_ACTION);
|
||||
+ registerReceiver(mReceiver, filter);
|
||||
+
|
||||
+ refresh();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onStopListening() {
|
||||
+ unregisterReceiver(mReceiver);
|
||||
+ super.onStopListening();
|
||||
+ }
|
||||
+
|
||||
+ private Dialog selectProfileDialog() {
|
||||
+
|
||||
+ Profile[] profilesList = mProfileManager.getProfiles();
|
||||
+ if (profilesList.length == 0) {
|
||||
+ return new AlertDialog.Builder(getBaseContext())
|
||||
+ .setTitle(R.string.dialog_system_profile_title)
|
||||
+ .setMessage(R.string.dialog_system_profile_message)
|
||||
+ .setPositiveButton(android.R.string.ok, null)
|
||||
+ .create();
|
||||
+ }
|
||||
+
|
||||
+ final CharSequence[] profileLabels = new CharSequence[profilesList.length];
|
||||
+ final UUID[] profileUuids = new UUID[profilesList.length];
|
||||
+ int selectedProfile = -1;
|
||||
+ for (int i = 0; i < profilesList.length; i++) {
|
||||
+ UUID profileUuuid = profilesList[i].getUuid();
|
||||
+ profileLabels[i] = profilesList[i].getName();
|
||||
+ profileUuids[i] = profileUuuid;
|
||||
+ if (mCurrentProfile != null && mCurrentProfile.getUuid().equals(profileUuuid)) {
|
||||
+ selectedProfile = i;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return new AlertDialog.Builder(getBaseContext())
|
||||
+ .setTitle(R.string.dialog_system_profile_title)
|
||||
+ .setSingleChoiceItems(profileLabels, selectedProfile,
|
||||
+ new DialogInterface.OnClickListener() {
|
||||
+ @Override
|
||||
+ public void onClick(DialogInterface dialogInterface, int index) {
|
||||
+ if (!mProfileManager.isProfilesEnabled()) {
|
||||
+ enableProfiles();
|
||||
+ }
|
||||
+ mProfileManager.setActiveProfile(profileUuids[index]);
|
||||
+ dialogInterface.dismiss();
|
||||
+ }
|
||||
+ })
|
||||
+ .setNegativeButton(android.R.string.cancel, null)
|
||||
+ .setCancelable(true)
|
||||
+ .create();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onClick() {
|
||||
+ super.onClick();
|
||||
+
|
||||
+ unlockAndRun(new Runnable() {
|
||||
+ @Override
|
||||
+ public void run() {
|
||||
+ showDialog(selectProfileDialog());
|
||||
+ }
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
+ private void refresh() {
|
||||
+ if (mProfileManager.isProfilesEnabled()) {
|
||||
+ mCurrentProfile = mProfileManager.getActiveProfile();
|
||||
+ getQsTile().setState(Tile.STATE_ACTIVE);
|
||||
+ getQsTile().setLabel(mCurrentProfile.getName());
|
||||
+ } else {
|
||||
+ mCurrentProfile = null;
|
||||
+ getQsTile().setState(Tile.STATE_INACTIVE);
|
||||
+ getQsTile().setLabel(getString(R.string.system_profile_label));
|
||||
+ }
|
||||
+ getQsTile().updateTile();
|
||||
+ }
|
||||
+
|
||||
+ private void enableProfiles() {
|
||||
+ CMSettings.System.putInt(getContentResolver(),
|
||||
+ CMSettings.System.SYSTEM_PROFILES_ENABLED, 1);
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.13.1
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue