diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index dd84ea7824f11be1eeda22377549cbc1aec7f980..0000000000000000000000000000000000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index bbcbbe7d61558adde3cbfd0c7a63a67c27ed6d30..0000000000000000000000000000000000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.gitignore b/.gitignore index aa724b77071afcbd9bb398053e05adaf7ac9405a..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ /build /captures .externalNativeBuild +/entry/.preview .cxx -local.properties diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 61a9130cd9669c3843e6445dfe1fee2d493869bc..0000000000000000000000000000000000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 9a340cb6131eec4ea08d69ff80232777a011bf0b..0000000000000000000000000000000000000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index c83a369c04fb0bf84bbc484b702198e1f1493570..0000000000000000000000000000000000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 0380d8d3dee94c0f1186417b05cac705d4173788..0000000000000000000000000000000000000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 19aa6a5559ac929fecd95af10f5c2ff912f41452..0000000000000000000000000000000000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfbbc029bcab630581847471d7f238ec53..0000000000000000000000000000000000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..a904ff9356b4214127958b02c491cb75acefc4ca --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## 0.0.1-SNAPSHOT +ohos 第一个版本,完整实现了原库的全部 api + + diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..30eaf4b8b53b47945a750c16370effbd08082b4a --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,20 @@ +[ + + { + + "Name": "PermissionUtils", + + "License": "MIT License", + + "License File": " LICENSE ", + + "Version Number": "3.0.0", + + "Upstream URL": "https://github.com/raphaelbussa/PermissionUtils", + + "Description": " + 轻松请求权限,链式调用,简介明了 + " + } + +] \ No newline at end of file diff --git a/README.md b/README.md index 83c2af89005d9d5266653e71ae877d3c15ab7310..731b05f3f091ec8d62d3eee15568e24b18638713 100644 --- a/README.md +++ b/README.md @@ -1,106 +1,122 @@ -# Permission Utils -[![Download](https://api.bintray.com/packages/raphaelbussa/maven/permission-utils/images/download.svg) ](https://bintray.com/raphaelbussa/maven/permission-utils/_latestVersion) [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) [![GitHub issues](https://img.shields.io/github/issues/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/issues) [![GitHub forks](https://img.shields.io/github/forks/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/network) [![GitHub stars](https://img.shields.io/github/stars/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/stargazers) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/LICENSE) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PermissionUtils-green.svg?style=true)](https://android-arsenal.com/details/1/3951) +# permissionsUtils -![Logo](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/sample/src/main/ic_launcher-web.png) +## 项目介绍 -Check marshmallow permission easily +- 项目名称:PermissionUtils +- 所属系列:openharmony的第三方组件适配移植 +- 功能:轻松请求权限,链式调用,简介明了 +- 项目移植状态:已完成 +- 调用差异:无 +- 开发版本:sdk5,DevEco Studio2.1 beta4 -### Import -At the moment the library is in my personal maven repo -```Gradle -repositories { - maven { - url 'http://dl.bintray.com/raphaelbussa/maven' - } -} +## 演示效果 + + + + + + + + + + +## 安装教程 + + +1. 在主项目entry中的grade文件依赖 ``` -```Gradle dependencies { - compile 'rebus:permission-utils:2.0.7' -} -``` -### How to use -#### Request a permission - -First, override onRequestPermissionsResult and call PermissionManager.handleResult(requestCode, permissions, grantResults); -```Java -@Override -public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - PermissionManager.handleResult(this, requestCode, permissions, grantResults); + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation project(path: ':library') } ``` +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, + +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +## 使用方法 -Now you can ask permission :D -```Java -PermissionManager.Builder() - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new FullCallback() { - @Override - public void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked) { - } - }) - .ask(this); +1.请求权限 +在Ability中重写 onRequestPermissionsFromUserResult ``` -or more permission -```Java -.permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) + @Override + public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { + PermissionManager.handleResult(this, requestCode, permissions, grantResults); + } +``` +2.开始请求权限 +``` + PermissionManager.Builder() + .key(num9000) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(MainAbilitySlice.this) + .ask(getAbility()); + ``` +或请求多个权限 + ``` +.permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) ``` or -```Java + ``` ArrayList permissionEnumArrayList = new ArrayList<>(); +permissionEnumArrayList.add(PermissionEnum.WRITE_EXTERNAL_STORAGE); permissionEnumArrayList.add(PermissionEnum.ACCESS_FINE_LOCATION); -permissionEnumArrayList.add(PermissionEnum.GET_ACCOUNTS); -permissionEnumArrayList.add(PermissionEnum.READ_CONTACTS); +permissionEnumArrayList.add(PermissionEnum.READ_CALENDAR); .permissions(permissionEnumArrayList) ``` - -if you need to simply check a permission, just call utils -```Java +如果你只需要检查权限,只需 +``` PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; boolean granted = PermissionUtils.isGranted(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE); -Toast.makeText(MainActivity.this, permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show() + new ToastDialog(getContext()) + .setText("permissionEnum.toString() + " isGranted [" + granted + "]") + .setAlignment(LayoutAlignment.CENTER) + .show(); ``` +3.您可以使用三种不同的回调,这取决于您的需求。 + +FullCallback:为您提供有关您请求的权限的所有信息 -#### Callbacks -You can use three different callback, it depends of your needs. +SimpleCallback:返回一个布尔值,表示是否所有许可请求都被允许 -* FullCallback: gives you all the information on permission requested by you -* SimpleCallback: returns a boolean that says if all permission requests were permitted -* SmartCallback: returns a boolean that says if all permission requests were permitted and a boolean that says if some permissions are denied forever +SmartCallback:返回一个布尔值,表示是否所有许可请求都被允许;以及一个布尔值,表示是否永久拒绝某些许可权 -#### Little extra -If user answer "Never ask again" to a request for permission, you can redirect user to app settings, with an utils -```Java -PermissionUtils.openApplicationSettings(MainActivity.this, R.class.getPackage().getName()); +4.如果用户对许可请求回答“不再询问”,则可以使用utils将用户重定向到应用程序设置 +``` +PermissionUtils.openApplicationSettings(getAbility()); ``` -# That's all folks! -### Sample -Browse the sample code [here](https://github.com/raphaelbussa/PermissionUtils/tree/master/sample) +5.判断权限是否已经拥有 +``` + boolean isGranted = PermissionUtils.isGranted(getAbility(), PermissionEnum.WRITE_EXTERNAL_STORAGE); +``` -### Javadoc -Browse Javadoc [here](https://raphaelbussa.github.io/PermissionUtils/javadoc/) -### App using Permission Utils -If you use this lib [contact me](mailto:raphaelbussa@gmail.com?subject=PermissionUtils) and I will add it to the list below: +## 测试信息 +CodeCheck代码测试无异常 -### Developed By -Raphaël Bussa - [raphaelbussa@gmail.com](mailto:raphaelbussa@gmail.com) +CloudTest代码测试无异常 -[ ![Twitter](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/img/social/twitter-icon.png) ](https://twitter.com/raphaelbussa)[ ![Linkedin](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/img/social/linkedin-icon.png) ](https://www.linkedin.com/in/raphaelbussa) +火绒安全病毒安全检测通过 -### License -``` -The MIT License (MIT) +当前版本demo功能与原组件基本无差异 + + +## 版本迭代 +0.0.1-SNAPSHOT + +## 版权和许可信息 + + The MIT License (MIT) Copyright (c) 2017-2019 Raphaël Bussa @@ -121,4 +137,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -``` diff --git a/build.gradle b/build.gradle index 8bdbdd53ff017fac25b573f3f06d19dec03ef7f8..d3c9f1fef7ce4e18162867c20c11bfc65e1a8d28 100644 --- a/build.gradle +++ b/build.gradle @@ -1,59 +1,37 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' -buildscript { - - ext { - var = [ - compileSdk: 30, - minSdk : 14, - targetSdk : 30, - version : "4.0.0" - ] +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 } +} +buildscript { repositories { - google() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() - mavenCentral() } - dependencies { - classpath "com.android.tools.build:gradle:4.1.2" + classpath 'com.huawei.ohos:hap:2.4.4.2' + classpath 'com.huawei.ohos:decctest:1.0.0.7' } } allprojects { repositories { - google() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() - mavenCentral() } } - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/docs/_config.yml b/docs/_config.yml deleted file mode 100755 index 3635c6473d6c1b11a10b8f21202220000c97621c..0000000000000000000000000000000000000000 --- a/docs/_config.yml +++ /dev/null @@ -1,8 +0,0 @@ -title: Permission Utils -description: Check marshmellow permission easily -google_analytics: -show_downloads: true -theme: jekyll-theme-minimal - -gems: - - jekyll-mentions diff --git a/docs/index.md b/docs/index.md deleted file mode 100755 index 02feaa1053e0218eb6ba9ab219832e4014b9323f..0000000000000000000000000000000000000000 --- a/docs/index.md +++ /dev/null @@ -1,124 +0,0 @@ -# Permission Utils -[![Download](https://api.bintray.com/packages/raphaelbussa/maven/permission-utils/images/download.svg) ](https://bintray.com/raphaelbussa/maven/permission-utils/_latestVersion) [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) [![GitHub issues](https://img.shields.io/github/issues/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/issues) [![GitHub forks](https://img.shields.io/github/forks/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/network) [![GitHub stars](https://img.shields.io/github/stars/raphaelbussa/PermissionUtils.svg)](https://github.com/raphaelbussa/PermissionUtils/stargazers) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/LICENSE) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PermissionUtils-green.svg?style=true)](https://android-arsenal.com/details/1/3951) - -![Logo](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/sample/src/main/ic_launcher-web.png) - -Check marshmallow permission easily - -### Import -At the moment the library is in my personal maven repo -```Gradle -repositories { - maven { - url 'http://dl.bintray.com/raphaelbussa/maven' - } -} -``` -```Gradle -dependencies { - compile 'rebus:permission-utils:2.0.7' -} -``` -### How to use -#### Request a permission - -First, override onRequestPermissionsResult and call PermissionManager.handleResult(requestCode, permissions, grantResults); -```Java -@Override -public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - PermissionManager.handleResult(this, requestCode, permissions, grantResults); -} -``` - -Now you can ask permission :D -```Java -PermissionManager.Builder() - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new FullCallback() { - @Override - public void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked) { - } - }) - .ask(this); -``` -or more permission -```Java -.permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) -``` -or -```Java -ArrayList permissionEnumArrayList = new ArrayList<>(); -permissionEnumArrayList.add(PermissionEnum.ACCESS_FINE_LOCATION); -permissionEnumArrayList.add(PermissionEnum.GET_ACCOUNTS); -permissionEnumArrayList.add(PermissionEnum.READ_CONTACTS); - -.permissions(permissionEnumArrayList) -``` - -if you need to simply check a permission, just call utils -```Java -PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; -boolean granted = PermissionUtils.isGranted(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE); -Toast.makeText(MainActivity.this, permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show() -``` - -#### Callbacks -You can use three different callback, it depends of your needs. - -* FullCallback: gives you all the information on permission requested by you -* SimpleCallback: returns a boolean that says if all permission requests were permitted -* SmartCallback: returns a boolean that says if all permission requests were permitted and a boolean that says if some permissions are denied forever - -#### Little extra -If user answer "Never ask again" to a request for permission, you can redirect user to app settings, with an utils -```Java -PermissionUtils.openApplicationSettings(MainActivity.this, R.class.getPackage().getName()); -``` -# That's all folks! - -### Sample -Browse the sample code [here](https://github.com/raphaelbussa/PermissionUtils/tree/master/sample) - -### Javadoc -Browse Javadoc [here](https://raphaelbussa.github.io/PermissionUtils/javadoc/) - -### App using Permission Utils -If you use this lib [contact me](mailto:raphaelbussa@gmail.com?subject=PermissionUtils) and I will add it to the list below: - -### Developed By -Raphaël Bussa - [raphaelbussa@gmail.com](mailto:raphaelbussa@gmail.com) - -[ ![Twitter](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/img/social/twitter-icon.png) ](https://twitter.com/raphaelbussa)[ ![Linkedin](https://raw.githubusercontent.com/raphaelbussa/PermissionUtils/master/img/social/linkedin-icon.png) ](https://www.linkedin.com/in/raphaelbussa) - -### License -``` -The MIT License (MIT) - -Copyright (c) 2017-2019 Raphaël Bussa - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -``` diff --git a/docs/javadoc/META-INF/MANIFEST.MF b/docs/javadoc/META-INF/MANIFEST.MF deleted file mode 100644 index 58630c02ef423cffd6dd6aafd946eb8512040c37..0000000000000000000000000000000000000000 --- a/docs/javadoc/META-INF/MANIFEST.MF +++ /dev/null @@ -1,2 +0,0 @@ -Manifest-Version: 1.0 - diff --git a/docs/javadoc/allclasses-frame.html b/docs/javadoc/allclasses-frame.html deleted file mode 100644 index 7590d0b5a012eefeeabacaefd93e687d156069c1..0000000000000000000000000000000000000000 --- a/docs/javadoc/allclasses-frame.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - -All Classes (library API) - - - - - -

All Classes

- - - diff --git a/docs/javadoc/allclasses-noframe.html b/docs/javadoc/allclasses-noframe.html deleted file mode 100644 index 73c10437d3138b956395ba9a1a40d172bc7b605d..0000000000000000000000000000000000000000 --- a/docs/javadoc/allclasses-noframe.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - -All Classes (library API) - - - - - -

All Classes

- - - diff --git a/docs/javadoc/constant-values.html b/docs/javadoc/constant-values.html deleted file mode 100644 index 197d9c04c480d8674ad95d7ded3e079502fff59e..0000000000000000000000000000000000000000 --- a/docs/javadoc/constant-values.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - -Constant Field Values (library API) - - - - - - - - - - - -
-

Constant Field Values

-

Contents

- -
-
- - -

rebus.permissionutils.*

- -
- - - - - - diff --git a/docs/javadoc/deprecated-list.html b/docs/javadoc/deprecated-list.html deleted file mode 100644 index fa57167edc0640c1d2b2d311bb6914ce101f659a..0000000000000000000000000000000000000000 --- a/docs/javadoc/deprecated-list.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - - -Deprecated List (library API) - - - - - - - - -
- - - - - - - -
- - -
-

Deprecated API

-

Contents

-
- -
- - - - - - - -
- - - - diff --git a/docs/javadoc/help-doc.html b/docs/javadoc/help-doc.html deleted file mode 100644 index 56b18ff41fe1530dc9ec4aef0ad05c284a6a2c5b..0000000000000000000000000000000000000000 --- a/docs/javadoc/help-doc.html +++ /dev/null @@ -1,217 +0,0 @@ - - - - - -API Help (library API) - - - - - - - - - - - -
-

How This API Document Is Organized

-
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
-
-
-
    -
  • -

    Package

    -

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    -
      -
    • Interfaces (italic)
    • -
    • Classes
    • -
    • Enums
    • -
    • Exceptions
    • -
    • Errors
    • -
    • Annotation Types
    • -
    -
  • -
  • -

    Class/Interface

    -

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
      -
    • Class inheritance diagram
    • -
    • Direct Subclasses
    • -
    • All Known Subinterfaces
    • -
    • All Known Implementing Classes
    • -
    • Class/interface declaration
    • -
    • Class/interface description
    • -
    -
      -
    • Nested Class Summary
    • -
    • Field Summary
    • -
    • Constructor Summary
    • -
    • Method Summary
    • -
    -
      -
    • Field Detail
    • -
    • Constructor Detail
    • -
    • Method Detail
    • -
    -

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    -
  • -
  • -

    Annotation Type

    -

    Each annotation type has its own separate page with the following sections:

    -
      -
    • Annotation Type declaration
    • -
    • Annotation Type description
    • -
    • Required Element Summary
    • -
    • Optional Element Summary
    • -
    • Element Detail
    • -
    -
  • -
  • -

    Enum

    -

    Each enum has its own separate page with the following sections:

    -
      -
    • Enum declaration
    • -
    • Enum description
    • -
    • Enum Constant Summary
    • -
    • Enum Constant Detail
    • -
    -
  • -
  • -

    Tree (Class Hierarchy)

    -

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    -
      -
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • -
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • -
    -
  • -
  • -

    Deprecated API

    -

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    -
  • -
  • -

    Index

    -

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    -
  • -
  • -

    Prev/Next

    -

    These links take you to the next or previous class, interface, package, or related page.

    -
  • -
  • -

    Frames/No Frames

    -

    These links show and hide the HTML frames. All pages are available with or without frames.

    -
  • -
  • -

    All Classes

    -

    The All Classes link shows all classes and interfaces except non-static nested types.

    -
  • -
  • -

    Serialized Form

    -

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    -
  • -
  • -

    Constant Field Values

    -

    The Constant Field Values page lists the static final fields and their values.

    -
  • -
-This help file applies to API documentation generated using the standard doclet.
- - - - - - diff --git a/docs/javadoc/index-all.html b/docs/javadoc/index-all.html deleted file mode 100644 index 04950949a126829dba08a092db624b4338922813..0000000000000000000000000000000000000000 --- a/docs/javadoc/index-all.html +++ /dev/null @@ -1,302 +0,0 @@ - - - - - -Index (library API) - - - - - - - - - - - -
A B C F H I K O P R S T V  - - -

A

-
-
ask(Activity) - Method in class rebus.permissionutils.PermissionManager
-
 
-
ask(Fragment) - Method in class rebus.permissionutils.PermissionManager
-
 
-
ask(Fragment) - Method in class rebus.permissionutils.PermissionManager
-
 
-
askAgain(boolean) - Method in class rebus.permissionutils.PermissionManager
-
 
-
AskAgainCallback - Interface in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
askAgainCallback(AskAgainCallback) - Method in class rebus.permissionutils.PermissionManager
-
 
-
AskAgainCallback.UserResponse - Interface in rebus.permissionutils
-
 
-
- - - -

B

-
-
Builder() - Static method in class rebus.permissionutils.PermissionManager
-
 
-
- - - -

C

-
-
callback(FullCallback) - Method in class rebus.permissionutils.PermissionManager
-
 
-
callback(SimpleCallback) - Method in class rebus.permissionutils.PermissionManager
-
 
-
callback(SmartCallback) - Method in class rebus.permissionutils.PermissionManager
-
 
-
- - - -

F

-
-
fromManifestPermission(String) - Static method in enum rebus.permissionutils.PermissionEnum
-
 
-
FullCallback - Interface in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
- - - -

H

-
-
handleResult(Activity, int, String[], int[]) - Static method in class rebus.permissionutils.PermissionManager
-
 
-
handleResult(Fragment, int, String[], int[]) - Static method in class rebus.permissionutils.PermissionManager
-
 
-
handleResult(Fragment, int, String[], int[]) - Static method in class rebus.permissionutils.PermissionManager
-
 
-
- - - -

I

-
-
isGranted(Context, PermissionEnum) - Static method in class rebus.permissionutils.PermissionUtils
-
 
-
isGranted(Context, PermissionEnum...) - Static method in class rebus.permissionutils.PermissionUtils
-
 
-
- - - -

K

-
-
key(int) - Method in class rebus.permissionutils.PermissionManager
-
 
-
KEY_PERMISSION - Static variable in class rebus.permissionutils.PermissionConstant
-
 
-
- - - -

O

-
-
openApplicationSettings(String) - Static method in class rebus.permissionutils.PermissionUtils
-
 
-
openApplicationSettings(Context, String) - Static method in class rebus.permissionutils.PermissionUtils
-
 
-
- - - -

P

-
-
permission(PermissionEnum) - Method in class rebus.permissionutils.PermissionManager
-
 
-
permission(PermissionEnum...) - Method in class rebus.permissionutils.PermissionManager
-
 
-
PermissionConstant - Class in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
PermissionConstant() - Constructor for class rebus.permissionutils.PermissionConstant
-
 
-
PermissionEnum - Enum in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
PermissionManager - Class in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
PermissionManager() - Constructor for class rebus.permissionutils.PermissionManager
-
 
-
permissions(ArrayList<PermissionEnum>) - Method in class rebus.permissionutils.PermissionManager
-
 
-
PermissionUtils - Class in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
PermissionUtils() - Constructor for class rebus.permissionutils.PermissionUtils
-
 
-
- - - -

R

-
-
rebus.permissionutils - package rebus.permissionutils
-
 
-
result(boolean) - Method in interface rebus.permissionutils.AskAgainCallback.UserResponse
-
 
-
result(ArrayList<PermissionEnum>, ArrayList<PermissionEnum>, ArrayList<PermissionEnum>, ArrayList<PermissionEnum>) - Method in interface rebus.permissionutils.FullCallback
-
 
-
result(boolean) - Method in interface rebus.permissionutils.SimpleCallback
-
 
-
result(boolean, boolean) - Method in interface rebus.permissionutils.SmartCallback
-
 
-
- - - -

S

-
-
showRequestPermission(AskAgainCallback.UserResponse) - Method in interface rebus.permissionutils.AskAgainCallback
-
 
-
SimpleCallback - Interface in rebus.permissionutils
-
-
Created by raphaelbussa on 22/06/16.
-
-
SmartCallback - Interface in rebus.permissionutils
-
-
Created by raphaelbussa on 16/11/16.
-
-
- - - -

T

-
-
toString() - Method in enum rebus.permissionutils.PermissionEnum
-
 
-
- - - -

V

-
-
valueOf(String) - Static method in enum rebus.permissionutils.PermissionEnum
-
-
Returns the enum constant of this type with the specified name.
-
-
values() - Static method in enum rebus.permissionutils.PermissionEnum
-
-
Returns an array containing the constants of this enum type, in -the order they are declared.
-
-
-A B C F H I K O P R S T V 
- - - - - - diff --git a/docs/javadoc/index.html b/docs/javadoc/index.html deleted file mode 100644 index 4ca49a42a7de7d6c8f063ef8ec99c1ca3d9bc987..0000000000000000000000000000000000000000 --- a/docs/javadoc/index.html +++ /dev/null @@ -1,72 +0,0 @@ - - - - - -library API - - - - - - -<noscript> -<div>JavaScript is disabled on your browser.</div> -</noscript> -<h2>Frame Alert</h2> -<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="rebus/permissionutils/package-summary.html">Non-frame version</a>.</p> - - - diff --git a/docs/javadoc/overview-tree.html b/docs/javadoc/overview-tree.html deleted file mode 100644 index 5f820e6e7b573039172aee0e8ec6d07165e49dca..0000000000000000000000000000000000000000 --- a/docs/javadoc/overview-tree.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - -Class Hierarchy (library API) - - - - - - - - - - - -
-

Hierarchy For All Packages

-Package Hierarchies: - -
-
-

Class Hierarchy

- -

Interface Hierarchy

- -

Enum Hierarchy

-
    -
  • java.lang.Object -
      -
    • java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable) - -
    • -
    -
  • -
-
- - - - - - diff --git a/docs/javadoc/package-list b/docs/javadoc/package-list deleted file mode 100644 index 39fad596a2f051b0b4f74043eead6e453ea878d2..0000000000000000000000000000000000000000 --- a/docs/javadoc/package-list +++ /dev/null @@ -1 +0,0 @@ -rebus.permissionutils diff --git a/docs/javadoc/rebus/permissionutils/AskAgainCallback.UserResponse.html b/docs/javadoc/rebus/permissionutils/AskAgainCallback.UserResponse.html deleted file mode 100644 index cb73a48f3a472c7f2aa2efdefd75f0df3c1c139f..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/AskAgainCallback.UserResponse.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - -AskAgainCallback.UserResponse (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Interface AskAgainCallback.UserResponse

-
-
-
-
    -
  • -
    -
    Enclosing interface:
    -
    AskAgainCallback
    -
    -
    -
    -
    public static interface AskAgainCallback.UserResponse
    -
  • -
-
-
- -
-
-
    -
  • - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        result

        -
        void result(boolean askAgain)
        -
        -
        Parameters:
        -
        askAgain - the response from the user if allow to ask again a permission
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/AskAgainCallback.html b/docs/javadoc/rebus/permissionutils/AskAgainCallback.html deleted file mode 100644 index cea3c17c87552f72323fd2e7a898431a38d8267b..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/AskAgainCallback.html +++ /dev/null @@ -1,241 +0,0 @@ - - - - - -AskAgainCallback (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Interface AskAgainCallback

-
-
-
-
    -
  • -
    -
    -
    public interface AskAgainCallback
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
- -
-
-
    -
  • - - -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/FullCallback.html b/docs/javadoc/rebus/permissionutils/FullCallback.html deleted file mode 100644 index 9f34103605e4f1845aa135cb0b21decb13cca134..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/FullCallback.html +++ /dev/null @@ -1,231 +0,0 @@ - - - - - -FullCallback (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Interface FullCallback

-
-
-
-
    -
  • -
    -
    -
    public interface FullCallback
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
- -
-
-
    -
  • - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        result

        -
        void result(java.util.ArrayList<PermissionEnum> permissionsGranted,
        -            java.util.ArrayList<PermissionEnum> permissionsDenied,
        -            java.util.ArrayList<PermissionEnum> permissionsDeniedForever,
        -            java.util.ArrayList<PermissionEnum> permissionsAsked)
        -
        -
        Parameters:
        -
        permissionsGranted - list of permission granted
        -
        permissionsDenied - list of permission denied
        -
        permissionsDeniedForever - list of permission denied forever
        -
        permissionsAsked - list of permission asked
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/PermissionConstant.html b/docs/javadoc/rebus/permissionutils/PermissionConstant.html deleted file mode 100644 index f4cba00928d220ab6abd48cb8caa9422c095cdcc..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/PermissionConstant.html +++ /dev/null @@ -1,274 +0,0 @@ - - - - - -PermissionConstant (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Class PermissionConstant

-
-
-
    -
  • java.lang.Object
  • -
  • -
      -
    • rebus.permissionutils.PermissionConstant
    • -
    -
  • -
-
-
    -
  • -
    -
    -
    public class PermissionConstant
    -extends java.lang.Object
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
-
    -
  • - -
      -
    • - - -

      Field Summary

      - - - - - - - - - - -
      Fields 
      Modifier and TypeField and Description
      static intKEY_PERMISSION 
      -
    • -
    - -
      -
    • - - -

      Constructor Summary

      - - - - - - - - -
      Constructors 
      Constructor and Description
      PermissionConstant() 
      -
    • -
    - -
      -
    • - - -

      Method Summary

      -
        -
      • - - -

        Methods inherited from class java.lang.Object

        -clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • -
      -
    • -
    -
  • -
-
-
-
    -
  • - - - -
      -
    • - - -

      Constructor Detail

      - - - -
        -
      • -

        PermissionConstant

        -
        public PermissionConstant()
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/PermissionEnum.html b/docs/javadoc/rebus/permissionutils/PermissionEnum.html deleted file mode 100644 index 46cf142a96451259473c6507b8243dbbdc11cc78..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/PermissionEnum.html +++ /dev/null @@ -1,753 +0,0 @@ - - - - - -PermissionEnum (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Enum PermissionEnum

-
-
-
    -
  • java.lang.Object
  • -
  • -
      -
    • java.lang.Enum<PermissionEnum>
    • -
    • -
        -
      • rebus.permissionutils.PermissionEnum
      • -
      -
    • -
    -
  • -
-
-
    -
  • -
    -
    All Implemented Interfaces:
    -
    java.io.Serializable, java.lang.Comparable<PermissionEnum>
    -
    -
    -
    -
    public enum PermissionEnum
    -extends java.lang.Enum<PermissionEnum>
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
- -
-
-
    -
  • - - - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        values

        -
        public static PermissionEnum[] values()
        -
        Returns an array containing the constants of this enum type, in -the order they are declared. This method may be used to iterate -over the constants as follows: -
        -for (PermissionEnum c : PermissionEnum.values())
        -    System.out.println(c);
        -
        -
        -
        Returns:
        -
        an array containing the constants of this enum type, in the order they are declared
        -
        -
      • -
      - - - -
        -
      • -

        valueOf

        -
        public static PermissionEnum valueOf(java.lang.String name)
        -
        Returns the enum constant of this type with the specified name. -The string must match exactly an identifier used to declare an -enum constant in this type. (Extraneous whitespace characters are -not permitted.)
        -
        -
        Parameters:
        -
        name - the name of the enum constant to be returned.
        -
        Returns:
        -
        the enum constant with the specified name
        -
        Throws:
        -
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        -
        java.lang.NullPointerException - if the argument is null
        -
        -
      • -
      - - - -
        -
      • -

        fromManifestPermission

        -
        public static PermissionEnum fromManifestPermission(@NonNull
        -                                                    java.lang.String value)
        -
      • -
      - - - -
        -
      • -

        toString

        -
        public java.lang.String toString()
        -
        -
        Overrides:
        -
        toString in class java.lang.Enum<PermissionEnum>
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/PermissionManager.html b/docs/javadoc/rebus/permissionutils/PermissionManager.html deleted file mode 100644 index 43e72b8c0145b1394c07fae87b2d99284974aa83..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/PermissionManager.html +++ /dev/null @@ -1,584 +0,0 @@ - - - - - -PermissionManager (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Class PermissionManager

-
-
-
    -
  • java.lang.Object
  • -
  • -
      -
    • rebus.permissionutils.PermissionManager
    • -
    -
  • -
-
-
    -
  • -
    -
    -
    public class PermissionManager
    -extends java.lang.Object
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
- -
-
-
    -
  • - -
      -
    • - - -

      Constructor Detail

      - - - -
        -
      • -

        PermissionManager

        -
        public PermissionManager()
        -
      • -
      -
    • -
    - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        Builder

        -
        public static PermissionManager Builder()
        -
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        handleResult

        -
        public static void handleResult(@NonNull
        -                                android.app.Activity activity,
        -                                int requestCode,
        -                                @NonNull
        -                                java.lang.String[] permissions,
        -                                @NonNull
        -                                int[] grantResults)
        -
        -
        Parameters:
        -
        activity - target activity
        -
        requestCode - requestCode
        -
        permissions - permissions
        -
        grantResults - grantResults
        -
        -
      • -
      - - - -
        -
      • -

        handleResult

        -
        public static void handleResult(@NonNull
        -                                android.support.v4.app.Fragment v4fragment,
        -                                int requestCode,
        -                                @NonNull
        -                                java.lang.String[] permissions,
        -                                @NonNull
        -                                int[] grantResults)
        -
        -
        Parameters:
        -
        v4fragment - target v4 fragment
        -
        requestCode - requestCode
        -
        permissions - permissions
        -
        grantResults - grantResults
        -
        -
      • -
      - - - -
        -
      • -

        handleResult

        -
        public static void handleResult(@NonNull
        -                                android.app.Fragment fragment,
        -                                int requestCode,
        -                                @NonNull
        -                                java.lang.String[] permissions,
        -                                @NonNull
        -                                int[] grantResults)
        -
        -
        Parameters:
        -
        fragment - target fragment
        -
        requestCode - requestCode
        -
        permissions - permissions
        -
        grantResults - grantResults
        -
        -
      • -
      - - - -
        -
      • -

        permissions

        -
        public PermissionManager permissions(java.util.ArrayList<PermissionEnum> permissions)
        -
        -
        Parameters:
        -
        permissions - an array of permission that you need to ask
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        permission

        -
        public PermissionManager permission(PermissionEnum permission)
        -
        -
        Parameters:
        -
        permission - permission you need to ask
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        permission

        -
        public PermissionManager permission(PermissionEnum... permissions)
        -
        -
        Parameters:
        -
        permissions - permission you need to ask
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        askAgain

        -
        public PermissionManager askAgain(boolean askAgain)
        -
        -
        Parameters:
        -
        askAgain - ask again when permission not granted
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        callback

        -
        public PermissionManager callback(FullCallback fullCallback)
        -
        -
        Parameters:
        -
        fullCallback - set fullCallback for the request
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        callback

        -
        public PermissionManager callback(SimpleCallback simpleCallback)
        -
        -
        Parameters:
        -
        simpleCallback - set simpleCallback for the request
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        callback

        -
        public PermissionManager callback(SmartCallback smartCallback)
        -
        -
        Parameters:
        -
        smartCallback - set smartCallback for the request
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        askAgainCallback

        -
        public PermissionManager askAgainCallback(AskAgainCallback askAgainCallback)
        -
        -
        Parameters:
        -
        askAgainCallback - set askAgainCallback for the request
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        key

        -
        public PermissionManager key(int key)
        -
        -
        Parameters:
        -
        key - set a custom request code
        -
        Returns:
        -
        current instance
        -
        -
      • -
      - - - -
        -
      • -

        ask

        -
        public void ask(android.app.Activity activity)
        -
        -
        Parameters:
        -
        activity - target activity - just start all permission manager
        -
        -
      • -
      - - - -
        -
      • -

        ask

        -
        public void ask(android.support.v4.app.Fragment v4fragment)
        -
        -
        Parameters:
        -
        v4fragment - target v4 fragment - just start all permission manager
        -
        -
      • -
      - - - -
        -
      • -

        ask

        -
        public void ask(android.app.Fragment fragment)
        -
        -
        Parameters:
        -
        fragment - target fragment - just start all permission manager
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/PermissionUtils.html b/docs/javadoc/rebus/permissionutils/PermissionUtils.html deleted file mode 100644 index f84ecb3af4cc08622ee4a8c8fc4a76afa7093bfb..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/PermissionUtils.html +++ /dev/null @@ -1,338 +0,0 @@ - - - - - -PermissionUtils (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Class PermissionUtils

-
-
-
    -
  • java.lang.Object
  • -
  • -
      -
    • rebus.permissionutils.PermissionUtils
    • -
    -
  • -
-
-
    -
  • -
    -
    -
    public class PermissionUtils
    -extends java.lang.Object
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
-
    -
  • - -
      -
    • - - -

      Constructor Summary

      - - - - - - - - -
      Constructors 
      Constructor and Description
      PermissionUtils() 
      -
    • -
    - -
      -
    • - - -

      Method Summary

      - - - - - - - - - - - - - - - - - - - - - - -
      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethod and Description
      static booleanisGranted(android.content.Context context, - PermissionEnum... permission) 
      static booleanisGranted(android.content.Context context, - PermissionEnum permission) 
      static voidopenApplicationSettings(android.content.Context context, - java.lang.String packageName) 
      static android.content.IntentopenApplicationSettings(java.lang.String packageName) 
      -
        -
      • - - -

        Methods inherited from class java.lang.Object

        -clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • -
      -
    • -
    -
  • -
-
-
-
    -
  • - -
      -
    • - - -

      Constructor Detail

      - - - -
        -
      • -

        PermissionUtils

        -
        public PermissionUtils()
        -
      • -
      -
    • -
    - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        isGranted

        -
        public static boolean isGranted(android.content.Context context,
        -                                PermissionEnum permission)
        -
        -
        Parameters:
        -
        context - current context
        -
        permission - permission to check
        -
        Returns:
        -
        if permission is granted return true
        -
        -
      • -
      - - - -
        -
      • -

        isGranted

        -
        public static boolean isGranted(android.content.Context context,
        -                                PermissionEnum... permission)
        -
        -
        Parameters:
        -
        context - current context
        -
        permission - all permission you need to check
        -
        Returns:
        -
        if one of permission is not granted return false
        -
        -
      • -
      - - - -
        -
      • -

        openApplicationSettings

        -
        public static android.content.Intent openApplicationSettings(java.lang.String packageName)
        -
        -
        Parameters:
        -
        packageName - package name of your app
        -
        Returns:
        -
        an intent to start for open settings app
        -
        -
      • -
      - - - -
        -
      • -

        openApplicationSettings

        -
        public static void openApplicationSettings(android.content.Context context,
        -                                           java.lang.String packageName)
        -
        -
        Parameters:
        -
        context - current context
        -
        packageName - package name of your app
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/SimpleCallback.html b/docs/javadoc/rebus/permissionutils/SimpleCallback.html deleted file mode 100644 index ab35c8449b3b67ace35e013db998e7a581f494ba..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/SimpleCallback.html +++ /dev/null @@ -1,222 +0,0 @@ - - - - - -SimpleCallback (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Interface SimpleCallback

-
-
-
-
    -
  • -
    -
    -
    public interface SimpleCallback
    -
    Created by raphaelbussa on 22/06/16.
    -
  • -
-
-
- -
-
-
    -
  • - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        result

        -
        void result(boolean allPermissionsGranted)
        -
        -
        Parameters:
        -
        allPermissionsGranted - true if all permissions are granted
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/SmartCallback.html b/docs/javadoc/rebus/permissionutils/SmartCallback.html deleted file mode 100644 index bec4610f46082f270f8b8abca26335fac5c6a14d..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/SmartCallback.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - -SmartCallback (library API) - - - - - - - - - - - - -
-
rebus.permissionutils
-

Interface SmartCallback

-
-
-
-
    -
  • -
    -
    -
    public interface SmartCallback
    -
    Created by raphaelbussa on 16/11/16.
    -
  • -
-
-
-
    -
  • - -
      -
    • - - -

      Method Summary

      - - - - - - - - - - -
      All Methods Instance Methods Abstract Methods 
      Modifier and TypeMethod and Description
      voidresult(boolean allPermissionsGranted, - boolean somePermissionsDeniedForever) 
      -
    • -
    -
  • -
-
-
-
    -
  • - -
      -
    • - - -

      Method Detail

      - - - -
        -
      • -

        result

        -
        void result(boolean allPermissionsGranted,
        -            boolean somePermissionsDeniedForever)
        -
        -
        Parameters:
        -
        allPermissionsGranted - true if all permissions are granted
        -
        somePermissionsDeniedForever - true if one of asked permissions are denied forever
        -
        -
      • -
      -
    • -
    -
  • -
-
-
- - - - - - - diff --git a/docs/javadoc/rebus/permissionutils/package-frame.html b/docs/javadoc/rebus/permissionutils/package-frame.html deleted file mode 100644 index e6007f0940602886435c99e0f74425837852931a..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/package-frame.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - -rebus.permissionutils (library API) - - - - - -

rebus.permissionutils

- - - diff --git a/docs/javadoc/rebus/permissionutils/package-summary.html b/docs/javadoc/rebus/permissionutils/package-summary.html deleted file mode 100644 index b354e0904e043055b1cb03bf05f991ed164ef8e5..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/package-summary.html +++ /dev/null @@ -1,208 +0,0 @@ - - - - - -rebus.permissionutils (library API) - - - - - - - - - - - -
-

Package rebus.permissionutils

-
-
- -
- - - - - - diff --git a/docs/javadoc/rebus/permissionutils/package-tree.html b/docs/javadoc/rebus/permissionutils/package-tree.html deleted file mode 100644 index 581508399aa0f764ec2499c3c3119050fbe4c3b9..0000000000000000000000000000000000000000 --- a/docs/javadoc/rebus/permissionutils/package-tree.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - - -rebus.permissionutils Class Hierarchy (library API) - - - - - - - - - - - -
-

Hierarchy For Package rebus.permissionutils

-
-
-

Class Hierarchy

- -

Interface Hierarchy

- -

Enum Hierarchy

-
    -
  • java.lang.Object -
      -
    • java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable) - -
    • -
    -
  • -
-
- - - - - - diff --git a/docs/javadoc/script.js b/docs/javadoc/script.js deleted file mode 100644 index b34635693143ac308ba6d22c29554e5631f64b74..0000000000000000000000000000000000000000 --- a/docs/javadoc/script.js +++ /dev/null @@ -1,30 +0,0 @@ -function show(type) -{ - count = 0; - for (var key in methods) { - var row = document.getElementById(key); - if ((methods[key] & type) != 0) { - row.style.display = ''; - row.className = (count++ % 2) ? rowColor : altColor; - } - else - row.style.display = 'none'; - } - updateTabs(type); -} - -function updateTabs(type) -{ - for (var value in tabs) { - var sNode = document.getElementById(tabs[value][0]); - var spanNode = sNode.firstChild; - if (value == type) { - sNode.className = activeTableTab; - spanNode.innerHTML = tabs[value][1]; - } - else { - sNode.className = tableTab; - spanNode.innerHTML = "" + tabs[value][1] + ""; - } - } -} diff --git a/docs/javadoc/stylesheet.css b/docs/javadoc/stylesheet.css deleted file mode 100644 index 98055b22d6d5bed7792d6857aa760cf914c62653..0000000000000000000000000000000000000000 --- a/docs/javadoc/stylesheet.css +++ /dev/null @@ -1,574 +0,0 @@ -/* Javadoc style sheet */ -/* -Overall document style -*/ - -@import url('resources/fonts/dejavu.css'); - -body { - background-color:#ffffff; - color:#353833; - font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; - font-size:14px; - margin:0; -} -a:link, a:visited { - text-decoration:none; - color:#4A6782; -} -a:hover, a:focus { - text-decoration:none; - color:#bb7a2a; -} -a:active { - text-decoration:none; - color:#4A6782; -} -a[name] { - color:#353833; -} -a[name]:hover { - text-decoration:none; - color:#353833; -} -pre { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; -} -h1 { - font-size:20px; -} -h2 { - font-size:18px; -} -h3 { - font-size:16px; - font-style:italic; -} -h4 { - font-size:13px; -} -h5 { - font-size:12px; -} -h6 { - font-size:11px; -} -ul { - list-style-type:disc; -} -code, tt { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - padding-top:4px; - margin-top:8px; - line-height:1.4em; -} -dt code { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - padding-top:4px; -} -table tr td dt code { - font-family:'DejaVu Sans Mono', monospace; - font-size:14px; - vertical-align:top; - padding-top:4px; -} -sup { - font-size:8px; -} -/* -Document title and Copyright styles -*/ -.clear { - clear:both; - height:0px; - overflow:hidden; -} -.aboutLanguage { - float:right; - padding:0px 21px; - font-size:11px; - z-index:200; - margin-top:-9px; -} -.legalCopy { - margin-left:.5em; -} -.bar a, .bar a:link, .bar a:visited, .bar a:active { - color:#FFFFFF; - text-decoration:none; -} -.bar a:hover, .bar a:focus { - color:#bb7a2a; -} -.tab { - background-color:#0066FF; - color:#ffffff; - padding:8px; - width:5em; - font-weight:bold; -} -/* -Navigation bar styles -*/ -.bar { - background-color:#4D7A97; - color:#FFFFFF; - padding:.8em .5em .4em .8em; - height:auto;/*height:1.8em;*/ - font-size:11px; - margin:0; -} -.topNav { - background-color:#4D7A97; - color:#FFFFFF; - float:left; - padding:0; - width:100%; - clear:right; - height:2.8em; - padding-top:10px; - overflow:hidden; - font-size:12px; -} -.bottomNav { - margin-top:10px; - background-color:#4D7A97; - color:#FFFFFF; - float:left; - padding:0; - width:100%; - clear:right; - height:2.8em; - padding-top:10px; - overflow:hidden; - font-size:12px; -} -.subNav { - background-color:#dee3e9; - float:left; - width:100%; - overflow:hidden; - font-size:12px; -} -.subNav div { - clear:left; - float:left; - padding:0 0 5px 6px; - text-transform:uppercase; -} -ul.navList, ul.subNavList { - float:left; - margin:0 25px 0 0; - padding:0; -} -ul.navList li{ - list-style:none; - float:left; - padding: 5px 6px; - text-transform:uppercase; -} -ul.subNavList li{ - list-style:none; - float:left; -} -.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { - color:#FFFFFF; - text-decoration:none; - text-transform:uppercase; -} -.topNav a:hover, .bottomNav a:hover { - text-decoration:none; - color:#bb7a2a; - text-transform:uppercase; -} -.navBarCell1Rev { - background-color:#F8981D; - color:#253441; - margin: auto 5px; -} -.skipNav { - position:absolute; - top:auto; - left:-9999px; - overflow:hidden; -} -/* -Page header and footer styles -*/ -.header, .footer { - clear:both; - margin:0 20px; - padding:5px 0 0 0; -} -.indexHeader { - margin:10px; - position:relative; -} -.indexHeader span{ - margin-right:15px; -} -.indexHeader h1 { - font-size:13px; -} -.title { - color:#2c4557; - margin:10px 0; -} -.subTitle { - margin:5px 0 0 0; -} -.header ul { - margin:0 0 15px 0; - padding:0; -} -.footer ul { - margin:20px 0 5px 0; -} -.header ul li, .footer ul li { - list-style:none; - font-size:13px; -} -/* -Heading styles -*/ -div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { - background-color:#dee3e9; - border:1px solid #d0d9e0; - margin:0 0 6px -8px; - padding:7px 5px; -} -ul.blockList ul.blockList ul.blockList li.blockList h3 { - background-color:#dee3e9; - border:1px solid #d0d9e0; - margin:0 0 6px -8px; - padding:7px 5px; -} -ul.blockList ul.blockList li.blockList h3 { - padding:0; - margin:15px 0; -} -ul.blockList li.blockList h2 { - padding:0px 0 20px 0; -} -/* -Page layout container styles -*/ -.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { - clear:both; - padding:10px 20px; - position:relative; -} -.indexContainer { - margin:10px; - position:relative; - font-size:12px; -} -.indexContainer h2 { - font-size:13px; - padding:0 0 3px 0; -} -.indexContainer ul { - margin:0; - padding:0; -} -.indexContainer ul li { - list-style:none; - padding-top:2px; -} -.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { - font-size:12px; - font-weight:bold; - margin:10px 0 0 0; - color:#4E4E4E; -} -.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { - margin:5px 0 10px 0px; - font-size:14px; - font-family:'DejaVu Sans Mono',monospace; -} -.serializedFormContainer dl.nameValue dt { - margin-left:1px; - font-size:1.1em; - display:inline; - font-weight:bold; -} -.serializedFormContainer dl.nameValue dd { - margin:0 0 0 1px; - font-size:1.1em; - display:inline; -} -/* -List styles -*/ -ul.horizontal li { - display:inline; - font-size:0.9em; -} -ul.inheritance { - margin:0; - padding:0; -} -ul.inheritance li { - display:inline; - list-style:none; -} -ul.inheritance li ul.inheritance { - margin-left:15px; - padding-left:15px; - padding-top:1px; -} -ul.blockList, ul.blockListLast { - margin:10px 0 10px 0; - padding:0; -} -ul.blockList li.blockList, ul.blockListLast li.blockList { - list-style:none; - margin-bottom:15px; - line-height:1.4; -} -ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { - padding:0px 20px 5px 10px; - border:1px solid #ededed; - background-color:#f8f8f8; -} -ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { - padding:0 0 5px 8px; - background-color:#ffffff; - border:none; -} -ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { - margin-left:0; - padding-left:0; - padding-bottom:15px; - border:none; -} -ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { - list-style:none; - border-bottom:none; - padding-bottom:0; -} -table tr td dl, table tr td dl dt, table tr td dl dd { - margin-top:0; - margin-bottom:1px; -} -/* -Table styles -*/ -.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { - width:100%; - border-left:1px solid #EEE; - border-right:1px solid #EEE; - border-bottom:1px solid #EEE; -} -.overviewSummary, .memberSummary { - padding:0px; -} -.overviewSummary caption, .memberSummary caption, .typeSummary caption, -.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { - position:relative; - text-align:left; - background-repeat:no-repeat; - color:#253441; - font-weight:bold; - clear:none; - overflow:hidden; - padding:0px; - padding-top:10px; - padding-left:1px; - margin:0px; - white-space:pre; -} -.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, -.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, -.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, -.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, -.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, -.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, -.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, -.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { - color:#FFFFFF; -} -.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, -.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - padding-bottom:7px; - display:inline-block; - float:left; - background-color:#F8981D; - border: none; - height:16px; -} -.memberSummary caption span.activeTableTab span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - margin-right:3px; - display:inline-block; - float:left; - background-color:#F8981D; - height:16px; -} -.memberSummary caption span.tableTab span { - white-space:nowrap; - padding-top:5px; - padding-left:12px; - padding-right:12px; - margin-right:3px; - display:inline-block; - float:left; - background-color:#4D7A97; - height:16px; -} -.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { - padding-top:0px; - padding-left:0px; - padding-right:0px; - background-image:none; - float:none; - display:inline; -} -.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, -.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { - display:none; - width:5px; - position:relative; - float:left; - background-color:#F8981D; -} -.memberSummary .activeTableTab .tabEnd { - display:none; - width:5px; - margin-right:3px; - position:relative; - float:left; - background-color:#F8981D; -} -.memberSummary .tableTab .tabEnd { - display:none; - width:5px; - margin-right:3px; - position:relative; - background-color:#4D7A97; - float:left; - -} -.overviewSummary td, .memberSummary td, .typeSummary td, -.useSummary td, .constantsSummary td, .deprecatedSummary td { - text-align:left; - padding:0px 0px 12px 10px; -} -th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, -td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ - vertical-align:top; - padding-right:0px; - padding-top:8px; - padding-bottom:3px; -} -th.colFirst, th.colLast, th.colOne, .constantsSummary th { - background:#dee3e9; - text-align:left; - padding:8px 3px 3px 7px; -} -td.colFirst, th.colFirst { - white-space:nowrap; - font-size:13px; -} -td.colLast, th.colLast { - font-size:13px; -} -td.colOne, th.colOne { - font-size:13px; -} -.overviewSummary td.colFirst, .overviewSummary th.colFirst, -.useSummary td.colFirst, .useSummary th.colFirst, -.overviewSummary td.colOne, .overviewSummary th.colOne, -.memberSummary td.colFirst, .memberSummary th.colFirst, -.memberSummary td.colOne, .memberSummary th.colOne, -.typeSummary td.colFirst{ - width:25%; - vertical-align:top; -} -td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { - font-weight:bold; -} -.tableSubHeadingColor { - background-color:#EEEEFF; -} -.altColor { - background-color:#FFFFFF; -} -.rowColor { - background-color:#EEEEEF; -} -/* -Content styles -*/ -.description pre { - margin-top:0; -} -.deprecatedContent { - margin:0; - padding:10px 0; -} -.docSummary { - padding:0; -} - -ul.blockList ul.blockList ul.blockList li.blockList h3 { - font-style:normal; -} - -div.block { - font-size:14px; - font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; -} - -td.colLast div { - padding-top:0px; -} - - -td.colLast a { - padding-bottom:3px; -} -/* -Formatting effect styles -*/ -.sourceLineNo { - color:green; - padding:0 30px 0 0; -} -h1.hidden { - visibility:hidden; - overflow:hidden; - font-size:10px; -} -.block { - display:block; - margin:3px 10px 2px 0px; - color:#474747; -} -.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, -.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, -.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { - font-weight:bold; -} -.deprecationComment, .emphasizedPhrase, .interfaceName { - font-style:italic; -} - -div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, -div.block div.block span.interfaceName { - font-style:normal; -} - -div.contentContainer ul.blockList li.blockList h2{ - padding-bottom:0px; -} diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..42964189233c3ab1700cf31c9baf3f844881badd --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + implementation project(path: ':library') +} +decc { + supportType = ['html', 'xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e668a3d57ab81dbda63cb9a6d836c73dfb6458df --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,109 @@ +{ + "app": { + "bundleName": "rebus.permissionutils.sample", + "vendor": "permissionutils", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 6, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "rebus.permissionutils.sample", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar" + } + ] + }, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "rebus.permissionutils.sample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar" + } + ] + }, + "orientation": "unspecified", + "name": "rebus.permissionutils.sample.FragmentActivity", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.WRITE_USER_STORAGE", + "reason": "读写权限", + "usedScene": { + "ability": [ + "rebus.permissionutils.sample.MainAbility", + "rebus.permissionutils.sample.FragmentActivity" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.LOCATION", + "reason": "设备位置", + "usedScene": { + "ability": [ + "rebus.permissionutils.sample.MainAbility", + "rebus.permissionutils.sample.FragmentActivity" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "获取日历", + "usedScene": { + "ability": [ + "rebus.permissionutils.sample.MainAbility", + "rebus.permissionutils.sample.FragmentActivity" + ], + "when": "inuse" + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/rebus/permissionutils/sample/AttrValue.java b/entry/src/main/java/rebus/permissionutils/sample/AttrValue.java new file mode 100644 index 0000000000000000000000000000000000000000..a94f56249e7243263370662c8abf3125bb357494 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/AttrValue.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.agp.components.Attr; +import ohos.agp.components.AttrSet; +import ohos.agp.components.element.Element; +import ohos.agp.utils.Color; + +/** + * 自定义属性工具类 + * + * @author:wjt + * @since 2021-04-06 + */ +public class AttrValue { + /** + * 构造 + */ + private AttrValue() { + } + + /** + * 获取自定义属性值 + * + * @param attrSet + * @param key + * @param defValue + * @param + * @return 属性值 + */ + @SuppressWarnings("unchecked cast") + public static T get(AttrSet attrSet, String key, T defValue) { + if (attrSet == null || !attrSet.getAttr(key).isPresent()) { + return (T) defValue; + } + + Attr attr = attrSet.getAttr(key).get(); + if (defValue instanceof String) { + return (T) attr.getStringValue(); + } else if (defValue instanceof Long) { + return (T) (Long) (attr.getLongValue()); + } else if (defValue instanceof Float) { + return (T) (Float) (attr.getFloatValue()); + } else if (defValue instanceof Integer) { + return (T) (Integer) (attr.getIntegerValue()); + } else if (defValue instanceof Boolean) { + return (T) (Boolean) (attr.getBoolValue()); + } else if (defValue instanceof Color) { + return (T) (attr.getColorValue()); + } else if (defValue instanceof Element) { + return (T) (attr.getElement()); + } else { + return (T) defValue; + } + } + + /** + * 自定义layout + * + * @param attrSet + * @param key + * @param def + * @return layout + */ + public static int getLayout(AttrSet attrSet, String key, int def) { + if (attrSet.getAttr(key).isPresent()) { + int layoutId = def; + String value = attrSet.getAttr(key).get().getStringValue(); + if (value != null) { + String subLayoutId = value.substring(value.indexOf(":")); + layoutId = Integer.parseInt(subLayoutId); + } + return layoutId; + } + return def; + } + + /** + * 获取自定义 Dimension 属性 + * + * @param attrSet + * @param key + * @param defDimensionValue + * @return Dimension + */ + public static int getDimension(AttrSet attrSet, String key, int defDimensionValue) { + if (!attrSet.getAttr(key).isPresent()) { + return defDimensionValue; + } + + Attr attr = attrSet.getAttr(key).get(); + return attr.getDimensionValue(); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/FragmentActivity.java b/entry/src/main/java/rebus/permissionutils/sample/FragmentActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..69b270154e76156b8a95e917282740e55ecd7203 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/FragmentActivity.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.fraction.FractionAbility; +import ohos.aafwk.content.Intent; +import ohos.agp.window.service.WindowManager; +import rebus.permissionutils.sample.slice.FragmentAbilitySlice; + +/** + * 描述 Fraction + * + * @author wjt + * @since 2021-04-07 + */ +public class FragmentActivity extends FractionAbility { + private RequestPermission requestPermission; + + @Override + protected void onStart(Intent intent) { + /** + * 沉浸式状态栏 + */ + getWindow().addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN); + getWindow().addFlags(WindowManager.LayoutConfig.MARK_FULL_SCREEN); + getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS); + super.onStart(intent); + super.setMainRoute(FragmentAbilitySlice.class.getName()); + } + + @Override + public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { + if (requestPermission != null) { + requestPermission.result(requestCode, permissions, grantResults); + } + } + + public void setRequestPermission(RequestPermission requestPermission) { + this.requestPermission = requestPermission; + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/InfoDialog.java b/entry/src/main/java/rebus/permissionutils/sample/InfoDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..374f107f45e163185b255127de41a291d2683619 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/InfoDialog.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayManager; +import ohos.utils.net.Uri; + +/** + * 描述 infoDialog + * + * @author wjt + * @since 2021-04-22 + */ +public class InfoDialog extends CommonDialog { + private Ability context; + private String message = ""; + private final int num10 = 10; + private final int num9 = 9; + private final int num3 = 3; + + /** + * 向外暴露的构造 + * + * @param context 上下文 + * @param info 显示的信息 + */ + public InfoDialog(Ability context, String info) { + super(context); + this.context = context; + this.message = info; + initViewDialog(); + } + + private void initViewDialog() { + Component component = LayoutScatter.getInstance(context) + .parse(ResourceTable.Layout_layout_info_dialog, null, true); + initComponent(component); + InfoDialog.this.setMovable(false); + InfoDialog.this.setAlignment(LayoutAlignment.CENTER); + InfoDialog.this.setTransparent(true); + InfoDialog.this.setContentCustomComponent(component); + } + + private void initComponent(Component component) { + Display display = DisplayManager.getInstance().getDefaultDisplay(context).get(); + int width = display.getAttributes().width; + int height = display.getAttributes().height; + int dialogWidth = (int) ((width / num10) * num9); + int titleHeight = height / num10; + int dialogHeight = titleHeight * num3; + InfoDialog.this.setSize(dialogWidth, dialogHeight); + final Text title = (Text) component.findComponentById(ResourceTable.Id_title); + final Text close = (Text) component.findComponentById(ResourceTable.Id_close); + final Text github = (Text) component.findComponentById(ResourceTable.Id_github); + final Text twitter = (Text) component.findComponentById(ResourceTable.Id_twitter); + final Text google = (Text) component.findComponentById(ResourceTable.Id_google); + final Text linkedin = (Text) component.findComponentById(ResourceTable.Id_linkedin); + github.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + goGitHub(); + } + }); + twitter.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + goTwitter(); + } + }); + google.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + goGoogle(); + } + }); + linkedin.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + goLinkedin(); + } + }); + + close.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + InfoDialog.this.destroy(); + } + }); + } + + private void goLinkedin() { + String link = context.getString(ResourceTable.String_Linkedin); + Intent intent2 = new Intent(); + Operation operationCommonComponts = new Intent.OperationBuilder() + .withUri(Uri.parse(link)) + .build(); + intent2.setOperation(operationCommonComponts); + context.startAbility(intent2); + } + + private void goGoogle() { + String google = context.getString(ResourceTable.String_Google); + Intent intent2 = new Intent(); + Operation operationCommonComponts = new Intent.OperationBuilder() + .withUri(Uri.parse(google)) + .build(); + intent2.setOperation(operationCommonComponts); + context.startAbility(intent2); + } + + private void goTwitter() { + String github = context.getString(ResourceTable.String_GitHub); + Intent intent2 = new Intent(); + Operation operationCommonComponts = new Intent.OperationBuilder() + .withUri(Uri.parse(github)) + .build(); + intent2.setOperation(operationCommonComponts); + context.startAbility(intent2); + } + + private void goGitHub() { + String github = context.getString(ResourceTable.String_GitHub); + Intent intent2 = new Intent(); + Operation operationCommonComponts = new Intent.OperationBuilder() + .withUri(Uri.parse(github)) + .build(); + intent2.setOperation(operationCommonComponts); + context.startAbility(intent2); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/ListDialog.java b/entry/src/main/java/rebus/permissionutils/sample/ListDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..88a3398be5e50c7ddd84ec74ca11e8a47c018a10 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/ListDialog.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.Ability; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.ListContainer; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayManager; + +import java.util.List; + +/** + * 描述 + * + * @author wjt + * @since 2021-04-08 + */ +public class ListDialog { + private List items; + private CommonDialog mCommonDialog = null; + private Ability context; + private final int ten = 10; + private final int num50 = 50; + private final int num6 = 6; + private final int num12 = 12; + private final int num9 = 9; + private final int num86 = 86; + + /** + * 构造 + * + * @param context + */ + public ListDialog(Ability context) { + this.context = context; + } + + /** + * 构造 + * + * @param context 上下文 + * @param listData 数据 + */ + public ListDialog(Ability context, List listData) { + this.context = context; + this.items = listData; + } + + /** + * 显示dialog + */ + public void show() { + if (mCommonDialog == null) { + mCommonDialog = new CommonDialog(context); + Component component1 = LayoutScatter.getInstance(context) + .parse(ResourceTable.Layout_layout_list_dialog, null, true); + initComponent(component1, mCommonDialog); + } + } + + private void initComponent(Component component1, CommonDialog dialog) { + Display display = DisplayManager.getInstance().getDefaultDisplay(context).get(); + int width = display.getAttributes().width; + int height = display.getAttributes().height; + ListContainer listContainer = (ListContainer) component1.findComponentById(ResourceTable.Id_list_dialog); + int simleHeight = AttrHelper.vp2px(num50,context); + int maxwidth = (width / ten) * num9; + int maxheight = simleHeight * num6; + if (items.size() < num12) { + int size = items.size(); + int heightt = simleHeight * size; + mCommonDialog.setSize(maxwidth,heightt + num86); + } else { + mCommonDialog.setSize(maxwidth, maxheight + ten + num86); + } + ListProvider listProvider = new ListProvider(context, items); + listContainer.setItemProvider(listProvider); + int width2 = listContainer.getWidth(); + mCommonDialog.setContentCustomComponent(component1); + mCommonDialog.siteRemovable(true); + mCommonDialog.setAutoClosable(true); + mCommonDialog.setAlignment(LayoutAlignment.CENTER); + mCommonDialog.show(); + listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() { + @Override + public void onItemClicked(ListContainer listContainer, Component component, int i, long l) { + if (dialog != null) { + dialog.hide(); + dialog.remove(); + } + } + }); + } + + /** + * 消除dialog + */ + public void cancel() { + if (mCommonDialog != null) { + mCommonDialog.hide(); + mCommonDialog.remove(); + } + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/ListProvider.java b/entry/src/main/java/rebus/permissionutils/sample/ListProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..af6451c34b632c193c3474bf065f8c844de15b74 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/ListProvider.java @@ -0,0 +1,77 @@ + +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.Ability; +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; + +import java.util.List; + +/** + * provider + * + * @author:wjt + * @since 2021-03-20 + */ +public class ListProvider extends BaseItemProvider { + private List data; + private Ability mainAbilitySlice; + + /** + * 构造 + * + * @param mainAbilitySlice + * @param data + */ + public ListProvider(Ability mainAbilitySlice, List data) { + this.data = data; + this.mainAbilitySlice = mainAbilitySlice; + } + + @Override + public int getCount() { + return data == null ? 0 : data.size(); + } + + @Override + public Object getItem(int position) { + return data.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Component getComponent(int position, Component component, ComponentContainer componentContainer) { + final Component cpt; + if (component == null) { + cpt = LayoutScatter.getInstance(mainAbilitySlice).parse(ResourceTable.Layout_item_sample, null, false); + } else { + cpt = component; + } + String sampleItem = data.get(position); + Text text = (Text) cpt.findComponentById(ResourceTable.Id_item_index); + text.setText(sampleItem); + return cpt; + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/LogUtils.java b/entry/src/main/java/rebus/permissionutils/sample/LogUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..22a065be4615aabfed18f8882e877f6d40091d84 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/LogUtils.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +/** + * description 日志类 + * + * @author wjt + * @since 2021-03-20 + */ +public class LogUtils { + /** + * 持续时间 + */ + public static final int DURATION = 2000; + + /** + * info + */ + public static final int INFO = 0; + /** + * error + */ + public static final int ERROR = 1; + /** + * debug + */ + public static final int DEBUG = 2; + /** + * warning + */ + public static final int WARN = 3; + /** + * 返回码 + */ + public static final int REQUEST_CODE = 300; + /** + * System + */ + public static final int SYETEM = 6; + /** + * 3 + */ + public static final int SAN = 3; + /** + * 5 + */ + public static final int WU = 5; + /** + * 2 + */ + public static final int TWO = 2; + /** + * 350 + */ + public static final int SANBAIWU = 350; + /** + * 120 + */ + public static final int YIBAIER = 120; + /** + * 40 + */ + public static final int SISHI = 40; + /** + * 400 + */ + public static final int SIBAI = 400; + /** + * 10 + */ + public static final int SHI = 10; + /** + * MENULATION + */ + public static final int MENULATION = -920; + /** + * LOGTAG + */ + public static final int LOGTAG = 0xD001100; + /** + * 持续时间 + */ + public static final String TAG = "wjtt"; + /** + * ACTIVITY_MOTION + */ + public static final String ACTIVITY_MOTION = "ohos.permission.ACTIVITY_MOTION"; + /** + * GYROSCOPE + */ + public static final String GYROSCOPE = "ohos.permission.GYROSCOPE"; + + /** + * 构造 + * + */ + private LogUtils() { + } + + /** + * Log + * + * @param logType LogUtils.INFO || LogUtils.ERROR || LogUtils.DEBUG|| LogUtils.WARN + * @param tag 日志标识 根据喜好,自定义 + * @param message 需要打印的日志信息 + */ + public static void log(int logType, String tag, String message) { + HiLogLabel lable = new HiLogLabel(logType, LOGTAG, tag); + switch (logType) { + case INFO: + HiLog.info(lable, message); + break; + case ERROR: + HiLog.error(lable, message); + break; + case DEBUG: + HiLog.debug(lable, message); + break; + case WARN: + HiLog.warn(lable, message); + break; + default: + break; + } + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/MainAbility.java b/entry/src/main/java/rebus/permissionutils/sample/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..b993f2b410efa283ecda219ef7b626c1dff10570 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/MainAbility.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.utils.Color; +import ohos.agp.window.service.WindowManager; +import rebus.permissionutils.PermissionManager; +import rebus.permissionutils.sample.slice.MainAbilitySlice; + +/** + * 主页面 + * + * @author:wjt + * @since 2021-04-12 + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + /** + * 沉浸式状态栏 + */ + getWindow().setStatusBarColor(Color.getIntColor("#FF4949FF")); + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } + + @Override + public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { + PermissionManager.handleResult(this, requestCode, permissions, grantResults); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/MainFraction.java b/entry/src/main/java/rebus/permissionutils/sample/MainFraction.java new file mode 100644 index 0000000000000000000000000000000000000000..961a247b2f4a217437d21ef6adbf62a699384954 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/MainFraction.java @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.fraction.Fraction; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayManager; +import rebus.permissionutils.AskAgainCallback; +import rebus.permissionutils.FullCallback; +import rebus.permissionutils.PermissionEnum; +import rebus.permissionutils.PermissionManager; +import rebus.permissionutils.PermissionUtils; +import rebus.permissionutils.SimpleCallback; +import rebus.permissionutils.SmartCallback; + +import java.util.ArrayList; +import java.util.List; + +/** + * 描述 + * + * @author wjt + * @since 2021-04-07 + */ +public class MainFraction extends Fraction implements Component.ClickedListener, FullCallback { + private SuperButton fragmentAskOnePermission; + private SuperButton fragmentAskThreePermission; + private SuperButton askOnePermissionSimple; + private SuperButton fragmentAskThreePermissionSimple; + private SuperButton fragmentAskOnePermissionSmart; + private SuperButton fragmentAskThreePermissionSmart; + private SuperButton fragmentCheckPermission; + + private final int num9001 = 9001; + private final int num801 = 801; + private final int num701 = 701; + private final int num601 = 601; + private final int num2101 = 2101; + private final int num2001 = 2001; + private final int num2 = 2; + private final int num3 = 3; + private final int num10 = 10; + private final int num8 = 8; + private final String allp = "allPermissionsGranted ["; + private final int num200 = 200; + private final String kh = "]"; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) { + Component component = scatter.parse(ResourceTable.Layout_ability_fragment, container, false); + initComponent(component); + return component; + } + + private void initComponent(Component component) { + fragmentAskOnePermission = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_one_permission); + fragmentAskThreePermission = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_three_permission); + askOnePermissionSimple = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_one_permission_simple); + fragmentAskThreePermissionSimple = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_three_permission_simple); + fragmentAskOnePermissionSmart = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_one_permission_smart); + fragmentAskThreePermissionSmart = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_ask_three_permission_smart); + fragmentCheckPermission = (SuperButton) component. + findComponentById(ResourceTable.Id_fragment_check_permission); + + fragmentAskOnePermission.setClickedListener(this); + fragmentAskThreePermission.setClickedListener(this); + askOnePermissionSimple.setClickedListener(this); + fragmentAskThreePermissionSimple.setClickedListener(this); + fragmentAskOnePermissionSmart.setClickedListener(this); + fragmentAskThreePermissionSmart.setClickedListener(this); + fragmentCheckPermission.setClickedListener(this); + + FragmentActivity fractionAbility = (FragmentActivity) getFractionAbility(); + fractionAbility.setRequestPermission(new RequestPermission() { + @Override + public void result(int requestCode, String[] permissions, int[] grantResults) { + PermissionManager.handleResult(MainFraction.this, requestCode, permissions, grantResults); + } + }); + } + + @Override + protected void onActive() { + super.onActive(); + } + + @Override + protected void onStop() { + super.onStop(); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + /** + * 申请一个权限 + */ + case ResourceTable.Id_fragment_ask_one_permission: + askOnePermission2(); + break; + case ResourceTable.Id_fragment_ask_three_permission: + fragmentAskThreePermission2(); + break; + case ResourceTable.Id_fragment_ask_one_permission_simple: + fragmentAskOnePermissionSimple(); + break; + case ResourceTable.Id_fragment_ask_three_permission_simple: + fragmentAskThreePermissionSimple(); + break; + case ResourceTable.Id_fragment_ask_one_permission_smart: + fragmentAskOnePermissionSmart2(); + break; + case ResourceTable.Id_fragment_ask_three_permission_smart: + fragmentAskThreePermissionSmart2(); + break; + case ResourceTable.Id_fragment_check_permission: + checkPermission(); + break; + default: + break; + } + } + + private void checkPermission() { + PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; + boolean isGranted = PermissionUtils.isGranted(getFractionAbility(), PermissionEnum.WRITE_EXTERNAL_STORAGE); + showToast(permissionEnum.toString() + " isGranted [" + isGranted + kh, getFractionAbility()); + } + + private void fragmentAskThreePermissionSmart2() { + PermissionManager.Builder() + .key(num2101) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SmartCallback() { + @Override + public void result(boolean isAllPermissionsGranted, boolean isSomePermissionsDeniedForever) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + + PermissionEnum.READ_CALENDAR.toString() + + allp + isAllPermissionsGranted + "] somePermissionsDeniedForever [" + + isSomePermissionsDeniedForever + kh, getFractionAbility()); + } + }) + .ask(MainFraction.this); + } + + private void fragmentAskOnePermissionSmart2() { + PermissionManager.Builder() + .key(num2001) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SmartCallback() { + @Override + public void result(boolean isAllPermissionsGranted, boolean isSomePermissionsDeniedForever) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + allp + + isAllPermissionsGranted + "] somePermissionsDeniedForever [" + + isSomePermissionsDeniedForever + kh, getFractionAbility()); + } + }) + .ask(MainFraction.this); + } + + private void fragmentAskThreePermissionSimple() { + PermissionManager.Builder() + .key(num601) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SimpleCallback() { + @Override + public void result(boolean isAllPermissionsGranted) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + + PermissionEnum.READ_CALENDAR.toString() + allp + + isAllPermissionsGranted + kh, getFractionAbility()); + } + }) + .ask(MainFraction.this); + } + + private void fragmentAskOnePermissionSimple() { + PermissionManager.Builder() + .key(num701) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SimpleCallback() { + @Override + public void result(boolean isAllPermissionsGranted) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + + allp + isAllPermissionsGranted + kh, getFractionAbility()); + } + }) + .ask(MainFraction.this); + } + + private void fragmentAskThreePermission2() { + PermissionManager.Builder() + .key(num801) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(MainFraction.this) + .ask(MainFraction.this); + } + + private void askOnePermission2() { + PermissionManager.Builder() + .key(num9001) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(MainFraction.this) + .ask(MainFraction.this); + } + + private void showDialog(AskAgainCallback.UserResponse response) { + CommonDialog commonDialog = new CommonDialog(getFractionAbility()); + Component component1 = LayoutScatter.getInstance(getFractionAbility()) + .parse(ResourceTable.Layout_layout_dialog, null, true); + inintDialogCommonDialog(component1, commonDialog, response); + commonDialog.setContentCustomComponent(component1); + Display display = DisplayManager.getInstance().getDefaultDisplay(getFractionAbility()).get(); + int width = display.getAttributes().width; + int height = display.getAttributes().height; + float height2 = (float) ((height / num10) * num3); + commonDialog.setSize(width / num10 * num8, (int) height2); + commonDialog.setMovable(false); + commonDialog.show(); + } + + private void inintDialogCommonDialog(Component component, + CommonDialog commonDialog, AskAgainCallback.UserResponse response) { + component.findComponentById(ResourceTable.Id_no).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + response.result(false); + if (commonDialog != null) { + commonDialog.hide(); + commonDialog.remove(); + } + } + }); + component.findComponentById(ResourceTable.Id_ok).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + response.result(true); + if (commonDialog != null) { + commonDialog.hide(); + commonDialog.remove(); + } + } + }); + } + + /** + * 显示Toast + * + * @param msg + * @param ability + */ + private void showToast(String msg, Ability ability) { + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability) + .parse(ResourceTable.Layout_layout_toast_and_image, null, false); + Text text = (Text) layout.findComponentById(ResourceTable.Id_msg_toast); + text.setText(msg); + Display display = DisplayManager.getInstance().getDefaultDisplay(getFractionAbility()).get(); + int height = display.getAttributes().height; + int width = display.getAttributes().width; + new ToastDialog(ability) + .setComponent(layout) + .setSize(width / num10 * num8, DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setAlignment(LayoutAlignment.CENTER) + .setOffset(0, height / num2 - num200) + .show(); + } + + @Override + public void result(ArrayList permissionsGranted, + ArrayList permissionsDenied, ArrayList permissionsDeniedForever, + ArrayList permissionsAsked) { + List msg = new ArrayList<>(); + for (PermissionEnum permissionEnum : permissionsGranted) { + msg.add(permissionEnum.toString() + " [Granted]"); + } + for (PermissionEnum permissionEnum : permissionsDenied) { + msg.add(permissionEnum.toString() + " [Denied]"); + } + for (PermissionEnum permissionEnum : permissionsDeniedForever) { + msg.add(permissionEnum.toString() + " [DeniedForever]"); + } + for (PermissionEnum permissionEnum : permissionsAsked) { + msg.add(permissionEnum.toString() + " [Asked]"); + } + ListDialog listDialog = new ListDialog(getFractionAbility(), msg); + listDialog.show(); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/MyApplication.java b/entry/src/main/java/rebus/permissionutils/sample/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..ee432e22c278a01970d775389410c2d86c0f9015 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/MyApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * 描述 MyApplication + * + * @author wjt + * @since 2021-04-07 + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/OnItemClicker.java b/entry/src/main/java/rebus/permissionutils/sample/OnItemClicker.java new file mode 100644 index 0000000000000000000000000000000000000000..ef53c0600d40207af1466f61566dbefcf298ffbc --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/OnItemClicker.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +/** + * 描述 单项单机事件 + * + * @author wjt + * @since 2021-04-08 + */ +public interface OnItemClicker { + /** + * 单项单机事件 + * + * @param position 位置 + */ + void onItemClicker(int position); +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/RequestPermission.java b/entry/src/main/java/rebus/permissionutils/sample/RequestPermission.java new file mode 100644 index 0000000000000000000000000000000000000000..d655faf33e271549db9ba8b8596fe301f0e1caeb --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/RequestPermission.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +/** + * 描述 + * + * @author wjt + * @since 2021-04-08 + */ +public interface RequestPermission { + /** + * 回调给Fraction + * + * @param requestCode + * @param permissions + * @param grantResults + */ + void result(int requestCode, String[] permissions, int[] grantResults); +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/SuperButton.java b/entry/src/main/java/rebus/permissionutils/sample/SuperButton.java new file mode 100644 index 0000000000000000000000000000000000000000..47ba9b8eea737a20fc4e081f4165c456a04463bf --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/SuperButton.java @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.agp.colors.RgbColor; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.AttrSet; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentState; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.components.element.StateElement; +import ohos.agp.render.Canvas; +import ohos.agp.utils.Color; +import ohos.app.Context; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; +import ohos.multimodalinput.event.TouchEvent; + +/** + * button + * + * @author:wjt + * @since 2021-04-22 + */ +public class SuperButton extends Button implements Component.DrawTask, + Component.TouchEventListener, Component.ComponentStateChangedListener { + private final int num255 = 255; + private final int down = 18432; + private final int up = 2048; + private final float numldq = 0.7F; + private float mPhase; + private float[] mDashPath; + + private int strokeWidth; + private float cornersRadius; + private float[] cornersRadius2; + + private RgbColor strokeColor; + private RgbColor normalColor; + private RgbColor selectColor; + private RgbColor[] gradientColors; + private RgbColor disabledColor; + + private StateElement mBackground; + + private EventHandler mHandle = new EventHandler(EventRunner.getMainEventRunner()); + + private int shape = ShapeElement.RECTANGLE; + private ShapeElement.Orientation gorientation5; + + /** + * 构造函数 + * + * @param context context + */ + public SuperButton(Context context) { + this(context, null); + } + + /** + * 构造 + * + * @param context + * @param attrSet + */ + public SuperButton(Context context, AttrSet attrSet) { + this(context, attrSet, null); + } + + /** + * 构造 + * + * @param context + * @param attrSet + * @param styleName + */ + public SuperButton(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + parseAttrSet(attrSet); + addDrawTask(this); + if (isClickable() && isEnabled()) { + setComponentStateChangedListener(this); + } + } + + private void parseAttrSet(AttrSet attrSet) { + Color defaultColor = new Color(); + shape = AttrValue.get(attrSet, "super_shape", ShapeElement.RECTANGLE); + Color normalColor2 = AttrValue.get(attrSet, "super_normal_color", defaultColor); + if (normalColor2.getValue() != 0) { + normalColor = RgbColor.fromArgbInt(normalColor2.getValue()); + } + Color selectColor2 = AttrValue.get(attrSet, "super_select_color", defaultColor); + if (selectColor2.getValue() != 0) { + selectColor = RgbColor.fromArgbInt(selectColor2.getValue()); + } + int strokeWidth2 = AttrValue.get(attrSet, "super_stroke_width", 0); + if (strokeWidth2 != 0) { + strokeWidth = AttrHelper.vp2px(strokeWidth2, getContext()); + } + Color strokeColor2 = AttrValue.get(attrSet, "super_stroke_color", defaultColor); + if (strokeColor2.getValue() != 0) { + strokeColor = RgbColor.fromArgbInt(strokeColor2.getValue()); + } + int cornersRadius3 = AttrValue.get(attrSet, "super_corners_radius", 0); + if (cornersRadius3 != 0) { + cornersRadius = AttrHelper.vp2px(cornersRadius3, getContext()); + } + if (shape == ShapeElement.RECTANGLE) { + int leftTop = AttrValue.get(attrSet, "super_lef_top_radius", 0); + int leftBottom = AttrValue.get(attrSet, "super_lef_bottom_radius", 0); + int rightTop = AttrValue.get(attrSet, "super_right_top_radius", 0); + int rightBottom = AttrValue.get(attrSet, "super_right_bottom_radius", 0); + cornersRadius2 = new float[]{leftTop, leftBottom, rightTop, rightBottom}; + } + Color notClickColor3 = AttrValue.get(attrSet, "super_disabled_color", defaultColor); + if (notClickColor3.getValue() != 0) { + disabledColor = RgbColor.fromArgbInt(notClickColor3.getValue()); + } + Color startColor3 = AttrValue.get(attrSet, "super_g_start_color", defaultColor); + Color endColor3 = AttrValue.get(attrSet, "super_g_end_color", defaultColor); + if (startColor3.getValue() != 0 && endColor3.getValue() != 0) { + RgbColor startColor = RgbColor.fromArgbInt(startColor3.getValue()); + RgbColor endColor = RgbColor.fromArgbInt(endColor3.getValue()); + gradientColors = new RgbColor[]{startColor, endColor}; + } + } + + @Override + public void onDraw(Component component, Canvas canvas) { + init(); + setBackground(mBackground); + } + + private void init() { + mBackground = new StateElement(); + apply(); + } + + private void apply() { + if (selectColor != null) { + applyPressedElement(); + } + if (disabledColor != null) { + applyDisabledElement(); + } + applyEmptyElement(); + } + + private void applyEmptyElement() { + ShapeElement mStateEmptyElement = new ShapeElement(); + mStateEmptyElement.setShape(shape); + if (normalColor != null) { + mStateEmptyElement.setRgbColor(normalColor); + } else { + normalColor = new RgbColor(num255, num255, num255, num255); + mStateEmptyElement.setRgbColor(normalColor); + } + if (strokeWidth != 0 && strokeColor != null) { + mStateEmptyElement.setStroke(strokeWidth, strokeColor); + } + if (cornersRadius != 0) { + mStateEmptyElement.setCornerRadius(cornersRadius); + } + if (cornersRadius2 != null) { + mStateEmptyElement.setCornerRadiiArray(cornersRadius2); + } + if (gradientColors != null) { + mStateEmptyElement.setRgbColors(gradientColors); + } + if (gorientation5 != null) { + mStateEmptyElement.setGradientOrientation(gorientation5); + } + if (mDashPath != null) { + mStateEmptyElement.setDashPathEffectValues(mDashPath, mPhase); + } + mBackground.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, mStateEmptyElement); + } + + private void applyDisabledElement() { + ShapeElement mDisabledElement = new ShapeElement(); + mDisabledElement.setShape(shape); + mDisabledElement.setRgbColor(disabledColor); + if (cornersRadius != 0) { + mDisabledElement.setCornerRadius(cornersRadius); + } + if (cornersRadius2 != null) { + mDisabledElement.setCornerRadiiArray(cornersRadius2); + } + mBackground.addState(new int[]{ComponentState.COMPONENT_STATE_DISABLED}, mDisabledElement); + } + + private void applyPressedElement() { + ShapeElement mStatePressedElement = new ShapeElement(); + mStatePressedElement.setShape(shape); + mStatePressedElement.setRgbColor(selectColor); + if (cornersRadius != 0) { + mStatePressedElement.setCornerRadius(cornersRadius); + } + if (cornersRadius2 != null) { + mStatePressedElement.setCornerRadiiArray(cornersRadius2); + } + mBackground.addState(new int[]{ComponentState.COMPONENT_STATE_PRESSED}, mStatePressedElement); + } + + /** + * 设置形状 + * + * @param shape + * @return button + */ + public SuperButton setShape(int shape) { + this.shape = shape; + invalidate(); + return this; + } + + /** + * 设置状态选择器颜色 + * + * @param selectColor3 + * @return button + */ + public SuperButton setShapeSelectorColor(RgbColor selectColor3) { + this.selectColor = selectColor3; + invalidate(); + return this; + } + + /** + * 设置填充的颜色 + * + * @param color 颜色 + * @return 对象 + */ + public SuperButton setShapeColor(RgbColor color) { + this.normalColor = color; + invalidate(); + return this; + } + + /** + * 设置边框宽度 + * + * @param strokeWidth3 边框宽度值 + * @param strokeColor3 设置边框颜色 + * @return 对象 + */ + public SuperButton setShapeStrokeWidthColor(int strokeWidth3, RgbColor strokeColor3) { + this.strokeWidth = AttrHelper.vp2px(strokeWidth3, getContext()); + this.strokeColor = strokeColor3; + invalidate(); + return this; + } + + /** + * 设置圆角半径 + * + * @param radius 半径 + * @return 对象 + */ + public SuperButton setShapeCornersRadius(float radius) { + this.cornersRadius = radius; + invalidate(); + return this; + } + + /** + * 分别设置四个角半径 + * + * @param radius + * @return button + */ + public SuperButton setShapeCornersRadius(float[] radius) { + this.cornersRadius2 = radius; + invalidate(); + return this; + } + + /** + * 设置背景渐变方向 + * + * @param orientation + * @return button + */ + public SuperButton setShapeGradientOrientation(ShapeElement.Orientation orientation) { + this.gorientation5 = orientation; + invalidate(); + return this; + } + + /** + * 设置渐变颜色 + * + * @param gradientColors2 + * @return button + */ + public SuperButton setShapeGradientColor(RgbColor[] gradientColors2) { + this.gradientColors = gradientColors2; + invalidate(); + return this; + } + + /** + * 设置不能点击状态的颜色 + * + * @param color + * @return button + */ + public SuperButton setDisabledColor(RgbColor color) { + this.disabledColor = color; + invalidate(); + return this; + } + + /** + * new float[]{10, 21, 32, 43, 54, 65}, 1 + * + * @param dashPath dashPath + * @param phase phase + * @return button + */ + public SuperButton setShapeDashPathEffectValues(float[] dashPath, float phase) { + this.mDashPath = dashPath; + this.mPhase = phase; + invalidate(); + return this; + } + + @Override + public boolean onTouchEvent(Component component, TouchEvent touchEvent) { + if (!isClickable() || !isEnabled()) { + return false; + } + + switch (touchEvent.getAction()) { + case TouchEvent.PRIMARY_POINT_DOWN: + case TouchEvent.POINT_MOVE: + + break; + case TouchEvent.PRIMARY_POINT_UP: + // 更新API5 不起作用了 + this.setAlpha(1F); + break; + default: + break; + } + return true; + } + + @Override + public void setEnabled(boolean isEnabled) { + super.setEnabled(isEnabled); + this.setAlpha(1F); + } + + @Override + public void onComponentStateChanged(Component component, int state) { + switch (state) { + case down: + if (selectColor == null) { + this.setAlpha(numldq); + } + break; + case up: + default: + setAlpha(1); + } + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/slice/FragmentAbilitySlice.java b/entry/src/main/java/rebus/permissionutils/sample/slice/FragmentAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..775ed9918cde6a5c832b71c7aa65d7c0ae410b66 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/slice/FragmentAbilitySlice.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.ability.fraction.FractionAbility; +import ohos.aafwk.ability.fraction.FractionScheduler; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import rebus.permissionutils.sample.MainFraction; +import rebus.permissionutils.sample.ResourceTable; + +/** + * Fraction的容器 + * + * @author wjt + * @since 2021-04-07 + */ +public class FragmentAbilitySlice extends AbilitySlice { + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_ability_fragment_container); + boolean isFragmentX = intent.getBooleanParam("IS_FRAGMENT_X",false); + initView(); + } + + private void initView() { + findComponentById(ResourceTable.Id_back).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + getAbility().terminateAbility(); + } + }); + FractionAbility fractionAbility = (FractionAbility) getAbility(); + FractionScheduler fractionScheduler = fractionAbility.getFractionManager().startFractionScheduler(); + fractionScheduler.add(ResourceTable.Id_container,new MainFraction()); + fractionScheduler.submit(); + } +} diff --git a/entry/src/main/java/rebus/permissionutils/sample/slice/MainAbilitySlice.java b/entry/src/main/java/rebus/permissionutils/sample/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..7e3fb1cdbb837facde64593504dbe44868d00bb9 --- /dev/null +++ b/entry/src/main/java/rebus/permissionutils/sample/slice/MainAbilitySlice.java @@ -0,0 +1,427 @@ +/* + * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample.slice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.Component; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayManager; +import rebus.permissionutils.AskAgainCallback; +import rebus.permissionutils.FullCallback; +import rebus.permissionutils.PermissionEnum; +import rebus.permissionutils.PermissionManager; +import rebus.permissionutils.PermissionUtils; +import rebus.permissionutils.SimpleCallback; +import rebus.permissionutils.SmartCallback; +import rebus.permissionutils.sample.InfoDialog; +import rebus.permissionutils.sample.ListDialog; +import rebus.permissionutils.sample.LogUtils; +import rebus.permissionutils.sample.ResourceTable; +import rebus.permissionutils.sample.SuperButton; + +import java.util.ArrayList; +import java.util.List; + +/** + * 主页面 + * + * @author:wjt + * @since 2021-04-06 + */ +public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener, FullCallback { + private CommonDialog mCommonDialog = null; + private SuperButton askOnePermission; + private SuperButton askThreePermission; + private SuperButton askOnePermissionSimple; + private SuperButton askThreePermissionSimple; + private SuperButton askOnePermissionSmart; + private SuperButton askThreePermissionSmart; + private SuperButton checkPermission; + private final int num9000 = 9000; + private final int num800 = 800; + private final int num700 = 700; + private final int num600 = 600; + private final int num2100 = 2100; + private final int num2000 = 2000; + private final int num2 = 2; + private final int num200 = 200; + private final int num10 = 10; + private final int num8 = 8; + private final int num3 = 3; + private final String allp = "allPermissionsGranted ["; + private final String kh = "]"; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + inintView(); + } + + private void inintView() { + askOnePermission = (SuperButton) findComponentById(ResourceTable.Id_ask_one_permission); + askThreePermission = (SuperButton) findComponentById(ResourceTable.Id_ask_three_permission); + askOnePermissionSimple = (SuperButton) findComponentById(ResourceTable.Id_ask_one_permission_simple); + askThreePermissionSimple = (SuperButton) findComponentById(ResourceTable.Id_ask_three_permission_simple); + askOnePermissionSmart = (SuperButton) findComponentById(ResourceTable.Id_ask_one_permission_smart); + askThreePermissionSmart = (SuperButton) findComponentById(ResourceTable.Id_ask_three_permission_smart); + checkPermission = (SuperButton) findComponentById(ResourceTable.Id_check_permission); + + askOnePermission.setClickedListener(this); + askThreePermission.setClickedListener(this); + askOnePermissionSimple.setClickedListener(this); + askThreePermissionSimple.setClickedListener(this); + askOnePermissionSmart.setClickedListener(this); + askThreePermissionSmart.setClickedListener(this); + checkPermission.setClickedListener(this); + findComponentById(ResourceTable.Id_menu).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + Display display = DisplayManager.getInstance().getDefaultDisplay(getAbility()).get(); + int width = display.getAttributes().width; + int height = display.getAttributes().height; + mCommonDialog = new CommonDialog(getAbility()); + Component component1 = LayoutScatter.getInstance(getContext()) + .parse(ResourceTable.Layout_layout_x, null, true); + initComponent(component1, mCommonDialog); + mCommonDialog.setSize(width / LogUtils.DEBUG, height / LogUtils.WU); + mCommonDialog.setContentCustomComponent(component1); + mCommonDialog.setAutoClosable(true); + mCommonDialog.setOffset(0, LogUtils.MENULATION); + mCommonDialog.setAlignment(LayoutAlignment.RIGHT); + mCommonDialog.show(); + } + }); + } + + private void initComponent(Component component, final CommonDialog dialog) { + Text setting = (Text) component.findComponentById(ResourceTable.Id_setting); + Text fragment = (Text) component.findComponentById(ResourceTable.Id_fragment); + Text info = (Text) component.findComponentById(ResourceTable.Id_info); + setting.setClickedListener(new Component.ClickedListener() { + /** + * 设置页面 todo 跳转系统页面 + * + * @param component Component + */ + @Override + public void onClick(Component component) { + PermissionUtils.openApplicationSettings(getAbility()); + dialog.remove(); + } + }); + /** + * Fraction 页面 + * + * @param component Component + */ + fragment.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + Intent intent = new Intent(); + Operation operationCommonComponts = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName("rebus.permissionutils.sample") + .withAbilityName("rebus.permissionutils.sample.FragmentActivity") + .build(); + intent.setOperation(operationCommonComponts); + getAbility().startAbility(intent); + dialog.remove(); + } + }); + info.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + dialog.remove(); + InfoDialog infoDialog = new InfoDialog(getAbility(), "hahahhaha"); + infoDialog.show(); + } + }); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + /** + * 请求一个权限 + */ + case ResourceTable.Id_ask_one_permission: + askonepermission(); + break; + case ResourceTable.Id_ask_three_permission: + askThreePermission2(); + break; + case ResourceTable.Id_ask_one_permission_simple: + askOnePermissionSimple2(); + break; + case ResourceTable.Id_ask_three_permission_simple: + askThreePermissionSimple2(); + break; + case ResourceTable.Id_ask_one_permission_smart: + askOnePermissionSmart2(); + break; + case ResourceTable.Id_ask_three_permission_smart: + askThreePermissionSmart2(); + break; + case ResourceTable.Id_check_permission: + checkPermission2(); + + break; + default: + break; + } + } + + private void checkPermission2() { + PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; + boolean isGranted = PermissionUtils.isGranted(getAbility(), PermissionEnum.WRITE_EXTERNAL_STORAGE); + showToast(permissionEnum.toString() + " isGranted [" + isGranted + kh, getAbility()); + } + + private void askThreePermissionSmart2() { + PermissionManager.Builder() + .key(num2100) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SmartCallback() { + @Override + public void result(boolean isAllPermissionsGranted, boolean isSomePermissionsDeniedForever) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + + + ", " + + PermissionEnum.ACCESS_FINE_LOCATION.toString() + + ", " + PermissionEnum.READ_CALENDAR.toString() + + allp + isAllPermissionsGranted + + "] somePermissionsDeniedForever [" + + isSomePermissionsDeniedForever + kh, getAbility()); + } + }) + .ask(getAbility()); + } + + private void askOnePermissionSmart2() { + PermissionManager.Builder() + .key(num2000) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SmartCallback() { + @Override + public void result(boolean isAllPermissionsGranted, boolean isSomePermissionsDeniedForever) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + + allp + isAllPermissionsGranted + "] somePermissionsDeniedForever [" + + isSomePermissionsDeniedForever + kh, getAbility()); + } + }) + .ask(getAbility()); + } + + private void askThreePermissionSimple2() { + PermissionManager.Builder() + .key(num600) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SimpleCallback() { + @Override + public void result(boolean isAllPermissionsGranted) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + ", " + + PermissionEnum.ACCESS_FINE_LOCATION.toString() + + ", " + PermissionEnum.READ_CALENDAR.toString() + + allp + isAllPermissionsGranted + kh, getAbility()); + } + }) + .ask(getAbility()); + } + + private void askOnePermissionSimple2() { + PermissionManager.Builder() + .key(num700) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(new SimpleCallback() { + @Override + public void result(boolean isAllPermissionsGranted) { + showToast(PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + allp + + isAllPermissionsGranted + kh, getAbility()); + } + }) + .ask(getAbility()); + } + + private void askThreePermission2() { + PermissionManager.Builder() + .key(num800) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE, PermissionEnum.ACCESS_FINE_LOCATION, + PermissionEnum.READ_CALENDAR) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + showDialog(response); + } + }) + .callback(MainAbilitySlice.this) + .ask(getAbility()); + } + + private void askonepermission() { + PermissionManager.Builder() + .key(num9000) + .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) + .askAgain(true) + .askAgainCallback(new AskAgainCallback() { + @Override + public void showRequestPermission(UserResponse response) { + LogUtils.log(LogUtils.INFO, "test", "跑到这里了"); + showDialog(response); + } + }) + .callback(MainAbilitySlice.this) + .ask(getAbility()); + } + + /** + * 显示Toast + * + * @param msg + * @param ability + */ + private void showToast(String msg, Ability ability) { + DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(ability) + .parse(ResourceTable.Layout_layout_toast_and_image, null, false); + Text text = (Text) layout.findComponentById(ResourceTable.Id_msg_toast); + text.setText(msg); + Display display = DisplayManager.getInstance().getDefaultDisplay(getAbility()).get(); + int height = display.getAttributes().height; + int width = display.getAttributes().width; + new ToastDialog(ability) + .setComponent(layout) + .setSize(width / num10 * num8, DirectionalLayout.LayoutConfig.MATCH_CONTENT) + .setAlignment(LayoutAlignment.CENTER) + .setOffset(0, height / num2 - num200) + .show(); + } + + /** + * 显示个dialog 权限需要提示 + * 这个应用程式确实需要使用这个权限,您要授权吗? + * + * @param response + */ + private void showDialog(final AskAgainCallback.UserResponse response) { + CommonDialog commonDialog = new CommonDialog(getAbility()); + Component component1 = LayoutScatter.getInstance(getContext()) + .parse(ResourceTable.Layout_layout_dialog, null, true); + inintDialogCommonDialog(component1, commonDialog, response); + commonDialog.setContentCustomComponent(component1); + Display display = DisplayManager.getInstance().getDefaultDisplay(getAbility()).get(); + int width = display.getAttributes().width; + int height = display.getAttributes().height; + float height2 = (float) ((height / num10) * num3); + commonDialog.setSize(width / num10 * num8, (int) height2); + commonDialog.setMovable(false); + commonDialog.show(); + } + + private void inintDialogCommonDialog(Component component, CommonDialog commonDialog, + AskAgainCallback.UserResponse response) { + component.findComponentById(ResourceTable.Id_no).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + response.result(false); + if (commonDialog != null) { + commonDialog.hide(); + commonDialog.remove(); + } + } + }); + component.findComponentById(ResourceTable.Id_ok).setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + response.result(true); + if (commonDialog != null) { + commonDialog.hide(); + commonDialog.remove(); + } + } + }); + } + + @Override + public void result(ArrayList permissionsGranted, + ArrayList permissionsDenied, ArrayList permissionsDeniedForever, + ArrayList permissionsAsked) { + List msg = new ArrayList<>(); + for (PermissionEnum permissionEnum : permissionsGranted) { + msg.add(permissionEnum.toString() + " [Granted]"); + } + for (PermissionEnum permissionEnum : permissionsDenied) { + msg.add(permissionEnum.toString() + " [Denied]"); + } + for (PermissionEnum permissionEnum : permissionsDeniedForever) { + msg.add(permissionEnum.toString() + " [DeniedForever]"); + } + for (PermissionEnum permissionEnum : permissionsAsked) { + msg.add(permissionEnum.toString() + " [Asked]"); + } + ListDialog listDialog = new ListDialog(getAbility(), msg); + listDialog.show(); + } +} diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..5a2d8e91919ca1a3757bdcb77b828e29ea1944f0 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "status", + "value": "#1C1C1C" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4f53f882616ef990006b591349cea885397ab0c2 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "app_name", + "value": "PermissionUtils" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "HelloWorld", + "value": "Hello World" + }, + { + "name": "GitHub", + "value": "https://github.com/rebus007" + }, + { + "name": "Twitter", + "value": "https://twitter.com/rebus_007" + }, + { + "name": "Google", + "value": "https://plus.google.com/+RaphaelBussa/posts" + }, + { + "name": "Linkedin", + "value": "https://www.linkedin.com/in/rebus007" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_infodialog.xml b/entry/src/main/resources/base/graphic/background_ability_infodialog.xml new file mode 100644 index 0000000000000000000000000000000000000000..4f44e71b8f473e5324b80275b8c1be823626319e --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_infodialog.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main_button.xml b/entry/src/main/resources/base/graphic/background_ability_main_button.xml new file mode 100644 index 0000000000000000000000000000000000000000..2db8dcb201ee8d523ff101a4c0c816f43d60509e --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main_button.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_toast_element.xml b/entry/src/main/resources/base/graphic/background_toast_element.xml new file mode 100644 index 0000000000000000000000000000000000000000..57ad59e885a4185a1c1608640d54b7acea0b2619 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_toast_element.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_fragment.xml b/entry/src/main/resources/base/layout/ability_fragment.xml new file mode 100644 index 0000000000000000000000000000000000000000..8a9b3b85ba45dc905ce94e304f370033c7541d5f --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_fragment.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_fragment_container.xml b/entry/src/main/resources/base/layout/ability_fragment_container.xml new file mode 100644 index 0000000000000000000000000000000000000000..7ea420069bb84594c8a06d3cdc16a749c0384c88 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_fragment_container.xml @@ -0,0 +1,46 @@ + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..0a9fb0282f2cb0341f6bccfce8de8aa6e72c9b1c --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/item_sample.xml b/entry/src/main/resources/base/layout/item_sample.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ace56e30b4b46d6291bd5b865610c4b4aea24a0 --- /dev/null +++ b/entry/src/main/resources/base/layout/item_sample.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/layout_dialog.xml b/entry/src/main/resources/base/layout/layout_dialog.xml new file mode 100644 index 0000000000000000000000000000000000000000..8133ccc8cf7d0308bd67ac7191d9db536ae00f78 --- /dev/null +++ b/entry/src/main/resources/base/layout/layout_dialog.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/layout_info_dialog.xml b/entry/src/main/resources/base/layout/layout_info_dialog.xml new file mode 100644 index 0000000000000000000000000000000000000000..a291a2a6252bd836969ef7527249b76260d32cf5 --- /dev/null +++ b/entry/src/main/resources/base/layout/layout_info_dialog.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/layout_list_dialog.xml b/entry/src/main/resources/base/layout/layout_list_dialog.xml new file mode 100644 index 0000000000000000000000000000000000000000..5ad22d3cb17f187c0d81b19fe27984cd68247960 --- /dev/null +++ b/entry/src/main/resources/base/layout/layout_list_dialog.xml @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/layout_toast_and_image.xml b/entry/src/main/resources/base/layout/layout_toast_and_image.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e5351f1229a141970ed5d33b64ea6ed1ea95634 --- /dev/null +++ b/entry/src/main/resources/base/layout/layout_toast_and_image.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/layout_x.xml b/entry/src/main/resources/base/layout/layout_x.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4a5d17fb9ff18f755b246ad16ae6bba057043bc --- /dev/null +++ b/entry/src/main/resources/base/layout/layout_x.xml @@ -0,0 +1,40 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/back.png b/entry/src/main/resources/base/media/back.png new file mode 100644 index 0000000000000000000000000000000000000000..cbd6c630d8d99949d3a63f4ef1cea5f47c8e490c Binary files /dev/null and b/entry/src/main/resources/base/media/back.png differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/entry/src/main/resources/base/media/ic_launcher_round.png similarity index 100% rename from sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to entry/src/main/resources/base/media/ic_launcher_round.png diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/base/media/menu2.png b/entry/src/main/resources/base/media/menu2.png new file mode 100644 index 0000000000000000000000000000000000000000..40aed049f4480990be7487cd71b56ffec809806e Binary files /dev/null and b/entry/src/main/resources/base/media/menu2.png differ diff --git a/entry/src/main/resources/base/media/menutwo.png b/entry/src/main/resources/base/media/menutwo.png new file mode 100644 index 0000000000000000000000000000000000000000..89acd16f5776553f5c124628e7a7b0a2f606da54 Binary files /dev/null and b/entry/src/main/resources/base/media/menutwo.png differ diff --git a/entry/src/ohosTest/config.json b/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..fb8fbd6cd96d727264786992b6b6b9d9fa6b6291 --- /dev/null +++ b/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "rebus.permissionutils.sample", + "vendor": "permissionutils", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 6, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "rebus.permissionutils.sample", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/rebus/permissionutils/sample/ExampleOhosTest.java b/entry/src/ohosTest/java/rebus/permissionutils/sample/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..39a3cb29629951f75e477f85b9a309a8d3be25a5 --- /dev/null +++ b/entry/src/ohosTest/java/rebus/permissionutils/sample/ExampleOhosTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain an copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rebus.permissionutils.sample; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; +import rebus.permissionutils.PermissionEnum; +import rebus.permissionutils.PermissionUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +/** + * 测试 + * + * @author:wjt + * @since 2021-05-27 + */ +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + String abilityName = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getAbilityName(); + assertEquals("rebus.permissionutils.sample", actualBundleName); + System.out.println("测试通过!"); + } + + @Test + public void isGranted(){ + boolean granted = PermissionUtils.isGranted(AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility(), PermissionEnum.WRITE_EXTERNAL_STORAGE); + assertFalse(granted); + } +} \ No newline at end of file diff --git a/entry/src/test/java/rebus/permissionutils/sample/ExampleTest.java b/entry/src/test/java/rebus/permissionutils/sample/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8b1646d02fc744fd9edbf7a4a5f84c418ae1a673 --- /dev/null +++ b/entry/src/test/java/rebus/permissionutils/sample/ExampleTest.java @@ -0,0 +1,9 @@ +package rebus.permissionutils.sample; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/gradle.properties b/gradle.properties index 98bed167dc90ffee72b7affb37a659966b1bd114..0daf1830fbdef07e50a44d74210c8c82f1b66278 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,10 @@ # Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: +# IDE (e.g. DevEco Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true -# Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official \ No newline at end of file +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f6b961fd5a86aa5fbfe90f707c3138408be7c718..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9c131423f15c28c44985b0a06de17763c1e25089..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Feb 08 13:20:55 CET 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000000000000000000000000000000000000..536f0272dd995f3afdb5e34e0f42bdf3d1986c22 --- /dev/null +++ b/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# 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 + +APP_NAME="Gradle" +APP_BASE_NAME=$(basename "$0") + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# 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 +nonstop=false +case "$(uname)" in +CYGWIN*) + cygwin=true + ;; +Darwin*) + darwin=true + ;; +MINGW*) + msys=true + ;; +NONSTOP*) + nonstop=true + ;; +esac + +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" -a "$nonstop" = "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 or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ]; 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=$(expr $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 + +# Escape application args +save() { + for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000000000000000000000000000000000..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/img/ability.gif b/img/ability.gif new file mode 100644 index 0000000000000000000000000000000000000000..4b90e86bbb233371148a25c038530adae726bcd8 Binary files /dev/null and b/img/ability.gif differ diff --git a/img/fraction.gif b/img/fraction.gif new file mode 100644 index 0000000000000000000000000000000000000000..b6b8e6569cb498ef7558311ee36c77591dd6b088 Binary files /dev/null and b/img/fraction.gif differ diff --git a/img/setting.gif b/img/setting.gif new file mode 100644 index 0000000000000000000000000000000000000000..9cdaab64222b5720ac8b6f0bc2f818299f606db4 Binary files /dev/null and b/img/setting.gif differ diff --git a/img/social/google-plus-icon.png b/img/social/google-plus-icon.png deleted file mode 100644 index c9e81d9de3a4f16d06aaa93122fbae33212c2cdd..0000000000000000000000000000000000000000 Binary files a/img/social/google-plus-icon.png and /dev/null differ diff --git a/img/social/linkedin-icon.png b/img/social/linkedin-icon.png deleted file mode 100644 index 21a5a84edbc25d994b4e18547b5fe3f1750cce2f..0000000000000000000000000000000000000000 Binary files a/img/social/linkedin-icon.png and /dev/null differ diff --git a/img/social/twitter-icon.png b/img/social/twitter-icon.png deleted file mode 100644 index 27af364867267d7968b815c6f1db1552f6f1fd7b..0000000000000000000000000000000000000000 Binary files a/img/social/twitter-icon.png and /dev/null differ diff --git a/library/.gitignore b/library/.gitignore index 42afabfd2abebf31384ca7797186a27a4b7dbee8..796b96d1c402326528b4ba3c12ee9d92d0e212e9 100644 --- a/library/.gitignore +++ b/library/.gitignore @@ -1 +1 @@ -/build \ No newline at end of file +/build diff --git a/library/build.gradle b/library/build.gradle index c91faf8f3fe3124c6061ac4fbffbae5f30357fd3..25ddf0cf1daa8f1533639ebc05ce352f4019b8ff 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,54 +1,21 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -apply plugin: 'com.android.library' - -android { - - compileSdkVersion var.compileSdk - +apply plugin: 'com.huawei.ohos.library' +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion var.minSdk - targetSdkVersion var.targetSdk - versionCode 1 - versionName "${var.version}" + compatibleSdkVersion 5 } buildTypes { - all { - resValue "string", "version", "${var.version}" - } release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } } } - lintOptions { - abortOnError false - } + } dependencies { - implementation 'androidx.legacy:legacy-support-v13:1.0.0' - implementation 'androidx.fragment:fragment:1.2.5' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' } diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index fd8637fdef15a05c9617a5b02d9ca23fedfb075b..f7666e47561d514b2a76d5a7dfbb43ede86da92a 100644 --- a/library/proguard-rules.pro +++ b/library/proguard-rules.pro @@ -1,17 +1 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/raphaelbussa/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# 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 *; -#} +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/library/src/androidTest/java/rebus/permissionutils/ApplicationTest.java b/library/src/androidTest/java/rebus/permissionutils/ApplicationTest.java deleted file mode 100644 index bb47ad8c01f727fefe6f42ce8515dceeac7efa6a..0000000000000000000000000000000000000000 --- a/library/src/androidTest/java/rebus/permissionutils/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package rebus.permissionutils; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml deleted file mode 100644 index f77605ff54fe9466411ac1c5b84218194e8ee3bb..0000000000000000000000000000000000000000 --- a/library/src/main/AndroidManifest.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - diff --git a/library/src/main/config.json b/library/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d35fe8d17a01062c87e528f5b2a72469201ce165 --- /dev/null +++ b/library/src/main/config.json @@ -0,0 +1,28 @@ +{ + "app": { + "bundleName": "rebus.permissionutils.sample", + "vendor": "permissionutils", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 6, + "releaseType": "Release" + } + }, + "deviceConfig": { + }, + "module": { + "package": "rebus.permissionutils", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "library", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/library/src/main/java/rebus/permissionutils/AskAgainCallback.java b/library/src/main/java/rebus/permissionutils/AskAgainCallback.java old mode 100755 new mode 100644 index 10d1a917633ddea709da3857eacab913f5d9fdad..0b2a1f15a3a554060f3bc2a57b2c35f53954a8c6 --- a/library/src/main/java/rebus/permissionutils/AskAgainCallback.java +++ b/library/src/main/java/rebus/permissionutils/AskAgainCallback.java @@ -25,22 +25,31 @@ package rebus.permissionutils; /** - * Created by raphaelbussa on 22/06/16. + * 在一次请求 + * + * + *@since 2021-03-20 */ public interface AskAgainCallback { - /** - * @param response user response + * user response + * + * @param response 请求 */ void showRequestPermission(UserResponse response); + /** + * 用户的响应 + * + * + * @since 2021-03-20 + */ interface UserResponse { - /** - * @param askAgain the response from the user if allow to ask again a permission + * 用户的响应(如果允许再次询问许可) + * + * @param askAgain 响应 */ void result(boolean askAgain); - } - } diff --git a/library/src/main/java/rebus/permissionutils/FullCallback.java b/library/src/main/java/rebus/permissionutils/FullCallback.java old mode 100755 new mode 100644 index 5bcca90fa9c865a8edfc93ef45233a84b4ffeaae..dea75185133b7277fde0f36174123422224b14c3 --- a/library/src/main/java/rebus/permissionutils/FullCallback.java +++ b/library/src/main/java/rebus/permissionutils/FullCallback.java @@ -27,16 +27,20 @@ package rebus.permissionutils; import java.util.ArrayList; /** - * Created by raphaelbussa on 22/06/16. + * 为您提供有关您请求的权限的所有信息 + * + * @author:wjt + * @since 2021-03-20 */ public interface FullCallback { - /** - * @param permissionsGranted list of permission granted - * @param permissionsDenied list of permission denied - * @param permissionsDeniedForever list of permission denied forever - * @param permissionsAsked list of permission asked + * 为您提供有关您请求的权限的所有信息 + * + * @param permissionsGranted + * @param permissionsDenied + * @param permissionsDeniedForever + * @param permissionsAsked */ - void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked); - + void result(ArrayList permissionsGranted, ArrayList permissionsDenied, + ArrayList permissionsDeniedForever, ArrayList permissionsAsked); } diff --git a/library/src/main/java/rebus/permissionutils/PermissionConstant.java b/library/src/main/java/rebus/permissionutils/PermissionConstant.java old mode 100755 new mode 100644 index edce59fcb206c849dfd012835cb3f28b6db3b4b5..c5cce7ddd9bbf97c01e27ab9ebdfb36dd1e395be --- a/library/src/main/java/rebus/permissionutils/PermissionConstant.java +++ b/library/src/main/java/rebus/permissionutils/PermissionConstant.java @@ -25,10 +25,19 @@ package rebus.permissionutils; /** - * Created by raphaelbussa on 22/06/16. + * 主页面 + * + * @author:wjt + * @since 2021-04-06 */ public class PermissionConstant { - - public final static int KEY_PERMISSION = 100; - + /** + * 权限请求码 + */ + public static final int KEY_PERMISSION = 100; + /** + * 构造参数 + */ + private PermissionConstant() { + } } diff --git a/library/src/main/java/rebus/permissionutils/PermissionEnum.java b/library/src/main/java/rebus/permissionutils/PermissionEnum.java old mode 100755 new mode 100644 index 66ca42adf1b4ba06584d269e24e24dc609eb8069..093fb1d1be6cfa83161dcfbc82f3dd217ddb8940 --- a/library/src/main/java/rebus/permissionutils/PermissionEnum.java +++ b/library/src/main/java/rebus/permissionutils/PermissionEnum.java @@ -24,52 +24,96 @@ package rebus.permissionutils; -import android.Manifest; -import android.annotation.SuppressLint; - -import androidx.annotation.NonNull; - /** - * Created by raphaelbussa on 22/06/16. + * 权限列表 + * + * @author:wjt + * @since 2021-03-20 */ -@SuppressLint("InlinedApi") public enum PermissionEnum { - - BODY_SENSORS(Manifest.permission.BODY_SENSORS), - READ_CALENDAR(Manifest.permission.READ_CALENDAR), - WRITE_CALENDAR(Manifest.permission.WRITE_CALENDAR), - READ_CONTACTS(Manifest.permission.READ_CONTACTS), - WRITE_CONTACTS(Manifest.permission.WRITE_CONTACTS), - GET_ACCOUNTS(Manifest.permission.GET_ACCOUNTS), - READ_EXTERNAL_STORAGE(Manifest.permission.READ_EXTERNAL_STORAGE), - WRITE_EXTERNAL_STORAGE(Manifest.permission.WRITE_EXTERNAL_STORAGE), - ACCESS_FINE_LOCATION(Manifest.permission.ACCESS_FINE_LOCATION), - ACCESS_COARSE_LOCATION(Manifest.permission.ACCESS_COARSE_LOCATION), - RECORD_AUDIO(Manifest.permission.RECORD_AUDIO), - READ_PHONE_STATE(Manifest.permission.READ_PHONE_STATE), - CALL_PHONE(Manifest.permission.CALL_PHONE), - READ_CALL_LOG(Manifest.permission.READ_CALL_LOG), - WRITE_CALL_LOG(Manifest.permission.WRITE_CALL_LOG), - ADD_VOICEMAIL(Manifest.permission.ADD_VOICEMAIL), - USE_SIP(Manifest.permission.USE_SIP), - PROCESS_OUTGOING_CALLS(Manifest.permission.PROCESS_OUTGOING_CALLS), - CAMERA(Manifest.permission.CAMERA), - SEND_SMS(Manifest.permission.SEND_SMS), - RECEIVE_SMS(Manifest.permission.RECEIVE_SMS), - READ_SMS(Manifest.permission.READ_SMS), - RECEIVE_WAP_PUSH(Manifest.permission.RECEIVE_WAP_PUSH), - RECEIVE_MMS(Manifest.permission.RECEIVE_MMS), - - GROUP_CALENDAR(Manifest.permission_group.CALENDAR), - GROUP_CAMERA(Manifest.permission_group.CAMERA), - GROUP_CONTACTS(Manifest.permission_group.CONTACTS), - GROUP_LOCATION(Manifest.permission_group.LOCATION), - GROUP_MICROPHONE(Manifest.permission_group.MICROPHONE), - GROUP_PHONE(Manifest.permission_group.PHONE), - GROUP_SENSORS(Manifest.permission_group.SENSORS), - GROUP_SMS(Manifest.permission_group.SMS), - GROUP_STORAGE(Manifest.permission_group.STORAGE), - + /** + * 加速度传感器 + */ + BODY_SENSORS(ohos.security.SystemPermission.ACCELEROMETER), + /** + * 陀螺仪传感器 + */ + GYROSCOPE_SENSORS(ohos.security.SystemPermission.GYROSCOPE), + /** + * 日历 + */ + READ_CALENDAR(ohos.security.SystemPermission.READ_CALENDAR), + /** + * 读取日历 + */ + WRITE_CALENDAR(ohos.security.SystemPermission.WRITE_CALENDAR), + /** + * 允许应用读取联系人(联系人是敏感权限,需要申请相应的权限证书) + */ + READ_CONTACTS(ohos.security.SystemPermission.READ_CONTACTS), + /** + * 允许应用程序添加,删除和修改联系人(联系人是敏感权限,需要申请相应的权限证书) + */ + WRITE_CONTACTS(ohos.security.SystemPermission.WRITE_CONTACTS), + /** + * 允许应用程序从设备的存储中读取文件 + */ + READ_EXTERNAL_STORAGE(ohos.security.SystemPermission.READ_USER_STORAGE), + /** + * 允许应用创建或删除文件,或将数据写入设备存储中的文件。 + */ + WRITE_EXTERNAL_STORAGE(ohos.security.SystemPermission.WRITE_USER_STORAGE), + /** + * 允许应用程序获取设备位置。 + */ + ACCESS_FINE_LOCATION(ohos.security.SystemPermission.LOCATION), + /** + * 允许后台应用程序获取设备位置 + */ + ACCESS_COARSE_LOCATION(ohos.security.SystemPermission.LOCATION_IN_BACKGROUND), + /** + * 麦克风录音 + */ + RECORD_AUDIO(ohos.security.SystemPermission.MICROPHONE), + /** + * 允许应用读取电话信息。(电话是敏感权限,需要申请相应的权限证书) + */ + READ_PHONE_STATE(ohos.security.SystemPermission.GET_TELEPHONY_STATE), + /** + * 允许应用程序拨打常规电话和紧急电话,而无需启动拨号程序。(电话是敏感权限,需要申请相应的权限证书) + */ + CALL_PHONE(ohos.security.SystemPermission.PLACE_CALL), + /** + * 允许应用读取呼叫日志(电话是敏感权限,需要申请相应的权限证书) + */ + READ_CALL_LOG(ohos.security.SystemPermission.READ_CALL_LOG), + /** + * 允许应用程序添加,删除和修改呼叫日志。(电话是敏感权限,需要申请相应的权限证书) + */ + WRITE_CALL_LOG(ohos.security.SystemPermission.WRITE_CALL_LOG), + /** + * 允允许应用程序在语音邮箱中添加消息(电话是敏感权限,需要申请相应的权限证书) + */ + ADD_VOICEMAIL(ohos.security.SystemPermission.MANAGE_VOICEMAIL), + /** + * 允许使用相机 + */ + CAMERA(ohos.security.SystemPermission.CAMERA), + /** + * 发送短信(电话是敏感权限,需要申请相应的权限证书) + */ + SEND_SMS(ohos.security.SystemPermission.SEND_MESSAGES), + /** + * 允许接受短信和处理(电话是敏感权限,需要申请相应的权限证书) + */ + RECEIVE_SMS(ohos.security.SystemPermission.RECEIVE_SMS), + /** + * 允许应用程序接收和处理WAP消息。 + */ + RECEIVE_WAP_PUSH(ohos.security.SystemPermission.RECEIVE_WAP_MESSAGES), + /** + * 空 + */ NULL(""); private final String permission; @@ -78,7 +122,13 @@ public enum PermissionEnum { this.permission = permission; } - public static PermissionEnum fromManifestPermission(@NonNull String value) { + /** + * 从项目参数中拿到参数值 + * + * @param value + * @return 权限名 + */ + public static PermissionEnum fromManifestPermission(String value) { for (PermissionEnum permissionEnum : PermissionEnum.values()) { if (value.equalsIgnoreCase(permissionEnum.permission)) { return permissionEnum; @@ -87,10 +137,9 @@ public enum PermissionEnum { return NULL; } - @NonNull @Override public String toString() { return permission; } - } + diff --git a/library/src/main/java/rebus/permissionutils/PermissionManager.java b/library/src/main/java/rebus/permissionutils/PermissionManager.java old mode 100755 new mode 100644 index 2166b0d6da80e68e3959f0d74a471a8d39043196..291bf9cf36fed05e537278229d91d5f6763343a4 --- a/library/src/main/java/rebus/permissionutils/PermissionManager.java +++ b/library/src/main/java/rebus/permissionutils/PermissionManager.java @@ -24,20 +24,19 @@ package rebus.permissionutils; -import android.content.pm.PackageManager; -import android.os.Build; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.fraction.Fraction; +import ohos.bundle.IBundleManager; import java.util.ArrayList; import java.util.Collections; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.legacy.app.FragmentCompat; - /** - * Created by raphaelbussa on 22/06/16. + * 权限管理器 + * + * @author:wjt + * @since 2021-04-06 */ -@SuppressWarnings("unused") public class PermissionManager { private static PermissionManager instance; @@ -50,14 +49,28 @@ public class PermissionManager { private boolean askAgain = false; private ArrayList permissions; + /** + * 授予权限 + */ private ArrayList permissionsGranted; + /** + * 没有权限 + */ private ArrayList permissionsDenied; + /** + * 永远拒绝的列表 + */ private ArrayList permissionsDeniedForever; + /** + * 准备请求的列表 + */ private ArrayList permissionToAsk; private int key = PermissionConstant.KEY_PERMISSION; /** + * 构建者 + * * @return current instance */ public static PermissionManager Builder() { @@ -68,51 +81,54 @@ public class PermissionManager { } /** + * 请求权限并返回结果 + * * @param activity target activity * @param requestCode requestCode * @param permissions permissions * @param grantResults grantResults */ - public static void handleResult(@NonNull android.app.Activity activity, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - handleResult(activity, null, null, requestCode, permissions, grantResults); + public static void handleResult(Ability activity, int requestCode, String[] permissions, int[] grantResults) { + handleResult(activity, null, requestCode, permissions, grantResults); } /** + * 请求权限并返回结果 + * * @param fragmentX target v4 fragment * @param requestCode requestCode * @param permissions permissions * @param grantResults grantResults */ - public static void handleResult(@NonNull androidx.fragment.app.Fragment fragmentX, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - handleResult(null, fragmentX, null, requestCode, permissions, grantResults); + public static void handleResult(Fraction fragmentX, int requestCode, String[] permissions, int[] grantResults) { + handleResult(null, fragmentX, requestCode, permissions, grantResults); } /** - * @param fragment target fragment - * @param requestCode requestCode - * @param permissions permissions - * @param grantResults grantResults + * 请求权限并返回结果 + * + * @param activity + * @param fragmentX + * @param requestCode + * @param permissions + * @param grantResults */ - @Deprecated - public static void handleResult(@NonNull android.app.Fragment fragment, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - handleResult(null, null, fragment, requestCode, permissions, grantResults); - } - - @SuppressWarnings("deprecation") - private static void handleResult(final android.app.Activity activity, final androidx.fragment.app.Fragment fragmentX, final android.app.Fragment fragment, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (instance == null) return; + private static void handleResult(final Ability activity, + final Fraction fragmentX, int requestCode, String[] permissions, + int[] grantResults) { + if (instance == null) { + return; + } if (requestCode == instance.key) { for (int i = 0; i < permissions.length; i++) { - if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { + if (grantResults[i] == IBundleManager.PERMISSION_GRANTED) { instance.permissionsGranted.add(PermissionEnum.fromManifestPermission(permissions[i])); } else { boolean permissionsDeniedForever = false; if (activity != null) { - permissionsDeniedForever = ActivityCompat.shouldShowRequestPermissionRationale(activity, permissions[i]); - } else if (fragment != null) { - permissionsDeniedForever = FragmentCompat.shouldShowRequestPermissionRationale(fragment, permissions[i]); + permissionsDeniedForever = activity.canRequestPermission(permissions[i]); } else if (fragmentX != null) { - permissionsDeniedForever = fragmentX.shouldShowRequestPermissionRationale(permissions[i]); + permissionsDeniedForever = fragmentX.getFractionAbility().canRequestPermission(permissions[i]); } if (!permissionsDeniedForever) { instance.permissionsDeniedForever.add(PermissionEnum.fromManifestPermission(permissions[i])); @@ -123,19 +139,20 @@ public class PermissionManager { } if (instance.permissionToAsk.size() != 0 && instance.askAgain) { instance.askAgain = false; - if (instance.askAgainCallback != null && instance.permissionsDeniedForever.size() != instance.permissionsDenied.size()) { + if (instance.askAgainCallback != null && instance.permissionsDeniedForever.size() + != instance.permissionsDenied.size()) { instance.askAgainCallback.showRequestPermission(new AskAgainCallback.UserResponse() { @Override public void result(boolean askAgain) { if (askAgain) { - instance.ask(activity, fragmentX, fragment); + instance.ask(activity, fragmentX); } else { instance.showResult(); } } }); } else { - instance.ask(activity, fragmentX, fragment); + instance.ask(activity, fragmentX); } } else { instance.showResult(); @@ -154,6 +171,8 @@ public class PermissionManager { } /** + * 请求的权限 + * * @param permission permission you need to ask * @return current instance */ @@ -164,6 +183,8 @@ public class PermissionManager { } /** + * 请求多个权限 + * * @param permissions permission you need to ask * @return current instance */ @@ -174,7 +195,9 @@ public class PermissionManager { } /** - * @param askAgain ask again when permission not granted + * 在未授予权限时再次询问 + * + * @param askAgain 在未授予权限时再次询问 * @return current instance */ public PermissionManager askAgain(boolean askAgain) { @@ -183,18 +206,22 @@ public class PermissionManager { } /** - * @param fullCallback set fullCallback for the request + * 放入回调事件 + * + * @param callback 为请求设置FullCallback * @return current instance */ - public PermissionManager callback(FullCallback fullCallback) { + public PermissionManager callback(FullCallback callback) { this.simpleCallback = null; this.smartCallback = null; - this.fullCallback = fullCallback; + this.fullCallback = callback; return this; } /** - * @param simpleCallback set simpleCallback for the request + * 为请求设置simpleCallback + * + * @param simpleCallback 为请求设置simpleCallback * @return current instance */ public PermissionManager callback(SimpleCallback simpleCallback) { @@ -205,7 +232,9 @@ public class PermissionManager { } /** - * @param smartCallback set smartCallback for the request + * 为请求设置smartCallback + * + * @param smartCallback 为请求设置askAgainCallback * @return current instance */ public PermissionManager callback(SmartCallback smartCallback) { @@ -216,7 +245,9 @@ public class PermissionManager { } /** - * @param askAgainCallback set askAgainCallback for the request + * 为请求设置askAgainCallback + * + * @param askAgainCallback 为请求设置askAgainCallback * @return current instance */ public PermissionManager askAgainCallback(AskAgainCallback askAgainCallback) { @@ -225,8 +256,10 @@ public class PermissionManager { } /** - * @param key set a custom request code - * @return current instance + * 设置自定义请求代码 + * + * @param key 设置自定义请求代码 + * @return current 单例 */ public PermissionManager key(int key) { this.key = key; @@ -234,67 +267,58 @@ public class PermissionManager { } /** + * 请求事件 + * * @param activity target activity - * just start all permission manager + * 只需启动所有权限管理器 */ - public void ask(android.app.Activity activity) { - ask(activity, null, null); + public void ask(Ability activity) { + ask(activity, null); } /** + * 请求事件重载 + * * @param fragmentX target v4 fragment - * just start all permission manager + * 只需启动所有权限管理器 */ - public void ask(androidx.fragment.app.Fragment fragmentX) { - ask(null, fragmentX, null); + public void ask(Fraction fragmentX) { + ask(null, fragmentX); } /** - * @param fragment target fragment - * just start all permission manager + * 开始请求权限 + * + * @param activity + * @param fragmentX */ - @Deprecated - public void ask(android.app.Fragment fragment) { - ask(null, null, fragment); - } - - @SuppressWarnings("deprecation") - private void ask(android.app.Activity activity, androidx.fragment.app.Fragment fragmentX, android.app.Fragment fragment) { + private void ask(Ability activity, Fraction fragmentX) { initArray(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - String[] permissionToAsk = permissionToAsk(activity, fragmentX, fragment); - if (permissionToAsk.length == 0) { - showResult(); - } else { - if (activity != null) { - ActivityCompat.requestPermissions(activity, permissionToAsk, key); - } else if (fragment != null) { - FragmentCompat.requestPermissions(fragment, permissionToAsk, key); - } else if (fragmentX != null) { - fragmentX.requestPermissions(permissionToAsk, key); - } - } - } else { - permissionsGranted.addAll(permissions); + String[] permissionToAsk = permissionToAsk(activity, fragmentX); + if (permissionToAsk.length == 0) { showResult(); + } else { + if (activity != null) { + activity.requestPermissionsFromUser(permissionToAsk, key); + } else if (fragmentX != null) { + fragmentX.getFractionAbility().requestPermissionsFromUser(permissionToAsk, key); + } } } /** - * @return permission that you really need to ask + * 得到请求的权限 + * + * @return 需要请求的权限 */ - @SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") - @NonNull - private String[] permissionToAsk(android.app.Activity activity, androidx.fragment.app.Fragment fragmentX, android.app.Fragment fragment) { + private String[] permissionToAsk(Ability activity, Fraction fragmentX) { ArrayList permissionToAsk = new ArrayList<>(); for (PermissionEnum permission : permissions) { boolean isGranted = false; if (activity != null) { isGranted = PermissionUtils.isGranted(activity, permission); - } else if (fragment != null) { - isGranted = PermissionUtils.isGranted(fragment.getActivity(), permission); } else if (fragmentX != null) { - isGranted = PermissionUtils.isGranted(fragmentX.getActivity(), permission); + isGranted = PermissionUtils.isGranted(fragmentX.getFractionAbility(), permission); } if (!isGranted) { permissionToAsk.add(permission.toString()); @@ -316,16 +340,19 @@ public class PermissionManager { } /** - * check if one of three types of callback are not null and pass data + * 检查三种回调类型之一是否不为null并传递数据 */ private void showResult() { - if (simpleCallback != null) + if (simpleCallback != null) { simpleCallback.result(permissionToAsk.size() == 0 || permissionToAsk.size() == permissionsGranted.size()); - if (fullCallback != null) + } + if (fullCallback != null) { fullCallback.result(permissionsGranted, permissionsDenied, permissionsDeniedForever, permissions); - if (smartCallback != null) - smartCallback.result(permissionToAsk.size() == 0 || permissionToAsk.size() == permissionsGranted.size(), !permissionsDeniedForever.isEmpty()); + } + if (smartCallback != null) { + smartCallback.result(permissionToAsk.size() == 0 || permissionToAsk.size() == permissionsGranted.size(), + !permissionsDeniedForever.isEmpty()); + } instance = null; } - } \ No newline at end of file diff --git a/library/src/main/java/rebus/permissionutils/PermissionUtils.java b/library/src/main/java/rebus/permissionutils/PermissionUtils.java old mode 100755 new mode 100644 index ff073cbb866e425cb66b735643a6d79392264e7e..bff2d6889c08abd740512750d6967a4641012665 --- a/library/src/main/java/rebus/permissionutils/PermissionUtils.java +++ b/library/src/main/java/rebus/permissionutils/PermissionUtils.java @@ -24,33 +24,43 @@ package rebus.permissionutils; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.Build; - -import androidx.core.content.ContextCompat; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.app.Context; +import ohos.bundle.IBundleManager; +import ohos.utils.IntentConstants; +import ohos.utils.net.Uri; /** - * Created by raphaelbussa on 22/06/16. + * 权限工具类 + * + * @author:wjt + * @since 2021-04-06 */ -@SuppressWarnings({"unused", "WeakerAccess"}) public class PermissionUtils { + /** + * 私有构造不允许new + */ + private PermissionUtils() { + } /** - * @param context current context - * @param permission permission to check - * @return if permission is granted return true + * 如果权限允许,则返回true + * + * @param context 上下文 + * @param permission 请求的权限 + * @return 是否可以申请权限 */ public static boolean isGranted(Context context, PermissionEnum permission) { - return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(context, permission.toString()) == PackageManager.PERMISSION_GRANTED; + return context.verifySelfPermission(permission.toString()) == IBundleManager.PERMISSION_GRANTED; } /** - * @param context current context + * 判读权限是否允许 + * + * @param context current context * @param permission all permission you need to check - * @return if one of permission is not granted return false + * @return 如果有一项权限未授予, 返回false */ public static boolean isGranted(Context context, PermissionEnum... permission) { for (PermissionEnum permissionEnum : permission) { @@ -62,21 +72,15 @@ public class PermissionUtils { } /** - * @param packageName package name of your app - * @return an intent to start for open settings app - */ - public static Intent openApplicationSettings(String packageName) { - Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.parse("package:" + packageName)); - return intent; - } - - /** - * @param context current context - * @param packageName package name of your app + * 打开设置页面 + * + * @param context current context */ - public static void openApplicationSettings(Context context, String packageName) { - context.startActivity(openApplicationSettings(packageName)); + public static void openApplicationSettings(Ability context) { + Intent intent = new Intent(); + intent.setAction(IntentConstants.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.setUri(Uri.parse("package:" + context.getBundleName())); + context.startAbility(intent, 1); } } diff --git a/library/src/main/java/rebus/permissionutils/SimpleCallback.java b/library/src/main/java/rebus/permissionutils/SimpleCallback.java old mode 100755 new mode 100644 index 15368d3e7fb85e29d054a2bdd77447d43c41d935..1ec105a2b708a1001d7ca31fe931fdda077d265e --- a/library/src/main/java/rebus/permissionutils/SimpleCallback.java +++ b/library/src/main/java/rebus/permissionutils/SimpleCallback.java @@ -25,11 +25,16 @@ package rebus.permissionutils; /** - * Created by raphaelbussa on 22/06/16. + * 权限回调 + * + * @author:wjt + * @since 2021-03-20 */ public interface SimpleCallback { /** + * 表明是否所有许可请求都被允许 + * * @param allPermissionsGranted true if all permissions are granted */ void result(boolean allPermissionsGranted); diff --git a/library/src/main/java/rebus/permissionutils/SmartCallback.java b/library/src/main/java/rebus/permissionutils/SmartCallback.java index 01ba7007eea3d755cdbbbd0d67e4bfe52b30cff8..e71939e537c68a25e96d57924b9b0878871c30df 100644 --- a/library/src/main/java/rebus/permissionutils/SmartCallback.java +++ b/library/src/main/java/rebus/permissionutils/SmartCallback.java @@ -25,15 +25,17 @@ package rebus.permissionutils; /** - * Created by raphaelbussa on 16/11/16. + * 返回一个布尔值,表明是否所有许可请求都被允许;以及一个布尔值,表明是否永远拒绝某些许可权 + * + * @author:wjt + * @since 2021-04-06 */ - public interface SmartCallback { - /** - * @param allPermissionsGranted true if all permissions are granted - * @param somePermissionsDeniedForever true if one of asked permissions are denied forever + * 返回一个布尔值,表明是否所有许可请求都被允许;以及一个布尔值,表明是否永远拒绝某些许可权 + * + * @param allPermissionsGranted 表明是否所有许可请求都被允许 + * @param somePermissionsDeniedForever 表明是否永远拒绝某些许可权 */ void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever); - } diff --git a/library/src/main/res/values/library_permissionutils_strings.xml b/library/src/main/res/values/library_permissionutils_strings.xml deleted file mode 100644 index 58a45c74027877d3e9a00b0ba0e9a33b9e5262cf..0000000000000000000000000000000000000000 --- a/library/src/main/res/values/library_permissionutils_strings.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - year;owner - Raphaël Bussa - http://rebus007.altervista.org - Permission Utils - Check marshmallow permission easily - https://rebus007.github.io/PermissionUtils - @string/version - true - https://github.com/rebus007/PermissionUtils - mit - Raphaël Bussa - 2017 - \ No newline at end of file diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml deleted file mode 100644 index e0aa0c93b32883a9763d676944d2b6a4335161d3..0000000000000000000000000000000000000000 --- a/library/src/main/res/values/strings.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - Permission Utils - diff --git a/library/src/main/resources/base/element/string.json b/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6c298286373e6266fd910aac81429792f08df437 --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Library" + } + ] +} diff --git a/library/src/test/java/rebus/permissionutils/ExampleTest.java b/library/src/test/java/rebus/permissionutils/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d83e649ca5afc94164f5e2468e115fb7e7e434c5 --- /dev/null +++ b/library/src/test/java/rebus/permissionutils/ExampleTest.java @@ -0,0 +1,9 @@ +package rebus.permissionutils; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/sample/.gitignore b/sample/.gitignore deleted file mode 100644 index 42afabfd2abebf31384ca7797186a27a4b7dbee8..0000000000000000000000000000000000000000 --- a/sample/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index bc331c5eafbd9d5c0731434b7fcb525d5325ea0b..0000000000000000000000000000000000000000 --- a/sample/build.gradle +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -apply plugin: 'com.android.application' - -android { - - compileSdkVersion var.compileSdk - - defaultConfig { - applicationId "com.raphaelbussa.permissionutils.sample" - minSdkVersion var.minSdk - targetSdkVersion var.targetSdk - versionCode 1 - versionName "${var.version}" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - lintOptions { - abortOnError false - } -} - -dependencies { - implementation project(':library') - implementation 'com.google.android.material:material:1.0.0' - implementation 'androidx.appcompat:appcompat:1.0.2' -} diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro deleted file mode 100644 index fd8637fdef15a05c9617a5b02d9ca23fedfb075b..0000000000000000000000000000000000000000 --- a/sample/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/raphaelbussa/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# 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 *; -#} diff --git a/sample/src/androidTest/java/rebus/permissionutils/sample/ApplicationTest.java b/sample/src/androidTest/java/rebus/permissionutils/sample/ApplicationTest.java deleted file mode 100644 index 7366689e3db69addc7910f87cf7a842d980620f2..0000000000000000000000000000000000000000 --- a/sample/src/androidTest/java/rebus/permissionutils/sample/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package rebus.permissionutils.sample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml deleted file mode 100644 index 19b1eded7f0493de2bcc7e15ce4f82d5bcb316e0..0000000000000000000000000000000000000000 --- a/sample/src/main/AndroidManifest.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/src/main/ic_launcher-web.png b/sample/src/main/ic_launcher-web.png deleted file mode 100644 index f4508afd163de586589d15745eda13fc680fe837..0000000000000000000000000000000000000000 Binary files a/sample/src/main/ic_launcher-web.png and /dev/null differ diff --git a/sample/src/main/java/rebus/permissionutils/sample/FragmentActivity.java b/sample/src/main/java/rebus/permissionutils/sample/FragmentActivity.java deleted file mode 100644 index 66d164c1735c8bb34fe3ccad28eab4e3bf4fed0f..0000000000000000000000000000000000000000 --- a/sample/src/main/java/rebus/permissionutils/sample/FragmentActivity.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package rebus.permissionutils.sample; - -import android.os.Bundle; -import android.view.MenuItem; - -import androidx.appcompat.app.AppCompatActivity; - -public class FragmentActivity extends AppCompatActivity { - - private final static String SECOND_FRAGMENT = "SECOND_FRAGMENT"; - private final static String SECOND_FRAGMENT_X = "SECOND_FRAGMENT_X"; - - @SuppressWarnings("ConstantConditions") - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_fragment); - - boolean isFragmentX = getIntent().getExtras().getBoolean("IS_FRAGMENT_X"); - - if (getSupportActionBar() != null) { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle(isFragmentX ? "Fragment V4" : "Fragment"); - } - - if (isFragmentX) { - if (savedInstanceState == null) { - androidx.fragment.app.Fragment fragment = androidx.fragment.app.Fragment.instantiate(this, SecondFragmentX.class.getName()); - getSupportFragmentManager().beginTransaction() - .add(R.id.container, fragment, SECOND_FRAGMENT_X) - .commit(); - } - } else { - if (savedInstanceState == null) { - android.app.Fragment fragment = android.app.Fragment.instantiate(this, SecondFragment.class.getName()); - getFragmentManager().beginTransaction() - .add(R.id.container, fragment, SECOND_FRAGMENT) - .commit(); - } - } - - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - break; - } - return super.onOptionsItemSelected(item); - } - -} diff --git a/sample/src/main/java/rebus/permissionutils/sample/MainActivity.java b/sample/src/main/java/rebus/permissionutils/sample/MainActivity.java deleted file mode 100644 index 8a8b9826c53c3b10e8d5cc533e5ed166f585c356..0000000000000000000000000000000000000000 --- a/sample/src/main/java/rebus/permissionutils/sample/MainActivity.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package rebus.permissionutils.sample; - -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.text.Html; -import android.text.Spanned; -import android.text.method.LinkMovementMethod; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import android.widget.Toast; - -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import rebus.permissionutils.AskAgainCallback; -import rebus.permissionutils.FullCallback; -import rebus.permissionutils.PermissionEnum; -import rebus.permissionutils.PermissionManager; -import rebus.permissionutils.PermissionUtils; -import rebus.permissionutils.SimpleCallback; -import rebus.permissionutils.SmartCallback; - -public class MainActivity extends AppCompatActivity implements FullCallback { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - if (getSupportActionBar() != null) { - getSupportActionBar().setSubtitle("Activity"); - } - - Button askOnePermission = findViewById(R.id.ask_one_permission); - Button askThreePermission = findViewById(R.id.ask_three_permission); - Button askOnePermissionSimple = findViewById(R.id.ask_one_permission_simple); - Button askThreePermissionSimple = findViewById(R.id.ask_three_permission_simple); - Button askOnePermissionSmart = findViewById(R.id.ask_one_permission_smart); - Button askThreePermissionSmart = findViewById(R.id.ask_three_permission_smart); - - Button checkPermission = findViewById(R.id.check_permission); - - askOnePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(9000) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(MainActivity.this) - .ask(MainActivity.this); - } - }); - askThreePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(800) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(MainActivity.this) - .ask(MainActivity.this); - } - }); - askOnePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(700) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(MainActivity.this); - } - }); - askThreePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(600) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(MainActivity.this, PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(MainActivity.this); - } - }); - askOnePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2000) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(MainActivity.this); - } - }); - askThreePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2100) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(MainActivity.this, PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(MainActivity.this); - } - }); - checkPermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; - boolean granted = PermissionUtils.isGranted(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE); - Toast.makeText(MainActivity.this, permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show(); - } - }); - - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - PermissionManager.handleResult(this, requestCode, permissions, grantResults); - } - - @SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") - @Override - public void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked) { - List msg = new ArrayList<>(); - for (PermissionEnum permissionEnum : permissionsGranted) { - msg.add(permissionEnum.toString() + " [Granted]"); - } - for (PermissionEnum permissionEnum : permissionsDenied) { - msg.add(permissionEnum.toString() + " [Denied]"); - } - for (PermissionEnum permissionEnum : permissionsDeniedForever) { - msg.add(permissionEnum.toString() + " [DeniedForever]"); - } - for (PermissionEnum permissionEnum : permissionsAsked) { - msg.add(permissionEnum.toString() + " [Asked]"); - } - String[] items = msg.toArray(new String[msg.size()]); - new AlertDialog.Builder(MainActivity.this) - .setTitle("Permission result") - .setItems(items, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }) - .show(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_main, menu); - return super.onCreateOptionsMenu(menu); - } - - @SuppressWarnings("ConstantConditions") - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_settings: - PermissionUtils.openApplicationSettings(MainActivity.this, R.class.getPackage().getName()); - break; - case R.id.action_fragment_v4: - Intent fragmentV4 = new Intent(MainActivity.this, FragmentActivity.class); - fragmentV4.putExtra("IS_FRAGMENT_X", true); - startActivity(fragmentV4); - break; - case R.id.action_fragment: - Intent fragment = new Intent(MainActivity.this, FragmentActivity.class); - fragment.putExtra("IS_FRAGMENT_X", false); - startActivity(fragment); - break; - case R.id.action_info: - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(getString(R.string.action_info)); - builder.setMessage(fromHtml(getString(R.string.info_message))); - builder.setPositiveButton(getString(R.string.close), null); - AlertDialog dialog = builder.create(); - dialog.show(); - TextView textView = dialog.findViewById(android.R.id.message); - if (textView != null) { - textView.setMovementMethod(LinkMovementMethod.getInstance()); - } - break; - } - return super.onOptionsItemSelected(item); - } - - private void showDialog(final AskAgainCallback.UserResponse response) { - new AlertDialog.Builder(MainActivity.this) - .setTitle("Permission needed") - .setMessage("This app realy need to use this permission, you wont to authorize it?") - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(true); - } - }) - .setNegativeButton("NOT NOW", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(false); - } - }) - .setCancelable(false) - .show(); - } - - @SuppressWarnings("deprecation") - private Spanned fromHtml(String value) { - if (value == null) { - value = ""; - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return Html.fromHtml(value, Html.FROM_HTML_MODE_LEGACY); - } else { - return Html.fromHtml(value); - } - } - -} diff --git a/sample/src/main/java/rebus/permissionutils/sample/SecondFragment.java b/sample/src/main/java/rebus/permissionutils/sample/SecondFragment.java deleted file mode 100644 index 69ef0b875201694945ed153130950f8a43e18a4d..0000000000000000000000000000000000000000 --- a/sample/src/main/java/rebus/permissionutils/sample/SecondFragment.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package rebus.permissionutils.sample; - -import android.annotation.SuppressLint; -import android.app.Fragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.Toast; - -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import rebus.permissionutils.AskAgainCallback; -import rebus.permissionutils.FullCallback; -import rebus.permissionutils.PermissionEnum; -import rebus.permissionutils.PermissionManager; -import rebus.permissionutils.PermissionUtils; -import rebus.permissionutils.SimpleCallback; -import rebus.permissionutils.SmartCallback; - -public class SecondFragment extends Fragment implements FullCallback { - - private Button askOnePermission; - private Button askThreePermission; - private Button checkPermission; - private Button askOnePermissionSimple; - private Button askThreePermissionSimple; - private Button askOnePermissionSmart; - private Button askThreePermissionSmart; - - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_second, null); - askOnePermission = view.findViewById(R.id.ask_one_permission); - askThreePermission = view.findViewById(R.id.ask_three_permission); - checkPermission = view.findViewById(R.id.check_permission); - askOnePermissionSimple = view.findViewById(R.id.ask_one_permission_simple); - askThreePermissionSimple = view.findViewById(R.id.ask_three_permission_simple); - askOnePermissionSmart = view.findViewById(R.id.ask_one_permission_smart); - askThreePermissionSmart = view.findViewById(R.id.ask_three_permission_smart); - return view; - } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - askOnePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(9001) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(SecondFragment.this) - .ask(SecondFragment.this); - } - }); - askThreePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(801) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(SecondFragment.this) - .ask(SecondFragment.this); - } - }); - askOnePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(701) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragment.this); - } - }); - askThreePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(601) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(getActivity(), PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragment.this); - } - }); - askOnePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2001) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragment.this); - } - }); - askThreePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2101) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(getActivity(), PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragment.this); - } - }); - checkPermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; - boolean granted = PermissionUtils.isGranted(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE); - Toast.makeText(getActivity(), permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show(); - } - }); - } - - private void showDialog(final AskAgainCallback.UserResponse response) { - new AlertDialog.Builder(getActivity()) - .setTitle("Permission needed") - .setMessage("This app realy need to use this permission, you wont to authorize it?") - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(true); - } - }) - .setNegativeButton("NOT NOW", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(false); - } - }) - .setCancelable(false) - .show(); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - PermissionManager.handleResult(this, requestCode, permissions, grantResults); - } - - @SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") - @Override - public void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked) { - List msg = new ArrayList<>(); - for (PermissionEnum permissionEnum : permissionsGranted) { - msg.add(permissionEnum.toString() + " [Granted]"); - } - for (PermissionEnum permissionEnum : permissionsDenied) { - msg.add(permissionEnum.toString() + " [Denied]"); - } - for (PermissionEnum permissionEnum : permissionsDeniedForever) { - msg.add(permissionEnum.toString() + " [DeniedForever]"); - } - for (PermissionEnum permissionEnum : permissionsAsked) { - msg.add(permissionEnum.toString() + " [Asked]"); - } - String[] items = msg.toArray(new String[msg.size()]); - new AlertDialog.Builder(getActivity()) - .setTitle("Permission result") - .setItems(items, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }) - .show(); - } -} diff --git a/sample/src/main/java/rebus/permissionutils/sample/SecondFragmentX.java b/sample/src/main/java/rebus/permissionutils/sample/SecondFragmentX.java deleted file mode 100644 index e557d9ae7bb787e7082eb4a5e79a6fd4437237f8..0000000000000000000000000000000000000000 --- a/sample/src/main/java/rebus/permissionutils/sample/SecondFragmentX.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2017 Raphaël Bussa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package rebus.permissionutils.sample; - -import android.annotation.SuppressLint; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.Toast; - -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.Fragment; -import rebus.permissionutils.AskAgainCallback; -import rebus.permissionutils.FullCallback; -import rebus.permissionutils.PermissionEnum; -import rebus.permissionutils.PermissionManager; -import rebus.permissionutils.PermissionUtils; -import rebus.permissionutils.SimpleCallback; -import rebus.permissionutils.SmartCallback; - -public class SecondFragmentX extends Fragment implements FullCallback { - - private Button askOnePermission; - private Button askThreePermission; - private Button checkPermission; - private Button askOnePermissionSimple; - private Button askThreePermissionSimple; - private Button askOnePermissionSmart; - private Button askThreePermissionSmart; - - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_second, null); - askOnePermission = view.findViewById(R.id.ask_one_permission); - askThreePermission = view.findViewById(R.id.ask_three_permission); - checkPermission = view.findViewById(R.id.check_permission); - askOnePermissionSimple = view.findViewById(R.id.ask_one_permission_simple); - askThreePermissionSimple = view.findViewById(R.id.ask_three_permission_simple); - askOnePermissionSmart = view.findViewById(R.id.ask_one_permission_smart); - askThreePermissionSmart = view.findViewById(R.id.ask_three_permission_smart); - return view; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - askOnePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(9001) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(SecondFragmentX.this) - .ask(SecondFragmentX.this); - } - }); - askThreePermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(801) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(SecondFragmentX.this) - .ask(SecondFragmentX.this); - } - }); - askOnePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(701) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragmentX.this); - } - }); - askThreePermissionSimple.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(601) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SimpleCallback() { - @Override - public void result(boolean allPermissionsGranted) { - Toast.makeText(getActivity(), PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragmentX.this); - } - }); - askOnePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2001) - .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragmentX.this); - } - }); - askThreePermissionSmart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionManager.Builder() - .key(2101) - .permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS) - .askAgain(true) - .askAgainCallback(new AskAgainCallback() { - @Override - public void showRequestPermission(UserResponse response) { - showDialog(response); - } - }) - .callback(new SmartCallback() { - @Override - public void result(boolean allPermissionsGranted, boolean somePermissionsDeniedForever) { - Toast.makeText(getActivity(), PermissionEnum.GET_ACCOUNTS.toString() + ", " + PermissionEnum.ACCESS_FINE_LOCATION.toString() + ", " + PermissionEnum.READ_SMS.toString() + " allPermissionsGranted [" + allPermissionsGranted + "] somePermissionsDeniedForever [" + somePermissionsDeniedForever + "]", Toast.LENGTH_SHORT).show(); - } - }) - .ask(SecondFragmentX.this); - } - }); - checkPermission.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE; - boolean granted = PermissionUtils.isGranted(getActivity(), PermissionEnum.WRITE_EXTERNAL_STORAGE); - Toast.makeText(getActivity(), permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show(); - } - }); - } - - private void showDialog(final AskAgainCallback.UserResponse response) { - if (getActivity() == null) return; - new AlertDialog.Builder(getActivity()) - .setTitle("Permission needed") - .setMessage("This app realy need to use this permission, you wont to authorize it?") - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(true); - } - }) - .setNegativeButton("NOT NOW", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - response.result(false); - } - }) - .setCancelable(false) - .show(); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - PermissionManager.handleResult(this, requestCode, permissions, grantResults); - } - - @SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") - @Override - public void result(ArrayList permissionsGranted, ArrayList permissionsDenied, ArrayList permissionsDeniedForever, ArrayList permissionsAsked) { - List msg = new ArrayList<>(); - for (PermissionEnum permissionEnum : permissionsGranted) { - msg.add(permissionEnum.toString() + " [Granted]"); - } - for (PermissionEnum permissionEnum : permissionsDenied) { - msg.add(permissionEnum.toString() + " [Denied]"); - } - for (PermissionEnum permissionEnum : permissionsDeniedForever) { - msg.add(permissionEnum.toString() + " [DeniedForever]"); - } - for (PermissionEnum permissionEnum : permissionsAsked) { - msg.add(permissionEnum.toString() + " [Asked]"); - } - String[] items = msg.toArray(new String[msg.size()]); - if (getActivity() == null) return; - new AlertDialog.Builder(getActivity()) - .setTitle("Permission result") - .setItems(items, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - - } - }) - .show(); - } -} diff --git a/sample/src/main/res/layout/activity_fragment.xml b/sample/src/main/res/layout/activity_fragment.xml deleted file mode 100644 index 0854a96ba1ac10eb009ba7fe90076e95e15bbe52..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/activity_fragment.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml deleted file mode 100644 index 546b2391119da34811efe1c5b11c7e7641a36d5c..0000000000000000000000000000000000000000 --- a/sample/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - -