-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cuizhen
committed
Mar 18, 2019
0 parents
commit 70e5a2f
Showing
50 changed files
with
2,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Android template | ||
# Built application files | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# IntelliJ | ||
*.iml | ||
.idea/ | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/gradle.xml | ||
.idea/assetWizardSettings.xml | ||
.idea/dictionaries | ||
.idea/libraries | ||
.idea/caches | ||
|
||
# Keystore files | ||
# Uncomment the following line if you do not want to check your keystore files in. | ||
#*.jks | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json | ||
|
||
# fastlane | ||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
fastlane/readme.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
minSdkVersion 14 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.yanzhenjie.permission:support:2.0.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="per.goweii.anypermission"> | ||
|
||
</manifest> |
100 changes: 100 additions & 0 deletions
100
anypermission/src/main/java/per/goweii/anypermission/AnyPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package per.goweii.anypermission; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.Fragment; | ||
|
||
import com.yanzhenjie.permission.AndPermission; | ||
import com.yanzhenjie.permission.option.Option; | ||
import com.yanzhenjie.permission.runtime.Permission; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 描述: | ||
* | ||
* @author Cuizhen | ||
* @date 2019/3/16 | ||
*/ | ||
public class AnyPermission { | ||
|
||
private final Context mContext; | ||
private final Option mOption; | ||
|
||
public static AnyPermission with(@NonNull final Context context) { | ||
return new AnyPermission(context); | ||
} | ||
|
||
public static AnyPermission with(@NonNull final Activity activity) { | ||
return new AnyPermission(activity); | ||
} | ||
|
||
public static AnyPermission with(@NonNull final Fragment fragment) { | ||
return new AnyPermission(fragment); | ||
} | ||
|
||
public static AnyPermission with(@NonNull final android.app.Fragment fragment) { | ||
return new AnyPermission(fragment); | ||
} | ||
|
||
private AnyPermission(final Context context){ | ||
mContext = context; | ||
mOption = AndPermission.with(context); | ||
} | ||
|
||
private AnyPermission(final Activity activity){ | ||
mContext = activity; | ||
mOption = AndPermission.with(activity); | ||
} | ||
|
||
private AnyPermission(final Fragment fragment){ | ||
mContext = fragment.getContext(); | ||
mOption = AndPermission.with(fragment); | ||
} | ||
|
||
private AnyPermission(final android.app.Fragment fragment){ | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
mContext = fragment.getContext(); | ||
} else { | ||
mContext = fragment.getActivity(); | ||
} | ||
mOption = AndPermission.with(fragment); | ||
} | ||
|
||
public String name(String permission) { | ||
return Permission.transformText(mContext, permission).get(0); | ||
} | ||
|
||
public Uri fileUri(File file) { | ||
return AndPermission.getFileUri(mContext, file); | ||
} | ||
|
||
public RuntimeRequester runtime(int requestCodeWhenGoSetting) { | ||
return new RuntimeRequester(mOption, mContext, requestCodeWhenGoSetting); | ||
} | ||
|
||
public InstallRequester install(File apkFile) { | ||
return new InstallRequester(mOption, apkFile); | ||
} | ||
|
||
public OverlayRequester overlay() { | ||
return new OverlayRequester(mOption); | ||
} | ||
|
||
@Deprecated | ||
public SettingRequester setting() { | ||
return new SettingRequester(mOption); | ||
} | ||
|
||
public NotificationShowRequester notificationShow() { | ||
return new NotificationShowRequester(mOption); | ||
} | ||
|
||
public NotificationAccessRequester notificationAccess() { | ||
return new NotificationAccessRequester(mOption); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
anypermission/src/main/java/per/goweii/anypermission/InstallRequester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package per.goweii.anypermission; | ||
|
||
import android.content.Context; | ||
|
||
import com.yanzhenjie.permission.Action; | ||
import com.yanzhenjie.permission.Rationale; | ||
import com.yanzhenjie.permission.RequestExecutor; | ||
import com.yanzhenjie.permission.option.Option; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 描述: | ||
* | ||
* @author Cuizhen | ||
* @date 2019/3/16 | ||
*/ | ||
public class InstallRequester implements Requester<Void> { | ||
|
||
private final Option mOption; | ||
private final File mApkFile; | ||
|
||
private OnPermissionProcess<File> mOnWithoutPermission = null; | ||
|
||
InstallRequester(Option option, File apkFile) { | ||
this.mOption = option; | ||
this.mApkFile = apkFile; | ||
} | ||
|
||
public InstallRequester onWithoutPermission(OnPermissionProcess<File> onWithoutPermission) { | ||
mOnWithoutPermission = onWithoutPermission; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Void start(final RequestListener listener) { | ||
mOption.install() | ||
.file(mApkFile) | ||
.rationale(new Rationale<File>() { | ||
@Override | ||
public void showRationale(Context c, File f, final RequestExecutor e) { | ||
if (mOnWithoutPermission == null) { | ||
e.execute(); | ||
} else { | ||
mOnWithoutPermission.process(f, new OnPermissionProcess.Processor() { | ||
@Override | ||
public void next() { | ||
e.execute(); | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
e.cancel(); | ||
} | ||
}); | ||
} | ||
} | ||
}) | ||
.onGranted(new Action<File>() { | ||
@Override | ||
public void onAction(File data) { | ||
listener.onSuccess(); | ||
} | ||
}) | ||
.onDenied(new Action<File>() { | ||
@Override | ||
public void onAction(File data) { | ||
listener.onFailed(); | ||
} | ||
}) | ||
.start(); | ||
return null; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
anypermission/src/main/java/per/goweii/anypermission/NotificationAccessRequester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package per.goweii.anypermission; | ||
|
||
import android.content.Context; | ||
|
||
import com.yanzhenjie.permission.Action; | ||
import com.yanzhenjie.permission.Rationale; | ||
import com.yanzhenjie.permission.RequestExecutor; | ||
import com.yanzhenjie.permission.option.Option; | ||
|
||
/** | ||
* 描述: | ||
* | ||
* @author Cuizhen | ||
* @date 2019/3/16 | ||
*/ | ||
public class NotificationAccessRequester implements Requester<Void> { | ||
|
||
private final Option mOption; | ||
|
||
private OnPermissionProcess<Void> mOnWithoutPermission = null; | ||
|
||
NotificationAccessRequester(Option option) { | ||
this.mOption = option; | ||
} | ||
|
||
public NotificationAccessRequester onWithoutPermission(OnPermissionProcess<Void> onWithoutPermission) { | ||
mOnWithoutPermission = onWithoutPermission; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Void start(final RequestListener listener) { | ||
mOption.notification().listener() | ||
.rationale(new Rationale<Void>() { | ||
@Override | ||
public void showRationale(Context c, Void d, final RequestExecutor e) { | ||
if (mOnWithoutPermission == null) { | ||
e.execute(); | ||
} else { | ||
mOnWithoutPermission.process(d, new OnPermissionProcess.Processor() { | ||
@Override | ||
public void next() { | ||
e.execute(); | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
e.cancel(); | ||
} | ||
}); | ||
} | ||
} | ||
}) | ||
.onGranted(new Action<Void>() { | ||
@Override | ||
public void onAction(Void data) { | ||
listener.onSuccess(); | ||
} | ||
}) | ||
.onDenied(new Action<Void>() { | ||
@Override | ||
public void onAction(Void data) { | ||
listener.onFailed(); | ||
} | ||
}) | ||
.start(); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.