use of android.graphics.Rect in project Talon-for-Twitter by klinker24.
the class ImageUtils method getCircle.
public static Bitmap getCircle(Bitmap currentImage, Context context) {
int scale = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96, context.getResources().getDisplayMetrics());
Bitmap bitmap;
if (currentImage == null) {
return null;
}
if (currentImage.getWidth() >= currentImage.getHeight()) {
bitmap = Bitmap.createBitmap(currentImage, currentImage.getWidth() / 2 - currentImage.getHeight() / 2, 0, currentImage.getHeight(), currentImage.getHeight());
} else {
bitmap = Bitmap.createBitmap(currentImage, 0, currentImage.getHeight() / 2 - currentImage.getWidth() / 2, currentImage.getWidth(), currentImage.getWidth());
}
Bitmap output;
try {
output = Bitmap.createBitmap(scale, scale, Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError e) {
return null;
}
Canvas canvas = new Canvas(output);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
Rect rect = new Rect(0, 0, scale, scale);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(scale / 2, scale / 2, (scale / 2) - (scale / 25), paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
try {
canvas.drawBitmap(bitmap, null, rect, paint);
} catch (Exception e) {
// bitmap is null i guess
}
ResourceHelper helper = new ResourceHelper(context, "com.klinker.android.twitter");
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(helper.getDimension("contact_picture_border"));
try {
TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.circle_border });
int resource = a.getResourceId(0, 0);
a.recycle();
paint.setColor(context.getResources().getColor(resource));
} catch (Exception e) {
paint.setColor(helper.getColor("circle_outline_dark"));
}
canvas.drawCircle(scale / 2, scale / 2, (scale / 2) - (scale / 25), paint);
return output;
}
use of android.graphics.Rect in project SmartAndroidSource by jaychou2012.
the class DragGridViewPager method onLayout.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int childCount = getChildCount();
mPageCount = (childCount + mPageSize - 1) / mPageSize;
mGridWidth = (getWidth() - mPaddingLeft - mPaddingRight - (mColCount - 1) * mGridGap) / mColCount;
mGridHeight = (getHeight() - mPaddingTop - mPaddingButtom - (mRowCount - 1) * mGridGap) / mRowCount;
mGridWidth = mGridHeight = Math.min(mGridWidth, mGridHeight);
mMaxOverScrollSize = mGridWidth / 2;
mEdgeSize = mGridWidth / 2;
newPositions.clear();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
final Rect rect = getRectByPosition(i);
child.measure(MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY));
DEBUG_LOG("child.layout position=" + i + ", rect=" + rect);
child.layout(rect.left, rect.top, rect.right, rect.bottom);
newPositions.add(-1);
}
}
use of android.graphics.Rect in project SmartAndroidSource by jaychou2012.
the class DragGridViewPager method animateDragged.
private void animateDragged() {
if (mLastDragged >= 0) {
final View v = getChildAt(mLastDragged);
final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
r.inset(-r.width() / 20, -r.height() / 20);
v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
v.layout(r.left, r.top, r.right, r.bottom);
AnimationSet animSet = new AnimationSet(true);
ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
scale.setDuration(ANIMATION_DURATION);
AlphaAnimation alpha = new AlphaAnimation(1, .5f);
alpha.setDuration(ANIMATION_DURATION);
animSet.addAnimation(scale);
animSet.addAnimation(alpha);
animSet.setFillEnabled(true);
animSet.setFillAfter(true);
v.clearAnimation();
v.startAnimation(animSet);
}
}
use of android.graphics.Rect in project SmartAndroidSource by jaychou2012.
the class CropImageView method getActualCropRect.
/**
* Gets the crop window's position relative to the source Bitmap (not the
* image displayed in the CropImageView).
*
* @return a RectF instance containing cropped area boundaries of the source
* Bitmap
*/
public RectF getActualCropRect() {
final Rect displayedImageRect = ImageViewUtil.getBitmapRectCenterInside(mBitmap, mImageView);
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for width.
final float actualImageWidth = mBitmap.getWidth();
final float displayedImageWidth = displayedImageRect.width();
final float scaleFactorWidth = actualImageWidth / displayedImageWidth;
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for height.
final float actualImageHeight = mBitmap.getHeight();
final float displayedImageHeight = displayedImageRect.height();
final float scaleFactorHeight = actualImageHeight / displayedImageHeight;
// Get crop window position relative to the displayed image.
final float displayedCropLeft = Edge.LEFT.getCoordinate() - displayedImageRect.left;
final float displayedCropTop = Edge.TOP.getCoordinate() - displayedImageRect.top;
final float displayedCropWidth = Edge.getWidth();
final float displayedCropHeight = Edge.getHeight();
// Scale the crop window position to the actual size of the Bitmap.
float actualCropLeft = displayedCropLeft * scaleFactorWidth;
float actualCropTop = displayedCropTop * scaleFactorHeight;
float actualCropRight = actualCropLeft + displayedCropWidth * scaleFactorWidth;
float actualCropBottom = actualCropTop + displayedCropHeight * scaleFactorHeight;
// Correct for floating point errors. Crop rect boundaries should not
// exceed the source Bitmap bounds.
actualCropLeft = Math.max(0f, actualCropLeft);
actualCropTop = Math.max(0f, actualCropTop);
actualCropRight = Math.min(mBitmap.getWidth(), actualCropRight);
actualCropBottom = Math.min(mBitmap.getHeight(), actualCropBottom);
final RectF actualCropRect = new RectF(actualCropLeft, actualCropTop, actualCropRight, actualCropBottom);
return actualCropRect;
}
use of android.graphics.Rect in project SmartAndroidSource by jaychou2012.
the class CropImageView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (mBitmap != null) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// heightSize is set to 0.
if (heightSize == 0)
heightSize = mBitmap.getHeight();
int desiredWidth;
int desiredHeight;
double viewToBitmapWidthRatio = Double.POSITIVE_INFINITY;
double viewToBitmapHeightRatio = Double.POSITIVE_INFINITY;
// Checks if either width or height needs to be fixed
if (widthSize < mBitmap.getWidth()) {
viewToBitmapWidthRatio = (double) widthSize / (double) mBitmap.getWidth();
}
if (heightSize < mBitmap.getHeight()) {
viewToBitmapHeightRatio = (double) heightSize / (double) mBitmap.getHeight();
}
// from there
if (viewToBitmapWidthRatio != Double.POSITIVE_INFINITY || viewToBitmapHeightRatio != Double.POSITIVE_INFINITY) {
if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) {
desiredWidth = widthSize;
desiredHeight = (int) (mBitmap.getHeight() * viewToBitmapWidthRatio);
} else {
desiredHeight = heightSize;
desiredWidth = (int) (mBitmap.getWidth() * viewToBitmapHeightRatio);
}
} else // Otherwise, the picture is within frame layout bounds. Desired
// width is
// simply picture size
{
desiredWidth = mBitmap.getWidth();
desiredHeight = mBitmap.getHeight();
}
int width = getOnMeasureSpec(widthMode, widthSize, desiredWidth);
int height = getOnMeasureSpec(heightMode, heightSize, desiredHeight);
mLayoutWidth = width;
mLayoutHeight = height;
final Rect bitmapRect = ImageViewUtil.getBitmapRectCenterInside(mBitmap.getWidth(), mBitmap.getHeight(), mLayoutWidth, mLayoutHeight);
mCropOverlayView.setBitmapRect(bitmapRect);
// MUST CALL THIS
setMeasuredDimension(mLayoutWidth, mLayoutHeight);
} else {
mCropOverlayView.setBitmapRect(EMPTY_RECT);
setMeasuredDimension(widthSize, heightSize);
}
}
Aggregations