map = new HashMap<>();
20 | // for(String p : perissions){
21 | // map.put(p, p);
22 | // }
23 | //
24 | // PermissionSuccess hasPermissions = method.getAnnotation(PermissionSuccess.class);
25 | //
26 | // String[] pems = hasPermissions.values();
27 | // if(perissions.length == pems.length){
28 | // boolean match = true;
29 | // for(String pem : pems){
30 | // if(!map.get(pem).equals(pem)){
31 | // match = false;
32 | // }
33 | // }
34 | // if(match) return true;
35 | // }
36 | // return false;
37 | //}
38 | }
39 |
--------------------------------------------------------------------------------
/permissiongen-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | ### Android ###
9 | # Built application files
10 | *.apk
11 | *.ap_
12 |
13 | # Files for the Dalvik VM
14 | *.dex
15 |
16 | # Java class files
17 | *.class
18 |
19 | # Generated files
20 | bin/
21 | gen/
22 |
23 | # Gradle files
24 | .gradle/
25 | build/
26 |
27 | # Local configuration file (sdk path, etc)
28 | local.properties
29 |
30 | # Proguard folder generated by Eclipse
31 | proguard/
32 |
33 | # Log Files
34 | *.log
35 |
36 | # Android Studio Navigation editor temp files
37 | .navigation/
38 |
39 | ### Android Patch ###
40 | gen-external-apklibs
41 |
42 | # Created by https://www.gitignore.io/api/intellij
43 |
44 | ### Intellij ###
45 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
46 |
47 | *.iml
48 |
49 | ## Directory-based project format:
50 | .idea/
51 | # if you remove the above rule, at least ignore the following:
52 |
53 | # User-specific stuff:
54 | # .idea/workspace.xml
55 | # .idea/tasks.xml
56 | # .idea/dictionaries
57 |
58 | # Sensitive or high-churn files:
59 | # .idea/dataSources.ids
60 | # .idea/dataSources.xml
61 | # .idea/sqlDataSources.xml
62 | # .idea/dynamic.xml
63 | # .idea/uiDesigner.xml
64 |
65 | # Gradle:
66 | # .idea/gradle.xml
67 | # .idea/libraries
68 |
69 | # Mongo Explorer plugin:
70 | # .idea/mongoSettings.xml
71 |
72 | ## File-based project format:
73 | *.ipr
74 | *.iws
75 |
76 | ## Plugin-specific files:
77 |
78 | # IntelliJ
79 | /out/
80 |
81 | # mpeltonen/sbt-idea plugin
82 | .idea_modules/
83 |
84 | # JIRA plugin
85 | atlassian-ide-plugin.xml
86 |
87 | # Crashlytics plugin (for Android Studio and IntelliJ)
88 | com_crashlytics_export_strings.xml
89 | crashlytics.properties
90 | crashlytics-build.properties
91 |
--------------------------------------------------------------------------------
/permissiongen-sample/src/main/java/kr/co/namee/permissiongen_sample/Dlog.java:
--------------------------------------------------------------------------------
1 | package kr.co.namee.permissiongen_sample;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 | import android.util.Log;
8 | import kr.co.namee.permissiongen.BuildConfig;
9 |
10 | /**
11 | * Created by namee on 2014. 11. 13..
12 | */
13 | public class Dlog {
14 | public static final String TAG = "NAMEE";
15 | public static final String OS = "AND";
16 |
17 | public static void debug(String str) {
18 | //if (!BuildConfig.DEBUG) return;
19 | Log.d(TAG, buildLogMsg(str));
20 | }
21 |
22 | public static void debug(String str, Throwable t) {
23 | if (!BuildConfig.DEBUG) return;
24 | Log.d(TAG, buildLogMsg(str), t);
25 | }
26 |
27 | public static void error(String str) {
28 | if (!BuildConfig.DEBUG) return;
29 | Log.e(TAG, buildLogMsg(str));
30 | }
31 |
32 | public static void error(String str, Throwable t) {
33 | if (!BuildConfig.DEBUG) return;
34 | Log.e(TAG, buildLogMsg(str), t);
35 | }
36 |
37 | /**
38 | * 앱 버젼
39 | *
40 | * @return version
41 | */
42 | public static int getAppVersion(Context context) {
43 | try {
44 | PackageInfo packageInfo =
45 | context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
46 | return packageInfo.versionCode;
47 | } catch (PackageManager.NameNotFoundException e) {
48 | throw new RuntimeException("Could not get package name: " + e);
49 | }
50 | }
51 |
52 | /**
53 | * 디바이스 고유값
54 | */
55 | public static String getDeviceSerialNumber() {
56 | try {
57 | return (String) Build.class.getField("SERIAL").get(null);
58 | } catch (Exception ignored) {
59 | return null;
60 | }
61 | }
62 |
63 | public static String buildLogMsg(String message) {
64 |
65 | StackTraceElement ste = Thread.currentThread().getStackTrace()[4];
66 |
67 | StringBuilder sb = new StringBuilder();
68 |
69 | sb.append("[");
70 | sb.append(ste.getFileName().replace(".java", ""));
71 | sb.append("::");
72 | sb.append(ste.getMethodName());
73 | sb.append("]");
74 | sb.append(message);
75 |
76 | return sb.toString();
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/permissiongen-sample/src/main/java/kr/co/namee/permissiongen_sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package kr.co.namee.permissiongen_sample;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.Toast;
10 | import butterknife.Bind;
11 | import butterknife.ButterKnife;
12 | import butterknife.OnClick;
13 | import kr.co.namee.permissiongen.PermissionFail;
14 | import kr.co.namee.permissiongen.PermissionGen;
15 | import kr.co.namee.permissiongen.PermissionSuccess;
16 | import kr.co.namee.permissiongen_sample.contacts.ContactActivity;
17 |
18 | public class MainActivity extends AppCompatActivity {
19 | @Bind(R.id.btn_contact) Button btnContact;
20 | @Bind(R.id.btn_camera) Button btnCamera;
21 |
22 |
23 | @Override protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | ButterKnife.bind(this);
27 | }
28 |
29 | @OnClick({R.id.btn_contact, R.id.btn_camera})
30 | public void open(View view){
31 | switch (view.getId()){
32 | case R.id.btn_contact:
33 | PermissionGen.with(MainActivity.this)
34 | .addRequestCode(100)
35 | .permissions(
36 | Manifest.permission.READ_CONTACTS,
37 | Manifest.permission.RECEIVE_SMS,
38 | Manifest.permission.WRITE_CONTACTS)
39 | .request();
40 | break;
41 | case R.id.btn_camera:
42 | PermissionGen.needPermission(this, 200, Manifest.permission.CAMERA);
43 | break;
44 | }
45 | }
46 |
47 | @PermissionSuccess(requestCode = 100)
48 | public void test(){
49 | startActivity(new Intent(this, ContactActivity.class));
50 | }
51 |
52 | @PermissionFail(requestCode = 100)
53 | private void test2() {
54 | Dlog.debug("contact fail");
55 | }
56 |
57 | @PermissionSuccess(requestCode = 200)
58 | public void openCamera(){
59 | Dlog.debug("open camera success");
60 | }
61 |
62 | @PermissionFail(requestCode = 200)
63 | public void failOpenCamera(){
64 | Toast.makeText(this, "Camera permission is not granted", Toast.LENGTH_SHORT).show();
65 | }
66 |
67 | @Override public void onRequestPermissionsResult(int requestCode, String[] permissions,
68 | int[] grantResults) {
69 | PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PermissionGen ([한글](https://github.com/lovedise/PermissionGen/blob/master/README-kr.md))
2 |
3 | [  ](https://bintray.com/lovedise/maven/PermissionGen/_latestVersion)
4 |
5 | ```PermissionGen``` can easily handle the permissions in the Android M.
6 |
7 | ##Download
8 |
9 | Grab via Maven:
10 |
11 | ```Maven
12 |
13 | com.lovedise
14 | permissiongen
15 | 0.0.6
16 |
17 | ```
18 |
19 | or Gradle:
20 |
21 | ```Gradle
22 | compile 'com.lovedise:permissiongen:0.0.6'
23 | ```
24 |
25 | ##Usage
26 | When you request permissions
27 |
28 | ```java
29 | PermissionGen.with(MainActivity.this)
30 | .addRequestCode(100)
31 | .permissions(
32 | Manifest.permission.READ_CONTACTS,
33 | Manifest.permission.RECEIVE_SMS,
34 | Manifest.permission.WRITE_CONTACTS)
35 | .request();
36 | ```
37 |
38 | or
39 |
40 | ```java
41 | PermissionGen.needPermission(ContactFragment.this, 100,
42 | new String[] {
43 | Manifest.permission.READ_CONTACTS,
44 | Manifest.permission.RECEIVE_SMS,
45 | Manifest.permission.WRITE_CONTACTS
46 | }
47 | );
48 | ```
49 |
50 | Override the onRequestPermissionsResult in activity or fragment and input this code.
51 |
52 | ```java
53 | @Override public void onRequestPermissionsResult(int requestCode, String[] permissions,
54 | int[] grantResults) {
55 | PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
56 | }
57 | ```
58 |
59 |
60 | When it succeeded in obtaining permission
61 |
62 | ```java
63 | @PermissionSuccess(requestCode = 100)
64 | public void doSomething(){
65 | Toast.makeText(this, "Contact permission is granted", Toast.LENGTH_SHORT).show();
66 | }
67 | ```
68 |
69 | When it failed in obtaining permission
70 |
71 | ```java
72 | @PermissionFail(requestCode = 100)
73 | public void doFailSomething(){
74 | Toast.makeText(this, "Contact permission is not granted", t.LENGTH_SHORT).show();
75 | }
76 | ```
77 |
78 | ##License
79 | ```
80 | Copyright 2015 Seunghwan Kim
81 |
82 | Licensed under the Apache License, Version 2.0 (the "License");
83 | you may not use this file except in compliance with the License.
84 | You may obtain a copy of the License at
85 |
86 | http://www.apache.org/licenses/LICENSE-2.0
87 |
88 | Unless required by applicable law or agreed to in writing, software
89 | distributed under the License is distributed on an "AS IS" BASIS,
90 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91 | See the License for the specific language governing permissions and
92 | limitations under the License.
93 | ```
94 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README-kr.md:
--------------------------------------------------------------------------------
1 | # PermissionGen ([Eng](https://github.com/lovedise/PermissionGen/blob/master/README.md))
2 |
3 | [  ](https://bintray.com/lovedise/maven/PermissionGen/_latestVersion)
4 |
5 | ```PermissionGen``` 은 Andorid M 에서 권한 관리를 쉽게 도와주는 라이브러리 입니다.
6 | ##설치방법
7 |
8 | Maven:
9 |
10 | ```Maven
11 |
12 | com.lovedise
13 | permissiongen
14 | 0.0.6
15 |
16 | ```
17 |
18 | or Gradle:
19 |
20 | ```Gradle
21 | compile 'com.lovedise:permissiongen:0.0.6'
22 | ```
23 |
24 | ##사용법
25 | 권한을 사용하는 곳에서 아래 코드를 호출합니다.
26 | requestCode 는 결과를 requestCode가 적용된 어노테이션에 매칭되어 실행 됩니다.
27 |
28 | ```java
29 | PermissionGen.with(MainActivity.this)
30 | .addRequestCode(100)
31 | .permissions(
32 | Manifest.permission.READ_CONTACTS,
33 | Manifest.permission.RECEIVE_SMS,
34 | Manifest.permission.WRITE_CONTACTS)
35 | .request();
36 | ```
37 |
38 | 또는 아래와 같이도 사용 가능합니다. 편한 방법으로 사용하시면 됩니다.
39 |
40 | ```java
41 | PermissionGen.needPermission(ContactFragment.this, 100,
42 | new String[] {
43 | Manifest.permission.READ_CONTACTS,
44 | Manifest.permission.RECEIVE_SMS,
45 | Manifest.permission.WRITE_CONTACTS
46 | }
47 | );
48 | ```
49 |
50 | 위에서 권한을 시도하면 Activity 또는 Fragment 에서 오버라이드한 onRequestPermissionsResult 에서 결과를 받을 수 있습니다.
51 | 그럼 아래와 같이 ```PermissionGen.onRequestPermissionsResult```
52 | 를 호출해야만 성공, 실패에 대한 어노테이션이 선언된 함수가 실행됩니다.
53 |
54 | ```java
55 | @Override public void onRequestPermissionsResult(int requestCode, String[] permissions,
56 | int[] grantResults) {
57 | PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
58 | }
59 | ```
60 |
61 | 위에서 호출한 결과로 권한들을 획득했으면 @PermissionSuccess 어노테이션이 선언된 메소드에 requestCode 와 일치하는 함수를 실행합니다.
62 |
63 | ```java
64 | @PermissionSuccess(requestCode = 100)
65 | public void doSomething(){
66 | Toast.makeText(this, "Contact permission is granted", Toast.LENGTH_SHORT).show();
67 | }
68 | ```
69 |
70 | 또는 권한이 하나의 퍼미션이라도 거부되었다면 @PermissionFail 어노테이션을 선언된 메소드에 requestCode 와 일치하는 함수를 실행합니다.
71 |
72 | ```java
73 | @PermissionFail(requestCode = 100)
74 | public void doFailSomething(){
75 | Toast.makeText(this, "Contact permission is not granted", t.LENGTH_SHORT).show();
76 | }
77 | ```
78 |
79 | 버그, 이슈, 텍스트수정등 어떤내용이라도 피드백 주시면 감사하겠습니다.
80 | 이슈나 Pull Request 를 이용주세요~~
81 |
82 | ##License
83 | ```
84 | Copyright 2015 Seunghwan Kim
85 |
86 | Licensed under the Apache License, Version 2.0 (the "License");
87 | you may not use this file except in compliance with the License.
88 | You may obtain a copy of the License at
89 |
90 | http://www.apache.org/licenses/LICENSE-2.0
91 |
92 | Unless required by applicable law or agreed to in writing, software
93 | distributed under the License is distributed on an "AS IS" BASIS,
94 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95 | See the License for the specific language governing permissions and
96 | limitations under the License.
97 | ```
--------------------------------------------------------------------------------
/permissiongen-sample/src/main/java/kr/co/namee/permissiongen_sample/contacts/ContactFragment.java:
--------------------------------------------------------------------------------
1 | package kr.co.namee.permissiongen_sample.contacts;
2 |
3 | import android.Manifest;
4 | import android.content.pm.PackageManager;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Toast;
11 | import kr.co.namee.permissiongen.PermissionFail;
12 | import kr.co.namee.permissiongen.PermissionGen;
13 | import kr.co.namee.permissiongen.PermissionSuccess;
14 | import kr.co.namee.permissiongen_sample.R;
15 |
16 | /**
17 | * A simple {@link Fragment} subclass.
18 | */
19 | public class ContactFragment extends Fragment {
20 | public ContactFragment() {
21 | }
22 |
23 | @Override public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | if (getArguments() != null) {
26 | }
27 | }
28 |
29 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
30 | Bundle savedInstanceState) {
31 | View v = inflater.inflate(R.layout.fragment_contact, container, false);
32 | v.findViewById(R.id.btn_camera).setOnClickListener(new View.OnClickListener() {
33 | @Override public void onClick(View v) {
34 | PermissionGen.with(ContactFragment.this)
35 | .addRequestCode(100)
36 | .permissions(
37 | Manifest.permission.READ_CONTACTS,
38 | Manifest.permission.RECEIVE_SMS,
39 | Manifest.permission.WRITE_CONTACTS)
40 | .request();
41 |
42 | //PermissionGen.needPermission(ContactFragment.this, 100, new String[] {
43 | // Manifest.permission.READ_CONTACTS, Manifest.permission.RECEIVE_SMS,
44 | // Manifest.permission.WRITE_CONTACTS
45 | //});
46 | }
47 | });
48 | return v;
49 | }
50 |
51 | @PermissionSuccess(requestCode = 100)
52 | public void openContact(){
53 | Toast.makeText(getActivity(), "Contact permission is granted", Toast.LENGTH_SHORT).show();
54 | }
55 |
56 | @PermissionFail(requestCode = 100)
57 | public void failContact() {
58 | Toast.makeText(getActivity(), "Contact permission is not granted", Toast.LENGTH_SHORT).show();
59 | }
60 | /**
61 | * Callback for the result from requesting permissions. This method
62 | * is invoked for every call on {@link #requestPermissions(String[], int)}.
63 | *
64 | * Note: It is possible that the permissions request interaction
65 | * with the user is interrupted. In this case you will receive empty permissions
66 | * and results arrays which should be treated as a cancellation.
67 | *
68 | *
69 | * @param requestCode The request code passed in {@link #requestPermissions(String[], int)}.
70 | * @param permissions The requested permissions. Never null.
71 | * @param grantResults The grant results for the corresponding permissions
72 | * which is either {@link PackageManager#PERMISSION_GRANTED}
73 | * or {@link PackageManager#PERMISSION_DENIED}. Never null.
74 | * @see #requestPermissions(String[], int)
75 | */
76 | @Override public void onRequestPermissionsResult(int requestCode, String[] permissions,
77 | int[] grantResults) {
78 | PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
79 | }
80 |
81 | public static Fragment newInstance() {
82 | return new ContactFragment();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/permissiongen/src/main/java/kr/co/namee/permissiongen/internal/Utils.java:
--------------------------------------------------------------------------------
1 | package kr.co.namee.permissiongen.internal;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 | import android.support.v4.app.Fragment;
8 | import java.lang.annotation.Annotation;
9 | import java.lang.reflect.Method;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import kr.co.namee.permissiongen.PermissionFail;
13 | import kr.co.namee.permissiongen.PermissionSuccess;
14 |
15 | /**
16 | * Created by namee on 2015. 11. 18..
17 | */
18 | final public class Utils {
19 | private Utils(){}
20 |
21 | public static boolean isOverMarshmallow() {
22 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
23 | }
24 |
25 | @TargetApi(value = Build.VERSION_CODES.M)
26 | public static List findDeniedPermissions(Activity activity, String... permission){
27 | List denyPermissions = new ArrayList<>();
28 | for(String value : permission){
29 | if(activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED){
30 | denyPermissions.add(value);
31 | }
32 | }
33 | return denyPermissions;
34 | }
35 |
36 | public static List findAnnotationMethods(Class clazz, Class extends Annotation> clazz1){
37 | List methods = new ArrayList<>();
38 | for(Method method : clazz.getDeclaredMethods()){
39 | if(method.isAnnotationPresent(clazz1)){
40 | methods.add(method);
41 | }
42 | }
43 | return methods;
44 | }
45 |
46 | public static Method findMethodPermissionFailWithRequestCode(Class clazz,
47 | Class permissionFailClass, int requestCode) {
48 | for(Method method : clazz.getDeclaredMethods()){
49 | if(method.isAnnotationPresent(permissionFailClass)){
50 | if(requestCode == method.getAnnotation(PermissionFail.class).requestCode()){
51 | return method;
52 | }
53 | }
54 | }
55 | return null;
56 | }
57 |
58 | public static boolean isEqualRequestCodeFromAnntation(Method m, Class clazz, int requestCode){
59 | if(clazz.equals(PermissionFail.class)){
60 | return requestCode == m.getAnnotation(PermissionFail.class).requestCode();
61 | } else if(clazz.equals(PermissionSuccess.class)){
62 | return requestCode == m.getAnnotation(PermissionSuccess.class).requestCode();
63 | } else {
64 | return false;
65 | }
66 | }
67 |
68 | public static Method findMethodWithRequestCode(Class clazz,
69 | Class annotation, int requestCode) {
70 | for(Method method : clazz.getDeclaredMethods()){
71 | if(method.isAnnotationPresent(annotation)){
72 | if(isEqualRequestCodeFromAnntation(method, annotation, requestCode)){
73 | return method;
74 | }
75 | }
76 | }
77 | return null;
78 | }
79 |
80 | public static Method findMethodPermissionSuccessWithRequestCode(Class clazz,
81 | Class permissionFailClass, int requestCode) {
82 | for(Method method : clazz.getDeclaredMethods()){
83 | if(method.isAnnotationPresent(permissionFailClass)){
84 | if(requestCode == method.getAnnotation(PermissionSuccess.class).requestCode()){
85 | return method;
86 | }
87 | }
88 | }
89 | return null;
90 | }
91 |
92 | public static Activity getActivity(Object object){
93 | if(object instanceof Fragment){
94 | return ((Fragment)object).getActivity();
95 | } else if(object instanceof Activity){
96 | return (Activity) object;
97 | }
98 | return null;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/permissiongen/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: "com.jfrog.bintray"
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "23.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 23
12 | versionCode 4
13 | versionName "0.1.1"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | debug {
22 | debuggable true
23 | }
24 | }
25 | }
26 |
27 | version "0.1.1"
28 | //1066b170a3e0eba4853ba07e7f0836560e740d7f
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | testCompile 'junit:junit:4.12'
32 | compile 'com.android.support:appcompat-v7:23.1.1'
33 | }
34 |
35 | def siteUrl = 'https://github.com/lovedise/PermissionGen' // Homepage URL of the library
36 | def gitUrl = 'https://github.com/lovedise/PermissionGen.git' // Git repository URL
37 |
38 | group = "com.lovedise"
39 |
40 |
41 | install {
42 | repositories.mavenInstaller {
43 | // This generates POM.xml with proper parameters
44 | pom {
45 | project {
46 | packaging 'aar'
47 |
48 | // Add your description here
49 | name 'PermissionGen'
50 | description = 'The project PermissionGen easy to use permission of Android M'
51 | url siteUrl
52 |
53 | // Set your license
54 | licenses {
55 | license {
56 | name 'The Apache Software License, Version 2.0'
57 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58 | }
59 | }
60 | developers {
61 | developer {
62 | id 'lovedise'
63 | name 'SeungHwan Kim'
64 | email 'lovedise@gmail.com'
65 | }
66 | }
67 | scm {
68 | connection gitUrl
69 | developerConnection gitUrl
70 | url siteUrl
71 |
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
78 | task sourcesJar(type: Jar) {
79 | from android.sourceSets.main.java.srcDirs
80 | classifier = 'sources'
81 | }
82 |
83 | afterEvaluate {
84 | javadoc.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
85 | }
86 |
87 | task javadoc(type: Javadoc) {
88 | source = android.sourceSets.main.java.srcDirs
89 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
90 | }
91 |
92 |
93 | task javadocJar(type: Jar, dependsOn: javadoc) {
94 | classifier = 'javadoc'
95 | from javadoc.destinationDir
96 |
97 | }
98 | artifacts {
99 | archives javadocJar
100 | archives sourcesJar
101 | }
102 |
103 |
104 |
105 | //Properties properties = new Properties()
106 | //properties.load(project.rootProject.file('local.properties').newDataInputStream())
107 |
108 | // https://github.com/bintray/gradle-bintray-plugin
109 | bintray {
110 | user = "lovedise"
111 | key = "1066b170a3e0eba4853ba07e7f0836560e740d7f"
112 | publish = true
113 | configurations = ['archives']
114 | pkg {
115 | repo = "maven"
116 | // it is the name that appears in bintray when logged
117 | name = "PermissionGen"
118 | websiteUrl = siteUrl
119 | vcsUrl = gitUrl
120 | licenses = ["Apache-2.0"]
121 | publish = true
122 | publicDownloadNumbers = true
123 |
124 | // version {
125 | // name = ""
126 | // desc = ""
127 | // vcsTag = ""
128 | // gpg {
129 | // sign = true //Determines whether to GPG sign the files. The default is false
130 | // passphrase = properties.getProperty("bintray.gpgPassword") //Optional. The passphrase for GPG signing'
131 | // }
132 | // }
133 | }
134 |
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/permissiongen/src/main/java/kr/co/namee/permissiongen/PermissionGen.java:
--------------------------------------------------------------------------------
1 | package kr.co.namee.permissiongen;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 | import android.support.v4.app.Fragment;
8 | import java.lang.reflect.InvocationTargetException;
9 | import java.lang.reflect.Method;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import kr.co.namee.permissiongen.internal.Utils;
13 |
14 | import static kr.co.namee.permissiongen.internal.Utils.getActivity;
15 |
16 | /**
17 | * Created by namee on 2015. 11. 17..
18 | */
19 | public class PermissionGen {
20 | private String[] mPermissions;
21 | private int mRequestCode;
22 | private Object object;
23 |
24 | private PermissionGen(Object object) {
25 | this.object = object;
26 | }
27 |
28 | public static PermissionGen with(Activity activity){
29 | return new PermissionGen(activity);
30 | }
31 |
32 | public static PermissionGen with(Fragment fragment){
33 | return new PermissionGen(fragment);
34 | }
35 | public PermissionGen permissions(String... permissions){
36 | this.mPermissions = permissions;
37 | return this;
38 | }
39 |
40 | public PermissionGen addRequestCode(int requestCode){
41 | this.mRequestCode = requestCode;
42 | return this;
43 | }
44 |
45 | @TargetApi(value = Build.VERSION_CODES.M)
46 | public void request(){
47 | requestPermissions(object, mRequestCode, mPermissions);
48 | }
49 |
50 | public static void needPermission(Activity activity, int requestCode, String[] permissions){
51 | requestPermissions(activity, requestCode, permissions);
52 | }
53 |
54 | public static void needPermission(Fragment fragment, int requestCode, String[] permissions){
55 | requestPermissions(fragment, requestCode, permissions);
56 | }
57 |
58 | public static void needPermission(Activity activity, int requestCode, String permission){
59 | needPermission(activity, requestCode, new String[] { permission });
60 | }
61 |
62 | public static void needPermission(Fragment fragment, int requestCode, String permission){
63 | needPermission(fragment, requestCode, new String[] { permission });
64 | }
65 |
66 | @TargetApi(value = Build.VERSION_CODES.M)
67 | private static void requestPermissions(Object object, int requestCode, String[] permissions){
68 | if(!Utils.isOverMarshmallow()) {
69 | doExecuteSuccess(object, requestCode);
70 | return;
71 | }
72 | List deniedPermissions = Utils.findDeniedPermissions(getActivity(object), permissions);
73 |
74 | if(deniedPermissions.size() > 0){
75 | if(object instanceof Activity){
76 | ((Activity)object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode);
77 | } else if(object instanceof Fragment){
78 | ((Fragment)object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode);
79 | } else {
80 | throw new IllegalArgumentException(object.getClass().getName() + " is not supported");
81 | }
82 |
83 | } else {
84 | doExecuteSuccess(object, requestCode);
85 | }
86 | }
87 |
88 |
89 | private static void doExecuteSuccess(Object activity, int requestCode) {
90 | Method executeMethod = Utils.findMethodWithRequestCode(activity.getClass(),
91 | PermissionSuccess.class, requestCode);
92 |
93 | executeMethod(activity, executeMethod);
94 | }
95 |
96 | private static void doExecuteFail(Object activity, int requestCode) {
97 | Method executeMethod = Utils.findMethodWithRequestCode(activity.getClass(),
98 | PermissionFail.class, requestCode);
99 |
100 | executeMethod(activity, executeMethod);
101 | }
102 |
103 | private static void executeMethod(Object activity, Method executeMethod) {
104 | if(executeMethod != null){
105 | try {
106 | if(!executeMethod.isAccessible()) executeMethod.setAccessible(true);
107 | executeMethod.invoke(activity, null);
108 | } catch (IllegalAccessException e) {
109 | e.printStackTrace();
110 | } catch (InvocationTargetException e) {
111 | e.printStackTrace();
112 | }
113 | }
114 | }
115 |
116 | public static void onRequestPermissionsResult(Activity activity, int requestCode, String[] permissions,
117 | int[] grantResults) {
118 | requestResult(activity, requestCode, permissions, grantResults);
119 | }
120 |
121 | public static void onRequestPermissionsResult(Fragment fragment, int requestCode, String[] permissions,
122 | int[] grantResults) {
123 | requestResult(fragment, requestCode, permissions, grantResults);
124 | }
125 |
126 | private static void requestResult(Object obj, int requestCode, String[] permissions,
127 | int[] grantResults){
128 | List deniedPermissions = new ArrayList<>();
129 | for(int i=0; i 0){
136 | doExecuteFail(obj, requestCode);
137 | } else {
138 | doExecuteSuccess(obj, requestCode);
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------