From da1606eb2a6021977bc599ae9eff6aa943437393 Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 17:53:22 +0100 Subject: [PATCH 1/8] Added support for source uri --- .../ananas/editimage/EditImageActivity.java | 27 ++- .../editimage/ImageEditorIntentBuilder.kt | 30 ++- .../ananas/editimage/utils/BitmapUtils.java | 180 +++++++++++++++++- 3 files changed, 232 insertions(+), 5 deletions(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java index aec2afa..61d016b 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java @@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.graphics.Bitmap; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; @@ -114,6 +115,7 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi private RedoUndoController redoUndoController; private OnMainBitmapChangeListener onMainBitmapChangeListener; private CompositeDisposable compositeDisposable = new CompositeDisposable(); + private Uri sourceUri; public static void start(Activity activity, Intent intent, int requestCode) { if (TextUtils.isEmpty(intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH))) { @@ -151,6 +153,7 @@ private void getData() { isPortraitForced = getIntent().getBooleanExtra(ImageEditorIntentBuilder.FORCE_PORTRAIT, false); isSupportActionBarEnabled = getIntent().getBooleanExtra(ImageEditorIntentBuilder.SUPPORT_ACTION_BAR_VISIBILITY, false); + sourceUri = (Uri) getIntent().getSerializableExtra(ImageEditorIntentBuilder.SOURCE_URI); sourceFilePath = getIntent().getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH); outputFilePath = getIntent().getStringExtra(ImageEditorIntentBuilder.OUTPUT_PATH); editorTitle = getIntent().getStringExtra(ImageEditorIntentBuilder.EDITOR_TITLE); @@ -228,7 +231,11 @@ private void initView() { ActivityCompat.requestPermissions(this, requiredPermissions, PERMISSIONS_REQUEST_CODE); } - loadImageFromFile(sourceFilePath); + if (sourceFilePath != null && sourceFilePath.trim().length() > 0) { + loadImageFromFile(sourceFilePath); + } else { + loadImageFromUri(sourceUri); + } } private void setOnMainBitmapChangeListener(OnMainBitmapChangeListener listener) { @@ -377,6 +384,19 @@ private Single saveImage(Bitmap finalBitmap) { }); } + private void loadImageFromUri(Uri uri) { + compositeDisposable.clear(); + + Disposable loadImageDisposable = loadImage(uri) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnSubscribe(subscriber -> loadingDialog.show()) + .doFinally(() -> loadingDialog.dismiss()) + .subscribe(processedBitmap -> changeMainBitmap(processedBitmap, false), e -> showToast(R.string.iamutkarshtiwari_github_io_ananas_load_error)); + + compositeDisposable.add(loadImageDisposable); + } + private void loadImageFromFile(String filePath) { compositeDisposable.clear(); @@ -395,6 +415,11 @@ private Single loadImage(String filePath) { imageHeight)); } + private Single loadImage(Uri uri) { + return Single.fromCallable(() -> BitmapUtils.decodeSampledBitmap(this, uri, + imageWidth, imageHeight)); + } + private void showToast(@StringRes int resId) { Toast.makeText(this, resId, Toast.LENGTH_SHORT).show(); } diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt index 87c9e28..cd40ac8 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt @@ -2,6 +2,7 @@ package iamutkarshtiwari.github.io.ananas.editimage import android.content.Context import android.content.Intent +import android.net.Uri class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Context, private val sourcePath: String?, @@ -11,6 +12,17 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co EditImageActivity::class.java ) ) { + private var sourceUri: Uri? = null + + constructor(context: Context, + sourceUri: Uri, + outputPath: String?, + intent: Intent = Intent( + context, + EditImageActivity::class.java + )) : this(context, null, outputPath, intent) { + this.sourceUri = sourceUri + } fun withAddText(): ImageEditorIntentBuilder { intent.putExtra(ADD_TEXT_FEATURE, true) @@ -62,8 +74,15 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co return this } + fun withSourceUri(sourceUri: Uri): ImageEditorIntentBuilder { + intent.putExtra(SOURCE_URI, sourceUri) + intent.removeExtra(SOURCE_PATH) + return this + } + fun withSourcePath(sourcePath: String): ImageEditorIntentBuilder { intent.putExtra(SOURCE_PATH, sourcePath) + intent.removeExtra(SOURCE_URI) return this } @@ -85,10 +104,14 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co @Throws(Exception::class) fun build(): Intent { - if (sourcePath.isNullOrBlank()) { - throw Exception("Output image path required. Use withOutputPath(path) to provide the output image path.") - } else { + if (sourcePath.isNullOrBlank() && sourceUri == null) { + throw Exception("Source image required. Use withSourcePath(path) or withSourceUri(uri) to provide the source.") + } else if (!sourcePath.isNullOrBlank() && sourceUri != null) { + throw Exception("Multiple source images specified. Use either withSourcePath(path) or withSourceUri(uri) to provide the source.") + } else if (!sourcePath.isNullOrBlank()) { intent.putExtra(SOURCE_PATH, sourcePath) + } else { + intent.putExtra(SOURCE_URI, sourceUri) } if (outputPath.isNullOrBlank()) { @@ -111,6 +134,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co const val BEAUTY_FEATURE = "beauty_feature" const val STICKER_FEATURE = "sticker_feature" + const val SOURCE_URI = "source_uri" const val SOURCE_PATH = "source_path" const val OUTPUT_PATH = "output_path" const val FORCE_PORTRAIT = "force_portrait" diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/utils/BitmapUtils.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/utils/BitmapUtils.java index 94d80db..b21fb84 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/utils/BitmapUtils.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/utils/BitmapUtils.java @@ -17,6 +17,8 @@ package iamutkarshtiwari.github.io.ananas.editimage.utils; import android.app.Activity; +import android.content.ContentResolver; +import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; @@ -24,8 +26,10 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.media.ExifInterface; +import android.net.Uri; import android.os.Environment; import android.util.Log; import android.view.Display; @@ -33,21 +37,32 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import javax.microedition.khronos.egl.EGL10; +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.egl.EGLContext; +import javax.microedition.khronos.egl.EGLDisplay; + public class BitmapUtils { /** * Used to tag logs */ @SuppressWarnings("unused") private static final String TAG = "BitmapUtils"; + private static final Rect EMPTY_RECT = new Rect(); public static final long MAX_SZIE = 1024 * 512;// 500KB + /** Used to know the max texture size allowed to be rendered */ + private static int mMaxTextureSize; + public static int getOrientation(final String imagePath) { int rotate = 0; try { @@ -350,7 +365,6 @@ public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeig return BitmapFactory.decodeFile(filePath, options); } - public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; @@ -373,6 +387,170 @@ public static int calculateInSampleSize(BitmapFactory.Options options, int reqWi return inSampleSize; } + public static Bitmap decodeSampledBitmap(Context context, Uri uri, int reqWidth, int reqHeight) { + + try { + ContentResolver resolver = context.getContentResolver(); + + // First decode with inJustDecodeBounds=true to check dimensions + BitmapFactory.Options options = decodeImageForOption(resolver, uri); + + if(options.outWidth == -1 && options.outHeight == -1) + throw new RuntimeException("File is not a picture"); + + // Calculate inSampleSize + options.inSampleSize = + Math.max( + calculateInSampleSizeByReqestedSize( + options.outWidth, options.outHeight, reqWidth, reqHeight), + calculateInSampleSizeByMaxTextureSize(options.outWidth, options.outHeight)); + + // Decode bitmap with inSampleSize set + Bitmap bitmap = decodeImage(resolver, uri, options); + + return bitmap; + + } catch (Exception e) { + throw new RuntimeException( + "Failed to load sampled bitmap: " + uri + "\r\n" + e.getMessage(), e); + } + } + + /** Decode image from uri using "inJustDecodeBounds" to get the image dimensions. */ + private static BitmapFactory.Options decodeImageForOption(ContentResolver resolver, Uri uri) + throws FileNotFoundException { + InputStream stream = null; + try { + stream = resolver.openInputStream(uri); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeStream(stream, EMPTY_RECT, options); + options.inJustDecodeBounds = false; + return options; + } finally { + closeSafe(stream); + } + } + + /** + * Decode image from uri using given "inSampleSize", but if failed due to out-of-memory then raise + * the inSampleSize until success. + */ + private static Bitmap decodeImage( + ContentResolver resolver, Uri uri, BitmapFactory.Options options) + throws FileNotFoundException { + do { + InputStream stream = null; + try { + stream = resolver.openInputStream(uri); + return BitmapFactory.decodeStream(stream, EMPTY_RECT, options); + } catch (OutOfMemoryError e) { + options.inSampleSize *= 2; + } finally { + closeSafe(stream); + } + } while (options.inSampleSize <= 512); + throw new RuntimeException("Failed to decode image: " + uri); + } + + /** + * Calculate the largest inSampleSize value that is a power of 2 and keeps both height and width + * larger than the requested height and width. + */ + private static int calculateInSampleSizeByReqestedSize( + int width, int height, int reqWidth, int reqHeight) { + int inSampleSize = 1; + if (height > reqHeight || width > reqWidth) { + while ((height / 2 / inSampleSize) > reqHeight && (width / 2 / inSampleSize) > reqWidth) { + inSampleSize *= 2; + } + } + return inSampleSize; + } + + /** + * Calculate the largest inSampleSize value that is a power of 2 and keeps both height and width + * smaller than max texture size allowed for the device. + */ + private static int calculateInSampleSizeByMaxTextureSize(int width, int height) { + int inSampleSize = 1; + if (mMaxTextureSize == 0) { + mMaxTextureSize = getMaxTextureSize(); + } + if (mMaxTextureSize > 0) { + while ((height / inSampleSize) > mMaxTextureSize + || (width / inSampleSize) > mMaxTextureSize) { + inSampleSize *= 2; + } + } + return inSampleSize; + } + + /** + * Get the max size of bitmap allowed to be rendered on the device.
+ * http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit. + */ + private static int getMaxTextureSize() { + // Safe minimum default size + final int IMAGE_MAX_BITMAP_DIMENSION = 2048; + + try { + // Get EGL Display + EGL10 egl = (EGL10) EGLContext.getEGL(); + EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + + // Initialise + int[] version = new int[2]; + egl.eglInitialize(display, version); + + // Query total number of configurations + int[] totalConfigurations = new int[1]; + egl.eglGetConfigs(display, null, 0, totalConfigurations); + + // Query actual list configurations + EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]]; + egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations); + + int[] textureSize = new int[1]; + int maximumTextureSize = 0; + + // Iterate through all the configurations to located the maximum texture size + for (int i = 0; i < totalConfigurations[0]; i++) { + // Only need to check for width since opengl textures are always squared + egl.eglGetConfigAttrib( + display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize); + + // Keep track of the maximum texture size + if (maximumTextureSize < textureSize[0]) { + maximumTextureSize = textureSize[0]; + } + } + + // Release + egl.eglTerminate(display); + + // Return largest texture size found, or default + return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION); + } catch (Exception e) { + return IMAGE_MAX_BITMAP_DIMENSION; + } + } + + /** + * Close the given closeable object (Stream) in a safe way: check if it is null and catch-log + * exception thrown. + * + * @param closeable the closable object to close + */ + private static void closeSafe(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (IOException ignored) { + } + } + } + public static boolean saveBitmap(Bitmap bm, String filePath) { File f = new File(filePath); if (f.exists()) { From fb4b373f73d56c899dcc556d953f79e6302112de Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 18:03:49 +0100 Subject: [PATCH 2/8] Minor fix to source uri --- .../github/io/ananas/editimage/ImageEditorIntentBuilder.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt index cd40ac8..6e57ca7 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt @@ -14,7 +14,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co ) { private var sourceUri: Uri? = null - constructor(context: Context, + @JvmOverloads constructor(context: Context, sourceUri: Uri, outputPath: String?, intent: Intent = Intent( @@ -75,6 +75,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co } fun withSourceUri(sourceUri: Uri): ImageEditorIntentBuilder { + this.sourceUri = sourceUri intent.putExtra(SOURCE_URI, sourceUri) intent.removeExtra(SOURCE_PATH) return this From 7610f9837c7ae131596d184ee712b8fba3739356 Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 18:12:18 +0100 Subject: [PATCH 3/8] added source uri to start validation --- .../github/io/ananas/editimage/EditImageActivity.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java index 61d016b..fbd33c5 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java @@ -118,7 +118,10 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi private Uri sourceUri; public static void start(Activity activity, Intent intent, int requestCode) { - if (TextUtils.isEmpty(intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH))) { + String sourcePath = intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH); + Uri sourceUri = (Uri) intent.getSerializableExtra(ImageEditorIntentBuilder.SOURCE_URI); + + if (TextUtils.isEmpty(sourcePath) && sourceUri == null) { Toast.makeText(activity, R.string.iamutkarshtiwari_github_io_ananas_not_selected, Toast.LENGTH_SHORT).show(); return; } From 8b0c071801c0c48d1a6616c8030f327043b89913 Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 18:35:25 +0100 Subject: [PATCH 4/8] more source uri fixes --- .../io/ananas/editimage/EditImageActivity.java | 13 +++++++++---- .../io/ananas/editimage/ImageEditorIntentBuilder.kt | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java index fbd33c5..e9d9666 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java @@ -119,9 +119,9 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi public static void start(Activity activity, Intent intent, int requestCode) { String sourcePath = intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH); - Uri sourceUri = (Uri) intent.getSerializableExtra(ImageEditorIntentBuilder.SOURCE_URI); + String sourceUriStr = intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_URI); - if (TextUtils.isEmpty(sourcePath) && sourceUri == null) { + if (TextUtils.isEmpty(sourcePath) && TextUtils.isEmpty(sourceUriStr)) { Toast.makeText(activity, R.string.iamutkarshtiwari_github_io_ananas_not_selected, Toast.LENGTH_SHORT).show(); return; } @@ -156,7 +156,11 @@ private void getData() { isPortraitForced = getIntent().getBooleanExtra(ImageEditorIntentBuilder.FORCE_PORTRAIT, false); isSupportActionBarEnabled = getIntent().getBooleanExtra(ImageEditorIntentBuilder.SUPPORT_ACTION_BAR_VISIBILITY, false); - sourceUri = (Uri) getIntent().getSerializableExtra(ImageEditorIntentBuilder.SOURCE_URI); + String sourceUriStr = getIntent().getStringExtra(ImageEditorIntentBuilder.SOURCE_URI); + if (!TextUtils.isEmpty(sourceUriStr)) { + sourceUri = Uri.parse(sourceUriStr); + } + sourceFilePath = getIntent().getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH); outputFilePath = getIntent().getStringExtra(ImageEditorIntentBuilder.OUTPUT_PATH); editorTitle = getIntent().getStringExtra(ImageEditorIntentBuilder.EDITOR_TITLE); @@ -234,7 +238,7 @@ private void initView() { ActivityCompat.requestPermissions(this, requiredPermissions, PERMISSIONS_REQUEST_CODE); } - if (sourceFilePath != null && sourceFilePath.trim().length() > 0) { + if (!TextUtils.isEmpty(sourceFilePath)) { loadImageFromFile(sourceFilePath); } else { loadImageFromUri(sourceUri); @@ -347,6 +351,7 @@ public void changeMainBitmap(Bitmap newBit, boolean needPushUndoStack) { protected void onSaveTaskDone() { Intent returnIntent = new Intent(); + returnIntent.putExtra(ImageEditorIntentBuilder.SOURCE_URI, sourceUri.toString()); returnIntent.putExtra(ImageEditorIntentBuilder.SOURCE_PATH, sourceFilePath); returnIntent.putExtra(ImageEditorIntentBuilder.OUTPUT_PATH, outputFilePath); returnIntent.putExtra(IS_IMAGE_EDITED, numberOfOperations > 0); diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt index 6e57ca7..1a1d477 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/ImageEditorIntentBuilder.kt @@ -76,7 +76,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co fun withSourceUri(sourceUri: Uri): ImageEditorIntentBuilder { this.sourceUri = sourceUri - intent.putExtra(SOURCE_URI, sourceUri) + intent.putExtra(SOURCE_URI, sourceUri.toString()) intent.removeExtra(SOURCE_PATH) return this } @@ -112,7 +112,7 @@ class ImageEditorIntentBuilder @JvmOverloads constructor(private val context: Co } else if (!sourcePath.isNullOrBlank()) { intent.putExtra(SOURCE_PATH, sourcePath) } else { - intent.putExtra(SOURCE_URI, sourceUri) + intent.putExtra(SOURCE_URI, sourceUri.toString()) } if (outputPath.isNullOrBlank()) { From 638bac3991012180179f11ba5ea2febb1ce44eca Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 20:19:32 +0100 Subject: [PATCH 5/8] Update README.md with correct output path key --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3121df8..25c6a9e 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ You can receive the new processed image path and it's edit status like this- super.onActivityResult(requestCode, resultCode, data); if (requestCode == PHOTO_EDITOR_REQUEST_CODE) { // same code you used while starting - String newFilePath = data.getStringExtra(EditImageActivity.OUTPUT_PATH); + String newFilePath = data.getStringExtra(ImageEditorIntentBuilder.OUTPUT_PATH); boolean isImageEdit = data.getBooleanExtra(EditImageActivity.IMAGE_IS_EDIT, false); } } From 7d86e64af2ca072f9b7e9876ad31a3ed09654256 Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Wed, 30 Sep 2020 20:23:09 +0100 Subject: [PATCH 6/8] Move sourceUri declaration near sourceFilePath --- .../github/io/ananas/editimage/EditImageActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java index e9d9666..786acbc 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java @@ -80,6 +80,7 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi Manifest.permission.WRITE_EXTERNAL_STORAGE }; + public Uri sourceUri; public String sourceFilePath; public String outputFilePath; public String editorTitle; @@ -115,7 +116,6 @@ public class EditImageActivity extends BaseActivity implements OnLoadingDialogLi private RedoUndoController redoUndoController; private OnMainBitmapChangeListener onMainBitmapChangeListener; private CompositeDisposable compositeDisposable = new CompositeDisposable(); - private Uri sourceUri; public static void start(Activity activity, Intent intent, int requestCode) { String sourcePath = intent.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH); From 982bdd33b5d61eebd1c35f9807282bdba0766325 Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Sun, 11 Oct 2020 14:27:35 +0100 Subject: [PATCH 7/8] Bug fix when pressing back from photo editor --- .../github/io/ananas/editimage/EditImageActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java index 786acbc..4e5f7b8 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/EditImageActivity.java @@ -351,7 +351,11 @@ public void changeMainBitmap(Bitmap newBit, boolean needPushUndoStack) { protected void onSaveTaskDone() { Intent returnIntent = new Intent(); - returnIntent.putExtra(ImageEditorIntentBuilder.SOURCE_URI, sourceUri.toString()); + + if (sourceUri != null) { + returnIntent.putExtra(ImageEditorIntentBuilder.SOURCE_URI, sourceUri.toString()); + } + returnIntent.putExtra(ImageEditorIntentBuilder.SOURCE_PATH, sourceFilePath); returnIntent.putExtra(ImageEditorIntentBuilder.OUTPUT_PATH, outputFilePath); returnIntent.putExtra(IS_IMAGE_EDITED, numberOfOperations > 0); From 1054be4790430c4b58f161a7e584a0d67ecfcc0f Mon Sep 17 00:00:00 2001 From: thirstycoda Date: Sun, 11 Oct 2020 14:57:44 +0100 Subject: [PATCH 8/8] Move undo redo buttons to toolbar --- .../editimage/widget/RedoUndoController.java | 4 +- ananas/src/main/res/drawable/ic_redo_24.xml | 5 ++ .../main/res/drawable/ic_redo_black_24dp.xml | 8 --- ananas/src/main/res/drawable/ic_undo_24.xml | 5 ++ .../main/res/drawable/ic_undo_black_24dp.xml | 9 --- .../main/res/layout/activity_image_edit.xml | 60 +++++++++---------- 6 files changed, 41 insertions(+), 50 deletions(-) create mode 100644 ananas/src/main/res/drawable/ic_redo_24.xml delete mode 100644 ananas/src/main/res/drawable/ic_redo_black_24dp.xml create mode 100644 ananas/src/main/res/drawable/ic_undo_24.xml delete mode 100644 ananas/src/main/res/drawable/ic_undo_black_24dp.xml diff --git a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/widget/RedoUndoController.java b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/widget/RedoUndoController.java index 4b6f0c8..319d603 100644 --- a/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/widget/RedoUndoController.java +++ b/ananas/src/main/java/iamutkarshtiwari/github/io/ananas/editimage/widget/RedoUndoController.java @@ -86,8 +86,8 @@ protected void redoClick() { public void updateBtns() { //System.out.println("缓存Size = " + mEditCache.getSize() + " current = " + mEditCache.getCur()); //System.out.println("content = " + mEditCache.debugLog()); - mUndoBtn.setVisibility(mEditCache.checkNextBitExist() ? View.VISIBLE : View.INVISIBLE); - mRedoBtn.setVisibility(mEditCache.checkPreBitExist() ? View.VISIBLE : View.INVISIBLE); + mUndoBtn.setVisibility(mEditCache.checkNextBitExist() ? View.VISIBLE : View.GONE); + mRedoBtn.setVisibility(mEditCache.checkPreBitExist() ? View.VISIBLE : View.GONE); } public void onDestroy() { diff --git a/ananas/src/main/res/drawable/ic_redo_24.xml b/ananas/src/main/res/drawable/ic_redo_24.xml new file mode 100644 index 0000000..f8a026a --- /dev/null +++ b/ananas/src/main/res/drawable/ic_redo_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/ananas/src/main/res/drawable/ic_redo_black_24dp.xml b/ananas/src/main/res/drawable/ic_redo_black_24dp.xml deleted file mode 100644 index 4954e92..0000000 --- a/ananas/src/main/res/drawable/ic_redo_black_24dp.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/ananas/src/main/res/drawable/ic_undo_24.xml b/ananas/src/main/res/drawable/ic_undo_24.xml new file mode 100644 index 0000000..874470d --- /dev/null +++ b/ananas/src/main/res/drawable/ic_undo_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/ananas/src/main/res/drawable/ic_undo_black_24dp.xml b/ananas/src/main/res/drawable/ic_undo_black_24dp.xml deleted file mode 100644 index c06107e..0000000 --- a/ananas/src/main/res/drawable/ic_undo_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/ananas/src/main/res/layout/activity_image_edit.xml b/ananas/src/main/res/layout/activity_image_edit.xml index 8fb7e49..3514cd7 100644 --- a/ananas/src/main/res/layout/activity_image_edit.xml +++ b/ananas/src/main/res/layout/activity_image_edit.xml @@ -15,28 +15,50 @@ android:layout_width="wrap_content" android:layout_height="55dp" android:layout_gravity="left|center_vertical" - android:layout_margin="10dp" - android:layout_marginLeft="8dp" + android:paddingHorizontal="8dp" android:src="@drawable/back_arrow" /> + + + + + + + @@ -44,6 +66,7 @@ android:id="@+id/save_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:paddingHorizontal="8dp" android:gravity="center" android:text="@string/iamutkarshtiwari_github_io_ananas_done" android:textAllCaps="true" @@ -54,6 +77,7 @@ android:id="@+id/apply" android:layout_width="wrap_content" android:layout_height="fill_parent" + android:paddingHorizontal="8dp" android:gravity="center" android:text="@string/iamutkarshtiwari_github_io_ananas_apply" android:textAllCaps="true" @@ -140,30 +164,4 @@ android:layout_gravity="center" android:visibility="gone" /> - - - - - - - -