Let


Source link: https://github.com/canelmas/let

Let

Annotation based simple API flavoured with AOP to handle new Android runtime permission model.

If you check Google's Samples 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.

@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();

  ... 
}
@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:

@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:

public class SampleActivity extends AppCompatActivity implements RuntimePermissionListener {

 // ....

 @Override
  public void onShowPermissionRationale(List<String> 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<DeniedPermission> 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!

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 :

buildscript {

  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.* <methods>; 
}
 

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 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. 

Resources

A lovely snail, you can use it as a seekbar or progressbar.

A beautiful RefreshLayout.

Android indeterminate loader widget with rubber shape and color animations.

Easy Android RSS (and also Atom) parser Library

Features:

  • Earl parses both Atom and RSS 1.0/2.0
  • Supports RSS extensions (Itunes and Media RSS for now)
  • It's lightweight. There is nothing there but parser. The only dependency it has is android annotations
  • Parser produces easy-to-use immutable POJOs
  • Runs on android versions starting from Android 2.2 (API 8)

Filter the react native android logcat.

This is a drop-down control, it is more beautiful and powerful than SwipeRefreshLayout.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes