diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 30aa626..681f41a 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,29 +1,116 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ 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/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/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/.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 4f20aba..8c9a46a 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +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/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/.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/permissions/build.gradle b/permissions/build.gradle
index 5b12744..a39a537 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'
@@ -25,12 +27,12 @@ ext {
}
android {
- compileSdkVersion 27
+ compileSdkVersion 29
defaultConfig {
//noinspection MinSdkTooLow
minSdkVersion 1
- targetSdkVersion 27
+ targetSdkVersion 29
versionCode 3
versionName "$libraryVersion"
}
@@ -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/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:
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
diff --git a/sample/build.gradle b/sample/build.gradle
index 114a2d4..20a0a4d 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -1,12 +1,14 @@
apply plugin: 'com.android.application'
+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"
}
@@ -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)
+ }
+}