├── rx1
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── io
│ │ └── victoralbertos
│ │ └── rx1_permissions_result
│ │ ├── internal
│ │ ├── OnResult.java
│ │ ├── Locale.java
│ │ ├── Request.java
│ │ ├── ShadowActivity.java
│ │ └── ActivitiesLifecycleCallbacks.java
│ │ ├── Result.java
│ │ └── RxPermissionsResult.java
├── proguard-rules.pro
└── build.gradle
├── rx2
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── io
│ │ └── victoralbertos
│ │ └── rx2_permissions_result
│ │ ├── internal
│ │ ├── OnResult.java
│ │ ├── Locale.java
│ │ ├── Request.java
│ │ ├── ShadowActivity.java
│ │ └── ActivitiesLifecycleCallbacks.java
│ │ ├── Result.java
│ │ └── RxPermissionsResult.java
├── proguard-rules.pro
└── build.gradle
├── sample-rx1
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ ├── splash_activity.xml
│ │ │ └── common.xml
│ │ ├── java
│ │ └── io
│ │ │ └── victoralbertos
│ │ │ └── rxpermissionsresult
│ │ │ ├── SplashActivity.java
│ │ │ ├── AppSample.java
│ │ │ ├── Helper.java
│ │ │ ├── OnCreateActivity.java
│ │ │ ├── OnCreateIntervalActivity.java
│ │ │ └── OnClickActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── sample-rx2
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ ├── splash_activity.xml
│ │ │ └── common.xml
│ │ ├── java
│ │ └── io
│ │ │ └── victoralbertos
│ │ │ └── sample_rx2
│ │ │ ├── SplashActivity.java
│ │ │ ├── AppSample.java
│ │ │ ├── Helper.java
│ │ │ ├── OnCreateActivity.java
│ │ │ ├── OnClickActivity.java
│ │ │ └── OnCreateIntervalActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE.txt
/rx1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rx2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-rx1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample-rx2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample-rx1', ':rx1', ':rx2', ':sample-rx2'
2 |
--------------------------------------------------------------------------------
/rx2/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | rx2
3 |
4 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | sample-rx2
3 |
4 |
--------------------------------------------------------------------------------
/rx1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | rx-permissions-result
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxPermissionsResult
3 |
4 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx1/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx1/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx2/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx2/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx1/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx1/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx1/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx2/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx2/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VictorAlbertos/RxPermissionsResult/HEAD/sample-rx2/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 19 10:07:26 CEST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/rx2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/rx1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/rx1/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/rx2/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | **/build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio
29 | .navigation/
30 | .idea/
31 | **/*.iml
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # .DS_Store files
37 | **/.DS_Store
--------------------------------------------------------------------------------
/rx1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/victor/Documents/AndroidStudio/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/rx2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/victor/Documents/AndroidStudio/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample-rx1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/victor/Documents/AndroidStudio/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample-rx2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/victor/Documents/AndroidStudio/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/layout/splash_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/layout/splash_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/internal/OnResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result.internal;
18 |
19 | import java.io.Serializable;
20 |
21 | public interface OnResult extends Serializable {
22 | void response(String permissions[], int[] grantResults);
23 | }
24 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/internal/OnResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result.internal;
18 |
19 | import java.io.Serializable;
20 |
21 | public interface OnResult extends Serializable {
22 | void response(String permissions[], int[] grantResults);
23 | }
24 |
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/internal/Locale.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result.internal;
18 |
19 | public interface Locale {
20 | String RX_PERMISSIONS_RESULT_NOT_REGISTER =
21 | "You must call RxPermissionsResult.register(application) before attempting to use startIntent";
22 | }
23 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/internal/Locale.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result.internal;
18 |
19 | public interface Locale {
20 | String RX_PERMISSIONS_RESULT_NOT_REGISTER =
21 | "You must call RxPermissionsResult.register(application) before attempting to use startIntent";
22 | }
23 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package io.victoralbertos.sample_rx2;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | public final class SplashActivity extends AppCompatActivity {
9 |
10 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.splash_activity);
13 |
14 | findViewById(R.id.bt_on_click).setOnClickListener(view ->
15 | startActivity(new Intent(this, OnClickActivity.class))
16 | );
17 |
18 | findViewById(R.id.bt_on_create).setOnClickListener(view ->
19 | startActivity(new Intent(this, OnCreateActivity.class))
20 | );
21 |
22 | findViewById(R.id.bt_on_create_interval).setOnClickListener(view ->
23 | startActivity(new Intent(this, OnCreateIntervalActivity.class))
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package io.victoralbertos.rxpermissionsresult;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | public final class SplashActivity extends AppCompatActivity {
9 |
10 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.splash_activity);
13 |
14 | findViewById(R.id.bt_on_click).setOnClickListener(view ->
15 | startActivity(new Intent(this, OnClickActivity.class))
16 | );
17 |
18 | findViewById(R.id.bt_on_create).setOnClickListener(view ->
19 | startActivity(new Intent(this, OnCreateActivity.class))
20 | );
21 |
22 | findViewById(R.id.bt_on_create_interval).setOnClickListener(view ->
23 | startActivity(new Intent(this, OnCreateIntervalActivity.class))
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/res/layout/common.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/res/layout/common.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/AppSample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.sample_rx2;
18 |
19 | import android.app.Application;
20 | import io.victoralbertos.rx2_permissions_result.RxPermissionsResult;
21 |
22 | public final class AppSample extends Application {
23 |
24 | @Override public void onCreate() {
25 | super.onCreate();
26 | RxPermissionsResult.register(this);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample-rx1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'me.tatarka.retrolambda'
3 |
4 | buildscript {
5 | repositories {
6 | mavenCentral()
7 | jcenter()
8 | }
9 |
10 | dependencies {
11 | classpath 'me.tatarka:gradle-retrolambda:3.2.4'
12 | }
13 | }
14 |
15 | android {
16 | compileSdkVersion 24
17 | buildToolsVersion "24.0.1"
18 |
19 | defaultConfig {
20 | applicationId "io.victoralbertos.rxpermissionsresult"
21 | minSdkVersion 18
22 | targetSdkVersion 24
23 | versionCode 1
24 | versionName "1.0"
25 | }
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 | }
37 |
38 | dependencies {
39 | compile project(':rx1')
40 | compile 'com.android.support:appcompat-v7:24.2.0'
41 | compile 'com.trello:rxlifecycle-components:0.7.0'
42 | }
43 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/AppSample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rxpermissionsresult;
18 |
19 | import android.app.Application;
20 | import io.victoralbertos.rx1_permissions_result.RxPermissionsResult;
21 |
22 | public final class AppSample extends Application {
23 |
24 | @Override public void onCreate() {
25 | super.onCreate();
26 | RxPermissionsResult.register(this);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample-rx2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'me.tatarka.retrolambda'
3 |
4 | buildscript {
5 | repositories {
6 | mavenCentral()
7 | jcenter()
8 | }
9 |
10 | dependencies {
11 | classpath 'me.tatarka:gradle-retrolambda:3.2.4'
12 | }
13 | }
14 |
15 | android {
16 | compileSdkVersion 24
17 | buildToolsVersion "24.0.1"
18 |
19 | defaultConfig {
20 | applicationId "io.victoralbertos.sample_rx2"
21 | minSdkVersion 16
22 | targetSdkVersion 24
23 | versionCode 1
24 | versionName "1.0"
25 | }
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 | packagingOptions {
37 | pickFirst 'META-INF/rxjava.properties'
38 | }
39 | }
40 |
41 | dependencies {
42 | compile project(':rx2')
43 | compile 'com.android.support:appcompat-v7:24.2.0'
44 | compile 'com.github.VictorAlbertos:RxLifecycleInterop:0.0.4'
45 | }
46 |
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/internal/Request.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result.internal;
18 |
19 | public class Request {
20 | private final String[] permissions;
21 | private OnResult onResult;
22 |
23 | public Request(String... permissions) {
24 | this.permissions = permissions;
25 | }
26 |
27 | public void setOnResult(OnResult onResult) {
28 | this.onResult = onResult;
29 | }
30 |
31 | public OnResult onResult() {
32 | return onResult;
33 | }
34 |
35 | public String[] permissions() {
36 | return permissions;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/internal/Request.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result.internal;
18 |
19 | public class Request {
20 | private final String[] permissions;
21 | private OnResult onResult;
22 |
23 | public Request(String... permissions) {
24 | this.permissions = permissions;
25 | }
26 |
27 | public void setOnResult(OnResult onResult) {
28 | this.onResult = onResult;
29 | }
30 |
31 | public OnResult onResult() {
32 | return onResult;
33 | }
34 |
35 | public String[] permissions() {
36 | return permissions;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/rx1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.VictorAlbertos'
4 |
5 | android {
6 | compileSdkVersion 24
7 | buildToolsVersion "24.0.1"
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 24
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile "io.reactivex:rxjava:1.2.1"
25 | compile 'com.android.support:appcompat-v7:24.2.0'
26 | }
27 |
28 | // build a jar with source files
29 | task sourcesJar(type: Jar) {
30 | from android.sourceSets.main.java.srcDirs
31 | classifier = 'sources'
32 | }
33 |
34 | task javadoc(type: Javadoc) {
35 | failOnError false
36 | source = android.sourceSets.main.java.sourceFiles
37 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
38 | classpath += configurations.compile
39 | }
40 |
41 | // build a jar with javadoc
42 | task javadocJar(type: Jar, dependsOn: javadoc) {
43 | classifier = 'javadoc'
44 | from javadoc.destinationDir
45 | }
46 |
47 | artifacts {
48 | archives sourcesJar
49 | archives javadocJar
50 | }
--------------------------------------------------------------------------------
/rx2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.VictorAlbertos'
4 |
5 | android {
6 | compileSdkVersion 24
7 | buildToolsVersion "24.0.1"
8 |
9 | defaultConfig {
10 | minSdkVersion 16
11 | targetSdkVersion 24
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile 'io.reactivex.rxjava2:rxjava:2.0.0'
25 | compile 'com.android.support:appcompat-v7:24.2.0'
26 | }
27 |
28 | // build a jar with source files
29 | task sourcesJar(type: Jar) {
30 | from android.sourceSets.main.java.srcDirs
31 | classifier = 'sources'
32 | }
33 |
34 | task javadoc(type: Javadoc) {
35 | failOnError false
36 | source = android.sourceSets.main.java.sourceFiles
37 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
38 | classpath += configurations.compile
39 | }
40 |
41 | // build a jar with javadoc
42 | task javadocJar(type: Jar, dependsOn: javadoc) {
43 | classifier = 'javadoc'
44 | from javadoc.destinationDir
45 | }
46 |
47 | artifacts {
48 | archives sourcesJar
49 | archives javadocJar
50 | }
51 |
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result;
18 |
19 | public class Result {
20 | private final T targetUI;
21 | private final String permissions[];
22 | private final int[] grantResults;
23 |
24 | public Result(T targetUI, String[] permissions, int[] grantResults) {
25 | this.targetUI = targetUI;
26 | this.permissions = permissions;
27 | this.grantResults = grantResults;
28 | }
29 |
30 | public T targetUI() {
31 | return targetUI;
32 | }
33 |
34 | public String[] permissions() {
35 | return permissions;
36 | }
37 |
38 | public int[] grantResults() {
39 | return grantResults;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result;
18 |
19 | public class Result {
20 | private final T targetUI;
21 | private final String permissions[];
22 | private final int[] grantResults;
23 |
24 | public Result(T targetUI, String[] permissions, int[] grantResults) {
25 | this.targetUI = targetUI;
26 | this.permissions = permissions;
27 | this.grantResults = grantResults;
28 | }
29 |
30 | public T targetUI() {
31 | return targetUI;
32 | }
33 |
34 | public String[] permissions() {
35 | return permissions;
36 | }
37 |
38 | public int[] grantResults() {
39 | return grantResults;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/Helper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.sample_rx2;
18 |
19 | import android.content.pm.PackageManager;
20 | import android.util.Log;
21 | import android.widget.TextView;
22 |
23 | public final class Helper {
24 |
25 | static void showPermissionStatus(TextView tvOutput, String[] permissions, int[] grantResults) {
26 | StringBuilder stringBuilder = new StringBuilder();
27 |
28 | for (int i = 0; i < permissions.length; i++) {
29 | String permission = permissions[i];
30 | boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
31 | if (granted) {
32 | stringBuilder.append(permission).append(" was granted").append("\n");
33 | } else {
34 | stringBuilder.append(permission).append(" wasn't granted").append("\n");
35 | }
36 | }
37 |
38 | Log.d("rx_permissions_result", stringBuilder.toString());
39 | tvOutput.setText(stringBuilder.toString());
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/Helper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rxpermissionsresult;
18 |
19 | import android.content.pm.PackageManager;
20 | import android.util.Log;
21 | import android.widget.TextView;
22 |
23 | public final class Helper {
24 |
25 | static void showPermissionStatus(TextView tvOutput, String[] permissions, int[] grantResults) {
26 | StringBuilder stringBuilder = new StringBuilder();
27 |
28 | for (int i = 0; i < permissions.length; i++) {
29 | String permission = permissions[i];
30 | boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
31 | if (granted) {
32 | stringBuilder.append(permission).append(" was granted").append("\n");
33 | } else {
34 | stringBuilder.append(permission).append(" wasn't granted").append("\n");
35 | }
36 | }
37 |
38 | Log.d("rx_permissions_result", stringBuilder.toString());
39 | tvOutput.setText(stringBuilder.toString());
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/OnCreateActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rxpermissionsresult;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.widget.TextView;
22 | import com.trello.rxlifecycle.components.RxActivity;
23 | import io.victoralbertos.rx1_permissions_result.RxPermissionsResult;
24 |
25 | public final class OnCreateActivity extends RxActivity {
26 |
27 | @Override protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.common);
30 |
31 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
32 | Manifest.permission.CAMERA};
33 |
34 | RxPermissionsResult.on(this).requestPermissions(permissions)
35 | .compose(bindToLifecycle())
36 | .subscribe(result ->
37 | result.targetUI()
38 | .showPermissionStatus(result.permissions(), result.grantResults())
39 | );
40 | }
41 |
42 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
43 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/OnCreateActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.sample_rx2;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.widget.TextView;
22 | import io.reactivex.BackpressureStrategy;
23 | import io.victoralbertos.rx2_permissions_result.RxPermissionsResult;
24 | import io.victoralbertos.rxlifecycle_interop.Rx2Activity;
25 |
26 | public final class OnCreateActivity extends Rx2Activity {
27 |
28 | @Override protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.common);
31 |
32 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
33 | Manifest.permission.CAMERA};
34 |
35 | RxPermissionsResult.on(this).requestPermissions(permissions)
36 | .compose(bindToLifecycle2x(BackpressureStrategy.LATEST))
37 | .subscribe(result ->
38 | result.targetUI()
39 | .showPermissionStatus(result.permissions(), result.grantResults())
40 | );
41 | }
42 |
43 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
44 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/OnClickActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.sample_rx2;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.view.View;
22 | import android.widget.TextView;
23 | import com.trello.rxlifecycle.components.RxActivity;
24 | import io.victoralbertos.rx2_permissions_result.RxPermissionsResult;
25 |
26 | public final class OnClickActivity extends RxActivity {
27 |
28 | @Override protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.common);
31 |
32 | findViewById(R.id.bt_ask_permissions).setVisibility(View.VISIBLE);
33 | findViewById(R.id.bt_ask_permissions).setOnClickListener(view -> {
34 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
35 | Manifest.permission.CAMERA};
36 |
37 | RxPermissionsResult.on(this).requestPermissions(permissions)
38 | .subscribe(result ->
39 | result.targetUI()
40 | .showPermissionStatus(result.permissions(), result.grantResults())
41 | );
42 | });
43 | }
44 |
45 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
46 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/OnCreateIntervalActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rxpermissionsresult;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.widget.TextView;
22 | import com.trello.rxlifecycle.components.RxActivity;
23 | import io.victoralbertos.rx1_permissions_result.RxPermissionsResult;
24 | import java.util.concurrent.TimeUnit;
25 | import rx.Observable;
26 |
27 | public final class OnCreateIntervalActivity extends RxActivity {
28 |
29 | @Override protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.common);
32 |
33 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
34 | Manifest.permission.CAMERA};
35 |
36 | Observable.interval(3, TimeUnit.SECONDS)
37 | .flatMap(ignored -> RxPermissionsResult.on(this).requestPermissions(permissions))
38 | .compose(bindToLifecycle())
39 | .subscribe(result ->
40 | result.targetUI()
41 | .showPermissionStatus(result.permissions(), result.grantResults())
42 | );
43 | }
44 |
45 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
46 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/sample-rx1/src/main/java/io/victoralbertos/rxpermissionsresult/OnClickActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rxpermissionsresult;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.view.View;
22 | import android.widget.TextView;
23 | import com.trello.rxlifecycle.components.RxActivity;
24 | import io.victoralbertos.rx1_permissions_result.RxPermissionsResult;
25 |
26 | public final class OnClickActivity extends RxActivity {
27 |
28 | @Override protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.common);
31 |
32 | findViewById(R.id.bt_ask_permissions).setVisibility(View.VISIBLE);
33 | findViewById(R.id.bt_ask_permissions).setOnClickListener(view -> {
34 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
35 | Manifest.permission.CAMERA};
36 |
37 | RxPermissionsResult.on(this).requestPermissions(permissions)
38 | .subscribe(result ->
39 | result.targetUI()
40 | .showPermissionStatus(result.permissions(), result.grantResults())
41 | );
42 | });
43 | }
44 |
45 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
46 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/internal/ShadowActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result.internal;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.support.v4.app.ActivityCompat;
22 |
23 | public class ShadowActivity extends Activity {
24 | private static Request request;
25 | private OnResult onResult;
26 | private String permissions[];
27 | private int[] grantResults;
28 |
29 | @Override protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 |
32 | if (request == null) {
33 | finish();
34 | return;
35 | }
36 |
37 | onResult = request.onResult();
38 |
39 | if (savedInstanceState != null) return;
40 |
41 | ActivityCompat.requestPermissions(this, request.permissions(), 0);
42 | }
43 |
44 | @Override public void onRequestPermissionsResult(int requestCode,
45 | String permissions[], int[] grantResults) {
46 | this.permissions = permissions;
47 | this.grantResults = grantResults;
48 | finish();
49 | }
50 |
51 | @Override protected void onDestroy() {
52 | super.onDestroy();
53 | if (onResult != null) {
54 | onResult.response(permissions, grantResults);
55 | }
56 | }
57 |
58 | public static void setRequest(Request aRequest) {
59 | request = aRequest;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/internal/ShadowActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result.internal;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.support.v4.app.ActivityCompat;
22 |
23 | public class ShadowActivity extends Activity {
24 | private static Request request;
25 | private OnResult onResult;
26 | private String permissions[];
27 | private int[] grantResults;
28 |
29 | @Override protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 |
32 | if (request == null) {
33 | finish();
34 | return;
35 | }
36 |
37 | onResult = request.onResult();
38 |
39 | if (savedInstanceState != null) return;
40 |
41 | ActivityCompat.requestPermissions(this, request.permissions(), 0);
42 | }
43 |
44 | @Override public void onRequestPermissionsResult(int requestCode,
45 | String permissions[], int[] grantResults) {
46 | this.permissions = permissions;
47 | this.grantResults = grantResults;
48 | finish();
49 | }
50 |
51 | @Override protected void onDestroy() {
52 | super.onDestroy();
53 | if (onResult != null) {
54 | onResult.response(permissions, grantResults);
55 | }
56 | }
57 |
58 | public static void setRequest(Request aRequest) {
59 | request = aRequest;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/sample-rx2/src/main/java/io/victoralbertos/sample_rx2/OnCreateIntervalActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.sample_rx2;
18 |
19 | import android.Manifest;
20 | import android.os.Bundle;
21 | import android.widget.TextView;
22 | import io.reactivex.BackpressureStrategy;
23 | import io.reactivex.Observable;
24 | import io.victoralbertos.rx2_permissions_result.RxPermissionsResult;
25 | import io.victoralbertos.rxlifecycle_interop.Rx2Activity;
26 | import java.util.concurrent.TimeUnit;
27 |
28 | public final class OnCreateIntervalActivity extends Rx2Activity {
29 |
30 | @Override protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.common);
33 |
34 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
35 | Manifest.permission.CAMERA};
36 |
37 | Observable.interval(3, TimeUnit.SECONDS)
38 | .flatMap(ignored -> RxPermissionsResult.on(this).requestPermissions(permissions))
39 | .compose(bindToLifecycle2x(BackpressureStrategy.LATEST))
40 | .subscribe(result ->
41 | result.targetUI()
42 | .showPermissionStatus(result.permissions(), result.grantResults())
43 | );
44 | }
45 |
46 | private void showPermissionStatus(String[] permissions, int[] grantResults) {
47 | Helper.showPermissionStatus((TextView) findViewById(R.id.tv_output), permissions, grantResults);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/rx1/src/main/java/io/victoralbertos/rx1_permissions_result/internal/ActivitiesLifecycleCallbacks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx1_permissions_result.internal;
18 |
19 | import android.app.Activity;
20 | import android.app.Application;
21 | import android.os.Bundle;
22 | import java.util.concurrent.TimeUnit;
23 | import rx.Observable;
24 | import rx.functions.Func1;
25 |
26 | public class ActivitiesLifecycleCallbacks {
27 | final Application application;
28 | volatile Activity liveActivityOrNull;
29 | Application.ActivityLifecycleCallbacks activityLifecycleCallbacks;
30 |
31 | public ActivitiesLifecycleCallbacks(Application application) {
32 | this.application = application;
33 | registerActivityLifeCycle();
34 | }
35 |
36 | private void registerActivityLifeCycle() {
37 | if (activityLifecycleCallbacks != null) application.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks);
38 |
39 | activityLifecycleCallbacks = new Application.ActivityLifecycleCallbacks() {
40 | @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
41 | liveActivityOrNull = activity;
42 | }
43 |
44 | @Override public void onActivityStarted(Activity activity) {}
45 |
46 | @Override public void onActivityResumed(Activity activity) {
47 | liveActivityOrNull = activity;
48 | }
49 |
50 | @Override public void onActivityPaused(Activity activity) {
51 | liveActivityOrNull = null;
52 | }
53 |
54 | @Override public void onActivityStopped(Activity activity) {}
55 |
56 | @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
57 |
58 | @Override public void onActivityDestroyed(Activity activity) {}
59 | };
60 |
61 | application.registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
62 | }
63 |
64 | public Activity getLiveActivity() {
65 | return liveActivityOrNull;
66 | }
67 |
68 | /**
69 | * Emits just one time a valid reference to the current activity
70 | * @return the current activity
71 | */
72 | volatile boolean emitted = false;
73 | public Observable getOLiveActivity() {
74 | emitted = false;
75 | return Observable.interval(50, 50, TimeUnit.MILLISECONDS)
76 | .map(new Func1() {
77 | @Override public Activity call(Long aLong) {
78 | return liveActivityOrNull;
79 | }
80 | })
81 | .takeWhile(new Func1() {
82 | @Override public Boolean call(Activity activity) {
83 | boolean continueEmitting = true;
84 | if (emitted) continueEmitting = false;
85 | if (activity != null) emitted = true;
86 | return continueEmitting;
87 | }
88 | })
89 | .filter(new Func1() {
90 | @Override public Boolean call(Activity activity) {
91 | return activity != null;
92 | }
93 | });
94 | }
95 |
96 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | :warning: This repository is deprecated :warning:
2 |
3 | You should use https://github.com/tbruyelle/RxPermissions
4 |
5 | [](http://android-arsenal.com/details/1/4376)
6 |
7 | # RxPermissionsResult
8 |
9 | Following the same approach that [RxActivityResult](https://github.com/VictorAlbertos/RxActivityResult) does, RxPermissionsResult is a reactive wrapper around the permission's Android Api, which allows to get the data without breaking the observable chain.
10 |
11 | ## Features:
12 | * Request permissions at runtime from any class, as long as you supply a valid `Activity` or `Fragment` instance.
13 | * Get the data back encapsulated in an `observable` and keep chaining.
14 | * Survive to configuration changes.
15 |
16 | ## SetUp
17 | Add to top level *gradle.build* file
18 |
19 | ```gradle
20 | allprojects {
21 | repositories {
22 | maven { url "https://jitpack.io" }
23 | }
24 | }
25 | ```
26 |
27 | Add to app module *gradle.build* file
28 | ```gradle
29 | dependencies {
30 | //RxJava1
31 | compile 'com.github.VictorAlbertos.RxPermissionsResult:rx1:0.0.4'
32 | compile 'io.reactivex:rxjava:1.2.1'
33 |
34 | //RxJava2
35 | compile 'com.github.VictorAlbertos.RxPermissionsResult:rx2:0.0.4'
36 | compile 'io.reactivex.rxjava2:rxjava:2.0.0'
37 | }
38 | ```
39 |
40 | ## Usage
41 |
42 | Call `RxPermissionsResult.register` in your Android `Application`.
43 |
44 | ```java
45 | public class SampleApp extends Application {
46 |
47 | @Override public void onCreate() {
48 | super.onCreate();
49 | RxPermissionsResult.register(this);
50 | }
51 | }
52 | ```
53 |
54 | You can call `RxPermissionsResult.on(this).requestPermissions(permissions)` supplying both, an `Activity` instance or a `Fragment` instance.
55 |
56 | **Limitation:**: Your fragments need to extend from `android.support.v4.app.Fragment` instead of `android.app.Fragment`, otherwise they won't be notified.
57 |
58 | ```java
59 | String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
60 |
61 | RxPermissionsResult.on(this).requestPermissions(permissions)
62 | .subscribe(result ->
63 | result.targetUI()
64 | .showPermissionStatus(result.permissions(), result.grantResults())
65 | );
66 |
67 | void showPermissionStatus(String[] permissions, int[] grantResults) {
68 | boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
69 | if (granted) {
70 | textView.setText(permissions[0] + " Granted")
71 | } else {
72 | textView.setText(permissions[0] + "Not granted")
73 | }
74 | }
75 | ```
76 |
77 | Please pay attention to the `targetUI()` method in the `Result` object emitted.
78 |
79 | This method returns a safety instance of the current `Activity`/`Fragment`. Because the original one may be recreated (due to configuration changes or some other system events) it would be unsafe calling it.
80 |
81 | Instead, you must call any method/variable of your `Activity`/`Fragment` from this instance encapsulated in the `Result` object.
82 |
83 | For a complete example about RxPermissionsResult, refer to this [module](https://github.com/VictorAlbertos/RxPermissionsResult/tree/master/sample-rx1) if you are using RxJava1, or to [this](https://github.com/VictorAlbertos/RxPermissionsResult/tree/master/sample-rx2) other one if using RxJava2.
84 |
85 | ## Another author's libraries:
86 | * [ReactiveCache](https://github.com/VictorAlbertos/ReactiveCache): A reactive cache for Android and Java which honors the Observable chain.
87 | * [RxActivityResult](https://github.com/VictorAlbertos/RxActivityResult): A reactive-tiny-badass-vindictive library to break with the OnActivityResult implementation as it breaks the observables chain.
88 | * [RxSocialConnect](https://github.com/VictorAlbertos/RxSocialConnect-Android): OAuth RxJava extension for Android.
89 |
--------------------------------------------------------------------------------
/rx2/src/main/java/io/victoralbertos/rx2_permissions_result/internal/ActivitiesLifecycleCallbacks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Copyright 2016 Víctor Albertos
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.victoralbertos.rx2_permissions_result.internal;
18 |
19 | import android.app.Activity;
20 | import android.app.Application;
21 | import android.os.Bundle;
22 | import io.reactivex.Observable;
23 | import io.reactivex.functions.Function;
24 | import io.reactivex.functions.Predicate;
25 | import java.util.concurrent.TimeUnit;
26 |
27 | public class ActivitiesLifecycleCallbacks {
28 | final Application application;
29 | volatile Activity liveActivityOrNull;
30 | Application.ActivityLifecycleCallbacks activityLifecycleCallbacks;
31 |
32 | public ActivitiesLifecycleCallbacks(Application application) {
33 | this.application = application;
34 | registerActivityLifeCycle();
35 | }
36 |
37 | private void registerActivityLifeCycle() {
38 | if (activityLifecycleCallbacks != null) application.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks);
39 |
40 | activityLifecycleCallbacks = new Application.ActivityLifecycleCallbacks() {
41 | @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
42 | liveActivityOrNull = activity;
43 | }
44 |
45 | @Override public void onActivityStarted(Activity activity) {}
46 |
47 | @Override public void onActivityResumed(Activity activity) {
48 | liveActivityOrNull = activity;
49 | }
50 |
51 | @Override public void onActivityPaused(Activity activity) {
52 | liveActivityOrNull = null;
53 | }
54 |
55 | @Override public void onActivityStopped(Activity activity) {}
56 |
57 | @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
58 |
59 | @Override public void onActivityDestroyed(Activity activity) {}
60 | };
61 |
62 | application.registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
63 | }
64 |
65 | public Activity getLiveActivity() {
66 | return liveActivityOrNull;
67 | }
68 |
69 | /**
70 | * Emits just one time a valid reference to the current activity
71 | * @return the current activity
72 | */
73 | volatile boolean emitted = false;
74 | public Observable getOLiveActivity() {
75 | emitted = false;
76 | return Observable.interval(50, 50, TimeUnit.MILLISECONDS)
77 | .map(new Function() {
78 | @Override public Object apply(Long aLong) throws Exception {
79 | if (liveActivityOrNull == null) return 0;
80 | return liveActivityOrNull;
81 | }
82 | })
83 | .takeWhile(new Predicate