Search in sources :

Example 6 with DrawableHighlightView

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

the class StickersPanel method addSticker.

/**
	 * Adds the sticker.
	 * 
	 * @param drawable
	 *           - the drawable
	 * @param rotateAndResize
	 *           - allow rotate and resize
	 */
private void addSticker(FeatherDrawable drawable, boolean rotateAndResize, RectF positionRect) {
    mLogger.info("addSticker: " + drawable + ", rotate: " + rotateAndResize + ", position: " + positionRect);
    setIsChanged(true);
    DrawableHighlightView hv = new DrawableHighlightView(mImageView, drawable);
    hv.setOnDeleteClickListener(new OnDeleteClickListener() {

        @Override
        public void onDeleteClick() {
            onClearCurrent(true);
        }
    });
    Matrix mImageMatrix = mImageView.getImageViewMatrix();
    int cropWidth, cropHeight;
    int x, y;
    final int width = mImageView.getWidth();
    final int height = mImageView.getHeight();
    // width/height of the sticker
    if (positionRect != null) {
        cropWidth = (int) positionRect.width();
        cropHeight = (int) positionRect.height();
    } else {
        cropWidth = drawable.getIntrinsicWidth();
        cropHeight = drawable.getIntrinsicHeight();
    }
    final int cropSize = Math.max(cropWidth, cropHeight);
    final int screenSize = Math.min(mImageView.getWidth(), mImageView.getHeight());
    if (cropSize > screenSize) {
        float ratio;
        float widthRatio = (float) mImageView.getWidth() / cropWidth;
        float heightRatio = (float) mImageView.getHeight() / cropHeight;
        if (widthRatio < heightRatio) {
            ratio = widthRatio;
        } else {
            ratio = heightRatio;
        }
        cropWidth = (int) ((float) cropWidth * (ratio / 2));
        cropHeight = (int) ((float) cropHeight * (ratio / 2));
        if (positionRect == null) {
            int w = mImageView.getWidth();
            int h = mImageView.getHeight();
            positionRect = new RectF(w / 2 - cropWidth / 2, h / 2 - cropHeight / 2, w / 2 + cropWidth / 2, h / 2 + cropHeight / 2);
        }
        positionRect.inset((positionRect.width() - cropWidth) / 2, (positionRect.height() - cropHeight) / 2);
    }
    if (positionRect != null) {
        x = (int) positionRect.left;
        y = (int) positionRect.top;
    } else {
        x = (width - cropWidth) / 2;
        y = (height - cropHeight) / 2;
    }
    Matrix matrix = new Matrix(mImageMatrix);
    matrix.invert(matrix);
    float[] pts = new float[] { x, y, x + cropWidth, y + cropHeight };
    MatrixUtils.mapPoints(matrix, pts);
    RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
    Rect imageRect = new Rect(0, 0, width, height);
    hv.setRotateAndScale(rotateAndResize);
    hv.setup(mImageMatrix, imageRect, cropRect, false);
    hv.drawOutlineFill(true);
    hv.drawOutlineStroke(true);
    hv.setPadding(mStickerHvPadding);
    hv.setOutlineStrokeColor(mStickerHvStrokeColorStateList);
    hv.setOutlineFillColor(mStickerHvFillColorStateList);
    hv.setOutlineEllipse(mStickerHvEllipse);
    hv.setMinSize(mStickerHvMinSize);
    Paint stroke = hv.getOutlineStrokePaint();
    stroke.setStrokeWidth(mStickerHvStrokeWidth);
    hv.getOutlineFillPaint().setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_ATOP));
    ((ImageViewDrawableOverlay) mImageView).addHighlightView(hv);
    ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(hv);
}
Also used : RectF(android.graphics.RectF) ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) OnDeleteClickListener(com.aviary.android.feather.widget.DrawableHighlightView.OnDeleteClickListener) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 7 with DrawableHighlightView

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

the class StickersPanel method onClearCurrent.

/**
	 * Remove the current sticker.
	 * 
	 * @param removed
	 *           - true if the current sticker is being removed, otherwise it was flattened
	 */
private void onClearCurrent(boolean removed) {
    mLogger.info("onClearCurrent. removed=" + removed);
    if (stickersOnScreen()) {
        final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
        final DrawableHighlightView hv = image.getHighlightViewAt(0);
        onClearCurrent(hv, removed);
    }
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView)

Example 8 with DrawableHighlightView

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

the class MemePanel method onAddBottomText.

/**
	 * Create and place the bottom editable text.
	 */
private void onAddBottomText() {
    final Matrix mImageMatrix = mImageView.getImageViewMatrix();
    final int width = (int) (mBitmap.getWidth());
    final int height = (int) (mBitmap.getHeight());
    final MemeTextDrawable text = new MemeTextDrawable("", (float) mBitmap.getHeight() / 7.0f, mTypeface);
    text.setTextColor(Color.WHITE);
    text.setTextStrokeColor(Color.BLACK);
    text.setContentSize(width, height);
    bottomHv = new DrawableHighlightView(mImageView, text);
    bottomHv.setAlignModeV(DrawableHighlightView.AlignModeV.Bottom);
    final int cropHeight = text.getIntrinsicHeight();
    final int x = 0;
    final int y = 0;
    final Matrix matrix = new Matrix(mImageMatrix);
    matrix.invert(matrix);
    final float[] pts = new float[] { x, y + height - cropHeight - (height / 30), x + width, y + height - (height / 30) };
    MatrixUtils.mapPoints(matrix, pts);
    final RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
    addEditable(bottomHv, mImageMatrix, cropRect);
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) MemeTextDrawable(com.aviary.android.feather.library.graphics.drawable.MemeTextDrawable) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView)

Example 9 with DrawableHighlightView

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

the class MemePanel method onAddTopText.

/**
	 * Creates and places the top editable text
	 */
private void onAddTopText() {
    final Matrix mImageMatrix = mImageView.getImageViewMatrix();
    final int width = (int) (mBitmap.getWidth());
    final int height = (int) (mBitmap.getHeight());
    final MemeTextDrawable text = new MemeTextDrawable("", (float) mBitmap.getHeight() / 7.f, mTypeface);
    text.setTextColor(Color.WHITE);
    text.setTextStrokeColor(Color.BLACK);
    text.setContentSize(width, height);
    topHv = new DrawableHighlightView(mImageView, text);
    topHv.setAlignModeV(DrawableHighlightView.AlignModeV.Top);
    final int cropHeight = text.getIntrinsicHeight();
    final int x = 0;
    final int y = 0;
    final Matrix matrix = new Matrix(mImageMatrix);
    matrix.invert(matrix);
    final float[] pts = new float[] { x, y, x + width, y + cropHeight };
    MatrixUtils.mapPoints(matrix, pts);
    final RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
    addEditable(topHv, mImageMatrix, cropRect);
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) MemeTextDrawable(com.aviary.android.feather.library.graphics.drawable.MemeTextDrawable) 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