Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pqpo/SmartCropper
Browse files Browse the repository at this point in the history
  • Loading branch information
pqpo committed May 9, 2019
2 parents 9323526 + 6a03255 commit 1e3a657
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
// implementation 'com.github.pqpo:SmartCropper:v1.2.3'
// For developers using AndroidX in their applications
//implementation 'pub.devrel:easypermissions:3.0.0'

// For developers using the Android Support Library
implementation 'pub.devrel:easypermissions:2.0.1'
// compile 'com.github.pqpo:SmartCropper:v1.2.3'
}
24 changes: 18 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.pqpo.smartcropper">
xmlns:tools="http://schemas.android.com/tools"
package="me.pqpo.smartcropper">

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

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CropActivity"/>
<activity android:name=".CropActivity" />
</application>

</manifest>
43 changes: 41 additions & 2 deletions app/src/main/java/me/pqpo/smartcropper/CropActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.pqpo.smartcropper;

import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -8,7 +9,9 @@
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
Expand All @@ -20,11 +23,13 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import me.pqpo.smartcropperlib.SmartCropper;
import me.pqpo.smartcropperlib.view.CropImageView;
import pub.devrel.easypermissions.EasyPermissions;

public class CropActivity extends AppCompatActivity {
public class CropActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{

private static final String EXTRA_FROM_ALBUM = "extra_from_album";
private static final String EXTRA_CROPPED_FILE = "extra_cropped_file";
Expand Down Expand Up @@ -87,10 +92,38 @@ public void onClick(final View v) {
}

tempFile = new File(getExternalFilesDir("img"), "temp.jpg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
EasyPermissions.requestPermissions(
CropActivity.this,
"申请权限",
0,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA);
}else{
selectPhoto();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
// Some permissions have been granted
// ...
selectPhoto();
}

@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
// Some permissions have been denied
// ...
}

private void selectPhoto() {
if (mFromAlbum) {
Intent selectIntent = new Intent(Intent.ACTION_PICK);
Expand All @@ -100,7 +133,13 @@ private void selectPhoto() {
}
} else {
Intent startCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(this, "me.pqpo.smartcropper.fileProvider", tempFile);
} else {
uri = Uri.fromFile(tempFile);
}
startCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
if (startCameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(startCameraIntent, REQUEST_CODE_TAKE_PHOTO);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_storage_root"
path="." />
</paths>

0 comments on commit 1e3a657

Please sign in to comment.