Skip to content

Commit

Permalink
Merge pull request #28 from mustafa01ali/development
Browse files Browse the repository at this point in the history
* Update all dependencies

* Add tile to toggle all animations (close #24) (#25)

* Setup codestyle (#27)
  • Loading branch information
mustafa01ali authored Nov 4, 2017
2 parents e0282a4 + 3acc667 commit 319c1a7
Show file tree
Hide file tree
Showing 20 changed files with 1,412 additions and 44 deletions.
11 changes: 10 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ jobs:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
- run:
name: Check code style
command: ./gradlew ktlint
- run:
name: Compile & Run Tests
command: ./gradlew assemble test
- store_artifacts:
path: app/build/reports
destination: reports
- store_artifacts:
path: app/build/analysis
destination: analysis
- store_artifacts:
path: app/build/outputs/apk
destination: apks
- store_test_results:
path: app/build/test-results
path: app/build/test-results
29 changes: 29 additions & 0 deletions analysis/code-style.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repositories {
mavenCentral()
}

configurations {
ktlint
}

dependencies {
ktlint "com.github.shyiko:ktlint:0.11.1"
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt", "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/analysis/ktlint.xml"
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}
31 changes: 17 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.oss.licenses.plugin'
apply from: '../analysis/code-style.gradle'

repositories {
mavenCentral()
Expand All @@ -10,16 +11,17 @@ repositories {

android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "xyz.mustafaali.devqstiles"
minSdkVersion 24

// Writing show taps setting fails on higher versions
//noinspection OldTargetApi
targetSdkVersion 22

versionCode 6
versionName "1.0.4"
versionCode 7
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -36,16 +38,17 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.android.support:appcompat-v7:$support_lib_version"
implementation "com.android.support:recyclerview-v7:$support_lib_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.google.android.gms:play-services-oss-licenses:11.4.2'
implementation 'com.jakewharton.timber:timber:4.5.1'

compile "com.android.support:appcompat-v7:$support_lib_version"
compile "com.android.support:recyclerview-v7:$support_lib_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.google.android.gms:play-services-oss-licenses:11.2.2'
compile 'com.jakewharton.timber:timber:4.5.1'
testImplementation 'junit:junit:4.12'

testCompile 'junit:junit:4.12'
}
androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@
</intent-filter>
</service>

<service
android:name="xyz.mustafaali.devqstiles.service.ToggleAnimationService"
android:enabled="true"
android:exported="true"
android:icon="@drawable/ic_animation"
android:label="@string/label_toggle_all_animations"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

<!-- To take advantage of larger aspect ratio on devices like the S8 -->
<!-- https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html -->
<meta-data
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/kotlin/xyz/mustafaali/devqstiles/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.mustafaali.devqstiles;
package xyz.mustafaali.devqstiles

import android.content.ActivityNotFoundException
import android.content.Intent
Expand All @@ -14,7 +14,6 @@ import timber.log.Timber
import xyz.mustafaali.devqstiles.model.Feature
import xyz.mustafaali.devqstiles.ui.FeaturesAdapter


class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -59,7 +58,7 @@ class MainActivity : AppCompatActivity() {
intent.data = Uri.parse("market://details?id=xyz.mustafaali.devqstiles")
try {
startActivity(intent)
} catch(e: ActivityNotFoundException) {
} catch (e: ActivityNotFoundException) {
Timber.e("Couldn't launch activity, maybe PlayStore is not installed")
}
}
Expand Down Expand Up @@ -105,7 +104,8 @@ class MainActivity : AppCompatActivity() {
Feature("Keep Screen On", "Keep screen on when connected via USB, but turn it off when connected to a charger", R.drawable.ic_toggle_keep_screen_on),
Feature("Show Touches", "Show touch points when you touch the screen, ideal for demos", R.drawable.ic_toggle_show_taps),
Feature("Demo Mode", "Cleans up the status bar for those perfect screenshots", R.drawable.ic_toggle_demo_mode),
Feature("Change Animator Duration", "Change the default animator duration to easily debug animations", R.drawable.ic_animator_duration)
Feature("Change Animator Duration", "Change the default animator duration to easily debug animations", R.drawable.ic_animator_duration),
Feature("Toggle Animation Scale", "Enable/disable all animations with one click, perfect for running Espresso tests", R.drawable.ic_animation)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package xyz.mustafaali.devqstiles.service

import android.graphics.drawable.Icon
import android.service.quicksettings.TileService
import xyz.mustafaali.devqstiles.util.AnimationScaler

/**
* A {@link TileService} for toggling Window Animation Scale, Transition Animation Scale, and Animator Duration Scale.
*/
class ToggleAnimationService : TileService() {

override fun onStartListening() {
super.onStartListening()
updateTile()
}

override fun onClick() {
AnimationScaler.toggleAnimationScale(this)
updateTile()
}

private fun updateTile() {
val scale = AnimationScaler.getAnimationScale(contentResolver)
val tile = qsTile
tile.icon = Icon.createWithResource(applicationContext, AnimationScaler.getIcon(scale))
tile.updateTile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ class ToggleAnimatorDurationService : TileService() {
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ class ToggleKeepScreenOnService : BaseTileService() {
}
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ class ToggleUsbDebuggingService : BaseTileService() {
override fun isFeatureEnabled(): Boolean {
return Settings.Global.getString(contentResolver, Settings.Global.ADB_ENABLED) == "1"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ class FeaturesAdapter(val features: List<Feature>, val listener: (Feature) -> Un
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(features[position], listener)

override fun getItemCount(): Int = features.size

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package xyz.mustafaali.devqstiles.util

import android.content.ContentResolver
import android.content.Context
import android.provider.Settings
import android.support.annotation.DrawableRes
import android.widget.Toast
import timber.log.Timber
import xyz.mustafaali.devqstiles.R

/**
* A utility class for working with system Window Animation Scale, Transition Animation Scale, and Animator Duration Scale.
*/
object AnimationScaler {

@DrawableRes
fun getIcon(scale: Float): Int {
when {
scale <= 0f -> return R.drawable.ic_animation_off
else -> return R.drawable.ic_animation_on
}
}

fun toggleAnimationScale(context: Context): Boolean {
val animationScale = if (getAnimationScale(context.contentResolver) == 1.0f) 0.0f else 1.0f
return try {
Settings.Global.putFloat(
context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, animationScale)
Settings.Global.putFloat(
context.contentResolver, Settings.Global.WINDOW_ANIMATION_SCALE, animationScale)
Settings.Global.putFloat(
context.contentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE, animationScale)
true
} catch (se: SecurityException) {
val message = context.getString(R.string.permission_required_toast)
Toast.makeText(context.applicationContext, message, Toast.LENGTH_LONG).show()
Timber.e(se, message)
false
}
}

fun getAnimationScale(contentResolver: ContentResolver?): Float {
var scale = 1f
try {
scale = maxOf(
Settings.Global.getFloat(contentResolver,
Settings.Global.ANIMATOR_DURATION_SCALE),
Settings.Global.getFloat(contentResolver,
Settings.Global.WINDOW_ANIMATION_SCALE),
Settings.Global.getFloat(contentResolver,
Settings.Global.TRANSITION_ANIMATION_SCALE))
} catch (e: Settings.SettingNotFoundException) {
Timber.e(e, "Could not read Animation Scale setting")
}

return if (scale >= 1) 1.0f else 0.0f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ object AnimatorDurationScaler {
Timber.e(se, message)
false
}

}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_animation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M10,9c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM10,13c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM7,9.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM10,16.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM7,13.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM10,7.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM14,9c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM14,7.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM17,13.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM17,9.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8zM14,16.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM14,13c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1z"
android:fillColor="#FFFFFF"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_animation_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M14,7c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1zM13.8,11.48l0.2,0.02c0.83,0 1.5,-0.67 1.5,-1.5s-0.67,-1.5 -1.5,-1.5 -1.5,0.67 -1.5,1.5l0.02,0.2c0.09,0.67 0.61,1.19 1.28,1.28zM14,3.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM10,3.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM21,10.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM10,7c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1zM18,15c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1zM18,11c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1zM18,7c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1zM14,20.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM2.5,5.27l3.78,3.78L6,9c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1c0,-0.1 -0.03,-0.19 -0.06,-0.28l2.81,2.81c-0.71,0.11 -1.25,0.73 -1.25,1.47 0,0.83 0.67,1.5 1.5,1.5 0.74,0 1.36,-0.54 1.47,-1.25l2.81,2.81c-0.09,-0.03 -0.18,-0.06 -0.28,-0.06 -0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1c0,-0.1 -0.03,-0.19 -0.06,-0.28l3.78,3.78L20,20.23 3.77,4 2.5,5.27zM10,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM21,13.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM6,13c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM3,9.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM10,20.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM6,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM3,13.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5z"
android:fillColor="#FFFFFF"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_animation_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M6,13c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM6,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM6,9c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM3,9.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5 0.5,-0.22 0.5,-0.5 -0.22,-0.5 -0.5,-0.5zM6,5c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM21,10.5c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5 -0.5,0.22 -0.5,0.5 0.22,0.5 0.5,0.5zM14,7c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1 -1,0.45 -1,1 0.45,1 1,1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5 -0.67,-1.5 -1.5,-1.5zM10,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1 1,-0.45 1,-1 -0.45,-1 -1,-1zM14,12.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM14,8.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5z"
android:fillColor="#FFFFFF"/>
</vector>
Loading

0 comments on commit 319c1a7

Please sign in to comment.