From 44cc49a3e444987bfd6b0bde0e133661bea49803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Garc=C3=ADa?= Date: Thu, 21 Mar 2019 11:21:15 +0100 Subject: [PATCH 1/4] Add support for Android 9+ --- .gitignore | 2 ++ .idea/misc.xml | 17 ++++++++++--- .idea/modules.xml | 3 +++ README.md | 4 ++-- app/build.gradle | 12 +++++----- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- lib/build.gradle | 12 +++++----- .../overlayhelper/OverlayDelegate.java | 24 +++++++++++++++++++ .../adriangl/overlayhelper/OverlayHelper.java | 7 ++++-- 10 files changed, 65 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 520a863..20b8838 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ captures/ .idea/gradle.xml .idea/dictionaries .idea/libraries +.idea/caches +.idea/codeStyles # Keystore files *.jks diff --git a/.idea/misc.xml b/.idea/misc.xml index 13c4629..ba57ba5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,26 +5,37 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml index 366a791..8c91f35 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,8 +3,11 @@ + + + \ No newline at end of file diff --git a/README.md b/README.md index 9898c1d..71ca0e6 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,14 @@ Add the following dependencies to your app's `build.gradle`: * For Gradle < 4.0 ```groovy dependencies { - compile "com.github.adriangl:overlayhelper:1.0.0" + compile "com.github.adriangl:overlayhelper:1.1.0" } ``` * For Gradle 4.0+ ```groovy dependencies { - implementation "com.github.adriangl:overlayhelper:1.0.0" + implementation "com.github.adriangl:overlayhelper:1.1.0" } ``` diff --git a/app/build.gradle b/app/build.gradle index 5105bfb..87e41e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: "com.android.application" android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { applicationId "com.adriangl.overlayhelperexample" minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -21,8 +21,8 @@ android { dependencies { implementation project(":lib") implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "com.android.support:appcompat-v7:27.0.2" + implementation "com.android.support:appcompat-v7:28.0.0" testImplementation "junit:junit:4.12" - androidTestImplementation "com.android.support.test:runner:1.0.1" - androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1" + androidTestImplementation "com.android.support.test:runner:1.0.2" + androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2" } diff --git a/build.gradle b/build.gradle index 834875c..607754b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath "com.android.tools.build:gradle:3.0.1" + classpath 'com.android.tools.build:gradle:3.4.0-rc02' classpath "com.github.dcendents:android-maven-gradle-plugin:2.0" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7e3f79d..e5ca79a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 25 16:20:43 CET 2018 +#Thu Mar 21 11:09:33 CET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index c640428..00aa3f9 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -4,13 +4,13 @@ apply plugin: 'com.github.dcendents.android-maven' group = "com.github.adriangl" android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { minSdkVersion 19 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -27,10 +27,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:support-annotations:27.0.2" + implementation "com.android.support:support-annotations:28.0.0" testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } // build a jar with source files diff --git a/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java b/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java index e7b5f20..e8b61bd 100644 --- a/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java +++ b/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java @@ -131,4 +131,28 @@ public boolean canDrawOverlays() { return canDrawOverlays; } } + + /** + * Implementation of {@link OverlayDelegate} for devices with API level >= 28. + */ + @RequiresApi(api = Build.VERSION_CODES.P) + class PieOverlayDelegate implements OverlayDelegate { + private final Context context; + + PieOverlayDelegate(Context context) { + this.context = context; + } + + @Override public void startWatching() { + // No-op + } + + @Override public void stopWatching() { + // No-op + } + + @Override public boolean canDrawOverlays() { + return Settings.canDrawOverlays(context); + } + } } diff --git a/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java b/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java index c2f688d..e25eda3 100644 --- a/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java +++ b/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java @@ -54,8 +54,11 @@ public OverlayHelper(@NonNull Context ctx, @Nullable OverlayPermissionChangedLis this.context = ctx.getApplicationContext(); this.overlayPermissionChangedListener = listener; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // API 26+ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + // API 28+: The checks return to API 23-like behaviour + this.overlayDelegate = new OverlayDelegate.PieOverlayDelegate(context); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // API 26+: Fucks up checks, so we need to store the values of the alert window setting in the delegate this.overlayDelegate = new OverlayDelegate.OreoOverlayDelegate(context); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // API 23+: check if the user has explicitly enabled overlays From 8dc1c445d4de119670b62ca763350266787c7f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Garc=C3=ADa?= Date: Thu, 21 Mar 2019 11:36:50 +0100 Subject: [PATCH 2/4] Migrate to AndroidX --- app/build.gradle | 8 ++++---- .../adriangl/overlayhelper/ExampleInstrumentedTest.java | 4 ++-- .../com/adriangl/overlayhelperexample/MainActivity.java | 2 +- lib/build.gradle | 8 ++++---- .../adriangl/overlayhelper/ExampleInstrumentedTest.java | 4 ++-- .../java/com/adriangl/overlayhelper/OverlayDelegate.java | 4 ++-- .../java/com/adriangl/overlayhelper/OverlayHelper.java | 9 +++++---- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 87e41e0..f00fb05 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.1" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -21,8 +21,8 @@ android { dependencies { implementation project(":lib") implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "com.android.support:appcompat-v7:28.0.0" + implementation 'androidx.appcompat:appcompat:1.0.2' testImplementation "junit:junit:4.12" - androidTestImplementation "com.android.support.test:runner:1.0.2" - androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2" + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } diff --git a/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java index 1e573e3..473f691 100644 --- a/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package com.adriangl.overlayhelper; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java b/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java index ed750bc..c1d61ae 100644 --- a/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java +++ b/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java @@ -2,7 +2,7 @@ import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; diff --git a/lib/build.gradle b/lib/build.gradle index 00aa3f9..c3df5cc 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -12,7 +12,7 @@ android { versionCode 1 versionName "1.1" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -27,10 +27,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:support-annotations:28.0.0" + implementation 'androidx.annotation:annotation:1.0.2' testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } // build a jar with source files diff --git a/lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java b/lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java index e80abfb..64aa1fd 100644 --- a/lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java +++ b/lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package com.adriangl.overlayhelper; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java b/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java index e8b61bd..1d31718 100644 --- a/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java +++ b/lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java @@ -4,8 +4,8 @@ import android.content.Context; import android.os.Build; import android.provider.Settings; -import android.support.annotation.RequiresApi; -import android.support.annotation.RequiresPermission; +import androidx.annotation.RequiresApi; +import androidx.annotation.RequiresPermission; /** * Interface used to implement custom overlay checking behaviour depending on device version. diff --git a/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java b/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java index e25eda3..c4c8090 100644 --- a/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java +++ b/lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java @@ -11,14 +11,15 @@ import android.net.Uri; import android.os.Build; import android.provider.Settings; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.RequiresPermission; -import android.support.annotation.StringRes; import java.util.Arrays; import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresPermission; +import androidx.annotation.StringRes; + /** * Helper class that takes care of querying and requesting permissions for drawing over other apps. *

From d9be5dbe1cc1b3ab8b26a9dd2e63b9a0dadeb861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Garc=C3=ADa?= Date: Thu, 21 Mar 2019 12:07:11 +0100 Subject: [PATCH 3/4] Fix JavaDoc --- .idea/modules.xml | 3 --- lib/build.gradle | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index 8c91f35..366a791 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,11 +3,8 @@ - - - \ No newline at end of file diff --git a/lib/build.gradle b/lib/build.gradle index c3df5cc..f271682 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -42,8 +42,8 @@ task sourcesJar(type: Jar) { task javadoc(type: Javadoc) { failOnError false source = android.sourceSets.main.java.sourceFiles - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - classpath += configurations.compile + configurations.implementation.setCanBeResolved(true) + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation } // build a jar with javadoc From dfcacda03f9ec5447bdd36b623c12a917ad48f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Garc=C3=ADa?= Date: Thu, 21 Mar 2019 12:32:33 +0100 Subject: [PATCH 4/4] Minor typo --- lib/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index f271682..1983ec3 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -22,7 +22,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - } dependencies {