Skip to content

Commit

Permalink
Add 'Show taps' tile; update README and graphic resources
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangl committed Apr 9, 2017
1 parent b97cef2 commit 9fb405c
Show file tree
Hide file tree
Showing 30 changed files with 319 additions and 60 deletions.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# Dev-QuickSettings
Android Quick Settings Tiles for Android developers
## What is this?
Android Quick Settings Tiles for Android developers, written in [Kotlin](https://kotlinlang.org/).

![Main image](https://raw.githubusercontent.com/adriangl/Android-Dev-QuickSettings/master/graphics/screenshots/en-US_main.png)

The app is based on the work of [Nick Butcher](https://github.com/nickbutcher) and his [Animator Duration Quick Settings Tile](https://github.com/nickbutcher/AnimatorDurationTile) which I borrowed for the animation duration tile.

## Current features
The app provides a few Quick Settings tiles that act as shortcut to Development Options in the Android device:
* USB Debugging
* Demo mode
* Keep screen on
* Animator duration scale
* Show taps on screen
* Destroy activities

## Where can I get it?
You can get it from [Google Play](https://play.google.com/store/apps/details?id=com.adriangl.devquicksettings) or from the [Releases](https://github.com/adriangl/Android-Dev-QuickSettings/releases) page :)

[![Get it on Google Play](https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png)](https://play.google.com/store/apps/details?id=com.adriangl.devquicksettings)


## License
```
Copyright (C) 2017 Adrián García
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.
```
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply from: "$rootDir/common.gradle"

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.adriangl.devquicksettings"
minSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
targetSdkVersion 22
versionCode computeVersionCode()
versionName computeVersionName()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2017 Adrián García
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,9 +18,17 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.adriangl.devquicktiles">

<!--
Permission needed to read/write from Settings, must be granted from adb with
adb shell pm grant <package-name> android.permission.WRITE_SETTINGS
-->
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />

<!--
Permission needed to read/write from secure Settings, must be granted from adb with
adb shell pm grant <package-name> android.permission.WRITE_SECURE_SETTING
adb shell pm grant <package-name> android.permission.WRITE_SECURE_SETTINGS
-->
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
Expand All @@ -40,6 +47,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".base.BaseApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

Expand Down Expand Up @@ -93,6 +101,16 @@
</intent-filter>
</service>

<service
android:icon="@drawable/ic_qs_show_taps_enabled"
android:label="@string/qs_show_taps"
android:name="com.adriangl.devquicktiles.tiles.show_taps.ShowTapsTileService"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/kotlin/com/adriangl/devquicktiles/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,29 @@ class MainActivity : AppCompatActivity() {
private fun getDescriptionItems(): List<QsDescriptionsItem> {
return listOf(
QsDescriptionsItem(
R.drawable.ic_qs_animator_duration_enabled,
getString(R.string.qs_animator_duration),
getString(R.string.qs_animator_duration_description)),
R.drawable.ic_qs_usb_debugging_enabled,
getString(R.string.qs_usb_debugging),
getString(R.string.qs_usb_debugging_description)),
QsDescriptionsItem(
R.drawable.ic_qs_demo_mode_enabled,
getString(R.string.qs_demo_mode),
getString(R.string.qs_demo_mode_description)),
QsDescriptionsItem(
R.drawable.ic_qs_finish_activities_enabled,
getString(R.string.qs_finish_activities),
getString(R.string.qs_finish_activities_description)),
QsDescriptionsItem(
R.drawable.ic_qs_keep_screen_on_enabled,
getString(R.string.qs_keep_screen_on),
getString(R.string.qs_keep_screen_on_description)),
QsDescriptionsItem(
R.drawable.ic_qs_usb_debugging_enabled,
getString(R.string.qs_usb_debugging),
getString(R.string.qs_usb_debugging_description))
R.drawable.ic_qs_animator_duration_enabled,
getString(R.string.qs_animator_duration),
getString(R.string.qs_animator_duration_description)),
QsDescriptionsItem(
R.drawable.ic_qs_show_taps_enabled,
getString(R.string.qs_show_taps),
getString(R.string.qs_show_taps_description)),
QsDescriptionsItem(
R.drawable.ic_qs_finish_activities_enabled,
getString(R.string.qs_finish_activities),
getString(R.string.qs_finish_activities_description))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,36 @@ abstract class DevelopmentTileService<T : Any> : TileService() {

lateinit var value: T

override fun onTileAdded() {
Timber.d("Tile added: {label=%s}", qsTile.label)
}

override fun onStartListening() {
Timber.d("Tile started listening: {label=%s, state=%s}", qsTile.label, qsTile.state)
value = queryValue()
updateState()
}

override fun onClick() {
try {
Timber.d("Tile clicked: {label=%s, state=%s}", qsTile.label, qsTile.state)
setNextValue()
} catch (e: SecurityException) {
Toast.makeText(applicationContext,
getString(R.string.qs_permissions_not_granted),
Toast.LENGTH_SHORT)
.show()
}
}

override fun onTileRemoved() {
Timber.d("Tile removed: {label=%s}", qsTile.label)
Timber.d("Tile clicked: {label=%s, state=%s}", qsTile.label, qsTile.state)
setNextValue()
}

private fun setNextValue() {
val newIndex = ((getValueList().indexOf(value) + 1) % getValueList().size)
value = getValueList()[newIndex]
val newValue = getValueList()[newIndex]
Timber.d("New value: %s, Tile: {label=%s, state=%s}", value, qsTile.label, qsTile.state)

// Disable tile while setting the value
qsTile.state = Tile.STATE_UNAVAILABLE
qsTile.updateTile()

saveValue(value)
try {
if (saveValue(newValue)) {
value = newValue
}
} catch (e: Exception) {
val permissionNotGrantedString = getString(R.string.qs_permissions_not_granted)
Toast.makeText(applicationContext, permissionNotGrantedString, Toast.LENGTH_LONG)
.show()
Timber.e(e, permissionNotGrantedString)
}

updateState()
}
Expand All @@ -83,7 +77,7 @@ abstract class DevelopmentTileService<T : Any> : TileService() {

abstract fun queryValue(): T

abstract fun saveValue(value: T)
abstract fun saveValue(value: T): Boolean

abstract fun getIcon(value: T): Icon?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class AnimatorDurationTileService : DevelopmentTileService<Float>() {
}

override fun queryValue(): Float {
return SettingsUtils.getFloatSetting(contentResolver, SETTING)
return SettingsUtils.getFloatFromGlobalSettings(contentResolver, SETTING)
}

override fun saveValue(value: Float) {
SettingsUtils.setFloatSetting(contentResolver, SETTING, value)
override fun saveValue(value: Float): Boolean {
return SettingsUtils.setFloatToGlobalSettings(contentResolver, SETTING, value)
}

override fun getValueList(): List<Float> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,24 @@ class DemoModeTileService : DevelopmentTileService<Int>() {

override fun queryValue(): Int {
return listOf(DemoMode.DEMO_MODE_ALLOWED, DemoMode.DEMO_MODE_ON)
.fold(1, { current, key -> SettingsUtils.getIntSetting(contentResolver, key) and current })
.fold(1, { current, key -> SettingsUtils.getIntFromGlobalSettings(contentResolver, key) and current })
}

override fun saveValue(value: Int) {
listOf(DemoMode.DEMO_MODE_ALLOWED, DemoMode.DEMO_MODE_ON)
.forEach { SettingsUtils.setIntSetting(contentResolver, it, value) }
if (value != 0) {
startDemoMode()
override fun saveValue(value: Int): Boolean {
val isSettingEnabled =
listOf(DemoMode.DEMO_MODE_ALLOWED, DemoMode.DEMO_MODE_ON)
.fold(true) {
initial, setting -> initial && SettingsUtils.setIntToGlobalSettings(contentResolver, setting, value)
}
if (isSettingEnabled) {
if (value != 0) {
startDemoMode()
} else {
stopDemoMode()
}
return true
} else {
stopDemoMode()
return false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class FinishActivitiesTileService : DevelopmentTileService<Int>() {
}

override fun queryValue(): Int {
var value = SettingsUtils.getIntSetting(contentResolver, SETTING)
var value = SettingsUtils.getIntFromGlobalSettings(contentResolver, SETTING)
if (value > 1) value = 1
return value
}

override fun saveValue(value: Int) {
SettingsUtils.setIntSetting(contentResolver, SETTING, value)
override fun saveValue(value: Int) : Boolean {
return SettingsUtils.setIntToGlobalSettings(contentResolver, SETTING, value)
}

override fun getValueList(): List<Int> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class KeepScreenOnTileService : DevelopmentTileService<Int>() {
}

override fun queryValue(): Int {
return SettingsUtils.getIntSetting(contentResolver, SETTING)
return SettingsUtils.getIntFromGlobalSettings(contentResolver, SETTING)
}

override fun saveValue(value: Int) {
SettingsUtils.setIntSetting(contentResolver, SETTING, value)
override fun saveValue(value: Int) : Boolean {
return SettingsUtils.setIntToGlobalSettings(contentResolver, SETTING, value)
}

override fun getValueList(): List<Int> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2017 Adrián García
*
* 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.adriangl.devquicktiles.tiles.show_taps

import android.graphics.drawable.Icon
import com.adriangl.devquicktiles.R
import com.adriangl.devquicktiles.tiles.DevelopmentTileService
import com.adriangl.devquicktiles.utils.SettingsUtils


class ShowTapsTileService : DevelopmentTileService<Int>() {
companion object {
val SETTING = "show_touches" // This is hidden for developers, so we use the string resource
}

override fun isActive(value: Int): Boolean {
return value != 0
}

override fun queryValue(): Int {
var value = SettingsUtils.getIntFromSystemSettings(contentResolver, SETTING)
if (value > 1) value = 1
return value
}

override fun saveValue(value: Int): Boolean {
/*
* The proper way to do this would be to check Settings.System.canWrite().
* If we can write there then write the setting and if we can't, then launch an Intent to
* Settings.ACTION_MANAGE_WRITE_SETTINGS to enable the app to write system settings.
*
* The problem is that from API 23+ we can't do that with the "show_touches" setting
* (and others I suppose) as it throws an IllegalArgumentException:
* You cannot change private secure settings.
*
* So we have to fall back to use a targetSdkVersion of 22 so we can write the setting.
* Kinda hacky, but it works ¯\_(ツ)_/¯.
*/

return SettingsUtils.setIntToSystemSettings(contentResolver, SETTING, value)
}

override fun getValueList(): List<Int> {
return listOf(0, 1)
}

override fun getIcon(value: Int): Icon? {
return Icon.createWithResource(applicationContext,
if (value != 0) R.drawable.ic_qs_show_taps_enabled else R.drawable.ic_qs_show_taps_disabled)
}

override fun getLabel(value: Int): CharSequence? {
return getString(R.string.qs_show_taps)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class UsbDebuggingTileService : DevelopmentTileService<Int>() {
}

override fun queryValue(): Int {
var value = SettingsUtils.getIntSetting(contentResolver, SETTING)
var value = SettingsUtils.getIntFromGlobalSettings(contentResolver, SETTING)
if (value > 1) value = 1
return value
}

override fun saveValue(value: Int) {
SettingsUtils.setIntSetting(contentResolver, SETTING, value)
override fun saveValue(value: Int) : Boolean {
return SettingsUtils.setIntToGlobalSettings(contentResolver, SETTING, value)
}

override fun getValueList(): List<Int> {
Expand Down
Loading

0 comments on commit 9fb405c

Please sign in to comment.