Skip to content

Commit

Permalink
Merge pull request #5 from bugyun/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bugyun authored Sep 20, 2019
2 parents 68da3df + ea8d5c0 commit 59187c8
Show file tree
Hide file tree
Showing 62 changed files with 2,843 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.PermissionChecker;

import java.util.Arrays;
import java.util.List;

public class MissPermissionHelper {

private static class SingletonHolder {

private static final MissPermissionHelper INSTANCE = new MissPermissionHelper();
}

Expand All @@ -41,51 +41,77 @@ private Builder(FragmentActivity activity) {
request = new PermissionRequest(activity);
}

/**
* 添加权限
*/
public Builder addPermission(String permission) {
request.addPermission(permission);
return this;
}

/**
* 添加权限
*/
public Builder addPermissions(List<String> permissions) {
request.addPermissions(permissions);
return this;
}

/**
* 添加权限
*/
public Builder addPermissions(String[] permissions) {
request.addPermissions(Arrays.asList(permissions));
return this;
}

/**
* 设置请求回调,并开始请求权限
*/
public void checkPermission(PermissionRequest.PermissionListener listener) {
//检查
if (null == request.getAction()) {
request.setAction(new DefaultAction());
}
request.start(listener);
}

/**
* 是否显示弹框
*/
public Builder showPrompt(boolean showPrompt) {
request.setShowPrompt(showPrompt);
return this;
}

/**
* 设置弹框的标题
*/
public Builder title(String title) {
request.setTitle(title);
return this;
}

/**
* 设置弹框的描述
*/
public Builder msg(String msg) {
request.setMsg(msg);
return this;
}

// public Builder filterColor(@ColorRes int filterColor) {
// request.setFilterColor(filterColor);
// return this;
// }

/**
* 设置显示 ui
*/
public Builder styleResId(@StyleRes int styleResId) {
request.setStyleResId(styleResId);
return this;
}

public Builder ischeck(boolean isCheck) {
/**
* 保留属性,是否需要检测
*/
public Builder isCheck(boolean isCheck) {
request.setIsCheck(isCheck);
return this;
}
Expand All @@ -98,10 +124,6 @@ public Builder action(IAction iAction) {

/**
* 简单有没有权限,如果 [] 为空或者 为 null 时,返回有权限
*
* @param context
* @param permissions
* @return
*/
public static boolean check(Context context, String[] permissions) {
boolean isHasPermission = true;//检测权限
Expand All @@ -117,7 +139,8 @@ public static boolean check(Context context, String[] permissions) {
}
} else {
for (String permission : permissions) {
if (PermissionChecker.checkSelfPermission(context, permission) != PermissionChecker.PERMISSION_GRANTED) {
if (PermissionChecker.checkSelfPermission(context, permission)
!= PermissionChecker.PERMISSION_GRANTED) {
isHasPermission = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public PermissionGroup(String permissionName, int permissionIconRes) {
this.permissionIconRes = permissionIconRes;
}

static HashMap<String, PermissionGroup> permissionGroupHashMap = new HashMap<>();
static HashMap<String, PermissionGroup> permissionGroupHashMap = new HashMap<>(35);

/**
* 添加图标
*/
static {
//CalendarChecker
PermissionGroup calendarGroup = new PermissionGroup(CalendarChecker.PERMISSION_NAME, CalendarChecker.PERMISSION_ICON_RES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public class PermissionRequest implements AvoidOnResultHelper.PermissionsCallBac
private PermissionListener permissionListener;
private final WeakReference<FragmentActivity> activityWeakReference;

//ui
//弹出 ui 样式
private boolean showPrompt;
private String title;
private String msg;
// private int filterColor = 0;
private int styleResId = R.style.MissPermissionHelperDefaultNormalStyle;

private boolean isCheck;
private IAction action = new DefaultAction();
private IAction action ;

PermissionRequest(FragmentActivity activity) {
activityWeakReference = new WeakReference<>(activity);
Expand Down Expand Up @@ -214,7 +214,6 @@ public PermissionException getException() {
return exception;
}


public boolean isShowPrompt() {
return showPrompt;
}
Expand All @@ -239,14 +238,6 @@ public void setMsg(String msg) {
this.msg = msg;
}

// public int getFilterColor() {
// return filterColor;
// }
//
// public void setFilterColor(int filterColor) {
// this.filterColor = filterColor;
// }

public int getStyleResId() {
return styleResId;
}
Expand Down
1 change: 1 addition & 0 deletions MissPermissionPro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions MissPermissionPro/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apply plugin: 'com.android.library'
apply from: 'jcenter.gradle'//上传 jcenter 的插件

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-fragment:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'vip.ruoyun.helper:avoid-onresult-helper:1.0.3'
}
Empty file.
20 changes: 20 additions & 0 deletions MissPermissionPro/jcenter.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//上传 jcenter 的插件
apply plugin: 'com.novoda.bintray-release' // 新增

/**
* 参考
* 'com.android.support.test.espresso:espresso-core:3.0.2'
* group: 'com.android.support.test.espresso', name: 'espresso-core', version: '3.0.2'
*/

// 新增
publish {
userOrg = 'bugyun' //bintray.com用户名
groupId = 'vip.ruoyun.permission' //jcenter group
artifactId = 'miss-pro' //项目名称 name
publishVersion = '1.0.0'//版本号 version
desc = 'Android 权限请求库 MissPermission pro版'//描述
website = 'https://github.com/bugyun/MissPermission' // github 网址
}

// ./gradlew clean build bintrayUpload -PbintrayUser=bintray.user -PbintrayKey=bintray.apikey -PdryRun=false
21 changes: 21 additions & 0 deletions MissPermissionPro/proguard-rules.pro
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package vip.ruoyun.permission.pro;

import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("vip.ruoyun.permission.pro.test", appContext.getPackageName());
}
}
2 changes: 2 additions & 0 deletions MissPermissionPro/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest package="vip.ruoyun.permission.pro"
xmlns:android="http://schemas.android.com/apk/res/android" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package vip.ruoyun.permission.pro;


import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.view.View;
import java.util.HashSet;
import java.util.Set;
import vip.ruoyun.helper.avoid.AvoidOnResultHelper;
import vip.ruoyun.permission.pro.ui.AgainRequestDialog;
import vip.ruoyun.permission.pro.ui.AlwaysDeniedDialog;
import vip.ruoyun.permission.pro.ui.RequestPromptDialog;


public class DefaultAction implements IAction {

private RequestPromptDialog requestPromptDialog;
private AlwaysDeniedDialog alwaysDeniedDialog;
private AgainRequestDialog againRequestDialog;

@Override
public void checkedAction(final PermissionRequest request, Set<PermissionGroup> permissionGroups) {
if (request.getDeniedPermissionList().size() == 0) {
request.next();
return;
}
if (requestPromptDialog == null) {
requestPromptDialog = RequestPromptDialog.getRequestPromptDialog(request.getContext());
requestPromptDialog.setTitleAndMsg(request.getTitle(), request.getMsg());
requestPromptDialog.setBtnOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (requestPromptDialog != null && requestPromptDialog.isShowing()) {
requestPromptDialog.dismiss();
}
request.next();
}
});
}
requestPromptDialog.setPermissionGroups(permissionGroups);
requestPromptDialog.setStyleId(request.getStyleResId());
requestPromptDialog.show();
}

@Override
public void deniedAction(final PermissionRequest request) {
StringBuilder sBuilder = new StringBuilder();
Set<PermissionGroup> permissionGroups = new HashSet<>();
for (String deniedPermission : request.getDeniedPermissionList()) {
PermissionGroup permissionGroup = PermissionGroup.permissionGroupHashMap.get(deniedPermission);
if (permissionGroup != null) {
permissionGroups.add(permissionGroup);
}
}
for (PermissionGroup permissionGroup : permissionGroups) {
sBuilder.append(permissionGroup.permissionName);
sBuilder.append(",");
}
if (sBuilder.length() > 0) {
sBuilder.deleteCharAt(sBuilder.length() - 1);
}
if (request.isAlwaysDenied()) {
if (alwaysDeniedDialog == null) {
alwaysDeniedDialog = AlwaysDeniedDialog.getAlwaysDeniedDialog(request.getContext());
alwaysDeniedDialog.setStyleId(request.getStyleResId());
alwaysDeniedDialog.setSettingClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (alwaysDeniedDialog != null && alwaysDeniedDialog.isShowing()) {
alwaysDeniedDialog.dismiss();
}
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + v.getContext().getPackageName()));
AvoidOnResultHelper.startActivityForResult(request.getContext(), intent, DefaultAction.this);
}
});
}
alwaysDeniedDialog.setTitleAndMsg("温馨提示", "获取" + sBuilder.toString() + "权限被禁用" + "\n请在 设置-应用管理-权限管理 (将权限打开)");
alwaysDeniedDialog.show();
} else {
if (againRequestDialog == null) {
againRequestDialog = AgainRequestDialog.getAlwaysDeniedDialog(request.getContext());
againRequestDialog.setStyleId(request.getStyleResId());
againRequestDialog.setSettingClickListener("验证权限", new View.OnClickListener() {
@Override
public void onClick(View v) {
request.requestPermissionsAgain();
if (againRequestDialog != null && againRequestDialog.isShowing()) {
againRequestDialog.dismiss();
}
}
});
againRequestDialog.setTitleAndMsg("温馨提示", "我们需要这些权限才能正常使用该功能");
}
againRequestDialog.show();
}
}

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

}
}
Loading

0 comments on commit 59187c8

Please sign in to comment.