summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/crop/CropActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/filtershow/crop/CropActivity.java')
-rw-r--r--src/com/android/gallery3d/filtershow/crop/CropActivity.java498
1 files changed, 325 insertions, 173 deletions
diff --git a/src/com/android/gallery3d/filtershow/crop/CropActivity.java b/src/com/android/gallery3d/filtershow/crop/CropActivity.java
index 26659a600..878b82fc6 100644
--- a/src/com/android/gallery3d/filtershow/crop/CropActivity.java
+++ b/src/com/android/gallery3d/filtershow/crop/CropActivity.java
@@ -21,11 +21,10 @@ import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
-import android.graphics.Point;
+import android.graphics.BitmapRegionDecoder;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.Uri;
@@ -34,8 +33,6 @@ import android.os.Bundle;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.util.Log;
-import android.util.TypedValue;
-import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
@@ -43,8 +40,11 @@ import android.widget.Toast;
import com.android.gallery3d.R;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
/**
@@ -52,19 +52,30 @@ import java.io.OutputStream;
*/
public class CropActivity extends Activity {
private static final String LOGTAG = "CropActivity";
+ public static final String CROP_ACTION = "com.android.camera.action.CROP";
private CropExtras mCropExtras = null;
private LoadBitmapTask mLoadBitmapTask = null;
- private SaveBitmapTask mSaveBitmapTask = null;
- private SetWallpaperTask mSetWallpaperTask = null;
+
private Bitmap mOriginalBitmap = null;
+ private RectF mOriginalBounds = null;
+ private Uri mSourceUri = null;
private CropView mCropView = null;
- private int mActiveBackgroundIO = 0;
+ private View mSaveButton = null;
+ private boolean finalIOGuard = false;
+
private Intent mResultIntent = null;
private static final int SELECT_PICTURE = 1; // request code for picker
- private static final int DEFAULT_DENSITY = 133;
+
private static final int DEFAULT_COMPRESS_QUALITY = 90;
public static final int MAX_BMAP_IN_INTENT = 990000;
+ // Flags
+ private static final int DO_SET_WALLPAPER = 1;
+ private static final int DO_RETURN_DATA = 1 << 1;
+ private static final int DO_EXTRA_OUTPUT = 1 << 2;
+
+ private static final int FLAG_CHECK = DO_SET_WALLPAPER | DO_RETURN_DATA | DO_EXTRA_OUTPUT;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -79,22 +90,30 @@ public class CropActivity extends Activity {
setContentView(R.layout.crop_activity);
mCropView = (CropView) findViewById(R.id.cropView);
- if (intent.getData() != null) {
- startLoadBitmap(intent.getData());
- } else {
- pickImage();
- }
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.filtershow_actionbar);
- View saveButton = actionBar.getCustomView();
- saveButton.setOnClickListener(new OnClickListener() {
+ View mSaveButton = actionBar.getCustomView();
+ mSaveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startFinishOutput();
}
});
+
+ if (intent.getData() != null) {
+ mSourceUri = intent.getData();
+ startLoadBitmap(mSourceUri);
+ } else {
+ pickImage();
+ }
+ }
+
+ private void enableSave(boolean enable) {
+ if (mSaveButton != null) {
+ mSaveButton.setEnabled(enable);
+ }
}
@Override
@@ -109,7 +128,7 @@ public class CropActivity extends Activity {
* Opens a selector in Gallery to chose an image for use when none was given
* in the CROP intent.
*/
- public void pickImage() {
+ private void pickImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
@@ -123,53 +142,25 @@ public class CropActivity extends Activity {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == SELECT_PICTURE) {
- Uri selectedImageUri = data.getData();
- startLoadBitmap(selectedImageUri);
+ mSourceUri = data.getData();
+ startLoadBitmap(mSourceUri);
}
}
/**
- * Gets the crop extras from the intent, or null if none exist.
- */
- public static CropExtras getExtrasFromIntent(Intent intent) {
- Bundle extras = intent.getExtras();
- if (extras != null) {
- return new CropExtras(extras.getInt(CropExtras.KEY_OUTPUT_X, 0),
- extras.getInt(CropExtras.KEY_OUTPUT_Y, 0),
- extras.getBoolean(CropExtras.KEY_SCALE, true) &&
- extras.getBoolean(CropExtras.KEY_SCALE_UP_IF_NEEDED, false),
- extras.getInt(CropExtras.KEY_ASPECT_X, 0),
- extras.getInt(CropExtras.KEY_ASPECT_Y, 0),
- extras.getBoolean(CropExtras.KEY_SET_AS_WALLPAPER, false),
- extras.getBoolean(CropExtras.KEY_RETURN_DATA, false),
- (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT),
- extras.getString(CropExtras.KEY_OUTPUT_FORMAT),
- extras.getBoolean(CropExtras.KEY_SHOW_WHEN_LOCKED, false),
- extras.getFloat(CropExtras.KEY_SPOTLIGHT_X),
- extras.getFloat(CropExtras.KEY_SPOTLIGHT_Y));
- }
- return null;
- }
-
- /**
* Gets screen size metric.
*/
private int getScreenImageSize() {
- DisplayMetrics metrics = new DisplayMetrics();
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
- display.getMetrics(metrics);
- int msize = Math.min(size.x, size.y);
- // TODO: WTF
- return (DEFAULT_DENSITY * msize) / metrics.densityDpi + 512;
+ DisplayMetrics outMetrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
+ return (int) Math.max(outMetrics.heightPixels, outMetrics.widthPixels);
}
/**
* Method that loads a bitmap in an async task.
*/
private void startLoadBitmap(Uri uri) {
- mActiveBackgroundIO++;
+ enableSave(false);
final View loading = findViewById(R.id.loading);
loading.setVisibility(View.VISIBLE);
mLoadBitmapTask = new LoadBitmapTask();
@@ -179,18 +170,19 @@ public class CropActivity extends Activity {
/**
* Method called on UI thread with loaded bitmap.
*/
- private void doneLoadBitmap(Bitmap bitmap) {
- mActiveBackgroundIO--;
+ private void doneLoadBitmap(Bitmap bitmap, RectF bounds) {
final View loading = findViewById(R.id.loading);
loading.setVisibility(View.GONE);
mOriginalBitmap = bitmap;
- // TODO: move these to dimens folder
- if (bitmap != null) {
- mCropView.setup(bitmap, (int) getPixelsFromDip(55), (int) getPixelsFromDip(25));
+ mOriginalBounds = bounds;
+ if (bitmap != null && bitmap.getWidth() != 0 && bitmap.getHeight() != 0) {
+ RectF imgBounds = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
+ mCropView.initialize(bitmap, imgBounds, imgBounds, 0);
+ enableSave(true);
} else {
Log.w(LOGTAG, "could not load image for cropping");
cannotLoadImage();
- setResult(RESULT_CANCELED, mResultIntent);
+ setResult(RESULT_CANCELED, new Intent());
done();
}
}
@@ -217,7 +209,6 @@ public class CropActivity extends Activity {
public LoadBitmapTask() {
mBitmapSize = getScreenImageSize();
- Log.v(LOGTAG, "bitmap size: " + mBitmapSize);
mContext = getApplicationContext();
mOriginalBounds = new Rect();
}
@@ -231,155 +222,279 @@ public class CropActivity extends Activity {
@Override
protected void onPostExecute(Bitmap result) {
- doneLoadBitmap(result);
- // super.onPostExecute(result);
+ doneLoadBitmap(result, new RectF(mOriginalBounds));
}
}
- private void startSaveBitmap(Bitmap bmap, Uri uri, String format) {
- if (bmap == null || uri == null) {
- throw new IllegalArgumentException("bad argument to startSaveBitmap");
+ private void startFinishOutput() {
+ if (finalIOGuard) {
+ return;
+ } else {
+ finalIOGuard = true;
}
- mActiveBackgroundIO++;
+ enableSave(false);
+ Uri destinationUri = null;
+ int flags = 0;
+ if (mOriginalBitmap != null && mCropExtras != null) {
+ if (mCropExtras.getExtraOutput() != null) {
+ destinationUri = mCropExtras.getExtraOutput();
+ flags |= DO_EXTRA_OUTPUT;
+ }
+ if (mCropExtras.getSetAsWallpaper()) {
+ flags |= DO_SET_WALLPAPER;
+ }
+ if (mCropExtras.getReturnData()) {
+ flags |= DO_RETURN_DATA;
+ }
+ }
+ if (flags == 0) {
+ destinationUri = CropLoader.makeAndInsertUri(this, mSourceUri);
+ if (destinationUri != null) {
+ flags |= DO_EXTRA_OUTPUT;
+ }
+ }
+ if ((flags & FLAG_CHECK) != 0) {
+ RectF photo = new RectF(0, 0, mOriginalBitmap.getWidth(), mOriginalBitmap.getHeight());
+ RectF crop = getBitmapCrop(photo);
+ startBitmapIO(flags, mOriginalBitmap, mSourceUri, destinationUri, crop,
+ photo, mOriginalBounds,
+ (mCropExtras == null) ? null : mCropExtras.getOutputFormat());
+ return;
+ }
+ setResult(RESULT_CANCELED, mResultIntent);
+ done();
+ return;
+ }
+
+ private void startBitmapIO(int flags, Bitmap currentBitmap, Uri sourceUri, Uri destUri,
+ RectF cropBounds, RectF photoBounds, RectF currentBitmapBounds, String format) {
+ if (cropBounds == null || photoBounds == null || currentBitmap == null
+ || currentBitmap.getWidth() == 0 || currentBitmap.getHeight() == 0
+ || cropBounds.width() == 0 || cropBounds.height() == 0 || photoBounds.width() == 0
+ || photoBounds.height() == 0) {
+ return; // fail fast
+ }
+ if ((flags & FLAG_CHECK) == 0) {
+ return; // no output options
+ }
+ if ((flags & DO_SET_WALLPAPER) != 0) {
+ Toast.makeText(this, R.string.setting_wallpaper, Toast.LENGTH_LONG).show();
+ }
+
final View loading = findViewById(R.id.loading);
loading.setVisibility(View.VISIBLE);
- mSaveBitmapTask = new SaveBitmapTask(uri, format);
- mSaveBitmapTask.execute(bmap);
+ BitmapIOTask ioTask = new BitmapIOTask(sourceUri, destUri, format, flags, cropBounds,
+ photoBounds, currentBitmapBounds);
+ ioTask.execute(currentBitmap);
}
- private void doneSaveBitmap(Uri uri) {
- mActiveBackgroundIO--;
+ private void doneBitmapIO(boolean success, Intent intent) {
final View loading = findViewById(R.id.loading);
loading.setVisibility(View.GONE);
- if (uri == null) {
- Log.w(LOGTAG, "failed to save bitmap");
- setResult(RESULT_CANCELED, mResultIntent);
- done();
- return;
+ if (success) {
+ setResult(RESULT_OK, intent);
+ } else {
+ setResult(RESULT_CANCELED, intent);
}
done();
}
- private class SaveBitmapTask extends AsyncTask<Bitmap, Void, Boolean> {
+ private class BitmapIOTask extends AsyncTask<Bitmap, Void, Boolean> {
+ private final WallpaperManager mWPManager;
+ InputStream mInStream = null;
OutputStream mOutStream = null;
String mOutputFormat = null;
Uri mOutUri = null;
-
- public SaveBitmapTask(Uri uri, String outputFormat) {
+ Uri mInUri = null;
+ int mFlags = 0;
+ RectF mCrop = null;
+ RectF mPhoto = null;
+ RectF mOrig = null;
+ Intent mResultIntent = null;
+
+ public BitmapIOTask(Uri sourceUri, Uri destUri, String outputFormat, int flags,
+ RectF cropBounds, RectF photoBounds, RectF originalBitmapBounds) {
mOutputFormat = outputFormat;
mOutStream = null;
- mOutUri = uri;
- try {
- mOutStream = getContentResolver().openOutputStream(uri);
- } catch (FileNotFoundException e) {
- Log.w(LOGTAG, "cannot write output: " + mOutUri.toString(), e);
- }
- }
+ mOutUri = destUri;
+ mInUri = sourceUri;
+ mFlags = flags;
+ mCrop = cropBounds;
+ mPhoto = photoBounds;
+ mOrig = originalBitmapBounds;
+ mWPManager = WallpaperManager.getInstance(getApplicationContext());
+ mResultIntent = new Intent();
- @Override
- protected Boolean doInBackground(Bitmap... params) {
- if (mOutStream == null) {
- return false;
+ if ((flags & DO_EXTRA_OUTPUT) != 0) {
+ if (mOutUri == null) {
+ Log.w(LOGTAG, "cannot write file, no output URI given");
+ } else {
+ try {
+ mOutStream = getContentResolver().openOutputStream(mOutUri);
+ } catch (FileNotFoundException e) {
+ Log.w(LOGTAG, "cannot write file: " + mOutUri.toString(), e);
+ }
+ }
}
- CompressFormat cf = convertExtensionToCompressFormat(getFileExtension(mOutputFormat));
- return params[0].compress(cf, DEFAULT_COMPRESS_QUALITY, mOutStream);
- }
- @Override
- protected void onPostExecute(Boolean result) {
- if (result.booleanValue() == false) {
- Log.w(LOGTAG, "could not compress to output: " + mOutUri.toString());
- doneSaveBitmap(null);
+ if ((flags & (DO_EXTRA_OUTPUT | DO_SET_WALLPAPER)) != 0) {
+ if (mInUri == null) {
+ Log.w(LOGTAG, "cannot read original file, no input URI given");
+ } else {
+ try {
+ mInStream = getContentResolver().openInputStream(mInUri);
+ } catch (FileNotFoundException e) {
+ Log.w(LOGTAG, "cannot read file: " + mInUri.toString(), e);
+ }
+ }
}
- doneSaveBitmap(mOutUri);
- }
- }
-
- private void startSetWallpaper(Bitmap bmap) {
- if (bmap == null) {
- throw new IllegalArgumentException("bad argument to startSetWallpaper");
- }
- mActiveBackgroundIO++;
- Toast.makeText(this, R.string.setting_wallpaper, Toast.LENGTH_LONG).show();
- mSetWallpaperTask = new SetWallpaperTask();
- mSetWallpaperTask.execute(bmap);
-
- }
-
- private void doneSetWallpaper() {
- mActiveBackgroundIO--;
- done();
- }
-
- private class SetWallpaperTask extends AsyncTask<Bitmap, Void, Boolean> {
- private final WallpaperManager mWPManager;
-
- public SetWallpaperTask() {
- mWPManager = WallpaperManager.getInstance(getApplicationContext());
}
@Override
protected Boolean doInBackground(Bitmap... params) {
- try {
- mWPManager.setBitmap(params[0]);
- } catch (IOException e) {
- Log.w(LOGTAG, "fail to set wall paper", e);
+ boolean failure = false;
+ Bitmap img = params[0];
+
+ // Set extra for crop bounds
+ if (mCrop != null && mPhoto != null && mOrig != null) {
+ RectF trueCrop = CropMath.getScaledCropBounds(mCrop, mPhoto, mOrig);
+ if (trueCrop != null) {
+ Rect rounded = new Rect();
+ trueCrop.roundOut(rounded);
+ mResultIntent.putExtra(CropExtras.KEY_CROPPED_RECT, rounded);
+ }
}
- return true;
- }
- @Override
- protected void onPostExecute(Boolean result) {
- doneSetWallpaper();
- }
- }
-
- private void startFinishOutput() {
- if (mOriginalBitmap != null && mCropExtras != null) {
- Bitmap cropped = null;
- if (mCropExtras.getExtraOutput() != null) {
- if (cropped == null) {
- cropped = getCroppedImage(mOriginalBitmap);
+ // Find the small cropped bitmap that is returned in the intent
+ if ((mFlags & DO_RETURN_DATA) != 0) {
+ assert (img != null);
+ Bitmap ret = getCroppedImage(img, mCrop, mPhoto);
+ if (ret != null) {
+ ret = getDownsampledBitmap(ret, MAX_BMAP_IN_INTENT);
}
- startSaveBitmap(cropped, mCropExtras.getExtraOutput(),
- mCropExtras.getOutputFormat());
- }
- if (mCropExtras.getSetAsWallpaper()) {
- if (cropped == null) {
- cropped = getCroppedImage(mOriginalBitmap);
+ if (ret == null) {
+ Log.w(LOGTAG, "could not downsample bitmap to return in data");
+ failure = true;
+ } else {
+ mResultIntent.putExtra(CropExtras.KEY_DATA, ret);
}
- startSetWallpaper(cropped);
}
- if (mCropExtras.getReturnData()) {
- if (cropped == null) {
- cropped = getCroppedImage(mOriginalBitmap);
+
+ // Do the large cropped bitmap and/or set the wallpaper
+ if ((mFlags & (DO_EXTRA_OUTPUT | DO_SET_WALLPAPER)) != 0 && mInStream != null) {
+ BitmapRegionDecoder decoder = null;
+ try {
+ decoder = BitmapRegionDecoder.newInstance(mInStream, true);
+ } catch (IOException e) {
+ Log.w(LOGTAG, "cannot open region decoder for file: " + mInUri.toString(), e);
+ }
+ if (decoder == null) {
+ failure = true;
+ return false;
+ }
+
+ // Find crop bounds (scaled to original image size)
+ RectF trueCrop = CropMath.getScaledCropBounds(mCrop, mPhoto, mOrig);
+ if (trueCrop == null) {
+ Log.w(LOGTAG, "cannot find crop for full size image");
+ failure = true;
+ return false;
+ }
+ Rect roundedTrueCrop = new Rect();
+ trueCrop.roundOut(roundedTrueCrop);
+
+ if (roundedTrueCrop.width() <= 0 || roundedTrueCrop.height() <= 0) {
+ Log.w(LOGTAG, "crop has bad values for full size image");
+ failure = true;
+ return false;
+ }
+ // Do region decoding to get crop bitmap
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inMutable = true;
+ Bitmap crop = decoder.decodeRegion(roundedTrueCrop, options);
+ decoder.recycle();
+
+ if (crop == null) {
+ Log.w(LOGTAG, "cannot region decode file: " + mInUri.toString());
+ failure = true;
+ return false;
}
- int bmapSize = cropped.getRowBytes() * cropped.getHeight();
- if (bmapSize > MAX_BMAP_IN_INTENT) {
- Log.w(LOGTAG, "Bitmap too large to be returned via intent");
+ // Get output compression format
+ CompressFormat cf =
+ convertExtensionToCompressFormat(getFileExtension(mOutputFormat));
+
+ // If we only need to output to a URI, compress straight to file
+ if (mFlags == DO_EXTRA_OUTPUT) {
+ if (mOutStream == null
+ || !crop.compress(cf, DEFAULT_COMPRESS_QUALITY, mOutStream)) {
+ Log.w(LOGTAG, "failed to compress bitmap to file: " + mOutUri.toString());
+ failure = true;
+ }
} else {
- mResultIntent.putExtra(CropExtras.KEY_DATA, cropped);
+ // Compress to byte array
+ ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
+ if (crop.compress(cf, DEFAULT_COMPRESS_QUALITY, tmpOut)) {
+
+ // If we need to output to a Uri, write compressed
+ // bitmap out
+ if ((mFlags & DO_EXTRA_OUTPUT) != 0) {
+ if (mOutStream == null) {
+ Log.w(LOGTAG,
+ "failed to compress bitmap to file: " + mOutUri.toString());
+ failure = true;
+ } else {
+ try {
+ mOutStream.write(tmpOut.toByteArray());
+ } catch (IOException e) {
+ Log.w(LOGTAG,
+ "failed to compress bitmap to file: "
+ + mOutUri.toString(), e);
+ failure = true;
+ }
+ }
+ }
+
+ // If we need to set to the wallpaper, set it
+ if ((mFlags & DO_SET_WALLPAPER) != 0 && mWPManager != null) {
+ if (mWPManager == null) {
+ Log.w(LOGTAG, "no wallpaper manager");
+ failure = true;
+ } else {
+ try {
+ mWPManager.setStream(new ByteArrayInputStream(tmpOut
+ .toByteArray()));
+ } catch (IOException e) {
+ Log.w(LOGTAG, "cannot write stream to wallpaper", e);
+ failure = true;
+ }
+ }
+ }
+ } else {
+ Log.w(LOGTAG, "cannot compress bitmap");
+ failure = true;
+ }
}
}
- setResult(RESULT_OK, mResultIntent);
- } else {
- setResult(RESULT_CANCELED, mResultIntent);
+ return !failure; // True if any of the operations failed
}
- done();
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ doneBitmapIO(result.booleanValue(), mResultIntent);
+ }
+
}
private void done() {
- if (mActiveBackgroundIO == 0) {
- finish();
- }
+ finish();
}
- private Bitmap getCroppedImage(Bitmap image) {
+ protected static Bitmap getCroppedImage(Bitmap image, RectF cropBounds, RectF photoBounds) {
RectF imageBounds = new RectF(0, 0, image.getWidth(), image.getHeight());
- RectF crop = getBitmapCrop(imageBounds);
+ RectF crop = CropMath.getScaledCropBounds(cropBounds, photoBounds, imageBounds);
if (crop == null) {
- return image;
+ return null;
}
Rect intCrop = new Rect();
crop.roundOut(intCrop);
@@ -387,29 +502,56 @@ public class CropActivity extends Activity {
intCrop.height());
}
- private RectF getBitmapCrop(RectF imageBounds) {
- RectF crop = new RectF();
- if (!mCropView.getCropBounds(crop, imageBounds)) {
- Log.w(LOGTAG, "could not get crop");
+ protected static Bitmap getDownsampledBitmap(Bitmap image, int max_size) {
+ if (image == null || image.getWidth() == 0 || image.getHeight() == 0 || max_size < 16) {
+ throw new IllegalArgumentException("Bad argument to getDownsampledBitmap()");
+ }
+ int shifts = 0;
+ int size = CropMath.getBitmapSize(image);
+ while (size > max_size) {
+ shifts++;
+ size /= 4;
+ }
+ Bitmap ret = Bitmap.createScaledBitmap(image, image.getWidth() >> shifts,
+ image.getHeight() >> shifts, true);
+ if (ret == null) {
return null;
}
- return crop;
+ // Handle edge case for rounding.
+ if (CropMath.getBitmapSize(ret) > max_size) {
+ return Bitmap.createScaledBitmap(ret, ret.getWidth() >> 1, ret.getHeight() >> 1, true);
+ }
+ return ret;
}
/**
- * Helper method for unit conversions.
+ * Gets the crop extras from the intent, or null if none exist.
*/
- public float getPixelsFromDip(float value) {
- Resources r = getResources();
- return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
- r.getDisplayMetrics());
+ protected static CropExtras getExtrasFromIntent(Intent intent) {
+ Bundle extras = intent.getExtras();
+ if (extras != null) {
+ return new CropExtras(extras.getInt(CropExtras.KEY_OUTPUT_X, 0),
+ extras.getInt(CropExtras.KEY_OUTPUT_Y, 0),
+ extras.getBoolean(CropExtras.KEY_SCALE, true) &&
+ extras.getBoolean(CropExtras.KEY_SCALE_UP_IF_NEEDED, false),
+ extras.getInt(CropExtras.KEY_ASPECT_X, 0),
+ extras.getInt(CropExtras.KEY_ASPECT_Y, 0),
+ extras.getBoolean(CropExtras.KEY_SET_AS_WALLPAPER, false),
+ extras.getBoolean(CropExtras.KEY_RETURN_DATA, false),
+ (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT),
+ extras.getString(CropExtras.KEY_OUTPUT_FORMAT),
+ extras.getBoolean(CropExtras.KEY_SHOW_WHEN_LOCKED, false),
+ extras.getFloat(CropExtras.KEY_SPOTLIGHT_X),
+ extras.getFloat(CropExtras.KEY_SPOTLIGHT_Y));
+ }
+ return null;
}
- private static CompressFormat convertExtensionToCompressFormat(String extension) {
+ protected static CompressFormat convertExtensionToCompressFormat(String extension) {
return extension.equals("png") ? CompressFormat.PNG : CompressFormat.JPEG;
}
- private static String getFileExtension(String requestFormat) {
+ protected static String getFileExtension(String requestFormat) {
String outputFormat = (requestFormat == null)
? "jpg"
: requestFormat;
@@ -419,4 +561,14 @@ public class CropActivity extends Activity {
: "jpg";
}
+ private RectF getBitmapCrop(RectF imageBounds) {
+ RectF crop = mCropView.getCrop();
+ RectF photo = mCropView.getPhoto();
+ if (crop == null || photo == null) {
+ Log.w(LOGTAG, "could not get crop");
+ return null;
+ }
+ RectF scaledCrop = CropMath.getScaledCropBounds(crop, photo, imageBounds);
+ return scaledCrop;
+ }
}