Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/canelmas/let
Annotation based simple API flavored with AOP to handle new Android runtime permission model
https://github.com/canelmas/let
android aop aop-aspectj gradle gradle-plugin kotlin kotlin-android library runtime-permissions
Last synced: 1 day ago
JSON representation
Annotation based simple API flavored with AOP to handle new Android runtime permission model
- Host: GitHub
- URL: https://github.com/canelmas/let
- Owner: canelmas
- License: apache-2.0
- Created: 2015-10-22T09:24:28.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-11T11:35:10.000Z (almost 7 years ago)
- Last Synced: 2025-01-13T02:07:29.330Z (8 days ago)
- Topics: android, aop, aop-aspectj, gradle, gradle-plugin, kotlin, kotlin-android, library, runtime-permissions
- Language: Java
- Homepage:
- Size: 2.68 MB
- Stars: 530
- Watchers: 12
- Forks: 40
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Let
====[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Let-green.svg?style=true)](https://android-arsenal.com/details/1/2843) [![](https://img.shields.io/badge/AndroidWeekly-%23182-red.svg)](http://androidweekly.net/issues/issue-182)
[![Join the chat at https://gitter.im/canelmas/let](https://badges.gitter.im/canelmas/let.svg)](https://gitter.im/canelmas/let?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)Annotation based simple API flavoured with [AOP](https://en.wikipedia.org/wiki/Aspect-oriented_programming) to handle new Android runtime permission model.
If you check [Google's Samples](https://github.com/googlesamples/android-RuntimePermissions/blob/master/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java)
about the new permission model, you'll see a lot of boiler plate code for requesting, handling
and retrying the request for required permissions.Let will minimize the boiler plate code you have to write for requesting and handling permissions and hence
help you keep your code more readable.
Let let Handle
====Annotate your methods requiring permissions with `@AskPermission` and let Let handle the rest.
```java
@AskPermission(ACCESS_FINE_LOCATION)
private void getUserLocationAndDoSomething() {
Toast.makeText(
SampleActivity.this,
"Now that I have the permission I need, I'll get your location and do something with it",
Toast.LENGTH_SHORT
).show();
...
}
``````java
@AskPermission({
Manifest.permission.READ_CONTACTS,
Manifest.permission.CALL_PHONE,
Manifest.permission.CAMERA
})
private void skipTutorial() {
// permissions needed for the best app experience are granted; let's go to the app's home screen
startActivity(new Intent(this, HomeActivity.class));
}
```Let will check these annotated methods and execute them unless the permissions required are granted;
otherwise Let will put on hold the method execution and request these permissions at runtime. After examining
the permission request result, Let will execute the method already put on hold only if the permissions are granted by user.
Let will also inform about the rationales before making any permission request
and tell about denied permissions; whether they're simply denied or with 'Never Ask Again' checked.
Just make sure to override the `onRequestPermissionsResult` in your Activity or Fragment, where your
`@AskPermission` annotated methods are located:```java
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
Let.handle(this, requestCode, permissions, grantResults);
}
```And make sure your Activity or Fragment implements `RuntimePermissionListener` in order to get notified
about denied permissions and rationales:```java
public class SampleActivity extends AppCompatActivity implements RuntimePermissionListener {
// ....
@Override
public void onShowPermissionRationale(List permissions, final RuntimePermissionRequest request) {
/**
* you may show permission rationales in a dialog, wait for user confirmation and retry the permission
* request by calling request.retry()
*/
}
@Override
public void onPermissionDenied(List deniedPermissionList) {
/**
* Do whatever you need to do about denied permissions:
* - update UI
* - if permission is denied with 'Never Ask Again', prompt a dialog to tell user
* to go to the app settings screen in order to grant again the permission denied
*/
}
// ...
}
```Usage
====Add it to your project today!
```groovy
buildscript {
repositories {
jcenter()
}dependencies {
classpath 'com.canelmas.let:let-plugin:0.1.11'
}
}apply plugin: 'com.android.application'
apply plugin: 'let'repositories {
jcenter()
}
```For kotlin :
```groovybuildscript {
repositories {
jcenter()
}dependencies {
classpath 'com.canelmas.let:let-plugin:1.0.0-beta1'
}
}apply plugin: 'com.android.application'
apply plugin: 'let'repositories {
jcenter()
}
```Proguard
====Make sure your proguard rule set includes following lines:
-keep class com.canelmas.let.** { *; }
-keepnames class * implements com.canelmas.let.RuntimePermissionListener-keepclassmembers class * implements com.canelmas.let.RuntimePermissionListener {
public void onRequestPermissionsResult(***);
}-keepclasseswithmembernames class * {
@com.canelmas.let.* ;
}License
====Copyright 2016 Can Elmas
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 athttp://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.