use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.
the class WallpaperCropActivity method setupImageEditor.
private void setupImageEditor(@NonNull Uri imageUri) {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
float ratio = width / (float) height;
EditorModel editorModel = EditorModel.createForWallpaperEditing(ratio);
EditorElement image = new EditorElement(new UriGlideRenderer(imageUri, true, width, height, UriGlideRenderer.WEAK_BLUR));
image.getFlags().setSelectable(false).persist();
editorModel.addElement(image);
imageEditor.setModel(editorModel);
imageEditor.setSizeChangedListener((newWidth, newHeight) -> {
float newRatio = newWidth / (float) newHeight;
Log.i(TAG, String.format(Locale.US, "Output size (%d, %d) (ratio %.2f)", newWidth, newHeight, newRatio));
editorModel.setFixedRatio(newRatio);
});
}
use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(R.string.app_name_short);
setSupportActionBar(toolbar);
imageEditorView = findViewById(R.id.image_editor);
imageEditorView.setUndoRedoStackListener((undoAvailable, redoAvailable) -> {
Log.d("ALAN", String.format("Undo/Redo available: %s, %s", undoAvailable ? "Y" : "N", redoAvailable ? "Y" : "N"));
if (menu == null)
return;
MenuItem undo = menu.findItem(R.id.action_undo);
MenuItem redo = menu.findItem(R.id.action_redo);
if (undo != null)
undo.setVisible(undoAvailable);
if (redo != null)
redo.setVisible(redoAvailable);
});
EditorModel model = null;
if (savedInstanceState != null) {
model = savedInstanceState.getParcelable("MODEL");
Log.d("ALAN", "Restoring instance " + (model != null ? model.hashCode() : 0));
}
if (model == null) {
model = initialModel();
Log.d("ALAN", "New instance created " + model.hashCode());
}
imageEditorView.setModel(model);
imageEditorView.setTapListener(new ImageEditorView.TapListener() {
@Override
public void onEntityDown(@Nullable EditorElement editorElement) {
Log.d("ALAN", "Entity down " + editorElement);
}
@Override
public void onEntitySingleTap(@Nullable EditorElement editorElement) {
Log.d("ALAN", "Entity single tapped " + editorElement);
}
@Override
public void onEntityDoubleTap(@NonNull EditorElement editorElement) {
Log.d("ALAN", "Entity double tapped " + editorElement);
if (editorElement.getRenderer() instanceof MultiLineTextRenderer) {
imageEditorView.startTextEditing(editorElement);
} else {
imageEditorView.deleteElement(editorElement);
}
}
});
}
use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.
the class MainActivity method initialModel.
private static EditorModel initialModel() {
EditorModel model = EditorModel.create();
EditorElement image = new EditorElement(new UrlRenderer("https://cdn.aarp.net/content/dam/aarp/home-and-family/your-home/2018/06/1140-house-inheriting.imgcache.rev68c065601779c5d76b913cf9ec3a977e.jpg"));
image.getFlags().setSelectable(false).persist();
model.addElement(image);
EditorElement elementC = new EditorElement(new UrlRenderer("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/220px-SNice.svg.png"));
elementC.getLocalMatrix().postScale(0.2f, 0.2f);
// elementC.getLocalMatrix().postRotate(30);
model.addElement(elementC);
EditorElement elementE = new EditorElement(new UrlRenderer("https://www.vitalessentialsraw.com/assets/images/background-images/laying-grey-cat.png"));
elementE.getLocalMatrix().postScale(0.2f, 0.2f);
// elementE.getLocalMatrix().postRotate(60);
model.addElement(elementE);
EditorElement elementD = new EditorElement(new UrlRenderer("https://petspluslubbocktx.com/files/2016/11/DC-Cat-Weight-Management.png"));
elementD.getLocalMatrix().postScale(0.2f, 0.2f);
// elementD.getLocalMatrix().postRotate(60);
model.addElement(elementD);
EditorElement elementF = new EditorElement(new UrlRenderer("https://purepng.com/public/uploads/large/purepng.com-black-top-hathatsstandard-sizeblacktop-14215263591972x0zh.png"));
elementF.getLocalMatrix().postScale(0.2f, 0.2f);
// elementF.getLocalMatrix().postRotatF(60);
model.addElement(elementF);
EditorElement elementG = new EditorElement(new UriRenderer(Uri.parse("file:///android_asset/food/apple.png")));
elementG.getLocalMatrix().postScale(0.2f, 0.2f);
// elementG.getLocalMatrix().postRotatG(60);
model.addElement(elementG);
EditorElement elementH = new EditorElement(new MultiLineTextRenderer("Hello, World!", 0xff0000ff, MultiLineTextRenderer.Mode.REGULAR));
// elementH.getLocalMatrix().postScale(0.2f, 0.2f);
model.addElement(elementH);
EditorElement elementH2 = new EditorElement(new MultiLineTextRenderer("Hello, World 2!", 0xff0000ff, MultiLineTextRenderer.Mode.REGULAR));
// elementH.getLocalMatrix().postScale(0.2f, 0.2f);
model.addElement(elementH2);
return model;
}
use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.
the class ImageEditorView method startADrawingSession.
private EditSession startADrawingSession(@NonNull PointF point) {
BezierDrawingRenderer renderer = new BezierDrawingRenderer(color, thickness * Bounds.FULL_BOUNDS.width(), cap, model.findCropRelativeToRoot());
EditorElement element = new EditorElement(renderer, mode == Mode.Blur ? EditorModel.Z_MASK : EditorModel.Z_DRAWING);
model.addElementCentered(element, 1);
Matrix elementInverseMatrix = model.findElementInverseMatrix(element, viewMatrix);
return DrawingSession.start(element, renderer, elementInverseMatrix, point);
}
use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.
the class ImageEditorFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == SELECT_STICKER_REQUEST_CODE && data != null) {
final Uri uri = data.getData();
if (uri != null) {
UriGlideRenderer renderer = new UriGlideRenderer(uri, true, imageMaxWidth, imageMaxHeight);
EditorElement element = new EditorElement(renderer, EditorModel.Z_STICKERS);
imageEditorView.getModel().addElementCentered(element, 0.4f);
setCurrentSelection(element);
hasMadeAnEditThisSession = true;
imageEditorHud.setMode(ImageEditorHudV2.Mode.MOVE_STICKER);
}
} else {
imageEditorHud.setMode(ImageEditorHudV2.Mode.DRAW);
}
}
Aggregations