Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit a54c44c

Browse files
SUPERCILEXsamtstern
authored andcommitted
Prep for 1.0 release (#156)
1 parent 32ab68f commit a54c44c

26 files changed

+219
-326
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ android:
1818
- android-26
1919

2020
script: ./gradlew build
21+
22+
after_failure:
23+
- cat app/build/reports/tests/testDebugUnitTest/index.html

app/build.gradle

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ android {
1010
targetSdkVersion targetSdk
1111
versionCode 1
1212
versionName "1.0"
13-
14-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1513
}
1614

1715
buildTypes {
@@ -23,10 +21,7 @@ android {
2321
}
2422

2523
dependencies {
26-
compile "com.android.support:appcompat-v7:$support_library_version"
27-
28-
compile project(':easypermissions')
24+
implementation "com.android.support:appcompat-v7:$support_library_version"
2925

30-
testCompile 'junit:junit:4.12'
31-
testCompile 'org.robolectric:robolectric:3.4.2'
26+
implementation project(':easypermissions')
3227
}

app/src/main/AndroidManifest.xml

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
<uses-permission android:name="android.permission.READ_SMS" />
1313

1414
<application
15+
android:label="@string/app_name"
1516
android:allowBackup="true"
1617
android:icon="@mipmap/ic_launcher"
17-
android:label="@string/app_name"
1818
android:supportsRtl="true"
1919
android:theme="@style/AppTheme"
2020
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
21+
2122
<activity android:name=".MainActivity">
2223
<intent-filter>
2324
<action android:name="android.intent.action.MAIN" />
@@ -26,9 +27,6 @@
2627
</intent-filter>
2728
</activity>
2829

29-
<!-- For testing only -->
30-
<activity
31-
android:name=".BasicActivity"
32-
android:exported="true" />
3330
</application>
31+
3432
</manifest>

app/src/main/java/pub/devrel/easypermissions/sample/BasicActivity.java

-68
This file was deleted.

app/src/main/java/pub/devrel/easypermissions/sample/MainActivity.java

+39-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
3434

3535
private static final String TAG = "MainActivity";
36+
private static final String[] LOCATION_AND_CONTACTS =
37+
{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_CONTACTS};
3638

3739
private static final int RC_CAMERA_PERM = 123;
3840
private static final int RC_LOCATION_CONTACTS_PERM = 124;
@@ -59,33 +61,52 @@ public void onClick(View v) {
5961
});
6062
}
6163

64+
private boolean hasCameraPermission() {
65+
return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
66+
}
67+
68+
private boolean hasLocationAndContactsPermissions() {
69+
return EasyPermissions.hasPermissions(this, LOCATION_AND_CONTACTS);
70+
}
71+
72+
private boolean hasSmsPermission() {
73+
return EasyPermissions.hasPermissions(this, Manifest.permission.READ_SMS);
74+
}
75+
6276
@AfterPermissionGranted(RC_CAMERA_PERM)
6377
public void cameraTask() {
64-
if (EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA)) {
78+
if (hasCameraPermission()) {
6579
// Have permission, do the thing!
6680
Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
6781
} else {
6882
// Ask for one permission
69-
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera),
70-
RC_CAMERA_PERM, Manifest.permission.CAMERA);
83+
EasyPermissions.requestPermissions(
84+
this,
85+
getString(R.string.rationale_camera),
86+
RC_CAMERA_PERM,
87+
Manifest.permission.CAMERA);
7188
}
7289
}
7390

7491
@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
7592
public void locationAndContactsTask() {
76-
String[] perms = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_CONTACTS };
77-
if (EasyPermissions.hasPermissions(this, perms)) {
93+
if (hasLocationAndContactsPermissions()) {
7894
// Have permissions, do the thing!
7995
Toast.makeText(this, "TODO: Location and Contacts things", Toast.LENGTH_LONG).show();
8096
} else {
8197
// Ask for both permissions
82-
EasyPermissions.requestPermissions(this, getString(R.string.rationale_location_contacts),
83-
RC_LOCATION_CONTACTS_PERM, perms);
98+
EasyPermissions.requestPermissions(
99+
this,
100+
getString(R.string.rationale_location_contacts),
101+
RC_LOCATION_CONTACTS_PERM,
102+
LOCATION_AND_CONTACTS);
84103
}
85104
}
86105

87106
@Override
88-
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
107+
public void onRequestPermissionsResult(int requestCode,
108+
@NonNull String[] permissions,
109+
@NonNull int[] grantResults) {
89110
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
90111

91112
// EasyPermissions handles the request result.
@@ -113,8 +134,17 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
113134
super.onActivityResult(requestCode, resultCode, data);
114135

115136
if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
137+
String yes = getString(R.string.yes);
138+
String no = getString(R.string.no);
139+
116140
// Do something after user returned from app settings screen, like showing a Toast.
117-
Toast.makeText(this, R.string.returned_from_app_settings_to_activity, Toast.LENGTH_SHORT)
141+
Toast.makeText(
142+
this,
143+
getString(R.string.returned_from_app_settings_to_activity,
144+
hasCameraPermission() ? yes : no,
145+
hasLocationAndContactsPermissions() ? yes : no,
146+
hasSmsPermission() ? yes : no),
147+
Toast.LENGTH_LONG)
118148
.show();
119149
}
120150
}

app/src/main/res/values/strings.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<resources>
22
<string name="app_name">Easy Permissions</string>
3+
<string name="yes">Yes</string>
4+
<string name="no">No</string>
5+
36
<string name="rationale_camera">This app needs access to your camera so you can take pictures.</string>
47
<string name="rationale_location_contacts">This app needs access to your location and contacts to know where and who you are.</string>
58
<string name="rationale_sms">This app needs access to your sms to read all your great messages.</string>
6-
<string name="returned_from_app_settings_to_activity">Returned from app settings to MainActivity</string>
9+
<string name="returned_from_app_settings_to_activity">
10+
Returned from app settings to MainActivity with the following permissions:
11+
\n\nCamera: %s
12+
\nLocation &amp; Contacts: %s
13+
\nSMS: %s
14+
</string>
715
<string name="camera">Camera</string>
816
<string name="location_and_contacts">Location and Contacts</string>
917
<string name="sms">SMS</string>

app/src/test/java/pub/devrel/easypermissions/sample/EasyPermissionsLowApiTest.java

-43
This file was deleted.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
8+
classpath 'com.android.tools.build:gradle:3.0.0-beta3'
99

1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

easypermissions/build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ android {
2020
}
2121

2222
dependencies {
23-
compile "com.android.support:appcompat-v7:$support_library_version"
23+
implementation "com.android.support:appcompat-v7:$support_library_version"
24+
api "com.android.support:support-compat:$support_library_version"
25+
api "com.android.support:support-fragment:$support_library_version"
26+
27+
testImplementation 'junit:junit:4.12'
28+
testImplementation 'org.robolectric:robolectric:3.4.2'
2429
}
2530

2631
apply from: 'maven.gradle'

0 commit comments

Comments
 (0)