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

Prep for 1.0 release #156

Merged
merged 7 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.

2 changes: 1 addition & 1 deletion 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 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I removed appcompat-v7 from the demo project, I couldn't get it to compile without these api declarations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is working as intended. Some of the AppCompat classes are part of our public API, so we need an api dependency on them.


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

apply from: 'maven.gradle'
Expand Down
Loading