From 640d462af2e3e30ddab486cfd0bf2ff9e018f72c Mon Sep 17 00:00:00 2001 From: Zaheer Date: Sun, 5 Feb 2023 12:04:08 +0500 Subject: [PATCH 1/3] Migrated to andriodx, implemented permission handler to draw over other apps. --- .idea/runConfigurations.xml | 12 ------- app/build.gradle | 10 +++--- app/src/main/AndroidManifest.xml | 1 + .../java/nl/rogro82/pipup/MainActivity.kt | 31 +++++++++++++++++-- .../java/nl/rogro82/pipup/PiPupService.kt | 6 ++-- .../main/java/nl/rogro82/pipup/Receiver.kt | 2 +- app/src/main/res/layout/activity_main.xml | 4 +-- build.gradle | 4 +-- gradle.properties | 2 ++ 9 files changed, 44 insertions(+), 28 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d9fbdb5..826d352 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,11 +5,11 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { applicationId "nl.rogro82.pipup" minSdkVersion 24 - targetSdkVersion 28 + targetSdkVersion 31 versionCode 6 versionName "0.1.5-beta" } @@ -24,13 +24,13 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support:leanback-v17:28.0.0' - implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'androidx.leanback:leanback:1.0.0' + implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.+' implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.+' implementation 'org.nanohttpd:nanohttpd:2.3.1' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2b1e445..ae76f0a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,6 +43,7 @@ = Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) { + askPermission(); + } // start service in foreground val textViewConnection = findViewById(R.id.textViewServerAddress) @@ -59,4 +67,23 @@ class MainActivity : Activity() { startService(serviceIntent) } } + + private fun askPermission() { + + val intent = + Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName")) + startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) + } + + @RequiresApi(api = Build.VERSION_CODES.M) + override fun onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) { + if (!Settings.canDrawOverlays(this)) { + askPermission() + } + } + } + + } diff --git a/app/src/main/java/nl/rogro82/pipup/PiPupService.kt b/app/src/main/java/nl/rogro82/pipup/PiPupService.kt index 4a0ae48..bd40036 100644 --- a/app/src/main/java/nl/rogro82/pipup/PiPupService.kt +++ b/app/src/main/java/nl/rogro82/pipup/PiPupService.kt @@ -8,7 +8,7 @@ import android.graphics.PixelFormat import android.os.Build import android.os.Handler import android.os.IBinder -import android.support.v4.app.NotificationCompat +import androidx.core.app.NotificationCompat import android.util.Log import android.view.Gravity import android.view.View @@ -33,7 +33,7 @@ class PiPupService : Service(), WebServer.Handler { val pendingIntent = PendingIntent.getActivity( this, 0, - Intent(this, MainActivity::class.java), 0 + Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE ) val mBuilder = NotificationCompat.Builder(this, "service_channel") @@ -269,7 +269,7 @@ class PiPupService : Service(), WebServer.Handler { } catch (ex: Throwable) { - Log.e(LOG_TAG, ex.message) + Log.e(LOG_TAG, ex.message.toString()) InvalidRequest(ex.message) } } diff --git a/app/src/main/java/nl/rogro82/pipup/Receiver.kt b/app/src/main/java/nl/rogro82/pipup/Receiver.kt index 28c7ac0..647a72b 100644 --- a/app/src/main/java/nl/rogro82/pipup/Receiver.kt +++ b/app/src/main/java/nl/rogro82/pipup/Receiver.kt @@ -4,7 +4,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build -import android.support.v4.content.ContextCompat.startForegroundService +import androidx.core.content.ContextCompat.startForegroundService class Receiver : BroadcastReceiver() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8ab5b50..7981d5f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/build.gradle b/build.gradle index b39ac10..c832cb8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,10 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.50' repositories { google() jcenter() - } dependencies { classpath 'com.android.tools.build:gradle:3.4.1' @@ -19,7 +18,6 @@ allprojects { repositories { google() jcenter() - } } diff --git a/gradle.properties b/gradle.properties index 85be9ea..3d8ce0c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,5 @@ org.gradle.jvmargs=-Xmx1536m # org.gradle.parallel=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +android.useAndroidX=true +android.enableJetifier=true From ead63de103a421bbded97aaa75934d4f57616a58 Mon Sep 17 00:00:00 2001 From: Zaheer Date: Sun, 5 Feb 2023 12:07:22 +0500 Subject: [PATCH 2/3] updated version for androidx builds and readme --- app/build.gradle | 4 ++-- readme.md | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 826d352..b6b4f81 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "nl.rogro82.pipup" minSdkVersion 24 targetSdkVersion 31 - versionCode 6 - versionName "0.1.5-beta" + versionCode 0 + versionName "1" } buildTypes { release { diff --git a/readme.md b/readme.md index a0fec8e..0a18940 100644 --- a/readme.md +++ b/readme.md @@ -105,4 +105,8 @@ Form-fields: | 3 | BottomLeft | | 4 | Center | -Color-properties are in `[AA]RRGGBB` where the alpha channel is optional e.g. #FFFFFF or #CCFFFFFF \ No newline at end of file +Color-properties are in `[AA]RRGGBB` where the alpha channel is optional e.g. #FFFFFF or #CCFFFFFF + + +### Contributors: + - Zaheer \ No newline at end of file From c36aec1591817c08c6fb8f8ece9e1f811f08516a Mon Sep 17 00:00:00 2001 From: Zaheer Date: Sun, 5 Feb 2023 12:10:13 +0500 Subject: [PATCH 3/3] android.defaultConfig.versionCode is set to 0, but it should be a positive integer. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index b6b4f81..1ff6944 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { applicationId "nl.rogro82.pipup" minSdkVersion 24 targetSdkVersion 31 - versionCode 0 + versionCode 1 versionName "1" } buildTypes {