Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur committed May 24, 2016
2 parents 78adc67 + f1e41c7 commit 8593889
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 101 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ For more information, see the [GitHub Wiki](https://github.com/ArthurHub/Android
- [Adding auto-zoom feature to Android-Image-Cropper](https://theartofdev.com/2016/04/25/adding-auto-zoom-feature-to-android-image-cropper/)

## Change log
*2.1.4*

- Support for requesting CAMERA permission for android M when CAMERA is requested in the manifest.
- Add `pick_image_intent_chooser_title` for changing and localizing pick image chooser title (thx maksymkhar).
- NPE when clicking crop twice fast (thx Jesse).

*2.1.1*

- Built-in `CropImageActivity` for quick start and common scenarios.
- Save cropped image to Uri API `saveCroppedImageAsync(Uri)`.
- Handle possible out-of-memory in image load by down-sampling until succeed.
Expand Down
2 changes: 1 addition & 1 deletion cropper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
ext {
PUBLISH_GROUP_ID = 'com.theartofdev.edmodo'
PUBLISH_ARTIFACT_ID = 'android-image-cropper'
PUBLISH_VERSION = '2.1.3'
PUBLISH_VERSION = '2.1.4'
// gradlew clean build generateRelease
}

Expand Down
273 changes: 199 additions & 74 deletions cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* All the possible options that can be set to customize crop image.<br>
* Initialized with default values.
*/
final class CropImageOptions implements Parcelable {
public class CropImageOptions implements Parcelable {

public static final Creator<CropImageOptions> CREATOR = new Creator<CropImageOptions>() {
@Override
Expand Down
5 changes: 4 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
package="com.example.croppersample"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault">
android:theme="@style/Theme.AppCompat">
<activity
android:name="com.theartofdev.edmodo.cropper.sample.MainActivity"
android:label="@string/app_title">
Expand All @@ -22,6 +23,8 @@
</activity>
<activity android:name="com.theartofdev.edmodo.cropper.sample.CropResultActivity">
</activity>
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity">
</activity>

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
package com.theartofdev.edmodo.cropper.sample;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
Expand All @@ -38,9 +40,10 @@ protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_crop_result);

imageView = ((ImageView) findViewById(R.id.resultImageView));
imageView.setBackgroundResource(R.drawable.backdrop);

if (mImage != null) {
imageView = ((ImageView) findViewById(R.id.resultImageView));
imageView.setBackgroundResource(R.drawable.backdrop);
imageView.setImageBitmap(mImage);
double ratio = ((int) (10 * mImage.getWidth() / (double) mImage.getHeight())) / 10d;
int byteCount = 0;
Expand All @@ -50,7 +53,13 @@ protected void onCreate(Bundle savedInstanceState) {
String desc = "(" + mImage.getWidth() + ", " + mImage.getHeight() + "), Ratio: " + ratio + ", Bytes: " + byteCount + "K";
((TextView) findViewById(R.id.resultImageText)).setText(desc);
} else {
Toast.makeText(this, "No image is set to show", Toast.LENGTH_LONG).show();
Intent intent = getIntent();
Uri imageUri = intent.getParcelableExtra("URI");
if (imageUri != null) {
imageView.setImageURI(imageUri);
} else {
Toast.makeText(this, "No image is set to show", Toast.LENGTH_LONG).show();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.util.Pair;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -34,7 +34,7 @@
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;

public class MainActivity extends Activity {
public class MainActivity extends AppCompatActivity {

//region: Fields and Consts

Expand Down Expand Up @@ -63,8 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

Expand Down Expand Up @@ -105,7 +105,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK) {
Uri imageUri = CropImage.getPickImageResultUri(this, data);

// For API >= 23 we need to check specifically that we have permissions to read external storage,
Expand All @@ -116,7 +118,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// request permissions and handle the result in onRequestPermissionsResult()
requirePermissions = true;
mCropImageUri = imageUri;
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
} else {

mCurrentFragment.setImageUri(imageUri);
Expand All @@ -126,17 +128,31 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (mCropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mCurrentFragment.setImageUri(mCropImageUri);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
if (requestCode == CropImage.CAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
CropImage.startPickImageActivity(this);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
if (requestCode == CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE) {
if (mCropImageUri != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mCurrentFragment.setImageUri(mCropImageUri);
} else {
Toast.makeText(this, "Cancelling, required permissions are not granted", Toast.LENGTH_LONG).show();
}
}
}

@SuppressLint("NewApi")
public void onDrawerOptionClicked(View view) {
switch (view.getId()) {
case R.id.drawer_option_load:
CropImage.startPickImageActivity(this);
if (CropImage.isExplicitCameraPermissionRequired(this)) {
requestPermissions(new String[]{Manifest.permission.CAMERA}, CropImage.CAMERA_CAPTURE_PERMISSIONS_REQUEST_CODE);
} else {
CropImage.startPickImageActivity(this);
}
mDrawerLayout.closeDrawers();
break;
case R.id.drawer_option_oval:
Expand Down Expand Up @@ -233,7 +249,7 @@ public void onDrawerOptionClicked(View view) {
}

private void setMainFragmentByPreset(CropDemoPreset demoPreset) {
FragmentManager fragmentManager = getFragmentManager();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, MainFragment.newInstance(demoPreset))
.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
package com.theartofdev.edmodo.cropper.sample;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -59,6 +59,8 @@ public static MainFragment newInstance(CropDemoPreset demoPreset) {
*/
public void setImageUri(Uri imageUri) {
mCropImageView.setImageUriAsync(imageUri);
// CropImage.activity(imageUri)
// .start(getContext(), this);
}

/**
Expand Down Expand Up @@ -191,11 +193,28 @@ public void onSetImageUriComplete(CropImageView view, Uri uri, Exception error)

@Override
public void onGetCroppedImageComplete(CropImageView view, Bitmap bitmap, Exception error) {
handleCropResult(null, bitmap, error);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
handleCropResult(result.getUri(), null, result.getError());
}
}

private void handleCropResult(Uri uri, Bitmap bitmap, Exception error) {
if (error == null) {
CropResultActivity.mImage = mCropImageView.getCropShape() == CropImageView.CropShape.OVAL
? CropImage.toOvalBitmap(bitmap)
: bitmap;
Intent intent = new Intent(getActivity(), CropResultActivity.class);
if (uri != null) {
intent.putExtra("URI", uri);
} else {
CropResultActivity.mImage = mCropImageView.getCropShape() == CropImageView.CropShape.OVAL
? CropImage.toOvalBitmap(bitmap)
: bitmap;
}
startActivity(intent);
} else {
Log.e("AIC", "Failed to crop image", error);
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<item
android:id="@+id/main_action_rotate"
android:icon="@android:drawable/ic_menu_rotate"
android:showAsAction="always"
android:title="@string/main_action_rotate"/>
android:title="@string/main_action_rotate"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/main_action_crop"
android:showAsAction="always"
android:title="@string/main_action_crop"/>
android:title="@string/main_action_crop"
app:showAsAction="always"/>

</menu>

0 comments on commit 8593889

Please sign in to comment.