use of android.graphics.Rect in project Klyph by jonathangerbaud.
the class AbsHListView method positionSelector.
protected void positionSelector(int position, View sel) {
if (position != INVALID_POSITION) {
mSelectorPosition = position;
}
final Rect selectorRect = mSelectorRect;
selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());
if (sel instanceof SelectionBoundsAdjuster) {
((SelectionBoundsAdjuster) sel).adjustListItemSelectionBounds(selectorRect);
}
positionSelector(selectorRect.left, selectorRect.top, selectorRect.right, selectorRect.bottom);
final boolean isChildViewEnabled = mIsChildViewEnabled;
if (sel.isEnabled() != isChildViewEnabled) {
mIsChildViewEnabled = !isChildViewEnabled;
if (getSelectedItemPosition() != INVALID_POSITION) {
refreshDrawableState();
}
}
}
use of android.graphics.Rect in project Klyph by jonathangerbaud.
the class HListView method dispatchDraw.
@Override
protected void dispatchDraw(Canvas canvas) {
if (mCachingStarted) {
mCachingActive = true;
}
// Draw the dividers
final int dividerWidth = mDividerWidth;
final Drawable overscrollHeader = mOverScrollHeader;
final Drawable overscrollFooter = mOverScrollFooter;
final boolean drawOverscrollHeader = overscrollHeader != null;
final boolean drawOverscrollFooter = overscrollFooter != null;
final boolean drawDividers = dividerWidth > 0 && mDivider != null;
if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) {
// Only modify the top and bottom in the loop, we set the left and right here
final Rect bounds = mTempRect;
bounds.top = getPaddingTop();
bounds.bottom = getBottom() - getTop() - getPaddingBottom();
final int count = getChildCount();
final int headerCount = mHeaderViewInfos.size();
final int itemCount = mItemCount;
final int footerLimit = itemCount - mFooterViewInfos.size() - 1;
final boolean headerDividers = mHeaderDividersEnabled;
final boolean footerDividers = mFooterDividersEnabled;
final int first = mFirstPosition;
final boolean areAllItemsSelectable = mAreAllItemsSelectable;
final ListAdapter adapter = mAdapter;
// If the list is opaque *and* the background is not, we want to
// fill a rect where the dividers would be for non-selectable items
// If the list is opaque and the background is also opaque, we don't
// need to draw anything since the background will do it for us
final boolean fillForMissingDividers = isOpaque() && !super.isOpaque();
if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) {
mDividerPaint = new Paint();
mDividerPaint.setColor(getCacheColorHint());
}
final Paint paint = mDividerPaint;
int effectivePaddingLeft = 0;
int effectivePaddingRight = 0;
// if ( ( mGroupFlags & CLIP_TO_PADDING_MASK ) == CLIP_TO_PADDING_MASK ) {
// effectivePaddingTop = mListPadding.top;
// effectivePaddingBottom = mListPadding.bottom;
// }
final int listRight = getRight() - getLeft() - effectivePaddingRight + getScrollX();
if (!mStackFromRight) {
int right = 0;
// Draw top divider or header for overscroll
final int scrollX = getScrollX();
if (count > 0 && scrollX < 0) {
if (drawOverscrollHeader) {
bounds.right = 0;
bounds.left = scrollX;
drawOverscrollHeader(canvas, overscrollHeader, bounds);
} else if (drawDividers) {
bounds.right = 0;
bounds.left = -dividerWidth;
drawDivider(canvas, bounds, -1);
}
}
for (int i = 0; i < count; i++) {
if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) {
View child = getChildAt(i);
right = child.getRight();
if (drawDividers && (right < listRight && !(drawOverscrollFooter && i == count - 1))) {
if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
bounds.left = right;
bounds.right = right + dividerWidth;
drawDivider(canvas, bounds, i);
} else if (fillForMissingDividers) {
bounds.left = right;
bounds.right = right + dividerWidth;
canvas.drawRect(bounds, paint);
}
}
}
}
final int overFooterBottom = getRight() + getScrollX();
if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > right) {
bounds.left = right;
bounds.right = overFooterBottom;
drawOverscrollFooter(canvas, overscrollFooter, bounds);
}
} else {
int left;
final int scrollX = getScrollX();
if (count > 0 && drawOverscrollHeader) {
bounds.left = scrollX;
bounds.right = getChildAt(0).getLeft();
drawOverscrollHeader(canvas, overscrollHeader, bounds);
}
final int start = drawOverscrollHeader ? 1 : 0;
for (int i = start; i < count; i++) {
if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) {
View child = getChildAt(i);
left = child.getLeft();
// Don't draw dividers next to items that are not enabled
if (left > effectivePaddingLeft) {
if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
bounds.left = left - dividerWidth;
bounds.right = left;
// Give the method the child ABOVE the divider, so we
// subtract one from our child
// position. Give -1 when there is no child above the
// divider.
drawDivider(canvas, bounds, i - 1);
} else if (fillForMissingDividers) {
bounds.left = left - dividerWidth;
bounds.right = left;
canvas.drawRect(bounds, paint);
}
}
}
}
if (count > 0 && scrollX > 0) {
if (drawOverscrollFooter) {
final int absListRight = getRight();
bounds.left = absListRight;
bounds.right = absListRight + scrollX;
drawOverscrollFooter(canvas, overscrollFooter, bounds);
} else if (drawDividers) {
bounds.left = listRight;
bounds.right = listRight + dividerWidth;
drawDivider(canvas, bounds, -1);
}
}
}
}
// Draw the indicators (these should be drawn above the dividers) and children
super.dispatchDraw(canvas);
}
use of android.graphics.Rect in project Klyph by jonathangerbaud.
the class AbsHListView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mSelector == null) {
useDefaultSelector();
}
final Rect listPadding = mListPadding;
listPadding.left = mSelectionLeftPadding + getPaddingLeft();
listPadding.top = mSelectionTopPadding + getPaddingTop();
listPadding.right = mSelectionRightPadding + getPaddingRight();
listPadding.bottom = mSelectionBottomPadding + getPaddingBottom();
// Check if our previous measured size was at a point where we should scroll later.
if (mTranscriptMode == TRANSCRIPT_MODE_NORMAL) {
final int childCount = getChildCount();
final int listRight = getWidth() - getPaddingRight();
final View lastChild = getChildAt(childCount - 1);
final int lastRight = lastChild != null ? lastChild.getRight() : listRight;
mForceTranscriptScroll = mFirstPosition + childCount >= mLastHandledItemCount && lastRight <= listRight;
}
}
use of android.graphics.Rect in project CountdownView by iwgang.
the class BaseCountdown method getDayAndHourContentWidth.
private float getDayAndHourContentWidth() {
float width = 0;
Rect tempRect = new Rect();
if (isShowDay) {
String tempDay = Utils.formatNum(mDay);
mTimeTextPaint.getTextBounds(tempDay, 0, tempDay.length(), tempRect);
mDayTimeTextWidth = tempRect.width();
width += mDayTimeTextWidth;
}
if (isShowHour) {
String tempHour = Utils.formatNum(mHour);
mMeasureHourWidthPaint.getTextBounds(tempHour, 0, tempHour.length(), tempRect);
mHourTimeTextWidth = tempRect.width();
width += mHourTimeTextWidth;
}
return width;
}
use of android.graphics.Rect in project Talon-for-Twitter by klinker24.
the class ImageUtils method getBiggerCircle.
public static Bitmap getBiggerCircle(Bitmap currentImage, Context context) {
int scale = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, context.getResources().getDisplayMetrics());
Bitmap bitmap;
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;
}
Aggregations