Remove Gingerbread support (in-memory crop)
This commit is contained in:
parent
80d0f0c754
commit
9d654fa2b3
|
|
@ -10,7 +10,7 @@ android {
|
|||
buildToolsVersion '21.1.1'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 21
|
||||
|
||||
testApplicationId 'com.soundcloud.android.crop.test'
|
||||
|
|
|
|||
|
|
@ -16,18 +16,15 @@
|
|||
|
||||
package com.soundcloud.android.crop;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapRegionDecoder;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.opengl.GLES10;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
|
|
@ -44,7 +41,6 @@ import java.util.concurrent.CountDownLatch;
|
|||
*/
|
||||
public class CropImageActivity extends MonitoredActivity {
|
||||
|
||||
private static final boolean IN_MEMORY_CROP = Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD_MR1;
|
||||
private static final int SIZE_DEFAULT = 2048;
|
||||
private static final int SIZE_LIMIT = 4096;
|
||||
|
||||
|
|
@ -254,11 +250,6 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* This should use the decode/crop/encode single step API so that the whole
|
||||
* (possibly large) Bitmap doesn't need to be read into memory
|
||||
*/
|
||||
private void onSaveClicked() {
|
||||
if (cropView == null || isSaving) {
|
||||
return;
|
||||
|
|
@ -283,27 +274,18 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
}
|
||||
}
|
||||
|
||||
if (IN_MEMORY_CROP && rotateBitmap != null) {
|
||||
croppedImage = inMemoryCrop(rotateBitmap, r, outWidth, outHeight);
|
||||
if (croppedImage != null) {
|
||||
imageView.setImageBitmapResetBase(croppedImage, true);
|
||||
imageView.center(true, true);
|
||||
imageView.highlightViews.clear();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
croppedImage = decodeRegionCrop(r, outWidth, outHeight);
|
||||
} catch (IllegalArgumentException e) {
|
||||
setResultException(e);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
croppedImage = decodeRegionCrop(r, outWidth, outHeight);
|
||||
} catch (IllegalArgumentException e) {
|
||||
setResultException(e);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (croppedImage != null) {
|
||||
imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true);
|
||||
imageView.center(true, true);
|
||||
imageView.highlightViews.clear();
|
||||
}
|
||||
if (croppedImage != null) {
|
||||
imageView.setImageRotateBitmapResetBase(new RotateBitmap(croppedImage, exifRotation), true);
|
||||
imageView.center(true, true);
|
||||
imageView.highlightViews.clear();
|
||||
}
|
||||
saveImage(croppedImage);
|
||||
}
|
||||
|
|
@ -323,7 +305,6 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@TargetApi(10)
|
||||
private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
|
||||
// Release memory now
|
||||
clearImageView();
|
||||
|
|
@ -374,33 +355,6 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
return croppedImage;
|
||||
}
|
||||
|
||||
private Bitmap inMemoryCrop(RotateBitmap rotateBitmap, Rect rect, int outWidth, int outHeight) {
|
||||
// In-memory crop means potential OOM errors,
|
||||
// but we have no choice as we can't selectively decode a bitmap with this API level
|
||||
System.gc();
|
||||
|
||||
Bitmap croppedImage = null;
|
||||
try {
|
||||
croppedImage = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.RGB_565);
|
||||
|
||||
Canvas canvas = new Canvas(croppedImage);
|
||||
RectF dstRect = new RectF(0, 0, rect.width(), rect.height());
|
||||
|
||||
Matrix m = new Matrix();
|
||||
m.setRectToRect(new RectF(rect), dstRect, Matrix.ScaleToFit.FILL);
|
||||
m.preConcat(rotateBitmap.getRotateMatrix());
|
||||
canvas.drawBitmap(rotateBitmap.getBitmap(), m, null);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.e("OOM cropping image: " + e.getMessage(), e);
|
||||
setResultException(e);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
// Release Bitmap memory as soon as possible
|
||||
clearImageView();
|
||||
return croppedImage;
|
||||
}
|
||||
|
||||
private void clearImageView() {
|
||||
imageView.clear();
|
||||
if (rotateBitmap != null) {
|
||||
|
|
@ -424,13 +378,10 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
CropUtil.closeSilently(outputStream);
|
||||
}
|
||||
|
||||
if (!IN_MEMORY_CROP) {
|
||||
// In-memory crop negates the rotation
|
||||
CropUtil.copyExifRotation(
|
||||
CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri),
|
||||
CropUtil.getFromMediaUri(this, getContentResolver(), saveUri)
|
||||
);
|
||||
}
|
||||
CropUtil.copyExifRotation(
|
||||
CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri),
|
||||
CropUtil.getFromMediaUri(this, getContentResolver(), saveUri)
|
||||
);
|
||||
|
||||
setResultUri(saveUri);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue