List of usage examples for android.graphics RectF set
public void set(Rect src)
From source file:com.lab47billion.appchooser.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/*from w w w . ja v a 2s .c o m*/ int selectedItem = mSelectedItem; float itemWithPadding = mItemWidth + mDividerSize; // translate horizontal to center canvas.translate(itemWithPadding * mSideItems, 0); if (mValues != null) { for (int i = 0; i < mValues.length; i++) { mTextPaint.setColor(getTextColor(i)); // get text layout View layout = mLayouts[i][0]; // layout.draw(canvas); //NEW View layoutSub = mLayouts[i][1]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = 40f; if (lineWidth > mItemWidth) { if (isRtl(mValues[i])) { x += (lineWidth - mItemWidth) / 2; } else { x -= (lineWidth - mItemWidth) / 2; } } /*set select item top padding */ int yTranslate; if (!isScrollingStart && i == selectedItem) { mTextPaint.setTextSize(mSelectedTextSize); } else { mTextPaint.setTextSize(mNormalTextSize); } // translate vertically to center if (layoutSub != null) { yTranslate = (canvas.getHeight() - (layout.getHeight() + layoutSub.getHeight())) / 2; } else { yTranslate = (canvas.getHeight() - layout.getHeight()) / 2; } if (i == selectedItem && topPadding != -1) { yTranslate = topPadding; } canvas.translate(-x, yTranslate); RectF clipBounds; if (x == 0) { clipBounds = mItemClipBounds; } else { clipBounds = mItemClipBoundsOffser; clipBounds.set(mItemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (layoutSub != null) { Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics(); int heightText = (int) (Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent)); canvas.translate(-x, (layout.getHeight() + heightText - getTopPadding()) / 2); canvas.clipRect(clipBounds); layoutSub.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, mLeftEdgeEffect, 270); drawEdgeEffect(canvas, mRightEdgeEffect, 90); }
From source file:com.bitflake.counter.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();//from w w w . ja va 2 s.c om int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { // set text color for item textPaint.setColor(getTextColor(i)); // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/*from ww w.j av a 2 s . co m*/ int selectedItem = mSelectedItem; float itemWithPadding = mItemWidth + mDividerSize; // translate horizontal to center canvas.translate(itemWithPadding * mSideItems, 0); if (mValues != null) { for (int i = 0; i < mValues.length; i++) { // set text color for item mTextPaint.setColor(getTextColor(i)); // get text layout BoringLayout layout = mLayouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > mItemWidth) { if (isRtl(mValues[i])) { x += (lineWidth - mItemWidth) / 2; } else { x -= (lineWidth - mItemWidth) / 2; } } if (mMarquee != null && i == selectedItem) { x += mMarquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = mItemClipBounds; } else { clipBounds = mItemClipBoundsOffser; clipBounds.set(mItemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (mMarquee != null && i == selectedItem && mMarquee.shouldDrawGhost()) { canvas.translate(mMarquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, mLeftEdgeEffect, 270); drawEdgeEffect(canvas, mRightEdgeEffect, 90); }
From source file:de.tud.nhd.petimo.libs.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();// ww w . j av a 2 s . co m int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { if (i == selectedItem) { textPaint.setColor(getResources().getColor(R.color.colorAccent)); //textPaint.setTextSize(40); textPaint.setFakeBoldText(true); } else { textPaint.setColor(getTextColor(i)); //textPaint.setTextSize(textSize); textPaint.setFakeBoldText(false); } // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:com.ionesmile.variousdemo.view.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/*from w w w .j a va 2 s .c o m*/ int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { // set text color for item textPaint.setColor(getTextColor(i)); textPaint.setTextSize(getTextSize(i)); // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:org.akop.crosswords.view.CrosswordView.java
private void bringIntoView(Crossword.Word word, int selectedCell) { if (word == null) { return;/*from w ww. j a v a 2 s . c o m*/ } RectF wordRect = new RectF(); wordRect.left = word.getStartColumn() * mScaledCellSize - mContentRect.left; wordRect.top = word.getStartRow() * mScaledCellSize - mContentRect.top; if (word.getDirection() == Crossword.Word.DIR_ACROSS) { wordRect.right = wordRect.left + word.getLength() * mScaledCellSize; wordRect.bottom = wordRect.top + mScaledCellSize; } else if (word.getDirection() == Crossword.Word.DIR_DOWN) { wordRect.right = wordRect.left + mScaledCellSize; wordRect.bottom = wordRect.top + word.getLength() * mScaledCellSize; } RectF objectRect = new RectF(wordRect); RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(), -mBitmapOffset.y + mContentRect.height()); if (visibleArea.contains(objectRect)) { return; // Already visible } if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) { // Available area isn't large enough to fit the entire word // Is the selected cell visible? If not, bring it into view CellOffset co = getCellOffset(word, selectedCell); RectF cellRect = new RectF(); cellRect.left = co.mColumn * mScaledCellSize; cellRect.top = co.mRow * mScaledCellSize; cellRect.right = cellRect.left + mScaledCellSize; cellRect.bottom = cellRect.top + mScaledCellSize; if (visibleArea.contains(cellRect)) { return; // Already visible } objectRect.set(cellRect); } // Compute view that includes the object in the center PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left, (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top); // Clamp the values clampPointF(end, mTranslationBounds); // Compute the distance to travel from current location float distanceX = end.x - mBitmapOffset.x; float distanceY = end.y - mBitmapOffset.y; // Scroll the point into view mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY, NAVIGATION_SCROLL_DURATION_MS); }
From source file:org.akop.ararat.view.CrosswordView.java
private void bringIntoView(Selectable sel) { if (sel == null) { return;/*from w ww. j a v a2 s. co m*/ } RectF wordRect = new RectF(); wordRect.left = sel.getStartColumn() * mScaledCellSize - mContentRect.left; wordRect.top = sel.getStartRow() * mScaledCellSize - mContentRect.top; if (sel.getDirection() == Crossword.Word.DIR_ACROSS) { wordRect.right = wordRect.left + sel.mWord.getLength() * mScaledCellSize; wordRect.bottom = wordRect.top + mScaledCellSize; } else if (sel.getDirection() == Crossword.Word.DIR_DOWN) { wordRect.right = wordRect.left + mScaledCellSize; wordRect.bottom = wordRect.top + sel.mWord.getLength() * mScaledCellSize; } RectF objectRect = new RectF(wordRect); RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(), -mBitmapOffset.y + mContentRect.height()); if (visibleArea.contains(objectRect)) { return; // Already visible } if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) { // Available area isn't large enough to fit the entire word // Is the selected cell visible? If not, bring it into view RectF cellRect = new RectF(); cellRect.left = sel.getColumn() * mScaledCellSize; cellRect.top = sel.getRow() * mScaledCellSize; cellRect.right = cellRect.left + mScaledCellSize; cellRect.bottom = cellRect.top + mScaledCellSize; if (visibleArea.contains(cellRect)) { return; // Already visible } objectRect.set(cellRect); } // Compute view that includes the object in the center PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left, (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top); // Clamp the values clampPointF(end, mTranslationBounds); // Compute the distance to travel from current location float distanceX = end.x - mBitmapOffset.x; float distanceY = end.y - mBitmapOffset.y; // Scroll the point into view mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY, NAVIGATION_SCROLL_DURATION_MS); }