Skip to content

Commit

Permalink
优化代码及注释
Browse files Browse the repository at this point in the history
  • Loading branch information
getActivity committed Feb 1, 2020
1 parent 54f344a commit c389263
Show file tree
Hide file tree
Showing 25 changed files with 111 additions and 245 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 权限请求框架

>[点击此处下载Demo](https://raw.githubusercontent.com/getActivity/XXPermissions/master/XXPermissions.apk)[博文地址:一句代码搞定权限请求,从未如此简单](https://www.jianshu.com/p/c69ff8a445ed)
> [点击此处下载Demo](https://raw.githubusercontent.com/getActivity/XXPermissions/master/XXPermissions.apk)[博文地址:一句代码搞定权限请求,从未如此简单](https://www.jianshu.com/p/c69ff8a445ed)
> 另外想对Android 6.0权限需要深入了解的,可以看这篇文章[Android 6.0运行权限解析(高级篇)](https://www.jianshu.com/p/6a4dff744031)
Expand All @@ -9,7 +9,7 @@
#### 集成步骤

dependencies {
implementation 'com.hjq:xxpermissions:6.0'
implementation 'com.hjq:xxpermissions:6.2'
}

#### 一句代码搞定权限请求,从未如此简单
Expand All @@ -26,7 +26,7 @@
.request(new OnPermission() {

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

Expand Down Expand Up @@ -74,23 +74,31 @@
> 但是还有一种情况,如果在请求多种权限的情况下,这些权限不是被全部授予或者全部拒绝了,而是部分授权部分拒绝这种情况,框架会如何处理回调呢?
> 框架会先调用noPermission方法,再调用hasPermission方法。其中我们可以通过hasPermission方法中的isAll参数来判断权限是否全部授予了。如果想知道回调中的某个权限是否被授权或者拒绝,可以调用List集合类中的contains(Permission.XXX)方法来判断这个集合中是否包含了这个权限。
> 框架会先调用noPermission方法,再调用hasPermission方法。其中我们可以通过hasPermission方法中的 all 参数来判断权限是否全部授予了。如果想知道回调中的某个权限是否被授权或者拒绝,可以调用List集合类中的contains(Permission.XXX)方法来判断这个集合中是否包含了这个权限。
#### 作者的其他开源项目

* 架构工程:[AndroidProject](https://github.com/getActivity/AndroidProject)

* 吐司框架:[ToastUtils](https://github.com/getActivity/ToastUtils)
* 网络框架:[EasyHttp](https://github.com/getActivity/EasyHttp)

* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)
* 日志框架:[Logcat](https://github.com/getActivity/Logcat)

* 吐司框架:[ToastUtils](https://github.com/getActivity/ToastUtils)

* 标题栏框架:[TitleBar](https://github.com/getActivity/TitleBar)

* 国际化框架:[MultiLanguages](https://github.com/getActivity/MultiLanguages)

* 悬浮窗框架:[XToast](https://github.com/getActivity/XToast)

#### Android技术讨论Q群:78797078

#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:

![](pay_ali.png) ![](pay_wechat.png)
![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_ali.png) ![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_wechat.png)

#### [点击查看捐赠列表](https://github.com/getActivity/Donate)

## License

Expand Down
Binary file modified XXPermissions.apk
Binary file not shown.
10 changes: 7 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.hjq.permissions.demo"
minSdkVersion 14
targetSdkVersion 28
versionCode 60
versionName "6.0"
versionCode 62
versionName "6.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -23,5 +23,9 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':library')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.hjq:toast:6.0'

// 吐司工具类:https://github.com/getActivity/ToastUtils
implementation 'com.hjq:toast:8.0'
// 内存泄漏捕捉:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0'
}
20 changes: 12 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@

<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

<!-- 8.0两个新权限 -->
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />

<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/hjq/permissions/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

//初始化吐司工具类
ToastUtils.init(getApplication(), new ToastWhiteStyle());
ToastUtils.init(getApplication(), new ToastWhiteStyle(getApplicationContext()));
}

public void requestPermission(View view) {
Expand All @@ -40,8 +40,8 @@ public void requestPermission(View view) {
.request(new OnPermission() {

@Override
public void hasPermission(List<String> granted, boolean isAll) {
if (isAll) {
public void hasPermission(List<String> granted, boolean all) {
if (all) {
ToastUtils.show("获取权限成功");
}else {
ToastUtils.show("获取权限成功,部分权限未正常授予");
Expand All @@ -56,6 +56,7 @@ public void noPermission(List<String> denied, boolean quick) {
XXPermissions.gotoPermissionSettings(MainActivity.this);
}else {
ToastUtils.show("获取权限失败");
System.out.println("测试失败了");
}
}
});
Expand Down
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
160 changes: 0 additions & 160 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,160 +0,0 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
19 changes: 9 additions & 10 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//文件开头配置
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

Expand All @@ -8,21 +7,21 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 26
versionCode 60
versionName "6.0"
versionCode 62
versionName "6.2"
}
}

publish {
userOrg = 'getactivity'//填写bintray用户名,注意大小写
groupId = 'com.hjq'//定义的maven group id最终引用形式
artifactId = 'xxpermissions'//maven的artifact id
version = '6.0'//maven 上发布版本号
description = 'Android 6.0 permissions adaptation framework'//描述,自己定义
website = "https://github.com/getActivity/XXPermissions"//项目在github中的地址
userOrg = 'getactivity'
groupId = 'com.hjq'
artifactId = 'xxpermissions'
version = '6.2'
description = 'Android 6.0 permissions adaptation framework'
website = "https://github.com/getActivity/XXPermissions"
}

tasks.withType(Javadoc) {//防止编码问题
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
Expand Down
20 changes: 20 additions & 0 deletions library/src/main/java/com/hjq/permissions/ManifestException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hjq.permissions;

/**
* author : Android 轮子哥
* github : https://github.com/getActivity/XXPermissions
* time : 2018/07/18
* desc : 动态申请的权限没有在清单文件中注册会抛出的异常
*/
final class ManifestException extends RuntimeException {

ManifestException() {
// 清单文件中没有注册任何权限
super("No permissions are registered in the manifest file");
}

ManifestException(String permission) {
// 申请的危险权限没有在清单文件中注册
super(permission + ": Permissions are not registered in the manifest file");
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions library/src/main/java/com/hjq/permissions/OnPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public interface OnPermission {
* 有权限被同意授予时回调
*
* @param granted 请求成功的权限组
* @param isAll 是否全部授予了
* @param all 是否全部授予了
*/
void hasPermission(List<String> granted, boolean isAll);
void hasPermission(List<String> granted, boolean all);

/**
* 有权限被拒绝授予时回调
Expand Down
Loading

0 comments on commit c389263

Please sign in to comment.