Search in sources :

Example 1 with ImageEditorView

use of org.signal.imageeditor.core.ImageEditorView 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 2 with ImageEditorView

use of org.signal.imageeditor.core.ImageEditorView 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);
            }
        }
    });
}
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)

Aggregations

MenuItem (android.view.MenuItem)2 Toolbar (androidx.appcompat.widget.Toolbar)2 ImageEditorView (org.signal.imageeditor.core.ImageEditorView)2 EditorElement (org.signal.imageeditor.core.model.EditorElement)2 EditorModel (org.signal.imageeditor.core.model.EditorModel)2 MultiLineTextRenderer (org.signal.imageeditor.core.renderers.MultiLineTextRenderer)2