Search in sources :

Example 1 with TextDrawable

use of com.aviary.android.feather.library.graphics.drawable.TextDrawable 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)

Aggregations

Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 TextDrawable (com.aviary.android.feather.library.graphics.drawable.TextDrawable)1 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)1 ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)1