Permiso


Source link: https://github.com/greysonp/permiso

Permiso

Permiso is an Android library that makes requesting runtime permissions a whole lot easier.

Have you seen the docs for how to request runtime permissions? Who wants to do that every time you request a permission? Let's clean this up!

Features

  • Localizes permission requests so you can handle everything using a simple callback mechanism.
  • Can easily make permission requests outside of the context of an Activity.
  • Simplifies showing the user your rationale for requesting a permission.
  • Can request multiple permissions at once.
  • Merges simultaneous requests for the same permission into a single request.

Usage

If your Activity subclasses PermisoActivity, requesting a permission is as simple as:

Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {

  @Override
  public void onPermissionResult(Permiso.ResultSet resultSet) {

if (resultSet.areAllPermissionsGranted()) {

 // Permission granted!

}
 else {

 // Permission denied.

}

  
}

@Override
  public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {

Permiso.getInstance().showRationaleInDialog("Title", "Message", null, callback);

  
}
 
}
, Manifest.permission.READ_EXTERNAL_STORAGE);

Requesting Multiple Permissions

Requesting multiple permissions at once is just as easy.

Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {

  @Override
  public void onPermissionResult(Permiso.ResultSet resultSet) {

if (resultSet.isPermissionGranted(Manifest.permission.READ_CONTACTS)) {

 // Contact permission granted!

}

if (resultSet.isPermissionGranted(Manifest.permission.READ_CALENDAR)) {

 // Calendar permission granted!

}

  
}

@Override
  public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {

Permiso.getInstance().showRationaleInDialog("Title", "Message", null, callback);

  
}
 
}
, Manifest.permission.READ_CONTACTS, Manifest.permission.READ_CALENDAR);

Gradle

Latest Stable Version

dependencies {

  compile 'com.greysonparrelli.permiso:permiso:0.3.0' 
}

Latest Dev Version

// In your top-level build.gradle repositories {

  maven {
 url "https://www.jitpack.io" 
}
 
}
 // In your module's build.gradle dependencies {

  compile 'com.github.greysonp:permiso:master-SNAPSHOT' 
}

FAQ

I don't want my Activity to subclass PermisoActivity. Do I have to?

Of course not! Permiso requires very little boilerplate, and therefore PermisoActivity does very little. If you don't want to subclass PermisoActivity, all you have to do is make sure you do the two following things:

  • In onCreate() and onResume(), invoke Permiso.getInstance().setActivity(this).
  • Forward the results of Activity.onRequestPermissionsResult() to Permiso.getInstance().onRequestPermissionResult().

Here's an example:

@Override protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  Permiso.getInstance().setActivity(this);
 
}
  @Override protected void onResume() {

  super.onResume();

  Permiso.getInstance().setActivity(this);
 
}
  @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

  super.onRequestPermissionsResult(requestCode, permissions, grantResults);

  Permiso.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults);
 
}

I don't want to show any rationale for my permissions.

According to the Android Guidelines you probably should, but there's no hard requirement. If you don't want to show a rationale, simply invoke the callback and do nothing else:

@Override public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {

  callback.onRationaleProvided();
 
}

I want to do some complicated logic with the results of my permission request, but the ResultSet doesn't let me.

Fear not! The ResultSet object has a method called toMap(), which will give you back a mapping of permissions -> Permiso.Result that you can iterate over to your heart's content.

What do you mean when you say that Permiso merges simultaneous requests for the same permission into a single request?

If you request the same permission in two places simultaneously, Permiso will automatically merge them into one request. You might think this is a rare scenario, but before you know it, you have master and detail fragments that both need access to the user's contacts, and now you have to manage your permissions so their simultaneous requests don't cause two separate pop-ups! Don't worry, Permiso handles this for you.

I request a permission but nothing happens? What's up?

Did you make sure to declare your permissions in your AndroidManifest.xml? If you don't, permission requests fail silently. That's an Android thing - not much Permiso can do there.

Resources

Parallax everywhere (PEW) is a library with alternative android views using parallax effects.

How it works?

  • Any parallax views (PEW*) needs to be inside a view with scroll events, ej: scrollView, listView, gridView....
  • Parallax effect on views will be related to its position on device screen.
  • Parallax effect in ImageView is calculated with left image in Scale mode centerCrop, centerInside or center. You can't make more parallax effect.
  • Parallax effect in no image views needs a size parallax parameter (read: Attributes)

The TileView widget is a subclass of ViewGroup that provides a mechanism to asynchronously display tile-based images, with additional functionality for 2D dragging, flinging, pinch or double-tap to zoom, adding overlaying Views (markers), built-in Hot Spot support, dynamic path drawing, multiple levels of detail, and support for any relative positioning or coordinate system.

FlowLayout is an opensource Android library that allows developers to easily integrate flow layout into their app. FlowLayout is an layout that display its children in multiple rows depending on their size.

An Android Parallax ListView item (this effect inspired by sound cloud android app).

Android comes with a few "wrapper" classes, like CursorWrapper, that make it relatively easy for you to add just a bit of functionality to an existing object. The wrapper delegates all behaviors to the wrapped object; you just override the specific behaviors you need. This works well in cases where there are many possible underlying implementations, so you could not robustly accomplish these ends by subclassing.

Android lacks such a wrapper for ListAdapter, though. There is a WrappedListAdapter entry in the SDK, but it is an interface, not an implementation.

So, CWAC offers an AdapterWrapper to fill this void.

Sometimes, you want your users to pick a color. A simple approach is to give the user a fixed roster of a handful of colors -- easy, but limited. A fancy approach is to use some form of color wheel, but these can be difficult to use on a touchscreen and perhaps impossible without a touchscreen.

ColorMixer is a widget that provides a simple set of SeekBars to let the user mix red, green, and blue to pick an arbitrary color. It is not very big, so it is easy to fit on a form, and it is still fairly finger-friendly.

It is also packaged as a dialog (ColorMixerDialog), a dialog-themed activity (ColorMixerActivity), and a preference (ColorPreference).

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