Skip to content

Commit

Permalink
[NEW] Disable clearAllViews onSave #54 #49 #42 and PR #71
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanrashid52 committed Aug 8, 2018
1 parent 7d32c75 commit 650463a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
Expand Up @@ -36,6 +36,7 @@
import ja.burhanrashid52.photoeditor.OnPhotoEditorListener;
import ja.burhanrashid52.photoeditor.PhotoEditor;
import ja.burhanrashid52.photoeditor.PhotoEditorView;
import ja.burhanrashid52.photoeditor.SaveSettings;
import ja.burhanrashid52.photoeditor.ViewType;
import ja.burhanrashid52.photoeditor.PhotoFilter;

Expand Down Expand Up @@ -220,7 +221,13 @@ private void saveImage() {
+ System.currentTimeMillis() + ".png");
try {
file.createNewFile();
mPhotoEditor.saveAsFile(file.getAbsolutePath(), new PhotoEditor.OnSaveListener() {

SaveSettings saveSettings = new SaveSettings.Builder()
.setClearViewsEnabled(true)
.setTransparencyEnabled(true)
.build();

mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
hideLoading();
Expand Down
Expand Up @@ -601,17 +601,31 @@ public void saveImage(@NonNull final String imagePath, @NonNull final OnSaveList
saveAsFile(imagePath, onSaveListener);
}

/**
* Save the edited image on given path
*
* @param imagePath path on which image to be saved
* @param onSaveListener callback for saving image
* @see OnSaveListener
*/
@RequiresPermission(allOf = {Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void saveAsFile(@NonNull final String imagePath, @NonNull final OnSaveListener onSaveListener) {
saveAsFile(imagePath, new SaveSettings.Builder().build(), onSaveListener);
}

/**
* Save the edited image on given path
*
* @param imagePath path on which image to be saved
* @param saveSettings builder for multiple save options {@link SaveSettings}
* @param onSaveListener callback for saving image
* @see OnSaveListener
*/
@SuppressLint("StaticFieldLeak")
@RequiresPermission(allOf = {Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void saveAsFile(@NonNull final String imagePath, @NonNull final OnSaveListener onSaveListener) {
public void saveAsFile(@NonNull final String imagePath,
@NonNull final SaveSettings saveSettings,
@NonNull final OnSaveListener onSaveListener) {
Log.d(TAG, "Image Path: " + imagePath);
parentView.saveFilter(new OnSaveBitmap() {
@Override
Expand All @@ -634,7 +648,9 @@ protected Exception doInBackground(String... strings) {
FileOutputStream out = new FileOutputStream(file, false);
if (parentView != null) {
parentView.setDrawingCacheEnabled(true);
Bitmap drawingCache = BitmapUtil.removeTransparency(parentView.getDrawingCache());
Bitmap drawingCache = saveSettings.isTransparencyEnabled()
? BitmapUtil.removeTransparency(parentView.getDrawingCache())
: parentView.getDrawingCache();
drawingCache.compress(Bitmap.CompressFormat.PNG, 100, out);
}
out.flush();
Expand All @@ -652,7 +668,8 @@ protected Exception doInBackground(String... strings) {
protected void onPostExecute(Exception e) {
super.onPostExecute(e);
if (e == null) {
clearAllViews();
//Clear all views if its enabled in save settings
if (saveSettings.isClearViewsEnabled()) clearAllViews();
onSaveListener.onSuccess(imagePath);
} else {
onSaveListener.onFailure(e);
Expand All @@ -664,7 +681,7 @@ protected void onPostExecute(Exception e) {

@Override
public void onFailure(Exception e) {

onSaveListener.onFailure(e);
}
});
}
Expand Down
@@ -0,0 +1,58 @@
package ja.burhanrashid52.photoeditor;

import android.graphics.Bitmap;

/**
* @author <a href="https://github.com/burhanrashid52">Burhanuddin Rashid</a>
* @since 8/8/2018
* Builder Class to apply multiple save options
*/
public class SaveSettings {
private boolean isTransparencyEnabled;
private boolean isClearViewsEnabled;

boolean isTransparencyEnabled() {
return isTransparencyEnabled;
}

boolean isClearViewsEnabled() {
return isClearViewsEnabled;
}

private SaveSettings(Builder builder) {
this.isClearViewsEnabled = builder.isClearViewsEnabled;
this.isTransparencyEnabled = builder.isTransparencyEnabled;
}

public static class Builder {
private boolean isTransparencyEnabled = true;
private boolean isClearViewsEnabled = true;

/**
* Define a flag to enable transparency while saving image
*
* @param transparencyEnabled true if enabled
* @return Builder
* @see BitmapUtil#removeTransparency(Bitmap)
*/
public Builder setTransparencyEnabled(boolean transparencyEnabled) {
isTransparencyEnabled = transparencyEnabled;
return this;
}

/**
* Define a flag to clear the view after saving the image
*
* @param clearViewsEnabled true if you want to clear all the views on {@link PhotoEditorView}
* @return
*/
public Builder setClearViewsEnabled(boolean clearViewsEnabled) {
isClearViewsEnabled = clearViewsEnabled;
return this;
}

public SaveSettings build() {
return new SaveSettings(this);
}
}
}

0 comments on commit 650463a

Please sign in to comment.