From 6ef4be9fa56da9135c7b0ec60ea063ea7b1dfb5e Mon Sep 17 00:00:00 2001 From: Dhruv Nagarajan Date: Tue, 29 Oct 2019 15:06:21 +0530 Subject: [PATCH 1/4] Add support for Kt Extensions --- .idea/codeStyles/Project.xml | 134 ++++++++++++++---- .idea/gradle.xml | 1 + build.gradle | 2 + permissions/build.gradle | 6 + .../nabinbhandari/android/permissions/Ext.kt | 16 +++ sample/build.gradle | 10 +- .../permissions/sample/MainActivity.java | 71 ---------- .../permissions/sample/MainActivity.kt | 64 +++++++++ 8 files changed, 206 insertions(+), 98 deletions(-) create mode 100644 permissions/src/main/java/com/nabinbhandari/android/permissions/Ext.kt delete mode 100644 sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.java create mode 100644 sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.kt diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 30aa626..ae78c11 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,29 +1,113 @@ - - - - - - - - - - + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 5b97d69..e79407b 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -13,6 +13,7 @@ diff --git a/build.gradle b/build.gradle index 0928e2b..a87cc9c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.50' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Uncomment following two lines only during publishing. // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' diff --git a/permissions/build.gradle b/permissions/build.gradle index 5b12744..06d953f 100644 --- a/permissions/build.gradle +++ b/permissions/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' ext { bintrayRepo = 'android' @@ -38,6 +40,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } // Uncomment following two lines only during publishing. diff --git a/permissions/src/main/java/com/nabinbhandari/android/permissions/Ext.kt b/permissions/src/main/java/com/nabinbhandari/android/permissions/Ext.kt new file mode 100644 index 0000000..02c0e12 --- /dev/null +++ b/permissions/src/main/java/com/nabinbhandari/android/permissions/Ext.kt @@ -0,0 +1,16 @@ +package com.nabinbhandari.android.permissions + +import android.app.Activity + +/** + * @author Dhruvaraj Nagarajan + */ +fun Activity.checkPermission(permissions: Array, rationale: String?, + options: Permissions.Options?, handler: PermissionHandler) { + Permissions.check(this, permissions, rationale, options, handler) +} + + +fun Activity.checkPermission(permissions: String, rationale: String?, handler: PermissionHandler) { + Permissions.check(this, permissions, rationale, handler) +} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 114a2d4..2630e9f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' android { compileSdkVersion 27 @@ -15,6 +17,10 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - // implementation project(':permissions') - implementation 'com.nabinbhandari.android:permissions:3.8' + implementation project(':permissions') +// implementation 'com.nabinbhandari.android:permissions:3.8' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.java b/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.java deleted file mode 100644 index c1a60e8..0000000 --- a/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nabinbhandari.permissions.sample; - -import android.Manifest; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.provider.Settings; -import android.view.View; -import android.widget.Toast; - -import com.nabinbhandari.android.permissions.PermissionHandler; -import com.nabinbhandari.android.permissions.Permissions; - -import java.util.ArrayList; - -public class MainActivity extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - public void requestPhone(View view) { - Permissions.check(this, Manifest.permission.CALL_PHONE, null, new PermissionHandler() { - @Override - public void onGranted() { - Toast.makeText(MainActivity.this, "Phone granted.", Toast.LENGTH_SHORT).show(); - } - }); - } - - public void requestCameraAndStorage(View view) { - String[] permissions = {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}; - Permissions.check(this, permissions, null, null, new PermissionHandler() { - @Override - public void onGranted() { - Toast.makeText(MainActivity.this, "Camera+Storage granted.", Toast.LENGTH_SHORT).show(); - } - }); - } - - public void requestLocation(View view) { - String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION}; - String rationale = "Please provide location permission so that you can ..."; - Permissions.Options options = new Permissions.Options() - .setRationaleDialogTitle("Info") - .setSettingsDialogTitle("Warning"); - - Permissions.check(this, permissions, rationale, options, new PermissionHandler() { - @Override - public void onGranted() { - Toast.makeText(MainActivity.this, "Location granted.", Toast.LENGTH_SHORT).show(); - } - - @Override - public void onDenied(Context context, ArrayList deniedPermissions) { - Toast.makeText(MainActivity.this, "Location denied.", Toast.LENGTH_SHORT).show(); - } - }); - } - - public void openSettings(View view) { - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, - Uri.fromParts("package", getPackageName(), null)); - startActivity(intent); - } - -} diff --git a/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.kt b/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.kt new file mode 100644 index 0000000..af16ffa --- /dev/null +++ b/sample/src/main/java/com/nabinbhandari/permissions/sample/MainActivity.kt @@ -0,0 +1,64 @@ +package com.nabinbhandari.permissions.sample + +import android.Manifest +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.provider.Settings +import android.view.View +import android.widget.Toast +import com.nabinbhandari.android.permissions.PermissionHandler +import com.nabinbhandari.android.permissions.Permissions +import com.nabinbhandari.android.permissions.checkPermission +import java.util.* + +class MainActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } + + fun requestPhone(view: View) { + checkPermission(Manifest.permission.CALL_PHONE, null, object : PermissionHandler() { + override fun onGranted() { + Toast.makeText(this@MainActivity, "Phone granted.", Toast.LENGTH_SHORT).show() + } + }) + } + + fun requestCameraAndStorage(view: View) { + val permissions = arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE) + checkPermission(permissions, null, null, object : PermissionHandler() { + override fun onGranted() { + Toast.makeText(this@MainActivity, "Camera+Storage granted.", Toast.LENGTH_SHORT).show() + } + }) + } + + fun requestLocation(view: View) { + val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION) + val rationale = "Please provide location permission so that you can ..." + val options = Permissions.Options() + .setRationaleDialogTitle("Info") + .setSettingsDialogTitle("Warning") + + checkPermission(permissions, rationale, options, object : PermissionHandler() { + override fun onGranted() { + Toast.makeText(this@MainActivity, "Location granted.", Toast.LENGTH_SHORT).show() + } + + override fun onDenied(context: Context, deniedPermissions: ArrayList) { + Toast.makeText(this@MainActivity, "Location denied.", Toast.LENGTH_SHORT).show() + } + }) + } + + fun openSettings(view: View) { + val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + Uri.fromParts("package", packageName, null)) + startActivity(intent) + } +} From b633dc8a765173e35734155e4685b35fdaed8265 Mon Sep 17 00:00:00 2001 From: Dhruv Nagarajan Date: Tue, 29 Oct 2019 15:08:46 +0530 Subject: [PATCH 2/4] Update gitignore --- permissions/.gitignore | 66 +++++++++++++++++++++++++++++++++++++++++- sample/.gitignore | 66 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 2 deletions(-) diff --git a/permissions/.gitignore b/permissions/.gitignore index 796b96d..3c117df 100644 --- a/permissions/.gitignore +++ b/permissions/.gitignore @@ -1 +1,65 @@ -/build +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md \ No newline at end of file diff --git a/sample/.gitignore b/sample/.gitignore index 796b96d..3c117df 100644 --- a/sample/.gitignore +++ b/sample/.gitignore @@ -1 +1,65 @@ -/build +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +.idea/caches + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md \ No newline at end of file From e4841e563335d557c5b6b157197947fe89d2fc57 Mon Sep 17 00:00:00 2001 From: Dhruv Nagarajan Date: Tue, 29 Oct 2019 15:29:46 +0530 Subject: [PATCH 3/4] Update readme --- .idea/modules.xml | 3 +++ readme.md | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.idea/modules.xml b/.idea/modules.xml index 4f20aba..b7b589e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,9 @@ + + + diff --git a/readme.md b/readme.md index 3942dc1..b3406f6 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,23 @@ implementation 'com.nabinbhandari.android:permissions:3.8' Usage: ------ +All call types shown below can be made directly from Activity as they are extensions as well. + +Example: +```kotlin +override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + checkPermission(Manifest.permission.CALL_PHONE, null, object: PermissionHandler { + override fun onGranted() { + // do your task. + } + }) +} +``` + + First declare your permissions in the manifest. Example: From 786083f9db703b7c3dcfb8607204dbc2ebad51eb Mon Sep 17 00:00:00 2001 From: Dhruv Nagarajan Date: Tue, 29 Oct 2019 15:34:03 +0530 Subject: [PATCH 4/4] Target SDK 29 --- .idea/codeStyles/Project.xml | 3 +++ .idea/compiler.xml | 22 ----------------- .idea/copyright/profiles_settings.xml | 3 --- .idea/misc.xml | 34 +-------------------------- .idea/modules.xml | 5 +--- .idea/vcs.xml | 7 +----- permissions/build.gradle | 4 ++-- sample/build.gradle | 6 ++--- 8 files changed, 11 insertions(+), 73 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index ae78c11..681f41a 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,6 +1,9 @@ + +
diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f3d13dd..0d45e8d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,36 +1,4 @@ - - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index b7b589e..8c9a46a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,10 +2,7 @@ - - - - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 5fc0921..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,11 +1,6 @@ - - - - + \ No newline at end of file diff --git a/permissions/build.gradle b/permissions/build.gradle index 06d953f..a39a537 100644 --- a/permissions/build.gradle +++ b/permissions/build.gradle @@ -27,12 +27,12 @@ ext { } android { - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { //noinspection MinSdkTooLow minSdkVersion 1 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 3 versionName "$libraryVersion" } diff --git a/sample/build.gradle b/sample/build.gradle index 2630e9f..20a0a4d 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 27 + compileSdkVersion 29 defaultConfig { applicationId "com.nabinbhandari.permissions.sample" minSdkVersion 14 - targetSdkVersion 27 + targetSdkVersion 29 versionCode 1 versionName "1.0" }