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/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..f00fb05 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,14 +1,14 @@ 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" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + versionName "1.1" + 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:27.0.2" + implementation 'androidx.appcompat:appcompat:1.0.2' 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 '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/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..1983ec3 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -4,15 +4,15 @@ 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" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -22,15 +22,14 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.android.support:support-annotations:27.0.2" + implementation 'androidx.annotation:annotation:1.0.2' 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 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } // build a jar with source files @@ -42,8 +41,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 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 e7b5f20..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. @@ -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..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. *

@@ -54,8 +55,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