com.hjq.permissions.OnPermission Java Examples

The following examples show how to use com.hjq.permissions.OnPermission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From XToast with Apache License 2.0 5 votes vote down vote up
public void show6(View v) {
    XXPermissions.with(this)
            .permission(Permission.SYSTEM_ALERT_WINDOW)
            .request(new OnPermission() {

                @Override
                public void hasPermission(List<String> granted, boolean isAll) {

                    // 传入 Application 表示这个是一个全局的 Toast
                    new XToast(getApplication())
                            .setView(R.layout.toast_phone)
                            .setGravity(Gravity.END | Gravity.BOTTOM)
                            .setXOffset(100)
                            .setYOffset(100)
                            // 设置指定的拖拽规则
                            .setDraggable(new SpringDraggable())
                            .setOnClickListener(android.R.id.icon, new OnClickListener<ImageView>() {

                                @Override
                                public void onClick(XToast toast, ImageView view) {
                                    // 点击后跳转到拨打电话界面
                                    Intent intent = new Intent(Intent.ACTION_DIAL);
                                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    toast.startActivity(intent);
                                }
                            })
                            .show();
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {
                    new XToast(MainActivity.this)
                            .setDuration(1000)
                            .setView(R.layout.toast_hint)
                            .setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_error)
                            .setText(android.R.id.message, "请先授予悬浮窗权限")
                            .show();
                }
            });
}
 
Example #2
Source File: MainActivity.java    From EasyHttp with Apache License 2.0 5 votes vote down vote up
/**
 * 安装 Apk
 */
private void installApk(final Context context, final File file) {
    XXPermissions.with(MainActivity.this)
            // 安装包权限
            .permission(Permission.REQUEST_INSTALL_PACKAGES)
            .request(new OnPermission() {
                @Override
                public void hasPermission(List<String> granted, boolean isAll) {
                    if (isAll) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        Uri uri;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                        } else {
                            uri = Uri.fromFile(file);
                        }

                        intent.setDataAndType(uri, "application/vnd.android.package-archive");
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(intent);
                    }
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {

                }
            });
}
 
Example #3
Source File: PermissionsAspect.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 在连接点进行方法替换
 */
@Around("method() && @annotation(permissions)")
public void aroundJoinPoint(final ProceedingJoinPoint joinPoint, Permissions permissions) {
    XXPermissions.with(ActivityStackManager.getInstance().getTopActivity())
            .permission(permissions.value())
            .request(new OnPermission() {

                @Override
                public void hasPermission(List<String> granted, boolean all) {
                    if (all) {
                        try {
                            // 获得权限,执行原方法
                            joinPoint.proceed();
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {
                    if (quick) {
                        ToastUtils.show(R.string.common_permission_fail);
                        XXPermissions.gotoPermissionSettings(ActivityStackManager.getInstance().getTopActivity(), false);
                    } else {
                        ToastUtils.show(R.string.common_permission_hint);
                    }
                }
            });
}
 
Example #4
Source File: MainActivity.java    From XXPermissions with Apache License 2.0 5 votes vote down vote up
public void requestPermission(View view) {
    XXPermissions.with(this)
            // 可设置被拒绝后继续申请,直到用户授权或者永久拒绝
            //.constantRequest()
            // 支持请求6.0悬浮窗权限8.0请求安装权限
            //.permission(Permission.REQUEST_INSTALL_PACKAGES)
            // 不指定权限则自动获取清单中的危险权限
            .permission(Permission.Group.STORAGE, Permission.Group.CALENDAR)
            .request(new OnPermission() {

                @Override
                public void hasPermission(List<String> granted, boolean all) {
                    if (all) {
                        ToastUtils.show("获取权限成功");
                    }else {
                        ToastUtils.show("获取权限成功,部分权限未正常授予");
                    }
                }

                @Override
                public void noPermission(List<String> denied, boolean quick) {
                    if(quick) {
                        ToastUtils.show("被永久拒绝授权,请手动授予权限");
                        //如果是被永久拒绝就跳转到应用权限系统设置页面
                        XXPermissions.startPermissionActivity(MainActivity.this);
                    } else {
                        ToastUtils.show("获取权限失败");
                    }
                }
            });
}
 
Example #5
Source File: TestFragmentC.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
@SingleClick
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_test_image1:
            mImageView.setVisibility(View.VISIBLE);
            GlideApp.with(this)
                    .load("https://www.baidu.com/img/bd_logo.png")
                    .into(mImageView);
            break;
        case R.id.btn_test_image2:
            mImageView.setVisibility(View.VISIBLE);
            GlideApp.with(this)
                    .load("https://www.baidu.com/img/bd_logo.png")
                    .circleCrop()
                    .into(mImageView);
            break;
        case R.id.btn_test_image3:
            mImageView.setVisibility(View.VISIBLE);
            GlideApp.with(this)
                    .load("https://www.baidu.com/img/bd_logo.png")
                    .transform(new RoundedCorners((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, this.getResources().getDisplayMetrics())))
                    .into(mImageView);
            break;
        case R.id.btn_test_image4:
            PhotoActivity.start(getAttachActivity(), new PhotoActivity.OnPhotoSelectListener() {

                @Override
                public void onSelected(List<String> data) {
                    mImageView.setVisibility(View.VISIBLE);
                    GlideApp.with(getAttachActivity())
                            .load(data.get(0))
                            .into(mImageView);
                }

                @Override
                public void onCancel() {
                    toast("取消了");
                }
            });
            break;
        case R.id.btn_test_toast:
            toast("我是吐司");
            break;
        case R.id.btn_test_permission:
            XXPermissions.with(getAttachActivity())
                    // 可设置被拒绝后继续申请,直到用户授权或者永久拒绝
                    //.constantRequest()
                    // 支持请求6.0悬浮窗权限8.0请求安装权限
                    //.permission(Permission.SYSTEM_ALERT_WINDOW, Permission.REQUEST_INSTALL_PACKAGES)
                    // 不指定权限则自动获取清单中的危险权限
                    .permission(Permission.CAMERA)
                    .request(new OnPermission() {

                        @Override
                        public void hasPermission(List<String> granted, boolean isAll) {
                            if (isAll) {
                                toast("获取权限成功");
                            } else {
                                toast("获取权限成功,部分权限未正常授予");
                            }
                        }

                        @Override
                        public void noPermission(List<String> denied, boolean quick) {
                            if(quick) {
                                toast("被永久拒绝授权,请手动授予权限");
                                //如果是被永久拒绝就跳转到应用权限系统设置页面
                                XXPermissions.gotoPermissionSettings(getAttachActivity());
                            } else {
                                toast("获取权限失败");
                            }
                        }
                    });
            break;
        case R.id.btn_test_setting:
            XXPermissions.gotoPermissionSettings(getAttachActivity());
            break;
        case R.id.btn_test_state_black:
            if (getAttachActivity().getStatusBarConfig() != null) {
                getAttachActivity().getStatusBarConfig().statusBarDarkFont(true).init();
            }
            break;
        case R.id.btn_test_state_white:
            if (getAttachActivity().getStatusBarConfig() != null) {
                getAttachActivity().getStatusBarConfig().statusBarDarkFont(false).init();
            }
            break;
        default:
            break;
    }
}