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);
}
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);
}
}
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);
}
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);
}
Aggregations