Search in sources :

Example 1 with OnDeleteClickListener

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

Aggregations

Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)1 OnDeleteClickListener (com.aviary.android.feather.widget.DrawableHighlightView.OnDeleteClickListener)1 ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)1