Search in sources :

Example 1 with DrawableHighlightView

use of com.aviary.android.feather.widget.DrawableHighlightView in project mobile-android by photo.

the class StickersPanel method onApplyCurrent.

/**
	 * Flatten the current sticker within the preview bitmap. No more changes will be possible on this sticker.
	 */
private void onApplyCurrent() {
    mLogger.info("onApplyCurrent");
    if (!stickersOnScreen())
        return;
    final DrawableHighlightView hv = ((ImageViewDrawableOverlay) mImageView).getHighlightViewAt(0);
    if (hv != null) {
        final StickerDrawable stickerDrawable = ((StickerDrawable) hv.getContent());
        RectF cropRect = hv.getCropRectF();
        Rect rect = new Rect((int) cropRect.left, (int) cropRect.top, (int) cropRect.right, (int) cropRect.bottom);
        Matrix rotateMatrix = hv.getCropRotationMatrix();
        Matrix matrix = new Matrix(mImageView.getImageMatrix());
        if (!matrix.invert(matrix)) {
        }
        int saveCount = mCanvas.save(Canvas.MATRIX_SAVE_FLAG);
        mCanvas.concat(rotateMatrix);
        stickerDrawable.setDropShadow(false);
        hv.getContent().setBounds(rect);
        hv.getContent().draw(mCanvas);
        mCanvas.restoreToCount(saveCount);
        mImageView.invalidate();
        if (mCurrentFilter != null) {
            final int w = mBitmap.getWidth();
            final int h = mBitmap.getHeight();
            mCurrentFilter.setTopLeft(cropRect.left / w, cropRect.top / h);
            mCurrentFilter.setBottomRight(cropRect.right / w, cropRect.bottom / h);
            mCurrentFilter.setRotation(Math.toRadians(hv.getRotation()));
            int dw = stickerDrawable.getBitmapWidth();
            int dh = stickerDrawable.getBitmapHeight();
            float scalew = cropRect.width() / dw;
            float scaleh = cropRect.height() / dh;
            mCurrentFilter.setCenter(cropRect.centerX() / w, cropRect.centerY() / h);
            mCurrentFilter.setScale(scalew, scaleh);
            mActionList.add(mCurrentFilter.getActions().get(0));
            Tracker.recordTag(stickerDrawable.getPackLabel() + ": Applied");
            mCurrentFilter = null;
        }
    }
    onClearCurrent(false);
    onPreviewChanged(mPreview, false);
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) RectF(android.graphics.RectF) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint) Point(android.graphics.Point) StickerDrawable(com.aviary.android.feather.library.graphics.drawable.StickerDrawable)

Example 2 with DrawableHighlightView

use of com.aviary.android.feather.widget.DrawableHighlightView in project mobile-android by photo.

the class TextPanel method onAddNewText.

/**
	 * Add a new editable text on the screen.
	 */
private void onAddNewText() {
    final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
    if (image.getHighlightCount() > 0)
        onApplyCurrent(image.getHighlightViewAt(0));
    final TextDrawable text = new TextDrawable("", defaultTextSize);
    text.setTextColor(mColor);
    text.setTextHint(getContext().getBaseContext().getString(R.string.enter_text_here));
    final DrawableHighlightView hv = new DrawableHighlightView(mImageView, text);
    final Matrix mImageMatrix = mImageView.getImageViewMatrix();
    final int width = mImageView.getWidth();
    final int height = mImageView.getHeight();
    final int imageSize = Math.max(width, height);
    // width/height of the sticker
    int cropWidth = text.getIntrinsicWidth();
    int cropHeight = text.getIntrinsicHeight();
    final int cropSize = Math.max(cropWidth, cropHeight);
    if (cropSize > imageSize) {
        cropWidth = width / 2;
        cropHeight = height / 2;
    }
    final int x = (width - cropWidth) / 2;
    final int y = (height - cropHeight) / 2;
    final Matrix matrix = new Matrix(mImageMatrix);
    matrix.invert(matrix);
    final float[] pts = new float[] { x, y, x + cropWidth, y + cropHeight };
    MatrixUtils.mapPoints(matrix, pts);
    final RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
    final Rect imageRect = new Rect(0, 0, width, height);
    hv.setRotateAndScale(true);
    hv.showDelete(false);
    hv.setup(mImageMatrix, imageRect, cropRect, false);
    hv.drawOutlineFill(true);
    hv.drawOutlineStroke(true);
    hv.setPadding(textPadding);
    hv.setMinSize(minTextSize);
    hv.setOutlineEllipse(mHighlightEllipse);
    hv.setOutlineFillColor(mHighlightFillColorStateList);
    hv.setOutlineStrokeColor(mHighlightStrokeColorStateList);
    Paint stroke = hv.getOutlineStrokePaint();
    stroke.setStrokeWidth(mHighlightStrokeWidth);
    image.addHighlightView(hv);
    // image.setSelectedHighlightView( hv );
    onClick(hv);
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) TextDrawable(com.aviary.android.feather.library.graphics.drawable.TextDrawable) RectF(android.graphics.RectF) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint)

Example 3 with DrawableHighlightView

use of com.aviary.android.feather.widget.DrawableHighlightView 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 4 with DrawableHighlightView

use of com.aviary.android.feather.widget.DrawableHighlightView 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 5 with DrawableHighlightView

use of com.aviary.android.feather.widget.DrawableHighlightView 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)

Aggregations

DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)9 ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)6 Matrix (android.graphics.Matrix)5 RectF (android.graphics.RectF)5 Paint (android.graphics.Paint)4 Rect (android.graphics.Rect)3 EditableDrawable (com.aviary.android.feather.library.graphics.drawable.EditableDrawable)3 Point (android.graphics.Point)2 MemeTextDrawable (com.aviary.android.feather.library.graphics.drawable.MemeTextDrawable)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnKeyListener (android.view.View.OnKeyListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 StickerDrawable (com.aviary.android.feather.library.graphics.drawable.StickerDrawable)1 TextDrawable (com.aviary.android.feather.library.graphics.drawable.TextDrawable)1 MoaActionList (com.aviary.android.feather.library.moa.MoaActionList)1 AdapterView (com.aviary.android.feather.widget.AdapterView)1 OnDeleteClickListener (com.aviary.android.feather.widget.DrawableHighlightView.OnDeleteClickListener)1