正在查看: Biko v2.0.23 应用的 EditorActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Biko v2.0.23 应用的 EditorActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package in.onato.imageeditor.editor;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import com.canhub.cropper.CropImage;
import com.canhub.cropper.CropImageContract;
import com.canhub.cropper.CropImageContractOptions;
import com.canhub.cropper.CropImageView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import in.onato.imageeditor.R;
import in.onato.imageeditor.editor.StickerBSFragment;
import in.onato.imageeditor.editor.TextEditorDialogFragment;
import in.onato.imageeditor.editor.VerticalSlideColorPicker;
import ja.burhanrashid52.photoeditor.OnSaveBitmap;
import ja.burhanrashid52.photoeditor.PhotoEditor;
import ja.burhanrashid52.photoeditor.PhotoEditorView;
import ja.burhanrashid52.photoeditor.SaveSettings;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class EditorActivity extends AppCompatActivity implements View.OnClickListener, StickerBSFragment.StickerListener {
VerticalSlideColorPicker colorPickerView;
private final ActivityResultLauncher<CropImageContractOptions> cropImage = registerForActivityResult(new CropImageContract(), new ActivityResultCallback() {
public final void onActivityResult(Object obj) {
EditorActivity.this.onCropImageResult((CropImageView.CropResult) obj);
}
});
FloatingActionButton fabPhotoDone;
ImageView imagePhotoEditBack;
ImageView imagePhotoEditCrop;
ImageView imagePhotoEditPaint;
ImageView imagePhotoEditRedo;
ImageView imagePhotoEditSticker;
ImageView imagePhotoEditText;
ImageView imagePhotoEditUndo;
private PhotoEditor mPhotoEditor;
private int mSelectedColor;
private StickerBSFragment mStickerBSFragment;
PhotoEditorView photoEditorView;
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_editor);
this.mSelectedColor = ContextCompat.getColor(this, R.color.yellow);
this.imagePhotoEditBack = (ImageView) findViewById(R.id.img_photo_edit_back);
this.imagePhotoEditUndo = (ImageView) findViewById(R.id.img_photo_edit_undo);
this.imagePhotoEditRedo = (ImageView) findViewById(R.id.img_photo_edit_redo);
this.imagePhotoEditCrop = (ImageView) findViewById(R.id.img_photo_edit_crop);
this.imagePhotoEditSticker = (ImageView) findViewById(R.id.img_photo_edit_stickers);
this.imagePhotoEditText = (ImageView) findViewById(R.id.img_photo_edit_text);
this.imagePhotoEditPaint = (ImageView) findViewById(R.id.img_photo_edit_paint);
this.photoEditorView = (PhotoEditorView) findViewById(R.id.photo_editor_view);
this.fabPhotoDone = findViewById(R.id.fab_photo_done);
PhotoEditor build = new PhotoEditor.Builder(this, this.photoEditorView).setPinchTextScalable(true).build();
this.mPhotoEditor = build;
build.setBrushSize(12.0f);
VerticalSlideColorPicker verticalSlideColorPicker = (VerticalSlideColorPicker) findViewById(R.id.color_picker_view);
this.colorPickerView = verticalSlideColorPicker;
verticalSlideColorPicker.setOnColorChangeListener(new VerticalSlideColorPicker.OnColorChangeListener() {
@Override
public void onColorChange(int i2) {
if (EditorActivity.this.colorPickerView.getVisibility() == 0) {
EditorActivity.this.mSelectedColor = i2;
EditorActivity.this.imagePhotoEditPaint.setBackgroundColor(i2);
EditorActivity.this.mPhotoEditor.setBrushColor(i2);
}
}
});
this.imagePhotoEditBack.setOnClickListener(this);
this.imagePhotoEditUndo.setOnClickListener(this);
this.imagePhotoEditRedo.setOnClickListener(this);
this.imagePhotoEditCrop.setOnClickListener(this);
this.imagePhotoEditSticker.setOnClickListener(this);
this.imagePhotoEditText.setOnClickListener(this);
this.imagePhotoEditPaint.setOnClickListener(this);
this.fabPhotoDone.setOnClickListener(this);
StickerBSFragment stickerBSFragment = new StickerBSFragment();
this.mStickerBSFragment = stickerBSFragment;
stickerBSFragment.setStickerListener(this);
showBrush(false);
try {
if (getIntent().getStringExtra("imageUri") == null) {
return;
}
Uri parse = Uri.parse(getIntent().getStringExtra("imageUri"));
if (parse == null) {
finish();
}
this.photoEditorView.getSource().setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(), parse));
} catch (Exception e2) {
e2.printStackTrace();
}
}
@Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.img_photo_edit_back) {
finish();
return;
}
if (id == R.id.img_photo_edit_undo) {
this.mPhotoEditor.undo();
return;
}
if (id == R.id.img_photo_edit_redo) {
this.mPhotoEditor.redo();
return;
}
if (id == R.id.img_photo_edit_crop) {
try {
this.mPhotoEditor.saveAsBitmap(new OnSaveBitmap() {
@Override
public void onFailure(Exception exc) {
}
@Override
public void onBitmapReady(Bitmap bitmap) {
Uri createImageFromBitmap = EditorActivity.this.createImageFromBitmap(bitmap);
Log.e("TAG", "onClick: Image Uri " + createImageFromBitmap);
SExtendActivity.INSTANCE.start(EditorActivity.this, createImageFromBitmap);
}
});
return;
} catch (Exception unused) {
return;
}
}
if (id == R.id.img_photo_edit_stickers) {
showBrush(false);
this.mStickerBSFragment.show(getSupportFragmentManager(), this.mStickerBSFragment.getTag());
} else if (id == R.id.img_photo_edit_text) {
showBrush(false);
TextEditorDialogFragment.show(this).setOnTextEditorListener(new TextEditorDialogFragment.TextEditor() {
@Override
public void onDone(String str, int i2) {
EditorActivity.this.mPhotoEditor.addText(str, i2);
}
});
} else if (id == R.id.img_photo_edit_paint) {
showBrush(this.colorPickerView.getVisibility() != 0);
} else if (id == R.id.fab_photo_done) {
saveImage();
}
}
@Override
public void onStickerClick(Bitmap bitmap) {
this.mPhotoEditor.addImage(bitmap);
}
private void showBrush(boolean z) {
if (z) {
this.mPhotoEditor.setBrushColor(this.mSelectedColor);
Log.e("TAG", "showBrush: mSelectedColor " + this.mSelectedColor);
this.imagePhotoEditPaint.setBackgroundColor(this.mSelectedColor);
this.mPhotoEditor.setBrushDrawingMode(true);
this.colorPickerView.setVisibility(0);
return;
}
this.imagePhotoEditPaint.setBackgroundColor(getResources().getColor(android.R.color.transparent));
this.mPhotoEditor.setBrushDrawingMode(false);
this.colorPickerView.setVisibility(4);
}
private void saveImage() {
File file = new File(getCacheDir().toString() + "/PhotoEditing");
if (!file.isDirectory()) {
file.mkdirs();
}
try {
new File(file + File.separator + "" + System.currentTimeMillis() + ".jpeg").createNewFile();
this.mPhotoEditor.saveAsBitmap(new SaveSettings.Builder().setClearViewsEnabled(true).setTransparencyEnabled(true).build(), new OnSaveBitmap() {
@Override
public void onBitmapReady(Bitmap bitmap) {
EditorActivity.this.setResult(-1, new Intent().putExtra("imagePath", EditorActivity.this.createImageJpegFromBitmap(bitmap)));
EditorActivity.this.finish();
}
@Override
public void onFailure(Exception exc) {
?? r3 = EditorActivity.this;
Toast.makeText((Context) r3, r3.getString(R.string.save_failed), 0).show();
}
});
} catch (IOException e2) {
e2.printStackTrace();
Toast.makeText((Context) this, (CharSequence) e2.getMessage(), 0).show();
}
}
public void onCropImageResult(CropImageView.CropResult cropResult) {
if (cropResult.isSuccessful()) {
return;
}
cropResult.equals(CropImage.CancelledResult.INSTANCE);
}
protected void onActivityResult(int i2, int i3, Intent intent) {
super.onActivityResult(i2, i3, intent);
if (i2 == 101 && i3 == -1 && intent != null) {
try {
Uri parse = Uri.parse(intent.getStringExtra("imageUri"));
if (parse != null) {
this.photoEditorView.getSource().setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(), parse));
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public Uri createImageFromBitmap(Bitmap bitmap) {
try {
File file = new File(getExternalCacheDir() + "/DCIM/");
if (!file.exists()) {
file.mkdirs();
}
File file2 = new File(getExternalCacheDir() + "/DCIM/tempImage.png");
FileOutputStream fileOutputStream = new FileOutputStream(file2);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.close();
return Uri.fromFile(file2);
} catch (Exception e2) {
e2.printStackTrace();
return null;
}
}
public String createImageJpegFromBitmap(Bitmap bitmap) {
String str = "tempImage1" + System.currentTimeMillis();
try {
File file = new File(getExternalCacheDir() + "/DCIM/");
if (!file.exists()) {
file.mkdirs();
}
File file2 = new File(getExternalCacheDir() + "/DCIM/" + str + ".jpeg");
FileOutputStream fileOutputStream = new FileOutputStream(file2);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.close();
return file2.getPath();
} catch (Exception e2) {
e2.printStackTrace();
return null;
}
}
}