Full Code of greysonp/permiso for AI

master 77717e27564e cached
40 files
70.5 KB
17.1k tokens
82 symbols
1 requests
Download .txt
Repository: greysonp/permiso
Branch: master
Commit: 77717e27564e
Files: 40
Total size: 70.5 KB

Directory structure:
gitextract_tjgmdgdi/

├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── greysonparrelli/
│       │               └── permisodemo/
│       │                   └── ApplicationTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── greysonparrelli/
│       │   │           └── permisodemo/
│       │   │               ├── MainActivity.java
│       │   │               └── NonPermisoActivity.java
│       │   └── res/
│       │       ├── layout/
│       │       │   ├── activity_main.xml
│       │       │   └── activity_non_permiso.xml
│       │       ├── menu/
│       │       │   └── menu_main.xml
│       │       ├── values/
│       │       │   ├── colors.xml
│       │       │   ├── dimens.xml
│       │       │   ├── strings.xml
│       │       │   └── styles.xml
│       │       ├── values-v21/
│       │       │   └── styles.xml
│       │       └── values-w820dp/
│       │           └── dimens.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── greysonparrelli/
│                       └── permisodemo/
│                           └── ExampleUnitTest.java
├── build.gradle
├── gradle/
│   ├── bintray.gradle
│   ├── maven.gradle
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── permiso/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── greysonparrelli/
│       │               └── permiso/
│       │                   └── ApplicationTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── greysonparrelli/
│       │   │           └── permiso/
│       │   │               ├── Permiso.java
│       │   │               ├── PermisoActivity.java
│       │   │               └── PermisoDialogFragment.java
│       │   └── res/
│       │       └── values/
│       │           └── strings.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── greysonparrelli/
│                       └── permiso/
│                           └── ExampleUnitTest.java
└── settings.gradle

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Android
local.properties

# IntelliJ
*.iml
.idea/

# OS X
.DS_Store

# Gradle
build
/reports
/.gradle

================================================
FILE: .travis.yml
================================================
language: android
jdk: oraclejdk8
android:
  components:
    # Uncomment the lines below if you want to
    # use the latest revision of Android SDK Tools
    - platform-tools
    - tools

    # The BuildTools version used by your project
    - build-tools-26.0.2

    # The SDK version used to compile your project
    - android-26

    # Additional components
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository
    - addon-google_apis-google-19

    # Specify at least one system image,
    # if you need to run emulator(s) during your tests
    # - sys-img-armeabi-v7a-android-19
    # - sys-img-x86-android-17
script: ./gradlew assembleDebug


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015 Greyson Parrelli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
Permiso [![Build Status](https://travis-ci.org/greysonp/permiso.svg?branch=master)](https://travis-ci.org/greysonp/permiso) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Permiso-green.svg?style=true)](https://android-arsenal.com/details/1/2818) [![Join the chat at https://gitter.im/permiso/Lobby](https://badges.gitter.im/permiso/Lobby.svg)](https://gitter.im/permiso/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
=======

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

Have you seen the [docs](http://developer.android.com/training/permissions/requesting.html) 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:

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

```java
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
```java
dependencies {
    compile 'com.greysonparrelli.permiso:permiso:0.3.0'
}
```

### Latest Dev Version
```java
// 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:

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

```java
@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.


================================================
FILE: app/.gitignore
================================================
/build


================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.greysonparrelli.permisodemo"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile project(':permiso')
}


================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/greyson/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}


================================================
FILE: app/src/androidTest/java/com/greysonparrelli/permisodemo/ApplicationTest.java
================================================
package com.greysonparrelli.permisodemo;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}

================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.greysonparrelli.permisodemo"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity
            android:name=".NonPermisoActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />
    </application>

</manifest>


================================================
FILE: app/src/main/java/com/greysonparrelli/permisodemo/MainActivity.java
================================================
package com.greysonparrelli.permisodemo;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.greysonparrelli.permiso.Permiso;
import com.greysonparrelli.permiso.PermisoActivity;
import com.greysonparrelli.permiso.PermisoDialogFragment;

/**
 * An activity that demonstrates the features of {@link Permiso}. This activity extends {@link PermisoActivity} in order
 * to handle some boilerplate. If you don't want to extend {@link PermisoActivity}, check out
 * {@link NonPermisoActivity}.
 */
public class MainActivity extends PermisoActivity {

    // =====================================================================
    // Overrides
    // =====================================================================

    @SuppressWarnings("ConstantConditions")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Set click listeners
        findViewById(R.id.btn_single).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onSingleClick();
            }
        });
        findViewById(R.id.btn_multiple).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onMultipleClick();
            }
        });
        findViewById(R.id.btn_duplicate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDuplicateClick();
            }
        });
        findViewById(R.id.btn_non_permiso).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onNonPermisoClick();
            }
        });
    }


    // =====================================================================
    // Click Listeners
    // =====================================================================

    /**
     * Request a single permission and display whether or not it was granted or denied.
     */
    private void onSingleClick() {
        // A request for a single permission
        Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
            @Override
            public void onPermissionResult(Permiso.ResultSet resultSet) {
                if (resultSet.isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    Toast.makeText(MainActivity.this, R.string.permission_granted, Toast.LENGTH_SHORT).show();
                } else if (resultSet.isPermissionPermanentlyDenied(Manifest.permission.WRITE_EXTERNAL_STORAGE)){
                    Toast.makeText(MainActivity.this, R.string.permission_permanently_denied, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
                PermisoDialogFragment.Builder builder = new PermisoDialogFragment.Builder(
                        R.string.permission_rationale,
                        R.string.needed_for_html_demo_purposes,
                        android.R.string.ok);
                builder.setHtmlInterpretation(true);
                Permiso.getInstance().showRationaleInDialog(builder, callback);
            }
        }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    /**
     * Request multiple permissions and display how many were granted.
     */
    private void onMultipleClick() {
        // A request for two permissions
        Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
            @Override
            public void onPermissionResult(Permiso.ResultSet resultSet) {
                int numGranted = 0;
                if (resultSet.isPermissionGranted(Manifest.permission.READ_CONTACTS)) {
                    numGranted++;
                }
                if (resultSet.isPermissionGranted(Manifest.permission.READ_CALENDAR)) {
                    numGranted++;
                }
                String message = getString(R.string.x_permissions_granted, numGranted);
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
                Permiso.getInstance().showRationaleInDialog(
                        getString(R.string.permission_rationale),
                        getString(R.string.needed_for_demo_purposes),
                        null,
                        callback);
            }
        }, Manifest.permission.READ_CONTACTS, Manifest.permission.READ_CALENDAR);
    }

    /**
     * Make two simultaneous requests for the same permission. Only one dialog will pop up, and the results from that
     * one request will be given to both callbacks.
     */
    private void onDuplicateClick() {
        // First request
        requestPermissions("1");

        // Second request for the same permission
        requestPermissions("2");
    }

    private void requestPermissions(final String requestNumber) {
        Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
            @Override
            public void onPermissionResult(Permiso.ResultSet resultSet) {
                if (resultSet.areAllPermissionsGranted()) {
                    Toast.makeText(
                            MainActivity.this,
                            getString(R.string.permission_granted) + " (" + requestNumber + ")",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(
                            MainActivity.this,
                            getString(R.string.permission_denied) + " (" + requestNumber + ")",
                            Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
                Permiso.getInstance().showRationaleInDialog(
                        getString(R.string.permission_rationale),
                        getString(R.string.needed_for_demo_purposes),
                        null,
                        callback);
            }
        }, Manifest.permission.CAMERA);
    }

    /**
     * Starts {@link NonPermisoActivity}.
     */
    private void onNonPermisoClick() {
        startActivity(new Intent(this, NonPermisoActivity.class));
    }
}


================================================
FILE: app/src/main/java/com/greysonparrelli/permisodemo/NonPermisoActivity.java
================================================
package com.greysonparrelli.permisodemo;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.greysonparrelli.permiso.Permiso;

/**
 * Created to demonstrate how to use Permiso without extending PermisoActivity.
 */
public class NonPermisoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_non_permiso);

        //
        // First, tell Permiso that you're using this activity
        //
        Permiso.getInstance().setActivity(this);

        findViewById(R.id.btn_request).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRequestClick();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        //
        // Second, we also have to set the activity here to handle transitioning between activities
        //
        Permiso.getInstance().setActivity(this);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        //
        // Third, forward the results of this method to Permiso
        //
        Permiso.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults);
    }

    private void onRequestClick() {
        //
        // And that's it! Now you can make permission requests as usual
        //
        Permiso.getInstance().requestPermissions(new Permiso.IOnPermissionResult() {
            @Override
            public void onPermissionResult(Permiso.ResultSet resultSet) {
                if (resultSet.isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    Toast.makeText(NonPermisoActivity.this, R.string.permission_granted, Toast.LENGTH_SHORT).show();
                } else if (resultSet.isPermissionPermanentlyDenied(Manifest.permission.WRITE_EXTERNAL_STORAGE)){
                    Toast.makeText(NonPermisoActivity.this, R.string.permission_permanently_denied, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(NonPermisoActivity.this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onRationaleRequested(Permiso.IOnRationaleProvided callback, String... permissions) {
                Permiso.getInstance().showRationaleInDialog(getString(R.string.permission_rationale), getString(R.string.needed_for_demo_purposes), null, callback);
            }
        }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

}


================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.greysonparrelli.permisodemo.MainActivity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center">

    <Button
        android:id="@+id/btn_single"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Request Single Permission"/>

    <Button
        android:id="@+id/btn_multiple"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Request Two Permissions"/>

    <Button
        android:id="@+id/btn_duplicate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Request Duplicate Permissions"/>

    <Button
        android:id="@+id/btn_non_permiso"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Open Non-PermisoActivity Example"/>

</LinearLayout>

================================================
FILE: app/src/main/res/layout/activity_non_permiso.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.greysonparrelli.permisodemo.MainActivity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center">

    <Button
        android:id="@+id/btn_request"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Request a Permission"/>

</LinearLayout>

================================================
FILE: app/src/main/res/menu/menu_main.xml
================================================
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context="com.greysonparrelli.permisodemo.MainActivity">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
</menu>


================================================
FILE: app/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>


================================================
FILE: app/src/main/res/values/dimens.xml
================================================
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="fab_margin">16dp</dimen>
</resources>


================================================
FILE: app/src/main/res/values/strings.xml
================================================
<resources>
    <string name="app_name">Permiso Demo</string>
    <string name="action_settings">Settings</string>
    <string name="permission_rationale">Permission Rationale</string>
    <string name="needed_for_html_demo_purposes"><![CDATA[<u>Needed</u> for html demo <b>purposes.</b>]]></string>
    <string name="needed_for_demo_purposes">Needed for demo purposes.</string>
    <string name="permission_granted">Permission Granted!</string>
    <string name="permission_permanently_denied">Permission Permanently Denied.</string>
    <string name="permission_denied">Permission Denied.</string>
    <string name="x_permissions_granted">%1$d Permissions Granted.</string>
</resources>


================================================
FILE: app/src/main/res/values/styles.xml
================================================
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>


================================================
FILE: app/src/main/res/values-v21/styles.xml
================================================
<resources>>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>


================================================
FILE: app/src/main/res/values-w820dp/dimens.xml
================================================
<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>


================================================
FILE: app/src/test/java/com/greysonparrelli/permisodemo/ExampleUnitTest.java
================================================
package com.greysonparrelli.permisodemo;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        assertEquals(4, 2 + 2);
    }
}

================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        // You need to add the following repository to download the new plugin.
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


================================================
FILE: gradle/bintray.gradle
================================================
apply plugin: 'com.jfrog.bintray'

version = libraryVersion

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
artifacts {
    archives javadocJar
    archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password")
                //Optional. The passphrase for GPG signing'
            }
        }
    }
}


================================================
FILE: gradle/maven.gradle
================================================
apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId                               // Maven Group ID for the artifact

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters`
        pom {
            project {
                packaging 'aar'
                groupId publishedGroupId
                artifactId artifact

                // Add your description here
                name libraryName
                description libraryDescription
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name licenseName
                        url licenseUrl
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}


================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Sun Oct 29 10:59:04 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip


================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

================================================
FILE: gradlew
================================================
#!/usr/bin/env bash

##############################################################################
##
##  Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
    echo "$*"
}

die ( ) {
    echo
    echo "$*"
    echo
    exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
  CYGWIN* )
    cygwin=true
    ;;
  Darwin* )
    darwin=true
    ;;
  MINGW* )
    msys=true
    ;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`"/$link"
    fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
    MAX_FD_LIMIT=`ulimit -H -n`
    if [ $? -eq 0 ] ; then
        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
            MAX_FD="$MAX_FD_LIMIT"
        fi
        ulimit -n $MAX_FD
        if [ $? -ne 0 ] ; then
            warn "Could not set maximum file descriptor limit: $MAX_FD"
        fi
    else
        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
    fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

    # We build the pattern for arguments to be converted via cygpath
    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
    SEP=""
    for dir in $ROOTDIRSRAW ; do
        ROOTDIRS="$ROOTDIRS$SEP$dir"
        SEP="|"
    done
    OURCYGPATTERN="(^($ROOTDIRS))"
    # Add a user-defined pattern to the cygpath arguments
    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
    fi
    # Now convert the arguments - kludge to limit ourselves to /bin/sh
    i=0
    for arg in "$@" ; do
        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option

        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
        else
            eval `echo args$i`="\"$arg\""
        fi
        i=$((i+1))
    done
    case $i in
        (0) set -- ;;
        (1) set -- "$args0" ;;
        (2) set -- "$args0" "$args1" ;;
        (3) set -- "$args0" "$args1" "$args2" ;;
        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
    esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
    JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"


================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega


================================================
FILE: permiso/.gitignore
================================================
/build


================================================
FILE: permiso/build.gradle
================================================
apply plugin: 'com.android.library'

ext {
    bintrayRepo = 'maven'
    bintrayName = 'permiso'

    publishedGroupId = 'com.greysonparrelli.permiso'
    libraryName = 'Permiso'
    artifact = 'permiso'

    libraryDescription = 'An Android library to make handling runtime permissions a whole lot easier.'

    siteUrl = 'https://github.com/greysonp/permiso'
    gitUrl = 'https://github.com/greysonp/permiso.git'

    libraryVersion = '0.3.0'

    developerId = 'greysonp'
    developerName = 'Greyson Parrelli'
    developerEmail = 'greyson.parrelli@gmail.com'

    licenseName = 'The MIT License (MIT)'
    licenseUrl = 'https://opensource.org/licenses/MIT'
    allLicenses = ["MIT"]
}

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.1.0'
}

// Only add in the bintray stuff if we're building locally
if (!"true".equalsIgnoreCase(System.getenv("CI"))) {
    apply from: rootProject.file('gradle/maven.gradle')
    apply from: rootProject.file('gradle/bintray.gradle')
}


================================================
FILE: permiso/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/greyson/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}


================================================
FILE: permiso/src/androidTest/java/com/greysonparrelli/permiso/ApplicationTest.java
================================================
package com.greysonparrelli.permiso;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}

================================================
FILE: permiso/src/main/AndroidManifest.xml
================================================
<manifest package="com.greysonparrelli.permiso"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:label="@string/app_name">

    </application>

</manifest>


================================================
FILE: permiso/src/main/java/com/greysonparrelli/permiso/Permiso.java
================================================
package com.greysonparrelli.permiso;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * A class to make permission-management easier. Provides methods to conveniently request permissions anywhere in your
 * app.
 */
public class Permiso {

    private static final String TAG = "Permiso";

    /**
     * A map to keep track of our outstanding permission requests. The key is the request code sent when we call
     * {@link ActivityCompat#requestPermissions(Activity, String[], int)}. The value is the {@link Permiso.RequestData}
     * bundle that holds all of the request information.
     */
    private Map<Integer, RequestData> mCodesToRequests;

    /**
     * The active activity. Used to make permissions requests. This must be set by the library-user through
     * {@link Permiso#setActivity(Activity)} or else bad things will happen.
     */
    private WeakReference<Activity> mActivity;

    /**
     * This is just a value we increment to generate new request codes for use with
     * {@link ActivityCompat#requestPermissions(Activity, String[], int)}.
     */
    private int mActiveRequestCode = 1;

    /**
     * The singleton instance.
     */
    private static Permiso sInstance = new Permiso();


    // =====================================================================
    // Creation
    // =====================================================================

    /**
     * @return An instance of {@link Permiso} to help you manage your permissions.
     */
    public static Permiso getInstance() {
        return sInstance;
    }

    /**
     * Implementing a singleton pattern, so this is private.
     */
    private Permiso() {
        mCodesToRequests = new HashMap<>();
    }


    // =====================================================================
    // Public
    // =====================================================================

    /**
     * This method should be invoked in the {@link Activity#onCreate(Bundle)} in every activity that requests
     * permissions. Even if you don't want to use Permiso in your current activity, you should call this method
     * with a null activity to prevent leaking the previously-set activity.
     * <p>
     * <strong>Important: </strong> If your activity subclasses {@link PermisoActivity}, this is already handled for you.
     * @param activity The activity that is currently active.
     */
    public void setActivity(@NonNull Activity activity) {
        mActivity = new WeakReference<>(activity);
    }

    /**
     * Request one or more permissions from the system. Make sure that you are either subclassing {@link PermisoActivity}
     * or that you have set your current activity using {@link Permiso#setActivity(Activity)}!
     * @param callback
     *      A callback that will be triggered when the results of your permission request are available.
     * @param permissions
     *      A list of permission constants that you are requesting. Use constants from
     *      {@link android.Manifest.permission}.
     */
    @MainThread
    public void requestPermissions(@NonNull IOnPermissionResult callback, String... permissions) {
        Activity activity = checkActivity();

        final RequestData requestData = new RequestData(callback, permissions);

        // Mark any permissions that are already granted
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED) {
                requestData.resultSet.grantPermissions(permission);
            }
        }

        // If we had all of them, yay! No need to do anything else.
        if (requestData.resultSet.areAllPermissionsGranted()) {
            requestData.onResultListener.onPermissionResult(requestData.resultSet);
        } else {
            // If we have some unsatisfied ones, let's first see if they can be satisfied by an active request. If it
            // can, we'll re-wire the callback of the active request to also trigger this new one.
            boolean linkedToExisting = linkToExistingRequestIfPossible(requestData);

            // If there was no existing request that can satisfy this one, then let's make a new permission request to
            // the system
            if (!linkedToExisting) {
                // Mark the request as active
                final int requestCode = markRequestAsActive(requestData);

                // First check if there's any permissions for which we need to provide a rationale for using
                String[] permissionsThatNeedRationale = requestData.resultSet.getPermissionsThatNeedRationale(activity);

                // If there are some that need a rationale, show that rationale, then continue with the request
                if (permissionsThatNeedRationale.length > 0) {
                    requestData.onResultListener.onRationaleRequested(new IOnRationaleProvided() {
                        @Override
                        public void onRationaleProvided() {
                            makePermissionRequest(requestCode, requestData);
                        }
                    }, permissionsThatNeedRationale);
                } else {
                    makePermissionRequest(requestCode, requestData);
                }
            }
        }
    }

    /**
     * This method needs to be called by your activity's {@link Activity#onRequestPermissionsResult(int, String[], int[])}.
     * Simply forward the results of that method here.
     * <p>
     * <strong>Important: </strong> If your activity subclasses {@link PermisoActivity}, this is already handled for you.
     * @param requestCode
     *      The request code given to you by {@link Activity#onRequestPermissionsResult(int, String[], int[])}.
     * @param permissions
     *      The permissions given to you by {@link Activity#onRequestPermissionsResult(int, String[], int[])}.
     * @param grantResults
     *      The grant results given to you by {@link Activity#onRequestPermissionsResult(int, String[], int[])}.
     */
    @MainThread
    public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
        Activity activity = checkActivity();
        if (mCodesToRequests.containsKey(requestCode)) {
            RequestData requestData = mCodesToRequests.get(requestCode);
            requestData.resultSet.parsePermissionResults(permissions, grantResults, activity);
            requestData.onResultListener.onPermissionResult(requestData.resultSet);
            mCodesToRequests.remove(requestCode);
        } else {
            Log.w(TAG, "onRequestPermissionResult() was given an unrecognized request code.");
        }
    }

    /**
     * A helper to show your rationale in a {@link android.app.DialogFragment} when implementing
     * {@link IOnRationaleProvided#onRationaleProvided()}. Automatically invokes the rationale callback when the user
     * dismisses the dialog.
     * @param title
     *      The title of the dialog. If null, there will be no title.
     * @param message
     *      The message displayed in the dialog.
     * @param buttonText
     *      The text you want the dismissal button to show. If null, defaults to {@link android.R.string#ok}.
     * @param rationaleCallback
     *      The callback to be trigger
     */
    @MainThread
    public void showRationaleInDialog(
            @Nullable String title,
            @NonNull String message,
            @Nullable String buttonText,
            @NonNull final IOnRationaleProvided rationaleCallback) {
        PermisoDialogFragment.Builder builder = new PermisoDialogFragment.Builder()
                .setTitle(title)
                .setMessage(message)
                .setButtonText(buttonText);
        showRationaleInDialog(builder, rationaleCallback);
    }

    /**
     * A helper to show your rationale in a {@link android.app.DialogFragment} when implementing
     * {@link IOnRationaleProvided#onRationaleProvided()}. Automatically invokes the rationale callback when the user
     * dismisses the dialog.
     * @param builder
     *      A reference to PermisoDialogFragment.Builder containing parameters for displaying the Dialog.
     * @param rationaleCallback
     *      The callback to be trigger
     */
    @MainThread
    public void showRationaleInDialog(
            final PermisoDialogFragment.Builder builder,
            final IOnRationaleProvided rationaleCallback) {
        Activity activity = checkActivity();
        FragmentManager fm = activity.getFragmentManager();

        PermisoDialogFragment dialogFragment = (PermisoDialogFragment) fm.findFragmentByTag(PermisoDialogFragment.TAG);
        if (dialogFragment != null) {
            dialogFragment.dismiss();
        }

        dialogFragment = builder.build(activity);

        // We show the rationale after the dialog is closed. We use setRetainInstance(true) in the dialog to ensure that
        // it retains the listener after an app rotation.
        dialogFragment.setOnCloseListener(new PermisoDialogFragment.IOnCloseListener() {
            @Override
            public void onClose() {
                rationaleCallback.onRationaleProvided();
            }
        });
        dialogFragment.show(fm, PermisoDialogFragment.TAG);
    }

    // =====================================================================
    // Private
    // =====================================================================

    /**
     * Checks to see if there are any active requests that are already requesting a superset of the permissions this
     * new request is asking for. If so, this will wire up this new request's callback to be triggered when the
     * existing request is completed and return true. Otherwise, this does nothing and returns false.
     * @param newRequest The new request that is about to be made.
     * @return True if a request was linked, otherwise false.
     */
    private boolean linkToExistingRequestIfPossible(final RequestData newRequest) {
        boolean found = false;

        // Go through all outstanding requests
        for (final RequestData activeRequest : mCodesToRequests.values()) {
            // If we find one that can satisfy all of the new request's permissions, we re-wire the active one's
            // callback to also call this new one's callback
            if (activeRequest.resultSet.containsAllUngrantedPermissions(newRequest.resultSet)) {
                final IOnPermissionResult originalOnResultListener = activeRequest.onResultListener;
                activeRequest.onResultListener = new IOnPermissionResult() {
                    @Override
                    public void onPermissionResult(ResultSet resultSet) {
                        // First, call the active one's callback. It was added before this new one.
                        originalOnResultListener.onPermissionResult(resultSet);

                        // Next, copy over the results to the new one's resultSet
                        String[] unsatisfied = newRequest.resultSet.getUngrantedPermissions();
                        for (String permission : unsatisfied) {
                            newRequest.resultSet.requestResults.put(permission, resultSet.requestResults.get(permission));
                        }

                        // Finally, trigger the new one's callback
                        newRequest.onResultListener.onPermissionResult(newRequest.resultSet);
                    }

                    @Override
                    public void onRationaleRequested(IOnRationaleProvided callback, String... permissions) {
                        activeRequest.onResultListener.onRationaleRequested(callback, permissions);
                    }
                };
                found = true;
                break;
            }
        }
        return found;
    }

    /**
     * Puts the RequestData in the map of requests and gives back the request code.
     * @return The request code generated for this request.
     */
    private int markRequestAsActive(RequestData requestData) {
        int requestCode = mActiveRequestCode++;
        mCodesToRequests.put(requestCode, requestData);
        return requestCode;
    }

    /**
     * Makes the permission request for the request that matches the provided request code.
     * @param requestCode The request code of the request you want to run.
     * @param requestData The {@link RequestData} representing the request you want to run.
     */
    private void makePermissionRequest(int requestCode, RequestData requestData) {
        Activity activity = checkActivity();
        ActivityCompat.requestPermissions(activity, requestData.resultSet.getUngrantedPermissions(), requestCode);
    }

    /**
     * Ensures that our WeakReference to the Activity is still valid. If it isn't, throw an exception saying that the
     * Activity needs to be set.
     */
    private Activity checkActivity() {
        Activity activity = mActivity.get();
        if (activity == null) {
            throw new IllegalStateException("No activity set. Either subclass PermisoActivity or call Permiso.setActivity() in onCreate() and onResume() of your Activity.");
        }
        return activity;
    }


    // =====================================================================
    // Inner Classes
    // =====================================================================

    /**
     * A callback interface for receiving the results of a permission request.
     */
    public interface IOnPermissionResult {
        /**
         * Invoked when the results of your permission request are ready.
         * @param resultSet An object holding the result of your permission request.
         */
        void onPermissionResult(ResultSet resultSet);

        /**
         * Called when the system recommends that you provide a rationale for a permission. This typically happens when
         * a user denies a permission, but they you request it again.
         * @param callback    A callback to be triggered when you are finished showing the user the rationale.
         * @param permissions The list of permissions for which the system recommends you provide a rationale.
         */
        void onRationaleRequested(IOnRationaleProvided callback, String... permissions);
    }

    /**
     * Simple callback to let Permiso know that you have finished providing the user a rationale for a set of permissions.
     * For easy handling of this callback, consider using
     * {@link Permiso#showRationaleInDialog(String, String, String, IOnRationaleProvided)}.
     */
    public interface IOnRationaleProvided {
        /**
         * Invoke this method when you are done providing a rationale to the user in
         * {@link IOnPermissionResult#onRationaleRequested(IOnRationaleProvided, String...)}. The permission request
         * will not be made until this method is invoked.
         */
        void onRationaleProvided();
    }

    private static class RequestData {
        IOnPermissionResult onResultListener;
        ResultSet resultSet;

        public RequestData(@NonNull IOnPermissionResult onResultListener, String... permissions) {
            this.onResultListener = onResultListener;
            resultSet = new ResultSet(permissions);
        }
    }

    /**
     * A class representing the results of a permission request.
     */
    public static class ResultSet {

        private Map<String, Result> requestResults;

        private ResultSet(String... permissions) {
            requestResults = new HashMap<>(permissions.length);
            for (String permission : permissions) {
                requestResults.put(permission, Result.DENIED);
            }
        }

        /**
         * Checks if a permission was granted during your permission request.
         * @param permission The permission you are inquiring about. This should be a constant from {@link android.Manifest.permission}.
         * @return True if the permission was granted, otherwise false.
         */
        public boolean isPermissionGranted(String permission) {
            return requestResults.containsKey(permission) && requestResults.get(permission) == Result.GRANTED;
        }

        /**
         * Determines if all permissions in the request were granted.
         * @return True if all permissions in the request were granted, otherwise false.
         */
        public boolean areAllPermissionsGranted() {
            return !requestResults.containsValue(Result.DENIED) && !requestResults.containsValue(Result.PERMANENTLY_DENIED);
        }

        /**
         * Checks if a permission was permanently denied by the user (i.e. they denied and selected "Dont Ask Again".)
         * @param permission The permission you are inquiring about. This should be a constant from {@link android.Manifest.permission}.
         * @return True if the permission was permanently denied, otherwise false.
         */
        public boolean isPermissionPermanentlyDenied(String permission) {
            return requestResults.containsKey(permission) && requestResults.get(permission) == Result.PERMANENTLY_DENIED;
        }

        /**
         * Returns a map representation of this result set. Useful if you'd like to do more complicated operations
         * with the results.
         * @return
         *      A mapping of permission constants to {@link Result}.
         */
        public Map<String, Result> toMap() {
            return new HashMap<>(requestResults);
        }

        private void grantPermissions(String... permissions) {
            for (String permission : permissions) {
                requestResults.put(permission, Result.GRANTED);
            }
        }

        private void parsePermissionResults(String[] permissions, int[] grantResults, Activity activity) {
            for (int i = 0; i < permissions.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    requestResults.put(permissions[i], Result.GRANTED);
                } else if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permissions[i])) {
                    requestResults.put(permissions[i], Result.PERMANENTLY_DENIED);
                } else {
                    requestResults.put(permissions[i], Result.DENIED);
                }
            }
        }

        private String[] getUngrantedPermissions() {
            List<String> ungrantedList = new ArrayList<>(requestResults.size());
            for (Map.Entry<String, Result> requestResultsEntry : requestResults.entrySet()) {
                Result result = requestResultsEntry.getValue();
                if (result == Result.DENIED || result == Result.PERMANENTLY_DENIED) {
                    ungrantedList.add(requestResultsEntry.getKey());
                }
            }
            return ungrantedList.toArray(new String[ungrantedList.size()]);
        }

        private boolean containsAllUngrantedPermissions(ResultSet set) {
            List<String> ungranted = Arrays.asList(set.getUngrantedPermissions());
            return requestResults.keySet().containsAll(ungranted);
        }

        private String[] getPermissionsThatNeedRationale(Activity activity) {
            String[] ungranted = getUngrantedPermissions();
            List<String> shouldShowRationale = new ArrayList<>(ungranted.length);
            for (String permission : ungranted) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
                    shouldShowRationale.add(permission);
                }
            }
            return shouldShowRationale.toArray(new String[shouldShowRationale.size()]);
        }
    }

    /**
     * Describes the result of a permission request.
     */
    public enum Result {
        /**
         * The permission was granted.
         */
        GRANTED,

        /**
         * The permission was denied, but not permanently.
         */
        DENIED,

        /**
         * The permission was permanently denied.
         */
        PERMANENTLY_DENIED
    }
}


================================================
FILE: permiso/src/main/java/com/greysonparrelli/permiso/PermisoActivity.java
================================================
package com.greysonparrelli.permiso;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;

/**
 * An Activity that handles the small amount of boilerplate that {@link Permiso} requires to run. If you'd rather not
 * use this as your base activity class, simply remember to do the following in each of your activities:
 * <ul>
 *     <li>Call {@link Permiso#setActivity(Activity)} in {@link Activity#onCreate(Bundle)} and {@link Activity#onResume()}</li>
 *     <li>Call {@link Permiso#onRequestPermissionResult(int, String[], int[])} in
 *      {@link Activity#onRequestPermissionsResult(int, String[], int[])}</li>
 * </ul>
 */
public class PermisoActivity extends AppCompatActivity {

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

================================================
FILE: permiso/src/main/java/com/greysonparrelli/permiso/PermisoDialogFragment.java
================================================
package com.greysonparrelli.permiso;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

/**
 * A DialogFragment created for convenience to show a simple message explaining why a certain permission is being
 * requested and trigger a listener when it has been closed. Intended to be used by
 * {@link Permiso#showRationaleInDialog(String, String, String, Permiso.IOnRationaleProvided)}.
 */
public class PermisoDialogFragment extends DialogFragment {

    public static final String TAG = "PermisoDialogFragment";

    private static final String KEY_TITLE = "title";
    private static final String KEY_MESSAGE = "message";
    private static final String KEY_BUTTON_TEXT = "button_text";
    private static final String KEY_HAS_HTML = "has_html";
    private static final String KEY_THEME_ID = "theme_id";

    private String mTitle;
    private String mMessage;
    private String mButtonText;
    private boolean mHasHtml;
    private int mThemeId;

    private IOnCloseListener mOnCloseListener;

    /**
     * Creates a new {@link PermisoDialogFragment}. Only intended to be used by
     * {@link Permiso#showRationaleInDialog(String, String, String, Permiso.IOnRationaleProvided)}.
     * @param title      The title of the dialog. If null, no title will be displayed.
     * @param message    The message to be shown in the dialog.
     * @param buttonText The text to label the dialog button. If null, defaults to {@link android.R.string#ok}.
     * @return A new {@link PermisoDialogFragment}.
     */
    public static PermisoDialogFragment newInstance(
            @Nullable String title,
            @NonNull String message,
            @Nullable String buttonText) {
        return newInstance(new Builder()
                .setTitle(title)
                .setMessage(message)
                .setButtonText(buttonText));
    }

    private static PermisoDialogFragment newInstance(@NonNull Builder builder) {
        PermisoDialogFragment dialogFragment = new PermisoDialogFragment();
        // Build arguments bundle
        Bundle args = new Bundle();
        args.putBoolean(KEY_HAS_HTML, builder.isHtml());
        args.putString(KEY_TITLE, builder.getTitle());
        args.putString(KEY_MESSAGE, builder.getMessage());
        args.putString(KEY_BUTTON_TEXT, builder.getButtonText());
        args.putInt(KEY_THEME_ID, builder.getThemeId());
        dialogFragment.setArguments(args);

        return dialogFragment ;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Retain instance state so we can keep our listeners registered after a rotation
        setRetainInstance(true);

        mTitle = getArguments().getString(KEY_TITLE);
        mMessage = getArguments().getString(KEY_MESSAGE);
        mButtonText = getArguments().getString(KEY_BUTTON_TEXT);
        mHasHtml = getArguments().getBoolean(KEY_HAS_HTML);
        mThemeId = getArguments().getInt(KEY_THEME_ID);
    }

    @Override
    public void onDestroyView() {
        // If we don't do this, the DialogFragment is not recreated after a rotation. See bug:
        // https://code.google.com/p/android/issues/detail?id=17423
        if (getDialog() != null && getRetainInstance()) {
            getDialog().setDismissMessage(null);
        }
        super.onDestroyView();
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), mThemeId);

        // Title
        if (mTitle != null) {
            builder.setTitle(mTitle);
        }

        // Message
        if (mHasHtml) {
            TextView msg = new TextView(getActivity());
            msg.setText(Html.fromHtml(mMessage));
            msg.setMovementMethod(LinkMovementMethod.getInstance());
            builder.setView(msg);
        } else if (mMessage != null) {
            builder.setMessage(mMessage);
        }

        // Button text
        String buttonText;
        if (mButtonText != null) {
            buttonText = mButtonText;
        } else {
            buttonText = getString(android.R.string.ok);
        }
        builder.setPositiveButton(buttonText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mOnCloseListener != null) {
                    mOnCloseListener.onClose();
                }
            }
        });
        return builder.create();
    }

    @Override
    public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
        if (mOnCloseListener != null) {
            mOnCloseListener.onClose();
        }
    }

    /**
     * Sets the listener that will be triggered when this dialog is closed by a user action. This includes clicking
     * the dismissal button as well as clicking in the area outside of the dialog. NOT triggered by rotation.
     * @param listener Listener you want triggered when this dialog is closed by a user action.
     */
    public void setOnCloseListener(IOnCloseListener listener) {
        mOnCloseListener = listener;
    }

    /**
     * A simple listener that will be triggered when this dialog is closed by a user action.
     */
    public interface IOnCloseListener {
        /**
         * Called when the dialog is closed by a user action. This includes clicking the dismissal button as well as
         * clicking in the area outside of the dialog. NOT triggered by rotation.
         */
        void onClose();
    }

    /**
     * Build a {@link PermisoDialogFragment}. Gives the opportunity to set strings using either a raw string or a
     * resource id.
     */
    public static class Builder {
        private int titleId = 0;
        private String title = null;
        private int buttonTextId = 0;
        private String message = null;
        private int messageId = 0;
        private boolean interpretHtml = false;
        private String buttonText = null;
        private int themeId = 0;

        public Builder() {}

        public Builder(int titleId, int msgBody, int buttonTextId) {
            this.titleId = titleId;
            this.messageId = msgBody;
            this.buttonTextId = buttonTextId;
        }

        // =====================================================================
        // Getters
        // =====================================================================

        public String getTitle() {
            return title;
        }

        public String getMessage() {
            return message;
        }

        public String getButtonText() {
            return buttonText;
        }

        public boolean isHtml() {
            return interpretHtml;
        }

        public int getThemeId() {
            return themeId;
        }


        // =====================================================================
        // Setters
        // =====================================================================

        /**
         * Set the title that will appear at the top of the dialog.
         */
        public Builder setTitle(@StringRes int resId) {
            titleId = resId;
            return this;
        }

        /**
         * Set the title that will appear at the top of the dialog.
         */
        public Builder setTitle(String val) {
            title = val;
            return this;
        }

        /**
         * Set the message that will appear in the body of the dialog.
         */
        public Builder setMessage(@StringRes int resId) {
            messageId = resId;
            return this;
        }

        /**
         * Set the message that will appear in the body of the dialog.
         */
        public Builder setMessage(String val) {
            message = val;
            return this;
        }

        /**
         * Set the text that will appear as dismissal button in the corner of the dialog.
         */
        public Builder setButtonText(@StringRes int resId) {
            buttonTextId = resId;
            return this;
        }

        /**
         * Set the text that will appear as dismissal button in the corner of the dialog.
         */
        public Builder setButtonText(String string) {
            buttonText = string;
            return this;
        }

        /**
         * Set whether or not you want the message text to be interpreted as HTML.
         */
        public Builder setHtmlInterpretation(boolean interpretHtml) {
            this.interpretHtml = interpretHtml;
            return this;
        }

        /**
         * Set theme id that the {@link AlertDialog} will use.
         */
        public Builder setThemeId(int themeId) {
            this.themeId = themeId;
            return this;
        }

        public PermisoDialogFragment build(Context context) {
            if (titleId > 0) { title = context.getString(titleId); }
            if (messageId > 0) { message = context.getString(messageId); }
            if (buttonTextId > 0) { buttonText = context.getString(buttonTextId); }
            return PermisoDialogFragment.newInstance(this);
        }
    }
}


================================================
FILE: permiso/src/main/res/values/strings.xml
================================================
<resources>
    <string name="app_name">Permiso</string>
</resources>


================================================
FILE: permiso/src/test/java/com/greysonparrelli/permiso/ExampleUnitTest.java
================================================
package com.greysonparrelli.permiso;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        assertEquals(4, 2 + 2);
    }
}

================================================
FILE: settings.gradle
================================================
include ':app', ':permiso'

rootProject.name = 'permiso-root'
Download .txt
gitextract_tjgmdgdi/

├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── greysonparrelli/
│       │               └── permisodemo/
│       │                   └── ApplicationTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── greysonparrelli/
│       │   │           └── permisodemo/
│       │   │               ├── MainActivity.java
│       │   │               └── NonPermisoActivity.java
│       │   └── res/
│       │       ├── layout/
│       │       │   ├── activity_main.xml
│       │       │   └── activity_non_permiso.xml
│       │       ├── menu/
│       │       │   └── menu_main.xml
│       │       ├── values/
│       │       │   ├── colors.xml
│       │       │   ├── dimens.xml
│       │       │   ├── strings.xml
│       │       │   └── styles.xml
│       │       ├── values-v21/
│       │       │   └── styles.xml
│       │       └── values-w820dp/
│       │           └── dimens.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── greysonparrelli/
│                       └── permisodemo/
│                           └── ExampleUnitTest.java
├── build.gradle
├── gradle/
│   ├── bintray.gradle
│   ├── maven.gradle
│   └── wrapper/
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── permiso/
│   ├── .gitignore
│   ├── build.gradle
│   ├── proguard-rules.pro
│   └── src/
│       ├── androidTest/
│       │   └── java/
│       │       └── com/
│       │           └── greysonparrelli/
│       │               └── permiso/
│       │                   └── ApplicationTest.java
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── java/
│       │   │   └── com/
│       │   │       └── greysonparrelli/
│       │   │           └── permiso/
│       │   │               ├── Permiso.java
│       │   │               ├── PermisoActivity.java
│       │   │               └── PermisoDialogFragment.java
│       │   └── res/
│       │       └── values/
│       │           └── strings.xml
│       └── test/
│           └── java/
│               └── com/
│                   └── greysonparrelli/
│                       └── permiso/
│                           └── ExampleUnitTest.java
└── settings.gradle
Download .txt
SYMBOL INDEX (82 symbols across 9 files)

FILE: app/src/androidTest/java/com/greysonparrelli/permisodemo/ApplicationTest.java
  class ApplicationTest (line 9) | public class ApplicationTest extends ApplicationTestCase<Application> {
    method ApplicationTest (line 10) | public ApplicationTest() {

FILE: app/src/main/java/com/greysonparrelli/permisodemo/MainActivity.java
  class MainActivity (line 18) | public class MainActivity extends PermisoActivity {
    method onCreate (line 24) | @SuppressWarnings("ConstantConditions")
    method onSingleClick (line 65) | private void onSingleClick() {
    method onMultipleClick (line 94) | private void onMultipleClick() {
    method onDuplicateClick (line 125) | private void onDuplicateClick() {
    method requestPermissions (line 133) | private void requestPermissions(final String requestNumber) {
    method onNonPermisoClick (line 164) | private void onNonPermisoClick() {

FILE: app/src/main/java/com/greysonparrelli/permisodemo/NonPermisoActivity.java
  class NonPermisoActivity (line 15) | public class NonPermisoActivity extends AppCompatActivity {
    method onCreate (line 17) | @Override
    method onResume (line 35) | @Override
    method onRequestPermissionsResult (line 45) | @Override
    method onRequestClick (line 55) | private void onRequestClick() {

FILE: app/src/test/java/com/greysonparrelli/permisodemo/ExampleUnitTest.java
  class ExampleUnitTest (line 10) | public class ExampleUnitTest {
    method addition_isCorrect (line 11) | @Test

FILE: permiso/src/androidTest/java/com/greysonparrelli/permiso/ApplicationTest.java
  class ApplicationTest (line 9) | public class ApplicationTest extends ApplicationTestCase<Application> {
    method ApplicationTest (line 10) | public ApplicationTest() {

FILE: permiso/src/main/java/com/greysonparrelli/permiso/Permiso.java
  class Permiso (line 25) | public class Permiso {
    method getInstance (line 61) | public static Permiso getInstance() {
    method Permiso (line 68) | private Permiso() {
    method setActivity (line 85) | public void setActivity(@NonNull Activity activity) {
    method requestPermissions (line 98) | @MainThread
    method onRequestPermissionResult (line 155) | @MainThread
    method showRationaleInDialog (line 181) | @MainThread
    method showRationaleInDialog (line 203) | @MainThread
    method linkToExistingRequestIfPossible (line 239) | private boolean linkToExistingRequestIfPossible(final RequestData newR...
    method markRequestAsActive (line 280) | private int markRequestAsActive(RequestData requestData) {
    method makePermissionRequest (line 291) | private void makePermissionRequest(int requestCode, RequestData reques...
    method checkActivity (line 300) | private Activity checkActivity() {
    type IOnPermissionResult (line 316) | public interface IOnPermissionResult {
      method onPermissionResult (line 321) | void onPermissionResult(ResultSet resultSet);
      method onRationaleRequested (line 329) | void onRationaleRequested(IOnRationaleProvided callback, String... p...
    type IOnRationaleProvided (line 337) | public interface IOnRationaleProvided {
      method onRationaleProvided (line 343) | void onRationaleProvided();
    class RequestData (line 346) | private static class RequestData {
      method RequestData (line 350) | public RequestData(@NonNull IOnPermissionResult onResultListener, St...
    class ResultSet (line 359) | public static class ResultSet {
      method ResultSet (line 363) | private ResultSet(String... permissions) {
      method isPermissionGranted (line 375) | public boolean isPermissionGranted(String permission) {
      method areAllPermissionsGranted (line 383) | public boolean areAllPermissionsGranted() {
      method isPermissionPermanentlyDenied (line 392) | public boolean isPermissionPermanentlyDenied(String permission) {
      method toMap (line 402) | public Map<String, Result> toMap() {
      method grantPermissions (line 406) | private void grantPermissions(String... permissions) {
      method parsePermissionResults (line 412) | private void parsePermissionResults(String[] permissions, int[] gran...
      method getUngrantedPermissions (line 424) | private String[] getUngrantedPermissions() {
      method containsAllUngrantedPermissions (line 435) | private boolean containsAllUngrantedPermissions(ResultSet set) {
      method getPermissionsThatNeedRationale (line 440) | private String[] getPermissionsThatNeedRationale(Activity activity) {
    type Result (line 455) | public enum Result {

FILE: permiso/src/main/java/com/greysonparrelli/permiso/PermisoActivity.java
  class PermisoActivity (line 17) | public class PermisoActivity extends AppCompatActivity {
    method onCreate (line 19) | @Override
    method onResume (line 25) | @Override
    method onRequestPermissionsResult (line 31) | @Override

FILE: permiso/src/main/java/com/greysonparrelli/permiso/PermisoDialogFragment.java
  class PermisoDialogFragment (line 21) | public class PermisoDialogFragment extends DialogFragment {
    method newInstance (line 47) | public static PermisoDialogFragment newInstance(
    method newInstance (line 57) | private static PermisoDialogFragment newInstance(@NonNull Builder buil...
    method onCreate (line 71) | @Override
    method onDestroyView (line 85) | @Override
    method onCreateDialog (line 95) | @NonNull
    method onCancel (line 133) | @Override
    method setOnCloseListener (line 146) | public void setOnCloseListener(IOnCloseListener listener) {
    type IOnCloseListener (line 153) | public interface IOnCloseListener {
      method onClose (line 158) | void onClose();
    class Builder (line 165) | public static class Builder {
      method Builder (line 175) | public Builder() {}
      method Builder (line 177) | public Builder(int titleId, int msgBody, int buttonTextId) {
      method getTitle (line 187) | public String getTitle() {
      method getMessage (line 191) | public String getMessage() {
      method getButtonText (line 195) | public String getButtonText() {
      method isHtml (line 199) | public boolean isHtml() {
      method getThemeId (line 203) | public int getThemeId() {
      method setTitle (line 215) | public Builder setTitle(@StringRes int resId) {
      method setTitle (line 223) | public Builder setTitle(String val) {
      method setMessage (line 231) | public Builder setMessage(@StringRes int resId) {
      method setMessage (line 239) | public Builder setMessage(String val) {
      method setButtonText (line 247) | public Builder setButtonText(@StringRes int resId) {
      method setButtonText (line 255) | public Builder setButtonText(String string) {
      method setHtmlInterpretation (line 263) | public Builder setHtmlInterpretation(boolean interpretHtml) {
      method setThemeId (line 271) | public Builder setThemeId(int themeId) {
      method build (line 276) | public PermisoDialogFragment build(Context context) {

FILE: permiso/src/test/java/com/greysonparrelli/permiso/ExampleUnitTest.java
  class ExampleUnitTest (line 10) | public class ExampleUnitTest {
    method addition_isCorrect (line 11) | @Test
Condensed preview — 40 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (77K chars).
[
  {
    "path": ".gitignore",
    "chars": 103,
    "preview": "# Android\nlocal.properties\n\n# IntelliJ\n*.iml\n.idea/\n\n# OS X\n.DS_Store\n\n# Gradle\nbuild\n/reports\n/.gradle"
  },
  {
    "path": ".travis.yml",
    "chars": 700,
    "preview": "language: android\njdk: oraclejdk8\nandroid:\n  components:\n    # Uncomment the lines below if you want to\n    # use the la"
  },
  {
    "path": "LICENSE",
    "chars": 1083,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Greyson Parrelli\n\nPermission is hereby granted, free of charge, to any person "
  },
  {
    "path": "README.md",
    "chars": 5690,
    "preview": "Permiso [![Build Status](https://travis-ci.org/greysonp/permiso.svg?branch=master)](https://travis-ci.org/greysonp/permi"
  },
  {
    "path": "app/.gitignore",
    "chars": 7,
    "preview": "/build\n"
  },
  {
    "path": "app/build.gradle",
    "chars": 712,
    "preview": "apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion 26\n    buildToolsVersion '26.0.2'\n\n    defaultC"
  },
  {
    "path": "app/proguard-rules.pro",
    "chars": 665,
    "preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
  },
  {
    "path": "app/src/androidTest/java/com/greysonparrelli/permisodemo/ApplicationTest.java",
    "chars": 362,
    "preview": "package com.greysonparrelli.permisodemo;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n"
  },
  {
    "path": "app/src/main/AndroidManifest.xml",
    "chars": 1250,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest package=\"com.greysonparrelli.permisodemo\"\n          xmlns:android=\"http"
  },
  {
    "path": "app/src/main/java/com/greysonparrelli/permisodemo/MainActivity.java",
    "chars": 6850,
    "preview": "package com.greysonparrelli.permisodemo;\n\nimport android.Manifest;\nimport android.content.Intent;\nimport android.os.Bund"
  },
  {
    "path": "app/src/main/java/com/greysonparrelli/permisodemo/NonPermisoActivity.java",
    "chars": 2934,
    "preview": "package com.greysonparrelli.permisodemo;\n\nimport android.Manifest;\nimport android.os.Bundle;\nimport android.support.anno"
  },
  {
    "path": "app/src/main/res/layout/activity_main.xml",
    "chars": 1180,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    "
  },
  {
    "path": "app/src/main/res/layout/activity_non_permiso.xml",
    "chars": 587,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    "
  },
  {
    "path": "app/src/main/res/menu/menu_main.xml",
    "chars": 425,
    "preview": "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n      xmlns:app=\"http://schemas.android.com/apk/res-aut"
  },
  {
    "path": "app/src/main/res/values/colors.xml",
    "chars": 208,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"colorPrimary\">#3F51B5</color>\n    <color name=\"color"
  },
  {
    "path": "app/src/main/res/values/dimens.xml",
    "chars": 253,
    "preview": "<resources>\n    <!-- Default screen margins, per the Android Design guidelines. -->\n    <dimen name=\"activity_horizontal"
  },
  {
    "path": "app/src/main/res/values/strings.xml",
    "chars": 689,
    "preview": "<resources>\n    <string name=\"app_name\">Permiso Demo</string>\n    <string name=\"action_settings\">Settings</string>\n    <"
  },
  {
    "path": "app/src/main/res/values/styles.xml",
    "chars": 706,
    "preview": "<resources>\n\n    <!-- Base application theme. -->\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar"
  },
  {
    "path": "app/src/main/res/values-v21/styles.xml",
    "chars": 328,
    "preview": "<resources>>\n\n    <style name=\"AppTheme.NoActionBar\">\n        <item name=\"windowActionBar\">false</item>\n        <item na"
  },
  {
    "path": "app/src/main/res/values-w820dp/dimens.xml",
    "chars": 358,
    "preview": "<resources>\n    <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n         (such as s"
  },
  {
    "path": "app/src/test/java/com/greysonparrelli/permisodemo/ExampleUnitTest.java",
    "chars": 324,
    "preview": "package com.greysonparrelli.permisodemo;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * To work on u"
  },
  {
    "path": "build.gradle",
    "chars": 822,
    "preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    r"
  },
  {
    "path": "gradle/bintray.gradle",
    "chars": 1365,
    "preview": "apply plugin: 'com.jfrog.bintray'\n\nversion = libraryVersion\n\ntask sourcesJar(type: Jar) {\n    from android.sourceSets.ma"
  },
  {
    "path": "gradle/maven.gradle",
    "chars": 1176,
    "preview": "apply plugin: 'com.github.dcendents.android-maven'\n\ngroup = publishedGroupId                               // Maven Grou"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "chars": 230,
    "preview": "#Sun Oct 29 10:59:04 IST 2017\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_"
  },
  {
    "path": "gradle.properties",
    "chars": 855,
    "preview": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will o"
  },
  {
    "path": "gradlew",
    "chars": 5080,
    "preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start "
  },
  {
    "path": "gradlew.bat",
    "chars": 2404,
    "preview": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@r"
  },
  {
    "path": "permiso/.gitignore",
    "chars": 7,
    "preview": "/build\n"
  },
  {
    "path": "permiso/build.gradle",
    "chars": 1456,
    "preview": "apply plugin: 'com.android.library'\n\next {\n    bintrayRepo = 'maven'\n    bintrayName = 'permiso'\n\n    publishedGroupId ="
  },
  {
    "path": "permiso/proguard-rules.pro",
    "chars": 665,
    "preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /U"
  },
  {
    "path": "permiso/src/androidTest/java/com/greysonparrelli/permiso/ApplicationTest.java",
    "chars": 358,
    "preview": "package com.greysonparrelli.permiso;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <"
  },
  {
    "path": "permiso/src/main/AndroidManifest.xml",
    "chars": 211,
    "preview": "<manifest package=\"com.greysonparrelli.permiso\"\n          xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\n "
  },
  {
    "path": "permiso/src/main/java/com/greysonparrelli/permiso/Permiso.java",
    "chars": 20694,
    "preview": "package com.greysonparrelli.permiso;\n\nimport android.app.Activity;\nimport android.app.FragmentManager;\nimport android.co"
  },
  {
    "path": "permiso/src/main/java/com/greysonparrelli/permiso/PermisoActivity.java",
    "chars": 1403,
    "preview": "package com.greysonparrelli.permiso;\n\nimport android.app.Activity;\nimport android.os.Bundle;\nimport android.support.anno"
  },
  {
    "path": "permiso/src/main/java/com/greysonparrelli/permiso/PermisoDialogFragment.java",
    "chars": 9589,
    "preview": "package com.greysonparrelli.permiso;\n\nimport android.app.Dialog;\nimport android.app.DialogFragment;\nimport android.conte"
  },
  {
    "path": "permiso/src/main/res/values/strings.xml",
    "chars": 70,
    "preview": "<resources>\n    <string name=\"app_name\">Permiso</string>\n</resources>\n"
  },
  {
    "path": "permiso/src/test/java/com/greysonparrelli/permiso/ExampleUnitTest.java",
    "chars": 320,
    "preview": "package com.greysonparrelli.permiso;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * To work on unit "
  },
  {
    "path": "settings.gradle",
    "chars": 62,
    "preview": "include ':app', ':permiso'\n\nrootProject.name = 'permiso-root'\n"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the greysonp/permiso GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 40 files (70.5 KB), approximately 17.1k tokens, and a symbol index with 82 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!