Search in sources :

Example 6 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.

the class ImageEditorFragment method addText.

protected void addText() {
    String initialText = "";
    int color = imageEditorHud.getActiveColor();
    MultiLineTextRenderer renderer = new MultiLineTextRenderer(initialText, color, MultiLineTextRenderer.Mode.REGULAR);
    EditorElement element = new EditorElement(renderer, EditorModel.Z_TEXT);
    imageEditorView.getModel().addElementCentered(element, 1);
    imageEditorView.invalidate();
    setCurrentSelection(element);
    startTextEntityEditing(element, true);
}
Also used : MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) EditorElement(org.signal.imageeditor.core.model.EditorElement) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 7 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.

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;
}
Also used : EditorModel(org.signal.imageeditor.core.model.EditorModel) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) EditorElement(org.signal.imageeditor.core.model.EditorElement) UrlRenderer(org.signal.imageeditor.app.renderers.UrlRenderer) UriRenderer(org.signal.imageeditor.app.renderers.UriRenderer)

Example 8 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.

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);
            }
        }
    });
}
Also used : EditorModel(org.signal.imageeditor.core.model.EditorModel) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) EditorElement(org.signal.imageeditor.core.model.EditorElement) MenuItem(android.view.MenuItem) ImageEditorView(org.signal.imageeditor.core.ImageEditorView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 9 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.

the class ImageEditorView method startAMoveAndResizeSession.

private EditSession startAMoveAndResizeSession(@NonNull Matrix inverse, @NonNull PointF point, @Nullable EditorElement selected) {
    Matrix elementInverseMatrix;
    if (selected == null)
        return null;
    if (selected.getRenderer() instanceof ThumbRenderer) {
        ThumbRenderer thumb = (ThumbRenderer) selected.getRenderer();
        EditorElement thumbControlledElement = getModel().findById(thumb.getElementToControl());
        if (thumbControlledElement == null)
            return null;
        EditorElement thumbsParent = getModel().getRoot().findParent(selected);
        if (thumbsParent == null)
            return null;
        Matrix thumbContainerRelativeMatrix = model.findRelativeMatrix(thumbsParent, thumbControlledElement);
        if (thumbContainerRelativeMatrix == null)
            return null;
        selected = thumbControlledElement;
        elementInverseMatrix = model.findElementInverseMatrix(selected, viewMatrix);
        if (elementInverseMatrix != null) {
            return ThumbDragEditSession.startDrag(selected, elementInverseMatrix, thumbContainerRelativeMatrix, thumb.getControlPoint(), point);
        } else {
            return null;
        }
    }
    return ElementDragEditSession.startDrag(selected, inverse, point);
}
Also used : Matrix(android.graphics.Matrix) EditorElement(org.signal.imageeditor.core.model.EditorElement) ThumbRenderer(org.signal.imageeditor.core.model.ThumbRenderer)

Example 10 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.

the class ImageEditorFragment method renderFaceBlurs.

private void renderFaceBlurs(@NonNull FaceDetectionResult result) {
    List<FaceDetector.Face> faces = result.faces;
    if (faces.isEmpty()) {
        cachedFaceDetection = null;
        return;
    }
    imageEditorView.getModel().pushUndoPoint();
    Matrix faceMatrix = new Matrix();
    for (FaceDetector.Face face : faces) {
        Renderer faceBlurRenderer = new FaceBlurRenderer();
        EditorElement element = new EditorElement(faceBlurRenderer, EditorModel.Z_MASK);
        Matrix localMatrix = element.getLocalMatrix();
        faceMatrix.setRectToRect(Bounds.FULL_BOUNDS, face.getBounds(), Matrix.ScaleToFit.FILL);
        localMatrix.set(result.position);
        localMatrix.preConcat(faceMatrix);
        element.getFlags().setEditable(false).setSelectable(false).persist();
        imageEditorView.getModel().addElementWithoutPushUndo(element);
    }
    imageEditorView.invalidate();
    cachedFaceDetection = new Pair<>(getUri(), result);
}
Also used : Matrix(android.graphics.Matrix) SelectableRenderer(org.signal.imageeditor.core.SelectableRenderer) Renderer(org.signal.imageeditor.core.Renderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer) BezierDrawingRenderer(org.signal.imageeditor.core.renderers.BezierDrawingRenderer) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer) EditorElement(org.signal.imageeditor.core.model.EditorElement) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer)

Aggregations

EditorElement (org.signal.imageeditor.core.model.EditorElement)24 EditorModel (org.signal.imageeditor.core.model.EditorModel)10 Matrix (android.graphics.Matrix)8 Point (android.graphics.Point)8 MultiLineTextRenderer (org.signal.imageeditor.core.renderers.MultiLineTextRenderer)8 Paint (android.graphics.Paint)6 BezierDrawingRenderer (org.signal.imageeditor.core.renderers.BezierDrawingRenderer)4 FaceBlurRenderer (org.signal.imageeditor.core.renderers.FaceBlurRenderer)4 Bitmap (android.graphics.Bitmap)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 RectF (android.graphics.RectF)2 Uri (android.net.Uri)2 DisplayMetrics (android.util.DisplayMetrics)2 MenuItem (android.view.MenuItem)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Toolbar (androidx.appcompat.widget.Toolbar)2 UriRenderer (org.signal.imageeditor.app.renderers.UriRenderer)2 UrlRenderer (org.signal.imageeditor.app.renderers.UrlRenderer)2 ColorableRenderer (org.signal.imageeditor.core.ColorableRenderer)2 ImageEditorView (org.signal.imageeditor.core.ImageEditorView)2