Search in sources :

Example 1 with ImageViewDrawableOverlay

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

the class StickersPanel method onClearCurrent.

/**
	 * Removes the current active sticker.
	 * 
	 * @param hv
	 *           - the {@link DrawableHighlightView} of the active sticker
	 * @param removed
	 *           - current sticker is removed
	 */
private void onClearCurrent(DrawableHighlightView hv, boolean removed) {
    mLogger.info("onClearCurrent. hv=" + hv + ", removed=" + removed);
    if (mCurrentFilter != null) {
        mCurrentFilter = null;
    }
    if (null != hv) {
        FeatherDrawable content = hv.getContent();
        if (removed) {
            if (content instanceof StickerDrawable) {
                String name = ((StickerDrawable) content).getStickerName();
                String packname = ((StickerDrawable) content).getPackLabel();
                Tracker.recordTag(name + ": Cancelled");
                Tracker.recordTag(packname + ": Cancelled");
            }
        }
    }
    hv.setOnDeleteClickListener(null);
    ((ImageViewDrawableOverlay) mImageView).removeHightlightView(hv);
    ((ImageViewDrawableOverlay) mImageView).invalidate();
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) FeatherDrawable(com.aviary.android.feather.library.graphics.drawable.FeatherDrawable) StickerDrawable(com.aviary.android.feather.library.graphics.drawable.StickerDrawable)

Example 2 with ImageViewDrawableOverlay

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

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

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

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

ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)10 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)7 Matrix (android.graphics.Matrix)3 Paint (android.graphics.Paint)3 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 EditableDrawable (com.aviary.android.feather.library.graphics.drawable.EditableDrawable)3 Point (android.graphics.Point)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 StickerDrawable (com.aviary.android.feather.library.graphics.drawable.StickerDrawable)2 ColorStateList (android.content.res.ColorStateList)1 Handler (android.os.Handler)1 ResultReceiver (android.os.ResultReceiver)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AsyncImageManager (com.aviary.android.feather.async_tasks.AsyncImageManager)1 FeatherDrawable (com.aviary.android.feather.library.graphics.drawable.FeatherDrawable)1