Rationale


Source link: https://github.com/KingsMentor/Rationale

Rationale

Android permission Rationale Helper. Similar to WhatsApp Permission Rationale Dialog that manages permission request .

How it Works.

  1. Init with a list of Permission called SmoothPermissions
  2. Rationale runs a check on all SmoothPermissions to determine which Permission to show a message for
  3. if the list is empty, it returns success with empty list
  4. if there is any permission to be granted, it shows the appropraite rationale to the user
  5. returns permissions to be requested for based on user interaction

Adding Rationale to your Project

Step 1 Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

 ...

 maven {
 url 'https://jitpack.io' 
}

}

  
}
 

Step 2 Add the dependency

dependencies {

 compile 'com.github.KingsMentor:Rationale:v1.0'
  
}

Using Rationale

Using in an Activity

private final int PERM = 2017;  final PermissionDetails smsPermissionDetails = new PermissionDetails().getPermissionDetails(this, Manifest.permission.READ_SMS, R.drawable.ic_sms_white_24dp);

Rationale.withActivity(this)

  .requestCode(PERM)

  .addSmoothPermission(new SmoothPermission(smsPermissionDetails))

  .includeStyle(R.style.Beliv_RationaleStyle).build(true);

Using in a Fragment*


  Rationale.withFragment(this)

  .requestCode(PERM)

  .addSmoothPermission(new SmoothPermission(smsPermissionDetails))

  .includeStyle(R.style.Beliv_RationaleStyle).build(true);
  • requestCode - request code to track response from onActivityResult
  • includeStyle - styling the Rationale Dialog. more details on styling is found below
  • SmoothPermissions - List of Permission to run Rationale Dialog on
  • build - takes true for Rationale Dialog to show Permission that has not been granted. false to only show rationale for permission permanently denied.
PermissionDetails

Build permission with :

  • Permission name
  • Permission Icon
  • rationaleMessage
  • deniedMessage - message to display when Permission is permanently denied by the user
  • description - System Permission Description
  • protectionLevel - Protection level of permission

Response from Rationale

Rationale returns response via onActivityResult. Here is a snippet on handling response from Rationale.

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (Rationale.isResultFromRationale(requestCode, PERM)) {

 RationaleResponse rationaleResponse = Rationale.getRationaleResponse(data);

 if (rationaleResponse.shouldRequestForPermissions()) {

  // a list of permission to be requested for

  ArrayList<SmoothPermission> smoothPermissions = rationaleResponse.getSmoothPermissions();

// request for permissions

 
}
 else if (rationaleResponse.userDecline()) {

  Toast.makeText(this, "user does not want to do this now", Toast.LENGTH_LONG).show();

 
}
 else {

  Toast.makeText(this, "permission is accepted", Toast.LENGTH_LONG).show();

 
}

}

}

Styling Rationale

Rationale dialog can be placing this in styles.xml changing the values to suite your need and including it when initialising Rationale with includeStyle(styleRes)

 <style name="Beliv.RationaleStyle" parent="Theme.AppCompat">

<!-- Customize your theme here. -->

<item name="bv_primary">@color/primary_color</item>

<item name="bv_secondary">@color/secondary_color</item>

<item name="bv_rationale_state_visibility">true</item>

<item name="bv_rationale_state_ignore_color">@color/ignore_state</item>

<item name="bv_rationale_state_deny_color">@color/deny_state</item>

<item name="bv_rationale_text_color_deny">@color/grey</item>

<item name="bv_rationale_text_color_ignore">@color/ignore_state</item>

<item name="bv_card_corner_radius">@dimen/card_corner</item>

<item name="bv_rationale_text_size">@dimen/rationale_text_size</item>

<item name="bv_rationale_text_font">@string/rationale_font</item>

</style>

#License The MIT License (MIT). Please see the License File for more information.

Resources

A Reactive wrapper around Google's YouTube Data API.

material-dialogs library allows you to use a consistently Material themed dialog on all versions of Android, along with specific customizations that make it easier to brand the dialog.

Navigation Drawer Activity with material design style and simplified methods.

Every major open-source project has its own style guide: a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style.

"Style" covers a lot of ground, from "use camelCase for variable names" to "never use global variables" to "never use exceptions." This project holds the style guidelines we use for Google code. If you are modifying a project that originated at Google, you may be pointed to this page to see the style guides that apply to that project.

This library display hierarchical data (e.g. comments) in a list view, so that the user can collapse and expand elements. Every element is indented accordingly to its level in the hierarchy.

Floating Action Menu for Android. Inspired by the Google Plus floating menu.

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