List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:com.ruesga.timelinechart.TimelineChartView.java
private void drawTickLabels(Canvas c, LongSparseArray<Pair<double[], int[]>> data) { final float alphaVariation = MAX_ZOOM_OUT - MIN_ZOOM_OUT; final float alpha = MAX_ZOOM_OUT - mCurrentZoom; mTickLabelFgPaint.setAlpha((int) ((alpha * 255) / alphaVariation)); final int size = data.size() - 1; final float cx = mGraphArea.left + (mGraphArea.width() / 2); for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0]; i--) { // Update the dynamic layout long timestamp = data.keyAt(i); final int tickFormat = getTickLabelFormat(timestamp); mTickDate.setTime(timestamp);/*from w ww .j a v a 2 s. c o m*/ final String text = mTickFormatter[tickFormat].format(mTickDate).replace(".", "") .toUpperCase(Locale.getDefault()); DynamicSpannableString spannable = mTickTextSpannables[tickFormat].get(text.length()); if (spannable == null) { // If we don't have an spannable for the text length, create a new one // that allow to use it now and in the future. Doing this here (on draw) // is not the best, but it supposed to only be performed one time per // different tick text length spannable = createSpannableTick(tickFormat, text); mTickTextSpannables[tickFormat].put(text.length(), spannable); } spannable.update(text); DynamicLayout layout = mTickTextLayouts[tickFormat].get(text.length()); if (layout == null) { // Update the layout as well layout = new DynamicLayout(spannable, mTickLabelFgPaint, (int) mBarItemWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 1.0f, false); mTickTextLayouts[tickFormat].put(text.length(), layout); } // Calculate the x position and draw the layout final float x = cx + mCurrentOffset - (mBarWidth * (size - i)) - (layout.getWidth() / 2); final int restoreCount = c.save(); c.translate(x, mFooterArea.top + (mFooterArea.height() / 2 - mTickLabelMinHeight / 2)); layout.draw(c); c.restoreToCount(restoreCount); } }
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mEdgeGlowTop != null) { final int scrollX = getScrollX(); final int scrollY = getScrollY(); if (scrollDirection == DIRECTION_HORIZONTAL) { // if (!mEdgeGlowLeft.isFinished()) { // Log.i("NestedScrollView", "draw "); // final int restoreCount = canvas.save(); // final int height = getHeight() - getPaddingTop() // - getPaddingBottom(); // // canvas.translate(getPaddingLeft(), height); // canvas.rotate(-90); // mEdgeGlowLeft.setSize(getWidth(), height); // if (mEdgeGlowLeft.draw(canvas)) { // ViewCompat.postInvalidateOnAnimation(this); // } // canvas.restoreToCount(restoreCount); // } // if (!mEdgeGlowRight.isFinished()) { // Log.i("NestedScrollView", "draw ?"); // final int restoreCount = canvas.save(); // final int height = getHeight() - getPaddingTop() // - getPaddingBottom(); ///* ww w . ja va 2 s . c o m*/ // canvas.translate(getPaddingLeft() + getWidth(),height); // canvas.rotate(90); // mEdgeGlowRight.setSize(getWidth(), height); // if (mEdgeGlowRight.draw(canvas)) { // ViewCompat.postInvalidateOnAnimation(this); // } // canvas.restoreToCount(restoreCount); // } if (!mEdgeGlowLeft.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(270); canvas.translate(-height + getPaddingTop() - scrollY, Math.min(0, scrollX)); mEdgeGlowLeft.setSize(height, getWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowRight.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop() + scrollY, -(Math.max(getHorizontalScrollRange(), scrollX) + width)); mEdgeGlowRight.setSize(height, width); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } } else if (scrollDirection == DIRECTION_VERTICAL) { if (!mEdgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(scrollX + getPaddingLeft(), Math.min(0, scrollY)); mEdgeGlowTop.setSize(width, getHeight()); if (mEdgeGlowTop.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); } canvas.restoreToCount(restoreCount); } if (!mEdgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.translate(scrollX - width + getPaddingLeft(), Math.max(getVerticalScrollRange(), scrollY) + height); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width, height); if (mEdgeGlowBottom.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); } canvas.restoreToCount(restoreCount); } } else { //do nothing } } }
From source file:com.aliyun.homeshell.Folder.java
void drawFolderIcon(Canvas c, int w, int h, float padding, float contentPadding, boolean dropMode, boolean hotSeat) { CellLayout mContent = mContentList.get(0); boolean supportCard = isSupportCardIcon(); int count = mContent.getShortcutAndWidgetContainer().getChildCount(); int desireWidth = mContent.getDesiredWidth(); if (mSupportCardIcon != supportCard) { updateFolderLayout(supportCard); }/*w w w .j a va 2 s. c o m*/ updateOrientation(); int countX = mContent.getCountX(); int cellWidth = mContent.getCellWidth(); int cellHeight = mContent.getCellHeight(); int widthGap = mContent.getWidthGap(); int heightGap = mContent.getHeightGap(); int topPadding = mContent.getPaddingTop(); int startPadding = mContent.getPaddingStart(); mHotSeat = hotSeat; mSupportCardIcon = supportCard; mIconChild = count; mLastDesireWidth = desireWidth; int contentWidth = mContent.getDesiredWidth(); float iconScale; if (supportCard) { iconScale = (float) w / contentWidth; padding = (int) (startPadding * iconScale); mIconPaddingX = contentPadding; if (!hotSeat) mIconPaddingY = contentPadding - iconScale * getFolderNamePadding(); } else { iconScale = (float) (w - padding * 2) / (contentWidth - startPadding * 2); float div = (cellHeight * countX + heightGap * (countX - 1) - cellWidth * countX + widthGap * (countX - 1)) / 2 * iconScale * 0.65f; c.translate(0, -div); mIconPaddingX = contentPadding - iconScale * startPadding; if (!hotSeat) mIconPaddingY = contentPadding - div - iconScale * (getFolderNamePadding() + topPadding); } if (hotSeat) mIconPaddingY = BubbleTextView.sTopPaddingHotseat - iconScale * getFolderNamePadding(); mIconScale = iconScale; if (supportCard) { c.clipRect(0, 0, w, h); } else c.clipRect(0, 0, w - padding * 2, h - padding); c.scale(iconScale, iconScale); int iconH = (int) (h / iconScale); int countY = (iconH - topPadding + heightGap) / (cellHeight + heightGap); ArrayList<View> icons = getItemsInReadingOrder(false); if (supportCard) c.translate(startPadding, topPadding); //YUNOS BEGIN PB //##modules(Homeshell): ##author:wutao.wt@alibaba-inc-com //##BugID:(5635800) ##date:20141213 //##decrpition: Homeshell crash if (mFolderIcon == null || mFolderIcon.mHideIcon) return; //YUNOS END PB boolean rtl = getResources().getConfiguration().getLayoutDirection() == LAYOUT_DIRECTION_RTL; mPageCount = countX * (supportCard ? countX : countX + 1); for (int i = 0, N = mDrawingLimit = Math.min(icons.size(), countX * countY); i < N; i++) { int x = (rtl ? (countX - (i % countX) - 1) : (i % countX)) * (cellWidth + widthGap); int y = (i / countX) * (cellHeight + heightGap); c.translate(x, y); ((BubbleTextView) icons.get(i)).drawWithRect(0, 0, cellWidth, cellHeight, c); c.translate(-x, -y); } }
From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { // BrantApps Change: Various, including the rotation and translation of the edges, padding applied to width not height // BrantApps Change: Was: /*//from ww w. j a va 2s . co m if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270); canvas.translate(-height + getPaddingTop(), mFirstOffset * width); mLeftEdge.setSize(height, width); needsInvalidate |= mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } */ if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.translate(-getPaddingLeft(), mFirstOffset * height); mTopEdge.setSize(width, height); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.rotate(180); canvas.translate(-width + getPaddingLeft(), -(mLastOffset + 1) * height); mBottomEdge.setSize(width, height); needsInvalidate |= mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mTopEdge.finish(); mBottomEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.codemx.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;/*w ww . jav a2 s . c om*/ } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderIcon.FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderIcon.FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderIcon.FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderIcon.FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.lite.android.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;// ww w . j av a2s . co m } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderRingAnimator.sSharedInnerRingDrawable; if (d != null) { width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.android.launcher3.Workspace.java
/** * Draw the View v into the given Canvas. * * @param v the view to draw/*from ww w . jav a2s . c o m*/ * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); boolean textVisible = false; destCanvas.save(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { if (v instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) v).getTextVisible()) { ((FolderIcon) v).setTextVisible(false); textVisible = true; } } destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) v).setTextVisible(true); } } destCanvas.restore(); }
From source file:com.android.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;/* w ww . j ava 2 s .c o m*/ } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:android.car.ui.provider.CarDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = findContentView().getLeft(); int clipRight = findContentView().getRight(); final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }/*from w w w. j av a 2s. c o m*/ if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) { clipLeft = vright; } } else { final int vleft = v.getLeft(); if (vleft < clipRight) { clipRight = vleft; } } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (drawingContent) { int scrimAlpha = SCRIM_ENABLED ? (int) (baseAlpha * Math.max(0, Math.min(1, onScreen())) * MAX_SCRIM_ALPHA) : 0; if (scrimAlpha > 0) { int color = scrimAlpha << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint); canvas.drawRect(clipLeft - 1, 0, clipLeft, getHeight(), mEdgeHighlightPaint); } LayoutParams drawerLp = (LayoutParams) findDrawerView().getLayoutParams(); if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.LEFT)) { final int offScreen = (int) ((1 - drawerLp.onScreen) * findDrawerView().getWidth()); final int drawerRight = getWidth() - drawerLp.getMarginEnd() - offScreen; final int shadowWidth = mShadow.getIntrinsicWidth(); final float alpha = Math.max(0, Math.min((float) drawerRight / mDragger.getEdgeSize(), 1.f)); mShadow.setBounds(drawerRight, child.getTop(), drawerRight + shadowWidth, child.getBottom()); mShadow.setAlpha((int) (255 * alpha * alpha * alpha)); mShadow.draw(canvas); } else if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.RIGHT)) { final int onScreen = (int) (findDrawerView().getWidth() * drawerLp.onScreen); final int drawerLeft = drawerLp.getMarginStart() + getWidth() - onScreen; final int shadowWidth = mShadow.getIntrinsicWidth(); final float alpha = Math.max(0, Math.min((float) onScreen / mDragger.getEdgeSize(), 1.f)); canvas.save(); canvas.translate(2 * drawerLeft - shadowWidth, 0); canvas.scale(-1.0f, 1.0f); mShadow.setBounds(drawerLeft - shadowWidth, child.getTop(), drawerLeft, child.getBottom()); mShadow.setAlpha((int) (255 * alpha * alpha * alpha * alpha)); mShadow.draw(canvas); canvas.restore(); } } return result; }
From source file:net.toload.main.hd.candidate.CandidateView.java
private void doDraw(Canvas canvas) { if (mSuggestions == null) return;/* w w w .j av a 2 s . c om*/ if (DEBUG) Log.i(TAG, "CandidateView:doDraw():Suggestion mCount:" + mCount + " mSuggestions.size:" + mSuggestions.size()); mTotalWidth = 0; updateFontSize(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } } final int height = mHeight; final Rect bgPadding = mBgPadding; final Paint candidatePaint = mCandidatePaint; final Paint candidateEmojiPaint = mCandidatePaint; candidateEmojiPaint.setTextSize((float) (candidateEmojiPaint.getTextSize() * 0.9)); final Paint selKeyPaint = mSelKeyPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final int textBaseLine = (int) (((height - mCandidatePaint.getTextSize()) / 2) - mCandidatePaint.ascent()); // Modified by jeremy '10, 3, 29. Update mselectedindex if touched and build wordX[i] and wordwidth[i] int x = 0; final int count = mCount; //Cache count here '11,8,18 for (int i = 0; i < count; i++) { if (count != mCount || mSuggestions == null || count != mSuggestions.size() || mSuggestions.size() == 0 || i >= mSuggestions.size()) return; // mSuggestion is updated, force abort String suggestion = mSuggestions.get(i).getWord(); if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord() && suggestion.length() > 8) { suggestion = suggestion.substring(0, 2) + ".."; } float base = (suggestion == null) ? 0 : candidatePaint.measureText(""); float textWidth = (suggestion == null) ? 0 : candidatePaint.measureText(suggestion); if (textWidth < base) { textWidth = base; } final int wordWidth = (int) textWidth + X_GAP * 2; mWordX[i] = x; mWordWidth[i] = wordWidth; if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { mSelectedIndex = i; } x += wordWidth; } mTotalWidth = x; if (DEBUG) Log.i(TAG, "CandidateView:doDraw():mTotalWidth :" + mTotalWidth + " this.getWidth():" + this.getWidth()); //Jeremy '11,8,11. If the candidate list is within 1 page and has more records, get full records first. if (mTotalWidth < this.getWidth()) checkHasMoreRecords(); // Paint all the suggestions and lines. if (canvas != null) { // Moved from above by jeremy '10 3, 29. Paint mSelectedindex in highlight here if (count > 0 && mSelectedIndex >= 0) { // candidatePaint.setColor(mColorComposingCode); // canvas.drawRect(mWordX[mSelectedIndex],bgPadding.top, mWordWidth[mSelectedIndex] , height, candidatePaint); canvas.translate(mWordX[mSelectedIndex], 0); mDrawableSuggestHighlight.setBounds(0, bgPadding.top, mWordWidth[mSelectedIndex], height); mDrawableSuggestHighlight.draw(canvas); canvas.translate(-mWordX[mSelectedIndex], 0); } if (mTransparentCandidateView) { canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); Paint backgroundPaint = new Paint(); backgroundPaint.setColor(ContextCompat.getColor(mContext, R.color.third_background_light)); backgroundPaint.setAlpha(33); backgroundPaint.setStyle(Paint.Style.FILL); canvas.drawRect(0.5f, bgPadding.top, mScreenWidth, height, backgroundPaint); } for (int i = 0; i < count; i++) { if (count != mCount || mSuggestions == null || count != mSuggestions.size() || mSuggestions.size() == 0 || i >= mSuggestions.size()) break; boolean isEmoji = mSuggestions.get(i).isEmojiRecord(); String suggestion = mSuggestions.get(i).getWord(); if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord() && suggestion.length() > 8) { suggestion = suggestion.substring(0, 2) + ".."; } int c = i + 1; switch (mSuggestions.get(i).getRecordType()) { case Mapping.RECORD_COMPOSING_CODE: if (mSelectedIndex == 0) { if (mTransparentCandidateView) { candidatePaint.setColor(mColorInvertedTextTransparent); } else { candidatePaint.setColor(mColorComposingCodeHighlight); } } else candidatePaint.setColor(mColorComposingCode); break; case Mapping.RECORD_CHINESE_PUNCTUATION_SYMBOL: case Mapping.RECORD_RELATED_PHRASE: selKeyPaint.setColor(mColorSelKeyShifted); if (i == mSelectedIndex) candidatePaint.setColor(mColorNormalTextHighlight); else candidatePaint.setColor(mColorNormalText); break; case Mapping.RECORD_EXACT_MATCH_TO_CODE: case Mapping.RECORD_PARTIAL_MATCH_TO_CODE: case Mapping.RECORD_RUNTIME_BUILT_PHRASE: case Mapping.RECORD_ENGLISH_SUGGESTION: default: selKeyPaint.setColor(mColorSelKey); if (i == mSelectedIndex) candidatePaint.setColor(mColorNormalTextHighlight); else candidatePaint.setColor(mColorNormalText); break; } if (isEmoji) { canvas.drawText(suggestion, mWordX[i] + X_GAP, Math.round(textBaseLine * 0.95), candidateEmojiPaint); } else { canvas.drawText(suggestion, mWordX[i] + X_GAP, textBaseLine, candidatePaint); } if (mShowNumber) { //Jeremy '11,6,17 changed from <=10 to mDisplaySelkey length. The length maybe 11 or 12 if shifted with space. if (c <= mDisplaySelkey.length()) { //Jeremy '11,6,11 Drawing text using relative font dimensions. canvas.drawText(mDisplaySelkey.substring(c - 1, c), mWordX[i] + mWordWidth[i] - height * 0.3f, height * 0.4f, selKeyPaint); } } //Draw spacer candidatePaint.setColor(mColorSpacer); canvas.drawLine(mWordX[i] + mWordWidth[i] + 0.5f, bgPadding.top + (mVerticalPadding / 2), mWordX[i] + mWordWidth[i] + 0.5f, height - (mVerticalPadding / 2), candidatePaint); candidatePaint.setFakeBoldText(false); } if (mTargetScrollX != getScrollX()) { if (DEBUG) Log.i(TAG, "CandidateView:doDraw():mTargetScrollX :" + mTargetScrollX + " getScrollX():" + getScrollX()); scrollToTarget(); } } }