Skip to content

Commit 61475c7

Browse files
authored
Merge pull request #1 from adriangl/feature/android-p
Android 9+ support
2 parents 39fafc3 + dfcacda commit 61475c7

File tree

12 files changed

+78
-38
lines changed

12 files changed

+78
-38
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ captures/
3939
.idea/gradle.xml
4040
.idea/dictionaries
4141
.idea/libraries
42+
.idea/caches
43+
.idea/codeStyles
4244

4345
# Keystore files
4446
*.jks

.idea/misc.xml

+14-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Add the following dependencies to your app's `build.gradle`:
1919
* For Gradle < 4.0
2020
```groovy
2121
dependencies {
22-
compile "com.github.adriangl:overlayhelper:1.0.0"
22+
compile "com.github.adriangl:overlayhelper:1.1.0"
2323
}
2424
```
2525
2626
* For Gradle 4.0+
2727
```groovy
2828
dependencies {
29-
implementation "com.github.adriangl:overlayhelper:1.0.0"
29+
implementation "com.github.adriangl:overlayhelper:1.1.0"
3030
}
3131
```
3232

app/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
apply plugin: "com.android.application"
22

33
android {
4-
compileSdkVersion 27
4+
compileSdkVersion 28
55
defaultConfig {
66
applicationId "com.adriangl.overlayhelperexample"
77
minSdkVersion 19
8-
targetSdkVersion 27
8+
targetSdkVersion 28
99
versionCode 1
10-
versionName "1.0"
11-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
10+
versionName "1.1"
11+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {
1414
release {
@@ -21,8 +21,8 @@ android {
2121
dependencies {
2222
implementation project(":lib")
2323
implementation fileTree(dir: "libs", include: ["*.jar"])
24-
implementation "com.android.support:appcompat-v7:27.0.2"
24+
implementation 'androidx.appcompat:appcompat:1.0.2'
2525
testImplementation "junit:junit:4.12"
26-
androidTestImplementation "com.android.support.test:runner:1.0.1"
27-
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
26+
androidTestImplementation 'androidx.test:runner:1.1.1'
27+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
2828
}

app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.adriangl.overlayhelper;
22

33
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.test.runner.AndroidJUnit4;
66

77
import org.junit.Test;
88
import org.junit.runner.RunWith;

app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import android.content.Intent;
44
import android.os.Bundle;
5-
import android.support.v7.app.AppCompatActivity;
5+
import androidx.appcompat.app.AppCompatActivity;
66
import android.view.View;
77
import android.widget.Button;
88
import android.widget.TextView;

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath "com.android.tools.build:gradle:3.0.1"
9+
classpath 'com.android.tools.build:gradle:3.4.0-rc02'
1010
classpath "com.github.dcendents:android-maven-gradle-plugin:2.0"
1111

1212
// NOTE: Do not place your application dependencies here; they belong
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Jan 25 16:20:43 CET 2018
1+
#Thu Mar 21 11:09:33 CET 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

lib/build.gradle

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ apply plugin: 'com.github.dcendents.android-maven'
44
group = "com.github.adriangl"
55

66
android {
7-
compileSdkVersion 27
7+
compileSdkVersion 28
88

99
defaultConfig {
1010
minSdkVersion 19
11-
targetSdkVersion 27
11+
targetSdkVersion 28
1212
versionCode 1
13-
versionName "1.0"
13+
versionName "1.1"
1414

15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616

1717
}
1818

@@ -22,15 +22,14 @@ android {
2222
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2323
}
2424
}
25-
2625
}
2726

2827
dependencies {
2928
implementation fileTree(dir: 'libs', include: ['*.jar'])
30-
implementation "com.android.support:support-annotations:27.0.2"
29+
implementation 'androidx.annotation:annotation:1.0.2'
3130
testImplementation 'junit:junit:4.12'
32-
androidTestImplementation 'com.android.support.test:runner:1.0.1'
33-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
31+
androidTestImplementation 'androidx.test:runner:1.1.1'
32+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
3433
}
3534

3635
// build a jar with source files
@@ -42,8 +41,8 @@ task sourcesJar(type: Jar) {
4241
task javadoc(type: Javadoc) {
4342
failOnError false
4443
source = android.sourceSets.main.java.sourceFiles
45-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
46-
classpath += configurations.compile
44+
configurations.implementation.setCanBeResolved(true)
45+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation
4746
}
4847

4948
// build a jar with javadoc

lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.adriangl.overlayhelper;
22

33
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.test.runner.AndroidJUnit4;
66

77
import org.junit.Test;
88
import org.junit.runner.RunWith;

lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import android.content.Context;
55
import android.os.Build;
66
import android.provider.Settings;
7-
import android.support.annotation.RequiresApi;
8-
import android.support.annotation.RequiresPermission;
7+
import androidx.annotation.RequiresApi;
8+
import androidx.annotation.RequiresPermission;
99

1010
/**
1111
* Interface used to implement custom overlay checking behaviour depending on device version.
@@ -131,4 +131,28 @@ public boolean canDrawOverlays() {
131131
return canDrawOverlays;
132132
}
133133
}
134+
135+
/**
136+
* Implementation of {@link OverlayDelegate} for devices with API level >= 28.
137+
*/
138+
@RequiresApi(api = Build.VERSION_CODES.P)
139+
class PieOverlayDelegate implements OverlayDelegate {
140+
private final Context context;
141+
142+
PieOverlayDelegate(Context context) {
143+
this.context = context;
144+
}
145+
146+
@Override public void startWatching() {
147+
// No-op
148+
}
149+
150+
@Override public void stopWatching() {
151+
// No-op
152+
}
153+
154+
@Override public boolean canDrawOverlays() {
155+
return Settings.canDrawOverlays(context);
156+
}
157+
}
134158
}

lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import android.net.Uri;
1212
import android.os.Build;
1313
import android.provider.Settings;
14-
import android.support.annotation.NonNull;
15-
import android.support.annotation.Nullable;
16-
import android.support.annotation.RequiresPermission;
17-
import android.support.annotation.StringRes;
1814

1915
import java.util.Arrays;
2016
import java.util.List;
2117

18+
import androidx.annotation.NonNull;
19+
import androidx.annotation.Nullable;
20+
import androidx.annotation.RequiresPermission;
21+
import androidx.annotation.StringRes;
22+
2223
/**
2324
* Helper class that takes care of querying and requesting permissions for drawing over other apps.
2425
* <p>
@@ -54,8 +55,11 @@ public OverlayHelper(@NonNull Context ctx, @Nullable OverlayPermissionChangedLis
5455
this.context = ctx.getApplicationContext();
5556
this.overlayPermissionChangedListener = listener;
5657

57-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
58-
// API 26+
58+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
59+
// API 28+: The checks return to API 23-like behaviour
60+
this.overlayDelegate = new OverlayDelegate.PieOverlayDelegate(context);
61+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
62+
// API 26+: Fucks up checks, so we need to store the values of the alert window setting in the delegate
5963
this.overlayDelegate = new OverlayDelegate.OreoOverlayDelegate(context);
6064
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
6165
// API 23+: check if the user has explicitly enabled overlays

0 commit comments

Comments
 (0)