Skip to content

Android 9+ support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ captures/
.idea/gradle.xml
.idea/dictionaries
.idea/libraries
.idea/caches
.idea/codeStyles

# Keystore files
*.jks
Expand Down
17 changes: 14 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
19 changes: 9 additions & 10 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}

Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
28 changes: 26 additions & 2 deletions lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}
16 changes: 10 additions & 6 deletions lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand Down Expand Up @@ -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
Expand Down