Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated getDrawingCache to capturing method. #324

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.os.AsyncTask;
import androidx.annotation.ColorInt;
Expand Down Expand Up @@ -653,7 +654,6 @@ public void onBitmapReady(Bitmap saveBitmap) {
protected void onPreExecute() {
super.onPreExecute();
clearHelperBox();
parentView.setDrawingCacheEnabled(false);
brushDrawingView.destroyDrawingCache();
}

Expand All @@ -665,11 +665,10 @@ protected Exception doInBackground(String... strings) {
try {
FileOutputStream out = new FileOutputStream(file, false);
if (parentView != null) {
parentView.setDrawingCacheEnabled(true);
Bitmap drawingCache = saveSettings.isTransparencyEnabled()
? BitmapUtil.removeTransparency(parentView.getDrawingCache())
: parentView.getDrawingCache();
drawingCache.compress(saveSettings.getCompressFormat(), saveSettings.getCompressQuality(), out);
Bitmap capturedBitmap = saveSettings.isTransparencyEnabled()
? BitmapUtil.removeTransparency(captureView(parentView))
: captureView(parentView);
capturedBitmap.compress(saveSettings.getCompressFormat(), saveSettings.getCompressQuality(), out);
}
out.flush();
out.close();
Expand Down Expand Up @@ -733,17 +732,15 @@ public void onBitmapReady(Bitmap saveBitmap) {
protected void onPreExecute() {
super.onPreExecute();
clearHelperBox();
parentView.setDrawingCacheEnabled(false);
brushDrawingView.destroyDrawingCache();
}

@Override
protected Bitmap doInBackground(String... strings) {
if (parentView != null) {
parentView.setDrawingCacheEnabled(true);
return saveSettings.isTransparencyEnabled() ?
BitmapUtil.removeTransparency(parentView.getDrawingCache())
: parentView.getDrawingCache();
BitmapUtil.removeTransparency(captureView(parentView))
: captureView(parentView);
} else {
return null;
}
Expand Down Expand Up @@ -781,6 +778,17 @@ private static String convertEmoji(String emoji) {
return returnedEmoji;
}

private Bitmap captureView(View view) {
Bitmap bitmap = Bitmap.createBitmap(
view.getWidth(),
view.getHeight(),
Bitmap.Config.ARGB_8888
);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}

/**
* Callback on editing operation perform on {@link PhotoEditorView}
*
Expand Down