Skip to content

Commit

Permalink
Merge pull request #2 from bugyun/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bugyun authored Aug 16, 2019
2 parents 6b886a0 + 1134047 commit 01a3e81
Show file tree
Hide file tree
Showing 19 changed files with 613 additions and 128 deletions.
6 changes: 2 additions & 4 deletions MissPermissionHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'
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.1'
api 'vip.ruoyun.helper:avoid-onresult-helper:1.0.3'
}
2 changes: 1 addition & 1 deletion MissPermissionHelper/jcenter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ publish {
userOrg = 'bugyun' //bintray.com用户名
groupId = 'vip.ruoyun.permission' //jcenter group
artifactId = 'miss-helper' //项目名称 name
publishVersion = '1.0.0'//版本号 version
publishVersion = '1.0.1'//版本号 version
desc = 'Android 权限请求库 MissPermissionHelper'//描述
website = 'https://github.com/bugyun/MissPermission' // github 网址
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,48 @@
package vip.ruoyun.permission.helper;


import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.view.View;
import android.view.Window;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import vip.ruoyun.permission.helper.ui.DialogUtil;
import vip.ruoyun.permission.helper.ui.MissPermissionView;
import vip.ruoyun.permission.helper.ui.PermissionAdapter;
import vip.ruoyun.helper.avoid.AvoidOnResultHelper;
import vip.ruoyun.permission.helper.ui.AgainRequestDialog;
import vip.ruoyun.permission.helper.ui.AlwaysDeniedDialog;
import vip.ruoyun.permission.helper.ui.RequestPromptDialog;


public class DefaultAction implements IAction {

private Dialog mDialog;
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;
}
mDialog = new Dialog(request.getContext());
MissPermissionView contentView = new MissPermissionView(request.getContext());
contentView.setGridViewColum(permissionGroups.size() < 3 ? permissionGroups.size() : 3);
contentView.setGridViewAdapter(new PermissionAdapter(new ArrayList<>(permissionGroups)));
// if (request.getFilterColor() != 0) {
// int mFilterColor = request.getContext().getResources().getColor(request.getFilterColor());
// contentView.setFilterColor(mFilterColor);
// }
contentView.setTitle(request.getTitle());
contentView.setMsg(request.getMsg());
contentView.setStyleId(request.getStyleResId());
contentView.setBtnOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
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();
}
request.next();
}
});
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(contentView);

mDialog.setCanceledOnTouchOutside(false);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
}
});
mDialog.show();
});
}
requestPromptDialog.setPermissionGroups(permissionGroups);
requestPromptDialog.setStyleId(request.getStyleResId());
requestPromptDialog.show();
}

@Override
Expand All @@ -81,17 +63,44 @@ public void deniedAction(final PermissionRequest request) {
sBuilder.deleteCharAt(sBuilder.length() - 1);
}
if (request.isAlwaysDenied()) {
DialogUtil.showPermissionManagerDialog(request.getContext(), sBuilder.toString());
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 {
new AlertDialog.Builder(request.getContext()).setTitle("温馨提示").setMessage("我们需要这些权限才能正常使用该功能").setNegativeButton("取消", null).setPositiveButton("验证权限", new DialogInterface.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(DialogInterface dialog, int which) {
request.requestPermissionsAgain();
}
}).setCancelable(false).show();
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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

import java.util.Set;

import vip.ruoyun.helper.avoid.AvoidOnResultHelper;

public interface IAction {

public interface IAction extends AvoidOnResultHelper.ActivityCallback {

/**
* 检测权限后,触发的事件
* @param request 权限请求
* @param permissionGroups 需要请求的权限集合
*/
void checkedAction(PermissionRequest request, Set<PermissionGroup> permissionGroups);

/**
* 拒绝触发的事件
* @param request 权限请求
*/
void deniedAction(PermissionRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package vip.ruoyun.permission.helper.ui;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;

public class AgainRequestDialog extends Dialog {
private MissPermissionAlwaysDeniedView contentView;

public AgainRequestDialog(@NonNull Context context) {
super(context);
init();
}

public AgainRequestDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
init();
}

public AgainRequestDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
init();
}

private void init() {
contentView = new MissPermissionAlwaysDeniedView(getContext());
contentView.setCancelClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isShowing()) {
dismiss();
}
}
});
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(contentView);
setCanceledOnTouchOutside(false);
if (getWindow() != null) {
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
}
});
}

public void setSettingClickListener(String name, View.OnClickListener listener) {
contentView.setBtSettingName(name);
contentView.setSettingClickListener(listener);
}

public void setStyleId(int styleId) {
contentView.setStyleId(styleId);
}

public void setTitleAndMsg(String title, String msg) {
contentView.setTitle(title);
contentView.setMsg(msg);
}

public MissPermissionAlwaysDeniedView getContentView() {
return contentView;
}


public static AgainRequestDialog getAlwaysDeniedDialog(Context context) {
AgainRequestDialog alwaysDialog = new AgainRequestDialog(context);
return alwaysDialog;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package vip.ruoyun.permission.helper.ui;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;

public class AlwaysDeniedDialog extends Dialog {
private MissPermissionAlwaysDeniedView contentView;

public AlwaysDeniedDialog(@NonNull Context context) {
super(context);
init();
}

public AlwaysDeniedDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
init();
}

public AlwaysDeniedDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
init();
}

private void init() {
contentView = new MissPermissionAlwaysDeniedView(getContext());
contentView.setCancelClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isShowing()) {
dismiss();
}
}
});
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(contentView);
setCanceledOnTouchOutside(false);
if (getWindow() != null) {
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
}
});
}

public void setSettingClickListener(View.OnClickListener listener) {
contentView.setSettingClickListener(listener);
}

public void setStyleId(int styleId) {
contentView.setStyleId(styleId);
}

public void setTitleAndMsg(String title, String msg) {
contentView.setTitle(title);
contentView.setMsg(msg);
}

public MissPermissionAlwaysDeniedView getContentView() {
return contentView;
}

public static AlwaysDeniedDialog getAlwaysDeniedDialog(Context context) {
return new AlwaysDeniedDialog(context);
}

}
Loading

0 comments on commit 01a3e81

Please sign in to comment.