Search in sources :

Example 1 with EditableDrawable

use of com.aviary.android.feather.library.graphics.drawable.EditableDrawable in project mobile-android by photo.

the class TextPanel method beginEdit.

/**
	 * Begin edit and open the android soft keyboard if available
	 * 
	 * @param view
	 *           the view
	 */
private void beginEdit(final DrawableHighlightView view) {
    if (null != view) {
        view.setFocused(true);
    }
    mEditTextWatcher.view = null;
    mEditText.removeTextChangedListener(mEditTextWatcher);
    mEditText.setOnKeyListener(null);
    final EditableDrawable editable = (EditableDrawable) view.getContent();
    final String oldText = editable.isTextHint() ? "" : (String) editable.getText();
    mEditText.setText(oldText);
    mEditText.setSelection(mEditText.length());
    mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    mEditText.requestFocusFromTouch();
    // mInputManager.showSoftInput( mEditText, InputMethodManager.SHOW_IMPLICIT );
    mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    mEditTextWatcher.view = view;
    mEditText.setOnEditorActionListener(this);
    mEditText.addTextChangedListener(mEditTextWatcher);
    mEditText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            mLogger.log("onKey: " + event);
            if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_BACK) {
                if (editable.isTextHint() && editable.isEditing()) {
                    editable.setText("");
                    view.forceUpdate();
                }
            }
            return false;
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) OnKeyListener(android.view.View.OnKeyListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AdapterView(com.aviary.android.feather.widget.AdapterView) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint)

Example 2 with EditableDrawable

use of com.aviary.android.feather.library.graphics.drawable.EditableDrawable in project mobile-android by photo.

the class TextPanel method onApplyCurrent.

/**
	 * Flatten the view on the current image
	 * 
	 * @param hv
	 *           the hv
	 */
private MoaActionList onApplyCurrent(final DrawableHighlightView hv) {
    MoaActionList actionList = MoaActionFactory.actionList();
    if (hv != null) {
        setIsChanged(true);
        final RectF cropRect = hv.getCropRectF();
        final Rect rect = new Rect((int) cropRect.left, (int) cropRect.top, (int) cropRect.right, (int) cropRect.bottom);
        final Matrix rotateMatrix = hv.getCropRotationMatrix();
        final int w = mBitmap.getWidth();
        final int h = mBitmap.getHeight();
        final float left = cropRect.left / w;
        final float top = cropRect.top / h;
        final float right = cropRect.right / w;
        final float bottom = cropRect.bottom / h;
        final Matrix matrix = new Matrix(mImageView.getImageMatrix());
        if (!matrix.invert(matrix))
            mLogger.error("unable to invert matrix");
        EditableDrawable editable = (EditableDrawable) hv.getContent();
        editable.endEdit();
        mImageView.invalidate();
        MoaAction action = MoaActionFactory.action("addtext");
        action.setValue("text", (String) editable.getText());
        action.setValue("fillcolor", new MoaColorParameter(mColor));
        action.setValue("outlinecolor", new MoaColorParameter(mStrokeColor));
        action.setValue("rotation", hv.getRotation());
        action.setValue("topleft", new MoaPointParameter(left, top));
        action.setValue("bottomright", new MoaPointParameter(right, bottom));
        actionList.add(action);
        final int saveCount = mCanvas.save(Canvas.MATRIX_SAVE_FLAG);
        mCanvas.concat(rotateMatrix);
        hv.getContent().setBounds(rect);
        hv.getContent().draw(mCanvas);
        mCanvas.restoreToCount(saveCount);
        mImageView.invalidate();
        onClearCurrent(hv);
    }
    onPreviewChanged(mPreview, false);
    return actionList;
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) MoaColorParameter(com.aviary.android.feather.library.moa.MoaColorParameter) MoaActionList(com.aviary.android.feather.library.moa.MoaActionList) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) MoaPointParameter(com.aviary.android.feather.library.moa.MoaPointParameter) MoaAction(com.aviary.android.feather.library.moa.MoaAction) Paint(android.graphics.Paint)

Example 3 with EditableDrawable

use of com.aviary.android.feather.library.graphics.drawable.EditableDrawable in project mobile-android by photo.

the class TextPanel method updateCurrentHighlightColor.

/**
	 * Update current highlight color.
	 */
private void updateCurrentHighlightColor() {
    final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
    if (image.getSelectedHighlightView() != null) {
        final DrawableHighlightView hv = image.getSelectedHighlightView();
        if (hv.getContent() instanceof EditableDrawable) {
            ((EditableDrawable) hv.getContent()).setTextColor(mColor);
            ((EditableDrawable) hv.getContent()).setTextStrokeColor(mStrokeColor);
            mImageView.postInvalidate();
        }
    }
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView)

Example 4 with EditableDrawable

use of com.aviary.android.feather.library.graphics.drawable.EditableDrawable in project mobile-android by photo.

the class TextPanel method onApplyCurrent.

/**
	 * apply the current text and flatten it over the image.
	 */
private MoaActionList onApplyCurrent() {
    final MoaActionList nullActions = MoaActionFactory.actionList();
    final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
    if (image.getHighlightCount() < 1)
        return nullActions;
    final DrawableHighlightView hv = ((ImageViewDrawableOverlay) mImageView).getHighlightViewAt(0);
    if (hv != null) {
        if (hv.getContent() instanceof EditableDrawable) {
            EditableDrawable editable = (EditableDrawable) hv.getContent();
            if (editable != null) {
                if (editable.isTextHint()) {
                    setIsChanged(false);
                    return nullActions;
                }
            }
        }
        return onApplyCurrent(hv);
    }
    return nullActions;
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) MoaActionList(com.aviary.android.feather.library.moa.MoaActionList) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView)

Example 5 with EditableDrawable

use of com.aviary.android.feather.library.graphics.drawable.EditableDrawable in project mobile-android by photo.

the class MemePanel method beginEditText.

/**
	 * Begin edit text.
	 * 
	 * @param view
	 *           the view
	 */
private void beginEditText(final DrawableHighlightView view) {
    mLogger.info("beginEditText", view);
    EditText editText = null;
    if (view == topHv) {
        editText = editTopText;
    } else if (view == bottomHv) {
        editText = editBottomText;
    }
    if (editText != null) {
        mEditTextWatcher.view = null;
        editText.removeTextChangedListener(mEditTextWatcher);
        final EditableDrawable editable = (EditableDrawable) view.getContent();
        final String oldText = (String) editable.getText();
        editText.setText(oldText);
        editText.setSelection(editText.length());
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        editText.requestFocusFromTouch();
        Handler handler = new Handler();
        ResultReceiver receiver = new ResultReceiver(handler);
        if (!mInputManager.showSoftInput(editText, 0, receiver)) {
            // TODO: verify
            mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
        mEditTextWatcher.view = view;
        editText.setOnEditorActionListener(this);
        editText.addTextChangedListener(mEditTextWatcher);
        ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(view);
        ((EditableDrawable) view.getContent()).setText(((EditableDrawable) view.getContent()).getText());
        view.forceUpdate();
    }
}
Also used : EditText(android.widget.EditText) ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) Handler(android.os.Handler) ResultReceiver(android.os.ResultReceiver)

Aggregations

EditableDrawable (com.aviary.android.feather.library.graphics.drawable.EditableDrawable)7 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)3 ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)3 Paint (android.graphics.Paint)2 MoaActionList (com.aviary.android.feather.library.moa.MoaActionList)2 Matrix (android.graphics.Matrix)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 Handler (android.os.Handler)1 ResultReceiver (android.os.ResultReceiver)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnKeyListener (android.view.View.OnKeyListener)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MoaAction (com.aviary.android.feather.library.moa.MoaAction)1 MoaColorParameter (com.aviary.android.feather.library.moa.MoaColorParameter)1 MoaPointParameter (com.aviary.android.feather.library.moa.MoaPointParameter)1 AdapterView (com.aviary.android.feather.widget.AdapterView)1