Skip to content

Commit

Permalink
Merge pull request #157 from googlesamples/version-1.0
Browse files Browse the repository at this point in the history
Version 1.0
  • Loading branch information
samtstern committed Aug 30, 2017
2 parents 32ab68f + 1b2fc70 commit 25302f5
Show file tree
Hide file tree
Showing 27 changed files with 221 additions and 328 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ android:
- android-26

script: ./gradlew build

after_failure:
- cat app/build/reports/tests/testDebugUnitTest/index.html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EasyPermissions is installed by adding the following dependency to your `build.g

```groovy
dependencies {
compile 'pub.devrel:easypermissions:0.4.3'
compile 'pub.devrel:easypermissions:1.0.0'
}
```

Expand Down
9 changes: 2 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ android {
targetSdkVersion targetSdk
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -23,10 +21,7 @@ android {
}

dependencies {
compile "com.android.support:appcompat-v7:$support_library_version"

compile project(':easypermissions')
implementation "com.android.support:appcompat-v7:$support_library_version"

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.4.2'
implementation project(':easypermissions')
}
8 changes: 3 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
<uses-permission android:name="android.permission.READ_SMS" />

<application
android:label="@string/app_name"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -26,9 +27,6 @@
</intent-filter>
</activity>

<!-- For testing only -->
<activity
android:name=".BasicActivity"
android:exported="true" />
</application>

</manifest>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {

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

private static final int RC_CAMERA_PERM = 123;
private static final int RC_LOCATION_CONTACTS_PERM = 124;
Expand All @@ -59,33 +61,52 @@ public void onClick(View v) {
});
}

private boolean hasCameraPermission() {
return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
}

private boolean hasLocationAndContactsPermissions() {
return EasyPermissions.hasPermissions(this, LOCATION_AND_CONTACTS);
}

private boolean hasSmsPermission() {
return EasyPermissions.hasPermissions(this, Manifest.permission.READ_SMS);
}

@AfterPermissionGranted(RC_CAMERA_PERM)
public void cameraTask() {
if (EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA)) {
if (hasCameraPermission()) {
// Have permission, do the thing!
Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
} else {
// Ask for one permission
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera),
RC_CAMERA_PERM, Manifest.permission.CAMERA);
EasyPermissions.requestPermissions(
this,
getString(R.string.rationale_camera),
RC_CAMERA_PERM,
Manifest.permission.CAMERA);
}
}

@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
public void locationAndContactsTask() {
String[] perms = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_CONTACTS };
if (EasyPermissions.hasPermissions(this, perms)) {
if (hasLocationAndContactsPermissions()) {
// Have permissions, do the thing!
Toast.makeText(this, "TODO: Location and Contacts things", Toast.LENGTH_LONG).show();
} else {
// Ask for both permissions
EasyPermissions.requestPermissions(this, getString(R.string.rationale_location_contacts),
RC_LOCATION_CONTACTS_PERM, perms);
EasyPermissions.requestPermissions(
this,
getString(R.string.rationale_location_contacts),
RC_LOCATION_CONTACTS_PERM,
LOCATION_AND_CONTACTS);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

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

if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
String yes = getString(R.string.yes);
String no = getString(R.string.no);

// Do something after user returned from app settings screen, like showing a Toast.
Toast.makeText(this, R.string.returned_from_app_settings_to_activity, Toast.LENGTH_SHORT)
Toast.makeText(
this,
getString(R.string.returned_from_app_settings_to_activity,
hasCameraPermission() ? yes : no,
hasLocationAndContactsPermissions() ? yes : no,
hasSmsPermission() ? yes : no),
Toast.LENGTH_LONG)
.show();
}
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<resources>
<string name="app_name">Easy Permissions</string>
<string name="yes">Yes</string>
<string name="no">No</string>

<string name="rationale_camera">This app needs access to your camera so you can take pictures.</string>
<string name="rationale_location_contacts">This app needs access to your location and contacts to know where and who you are.</string>
<string name="rationale_sms">This app needs access to your sms to read all your great messages.</string>
<string name="returned_from_app_settings_to_activity">Returned from app settings to MainActivity</string>
<string name="returned_from_app_settings_to_activity">
Returned from app settings to MainActivity with the following permissions:
\n\nCamera: %s
\nLocation &amp; Contacts: %s
\nSMS: %s
</string>
<string name="camera">Camera</string>
<string name="location_and_contacts">Location and Contacts</string>
<string name="sms">SMS</string>
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
classpath 'com.android.tools.build:gradle:3.0.0-beta3'

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
Expand All @@ -31,7 +31,7 @@ ext {

mavenGroup = 'pub.devrel'
mavenArtifactId = 'easypermissions'
mavenVersion = '0.4.3'
mavenVersion = '1.0.0'

bintrayOrg = 'easygoogle'

Expand Down
7 changes: 6 additions & 1 deletion easypermissions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ android {
}

dependencies {
compile "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
api "com.android.support:support-compat:$support_library_version"
api "com.android.support:support-fragment:$support_library_version"

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.4.2'
}

apply from: 'maven.gradle'
Expand Down
Loading

0 comments on commit 25302f5

Please sign in to comment.