Skip to content

Commit

Permalink
Merge pull request #1 from adriangl/feature/android-p
Browse files Browse the repository at this point in the history
Android 9+ support
  • Loading branch information
adriangl authored Mar 21, 2019
2 parents 39fafc3 + dfcacda commit 61475c7
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 38 deletions.
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

0 comments on commit 61475c7

Please sign in to comment.