From 87777ea5202ad4b507c4351f45385a9c3517b248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Garc=C3=ADa?= Date: Tue, 30 Jan 2018 10:55:21 +0100 Subject: [PATCH] Add library files --- .idea/checkstyle-idea.xml | 18 ++ .idea/codeStyleSettings.xml | 240 +++++++++++++++ .idea/encodings.xml | 6 + .idea/markdown-navigator.xml | 72 +++++ .../markdown-navigator/profiles_settings.xml | 3 + .idea/misc.xml | 49 ++++ .idea/modules.xml | 10 + .idea/runConfigurations.xml | 12 + .idea/vcs.xml | 6 + README.md | 60 +++- app/build.gradle | 28 ++ app/proguard-rules.pro | 21 ++ .../ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 23 ++ .../overlayhelperexample/MainActivity.java | 77 +++++ .../drawable-v24/ic_launcher_foreground.xml | 34 +++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++ app/src/main/res/layout/activity_main.xml | 34 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 10 + .../adriangl/overlayhelper/ExampleUnitTest.kt | 16 + build.gradle | 26 ++ checkstyle.xml | 161 +++++++++++ code-style.xml | 242 ++++++++++++++++ gradle.properties | 17 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 ++++++++++ gradlew.bat | 90 ++++++ lib/.gitignore | 1 + lib/build.gradle | 59 ++++ lib/proguard-rules.pro | 21 ++ .../ExampleInstrumentedTest.java | 26 ++ lib/src/main/AndroidManifest.xml | 6 + .../overlayhelper/OverlayDelegate.java | 134 +++++++++ .../adriangl/overlayhelper/OverlayHelper.java | 273 ++++++++++++++++++ .../overlayhelper/ExampleUnitTest.java | 17 ++ settings.gradle | 1 + 51 files changed, 2173 insertions(+), 1 deletion(-) create mode 100644 .idea/checkstyle-idea.xml create mode 100644 .idea/codeStyleSettings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/markdown-navigator.xml create mode 100644 .idea/markdown-navigator/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/adriangl/overlayhelper/ExampleUnitTest.kt create mode 100644 build.gradle create mode 100644 checkstyle.xml create mode 100644 code-style.xml create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 lib/.gitignore create mode 100644 lib/build.gradle create mode 100644 lib/proguard-rules.pro create mode 100644 lib/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java create mode 100644 lib/src/main/AndroidManifest.xml create mode 100644 lib/src/main/java/com/adriangl/overlayhelper/OverlayDelegate.java create mode 100644 lib/src/main/java/com/adriangl/overlayhelper/OverlayHelper.java create mode 100644 lib/src/test/java/com/adriangl/overlayhelper/ExampleUnitTest.java create mode 100644 settings.gradle diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..3336ea0 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..e331aec --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,240 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..dbe0e46 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..13c4629 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..366a791 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 9e2cc16..3896bc1 100644 --- a/README.md +++ b/README.md @@ -1 +1,59 @@ -# OverlayHelper \ No newline at end of file +# OverlayHelper +[![Release](https://jitpack.io/v/adriangl/overlayhelper.svg)](https://jitpack.io/#adriangl/overlayhelper) + +This utility library aims to help Android developers handle "draw overlays" (also called "draw over other apps") permissions +and queries in a version-agnostic way. + +## Installation +Add the following dependencies to your main `build.gradle`: +```groovy +allprojects { + repositories { + maven { url "https://jitpack.io" } + } +} +``` + +Add the following dependencies to your app's `build.gradle`: + +* For Gradle < 4.0 + ```groovy + dependencies { + compile "com.github.adriangl:overlayhelper:1.0.0" + } + ``` + +* For Gradle 4.0+ + ```groovy + dependencies { + implementation "com.github.adriangl:overlayhelper:1.0.0" + } + ``` + +## Usage + +* Create a new _OverlayHelper_ with a _OverlayPermissionChangedListener_. +* Start watching settings changes with _OverlayHelper.startWatching()_, for example in _onCreate()_. +* Stop watching changes with _OverlayHelper.stopWatching()_ _onDestroy()_. +* If you want to check if the app has their "draw overlays" permission enabled, use _OverlayHelper.canDrawOverlays()_. +* Call _OverlayHelper.requestDrawOverlaysPermission()_ wherever you want in your activity. You'll have to also add _OverlayHelper.onRequestDrawOverlaysPermissionResult(int)_ in the activity's _onActivityResult()_, so the helper can retrieve the needed data. +* You'll receive your permission results in the _OverlayPermissionChangedListener_ that you registered when creating the helper. + +Check the [example app](app) for more implementation details. + +## License +``` +Copyright (C) 2018 Adrián García + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..5105bfb --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: "com.android.application" + +android { + compileSdkVersion 27 + defaultConfig { + applicationId "com.adriangl.overlayhelperexample" + minSdkVersion 19 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + } + } +} + +dependencies { + implementation project(":lib") + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "com.android.support:appcompat-v7:27.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" +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java new file mode 100644 index 0000000..1e573e3 --- /dev/null +++ b/app/src/androidTest/java/com/adriangl/overlayhelper/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.adriangl.overlayhelper; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.adriangl.overlayhelper.test", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..806ea20 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java b/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java new file mode 100644 index 0000000..ed750bc --- /dev/null +++ b/app/src/main/java/com/adriangl/overlayhelperexample/MainActivity.java @@ -0,0 +1,77 @@ +package com.adriangl.overlayhelperexample; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.adriangl.overlayhelper.OverlayHelper; + +/** + * Main {@link android.app.Activity} to test the library. + */ +public class MainActivity extends AppCompatActivity { + + @SuppressWarnings("FieldCanBeLocal") + private Button requestDrawOverlaysPermissionsButton; + private TextView drawOverlaysPermissionStatusTextView; + private OverlayHelper overlayHelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + requestDrawOverlaysPermissionsButton = findViewById(R.id.request_draw_overlays_button); + drawOverlaysPermissionStatusTextView = findViewById(R.id.draw_overlays_status_value); + + requestDrawOverlaysPermissionsButton.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + overlayHelper.requestDrawOverlaysPermission( + MainActivity.this, + "Request draw overlays permission?", + "You have to enable the draw overlays permission for this app to work", + "Enable", + "Cancel"); + } + }); + + overlayHelper = new OverlayHelper(this.getApplicationContext(), new OverlayHelper.OverlayPermissionChangedListener() { + @Override public void onOverlayPermissionCancelled() { + Toast.makeText(MainActivity.this, "Draw overlay permissions request canceled", Toast.LENGTH_SHORT).show(); + } + + @Override public void onOverlayPermissionGranted() { + Toast.makeText(MainActivity.this, "Draw overlay permissions request granted", Toast.LENGTH_SHORT).show(); + } + + @Override public void onOverlayPermissionDenied() { + Toast.makeText(MainActivity.this, "Draw overlay permissions request denied", Toast.LENGTH_SHORT).show(); + } + }); + + overlayHelper.startWatching(); + + updateOverlayStatusText(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + overlayHelper.onRequestDrawOverlaysPermissionResult(requestCode); + updateOverlayStatusText(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + overlayHelper.stopWatching(); + } + + private void updateOverlayStatusText() { + drawOverlaysPermissionStatusTextView.setText(overlayHelper.canDrawOverlays() ? "Enabled" : "Disabled"); + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..8e9dacc --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..f1cc2f6 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..3b4ca58 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + +