Cleaning
This commit is contained in:
parent
97f2401cfd
commit
8d58d01465
|
|
@ -11,6 +11,8 @@ import android.os.Build;
|
|||
import android.provider.MediaStore;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.soundcloud.android.crop.util.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Builder for crop Intents and utils for handling result
|
||||
*/
|
||||
|
|
@ -103,7 +105,7 @@ public class Crop {
|
|||
fragment.startActivityForResult(getIntent(context), REQUEST_CROP);
|
||||
}
|
||||
|
||||
//VisibleForTesting
|
||||
@VisibleForTesting
|
||||
Intent getIntent(Context context) {
|
||||
cropIntent.setClass(context, CropImageActivity.class);
|
||||
return cropIntent;
|
||||
|
|
@ -129,7 +131,7 @@ public class Crop {
|
|||
}
|
||||
|
||||
/**
|
||||
* Utility method that starts an image picker. Often preceded a crop.
|
||||
* Utility method that starts an image picker since that often precedes a crop
|
||||
*
|
||||
* @param activity Activity that will receive result
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,10 +30,11 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
||||
import com.soundcloud.android.crop.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
|
@ -119,20 +120,20 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
|
||||
mSourceUri = intent.getData();
|
||||
if (mSourceUri != null) {
|
||||
mExifRotation = Util.getExifRotation(Util.getFromMediaUri(getContentResolver(), mSourceUri));
|
||||
mExifRotation = CropUtil.getExifRotation(CropUtil.getFromMediaUri(getContentResolver(), mSourceUri));
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = getContentResolver().openInputStream(mSourceUri);
|
||||
mRotateBitmap = new RotateBitmap(BitmapFactory.decodeStream(is), mExifRotation);
|
||||
} catch (IOException e) {
|
||||
Log.e(Util.TAG, "Error reading picture: " + e.getMessage(), e);
|
||||
Log.e("Error reading picture: " + e.getMessage(), e);
|
||||
setResultException(e);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.e(Util.TAG, "OOM while reading picture: " + e.getMessage(), e);
|
||||
Log.e("OOM while reading picture: " + e.getMessage(), e);
|
||||
setResultException(e);
|
||||
} finally{
|
||||
Util.closeSilently(is);
|
||||
CropUtil.closeSilently(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,7 +143,7 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
return;
|
||||
}
|
||||
mImageView.setImageRotateBitmapResetBase(mRotateBitmap, true);
|
||||
Util.startBackgroundJob(this, null, getResources().getString(R.string.crop__wait),
|
||||
CropUtil.startBackgroundJob(this, null, getResources().getString(R.string.crop__wait),
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
|
@ -266,7 +267,7 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
private void saveImage(Bitmap croppedImage) {
|
||||
if (croppedImage != null) {
|
||||
final Bitmap b = croppedImage;
|
||||
Util.startBackgroundJob(this, null, getResources().getString(R.string.crop__saving),
|
||||
CropUtil.startBackgroundJob(this, null, getResources().getString(R.string.crop__saving),
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
saveOutput(b);
|
||||
|
|
@ -313,10 +314,10 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(Util.TAG, "Error cropping picture: " + e.getMessage(), e);
|
||||
Log.e("Error cropping picture: " + e.getMessage(), e);
|
||||
finish();
|
||||
} finally {
|
||||
Util.closeSilently(is);
|
||||
CropUtil.closeSilently(is);
|
||||
}
|
||||
return croppedImage;
|
||||
}
|
||||
|
|
@ -339,7 +340,7 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
canvas.drawBitmap(rotateBitmap.getBitmap(), m, null);
|
||||
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.e(Util.TAG, "Error cropping picture: " + e.getMessage(), e);
|
||||
Log.e("Error cropping picture: " + e.getMessage(), e);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
|
@ -367,16 +368,16 @@ public class CropImageActivity extends MonitoredActivity {
|
|||
|
||||
} catch (IOException e) {
|
||||
setResultException(e);
|
||||
Log.e(Util.TAG, "Cannot open file: " + mSaveUri, e);
|
||||
Log.e("Cannot open file: " + mSaveUri, e);
|
||||
} finally {
|
||||
Util.closeSilently(outputStream);
|
||||
CropUtil.closeSilently(outputStream);
|
||||
}
|
||||
|
||||
if (!IN_MEMORY_CROP){
|
||||
// In-memory crop negates the rotation
|
||||
Util.copyExifRotation(
|
||||
Util.getFromMediaUri(getContentResolver(), mSourceUri),
|
||||
Util.getFromMediaUri(getContentResolver(), mSaveUri)
|
||||
CropUtil.copyExifRotation(
|
||||
CropUtil.getFromMediaUri(getContentResolver(), mSourceUri),
|
||||
CropUtil.getFromMediaUri(getContentResolver(), mSaveUri)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ import android.net.Uri;
|
|||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.soundcloud.android.crop.util.Log;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
|
|
@ -33,9 +34,7 @@ import java.io.IOException;
|
|||
/*
|
||||
* Modified from original in AOSP.
|
||||
*/
|
||||
class Util {
|
||||
|
||||
public static final String TAG = "android-crop";
|
||||
class CropUtil {
|
||||
|
||||
private static final String SCHEME_FILE = "file";
|
||||
private static final String SCHEME_CONTENT = "content";
|
||||
|
|
@ -65,7 +64,7 @@ class Util {
|
|||
return ExifInterface.ORIENTATION_UNDEFINED;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error getting Exif data", e);
|
||||
Log.e("Error getting Exif data", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +78,7 @@ class Util {
|
|||
exifDest.saveAttributes();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error copying Exif data", e);
|
||||
Log.e("Error copying Exif data", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.soundcloud.android.crop.util;
|
||||
|
||||
public class Log {
|
||||
|
||||
private static final String TAG = "android-crop";
|
||||
|
||||
public static final void e(String msg) {
|
||||
android.util.Log.e(TAG, msg);
|
||||
}
|
||||
|
||||
public static final void e(String msg, Throwable e) {
|
||||
android.util.Log.e(TAG, msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.soundcloud.android.crop.util;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
|
||||
public @interface VisibleForTesting {}
|
||||
Loading…
Reference in New Issue