List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:com.support.chikeong.centerviewpager.lib.CenterViewPager.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)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);/*from ww w . j a v a2s . co m*/ canvas.translate(-height + getPaddingTop(), mFirstOffset * width - (getWidth() - getWidth() * mAdapter.getPageWidth(mCurItem)) / 2); 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 - (getWidth() - getWidth() * mAdapter.getPageWidth(mCurItem)) / 2); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.my.infiniteviewpager.view.InfiniteViewPager.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)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);/*from w w w . ja va2 s. co m*/ 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); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.suning.boxcontroller.control.ExViewPager.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)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(ANGLE_ONE);/*ww w .j a v a 2 s . c o m*/ 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(ANGLE_TWO); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalViewPagerImpl.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)) { if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(getPaddingLeft(), mFirstOffset * height); mTopEdge.setSize(width, height); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); }/*from w w w . j av a 2 s .c om*/ if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); 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:fr.magistry.taigime.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick the target * candidate.//from ww w . j a v a 2s. c o m */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; if (mSuggestions == null) return; if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } } int x = 0; final int count = mSuggestions.size(); final int height = getHeight(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final int y; //= (int) ( - mPaint.ascent() + mVerticalPadding); final int y2; //= (int) (height - mPaintTRS.descent()); // (y - mVerticalPadding - mPaint.descent() - mPaintTRS.ascent()) ; final float initialTRSsize = mPaintTRS.getTextSize(); if (mOutputTRS) { y2 = (int) (-mPaintTRS.ascent() + mVerticalPadding); y = (int) (height - mPaint.descent()); } else { y = (int) (-mPaint.ascent() + mVerticalPadding); y2 = (int) (height - mPaintTRS.descent()); } for (int i = 0; i < count; i++) { Candidate suggestion = mSuggestions.get(i); String hanji = suggestion.getWord().getHanji(); String trs = ""; switch (ROMANISATION_OUTPUT_MODE) { case 0: trs = suggestion.getWord().getTailuo(); break; case 1: trs = suggestion.getWord().getPOJ(); break; case 2: trs = suggestion.getWord().getPOJ_safe(); break; default: trs = suggestion.getWord().getTailuo(); } float textWidth; if (i == 0) { hanji = ""; trs = "";//hanji;//TODO: conversion? //if(mOutputTRS){ trs = suggestion.getWord().getBopomo(); if (trs != "") textWidth = mPaintBPM.measureText(trs); else textWidth = 3; //} //else { // hanji = suggestion.getWord().getBopomo(); // textWidth = paint.measureText(hanji); //} } else textWidth = paint.measureText(hanji); if (textWidth == 0.0) textWidth = paint.measureText(" "); final int wordWidth = (int) textWidth + X_GAP * 2; mWordX[i] = x; mWordWidth[i] = wordWidth; mPaintTRS.setTextSize(initialTRSsize); mPaintTRS.setTextSize(reduceTextSizeFromWidth(mPaintTRS, trs, textWidth)); paint.setColor(mColorNormal); if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { if (canvas != null) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedIndex = i; } if (canvas != null) { Paint activePaint = null; Paint secondPaint = null; if (mOutputTRS) { activePaint = mPaintTRS; secondPaint = paint; } else { activePaint = paint; secondPaint = mPaintTRS; } if (i == 0) { activePaint = mPaintBPM; } secondPaint.setAlpha(150); if ((i == mCursor)) { activePaint.setFakeBoldText(true); activePaint.setColor(mColorRecommended); } else if (i != 0) { activePaint.setColor(mColorOther); } if (i == 0) { canvas.drawText(trs, x + X_GAP, y2, mPaintBPM); } else { canvas.drawText(hanji, x + X_GAP, y, paint); canvas.drawText(trs, x + X_GAP, y2, mPaintTRS); } activePaint.setColor(mColorOther); canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top, x + wordWidth + 0.5f, height + 1, paint); activePaint.setFakeBoldText(false); secondPaint.setAlpha(255); } x += wordWidth; mPaintTRS.setTextSize(initialTRSsize); } mTotalWidth = x; if (mTargetScrollX != getScrollX()) { scrollToTarget(); } }
From source file:com.dian.diabetes.widget.VerticalViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; //jelle disabled edge effect final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); if (!mTopEdge.isFinished()) { mTopEdge.setSize(width, height); needsInvalidate |= mTopEdge.draw(canvas); }// ww w. jav a 2 s .c om if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.translate(-width + getPaddingLeft(), getScrollY() + height); canvas.rotate(180, width, 0); 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.bloomimpact.bancus.ui.views.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)) { if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.rotate(270);// w ww . j a v a 2 s . c o m canvas.translate(mFirstOffset * height, -width + getPaddingLeft()); mTopEdge.setSize(width, height); needsInvalidate |= mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(90); canvas.translate(-(mLastOffset + 1) * height, -getPaddingLeft()); 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.tct.mail.browse.ConversationItemView.java
@Override protected void onDraw(Canvas canvas) { // TS: jin.dongjin 2015-06-23 EMAIL BUGFIX_1015610 MOD_S if (mCoordinates == null) { LogUtils.e(LOG_TAG, "null coordinates in ConversationItemView#onDraw"); return;// w w w . ja v a 2 s . c o m } // TS: jin.dongjin 2015-06-23 EMAIL BUGFIX_1015610 MOD_E Utils.traceBeginSection("CIVC.draw"); // Contact photo if (mGadgetMode == ConversationItemViewCoordinates.GADGET_CONTACT_PHOTO) { canvas.save(); Utils.traceBeginSection("draw senders image"); drawSendersImage(canvas); Utils.traceEndSection(); canvas.restore(); } //TS: yanhua.chen 2015-9-2 EMAIL CR_ID MOD_S // Subject. boolean isUnread = mHeader.unread; // Old style subject; apply text colors/ sizes/ styling. canvas.save(); if (mHeader.subjectDisplayLayout != null) { sPaint.setTextSize(mCoordinates.subjectFontSize); sPaint.setTypeface(Typeface.DEFAULT); // [FEATURE]-ADD-BEGIN by TSNJ,zhujian.shao,10/23/2014,FR-736411(porting from FR622697) canvas.translate(mSubjectWidth - mPriorityX, mCoordinates.subjectY + mHeader.subjectDisplayLayout.getTopPadding()); // [FEATURE]-ADD-END by TSNJ,zhujian.shao,10/23/2014,FR-736411 mHeader.subjectDisplayLayout.draw(canvas); } else { drawSubject(canvas); } canvas.restore(); // Sender. sPaint.setTypeface(Typeface.DEFAULT); canvas.save(); drawSenders(canvas); canvas.restore(); //TS: yanhua.chen 2015-9-2 EMAIL CR_ID MOD_E canvas.save(); drawSnippet(canvas); canvas.restore(); // Folders. if (mConfig.areFoldersVisible()) { mHeader.folderDisplayer.drawFolders(canvas, mCoordinates, ViewUtils.isViewRtl(this)); } // If this folder has a color (combined view/Email), show it here if (mConfig.isColorBlockVisible()) { sFoldersPaint.setColor(mHeader.conversation.color); sFoldersPaint.setStyle(Paint.Style.FILL); canvas.drawRect(mCoordinates.colorBlockX, mCoordinates.colorBlockY, mCoordinates.colorBlockX + mCoordinates.colorBlockWidth, mCoordinates.colorBlockY + mCoordinates.colorBlockHeight, sFoldersPaint); } // Draw the reply state. Draw nothing if neither replied nor forwarded. if (mConfig.isReplyStateVisible()) { if (mHeader.hasBeenRepliedTo && mHeader.hasBeenForwarded) { canvas.drawBitmap(STATE_REPLIED_AND_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.hasBeenRepliedTo) { canvas.drawBitmap(STATE_REPLIED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.hasBeenForwarded) { canvas.drawBitmap(STATE_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.isInvite) { canvas.drawBitmap(STATE_CALENDAR_INVITE, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } } if (mConfig.isPersonalIndicatorVisible()) { canvas.drawBitmap(mHeader.personalLevelBitmap, mCoordinates.personalIndicatorX, mCoordinates.personalIndicatorY, null); } // Info icon if (mHeader.infoIcon != null) { canvas.drawBitmap(mHeader.infoIcon, mInfoIconX, mCoordinates.infoIconY, sPaint); } // Date. sPaint.setTextSize(mCoordinates.dateFontSize); sPaint.setTypeface(isUnread ? Typeface.SANS_SERIF : SANS_SERIF_LIGHT); sPaint.setColor(isUnread ? sDateTextColorUnread : sDateTextColorRead); drawText(canvas, mHeader.dateText, mDateX, mCoordinates.dateYBaseline, sPaint); //TS: yanhua.chen 2015-6-19 EMAIL BUGFIX_305581 MOD_S //TS: wenggangjin 2015-01-27 EMAIL BUGFIX_-888881 MOD_S //TS: wenggangjin 2015-01-15 EMAIL BUGFIX_886241 MOD_S // if (mHeader.conversation.hasAttachments && !mDisplayedFolder.isSearch()) { if (mHeader.conversation.hasAttachments) { mHeader.paperclip = ATTACHMENT; } else { mHeader.paperclip = null; } //TS: wenggangjin 2015-01-15 EMAIL BUGFIX_886241 MOD_E //TS: wenggangjin 2015-01-27 EMAIL BUGFIX_-888881 MOD_S //TS: yanhua.chen 2015-6-19 EMAIL BUGFIX_305581 MOD_E // Paper clip icon. if (mHeader.paperclip != null) { canvas.drawBitmap(mHeader.paperclip, mPaperclipX, mCoordinates.paperclipY, sPaint); } //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398) //priority icon Bitmap sPrio = sNormalPriorityIcon; mPriority = mHeader.conversation.flagPriority; if (mPriority == HIGH_PRIORITY) { sPrio = sHighPriorityIcon; } else if (mPriority == LOW_PRIORITY) { sPrio = sLowPriorityIcon; } // TS: zhaotianyong 2014-12-15 EMAIL BUGFIX_859814 ADD_S sPrio = resizeBitMap(sPrio, 0.6f, 0.6f); // TS: zhaotianyong 2014-12-15 EMAIL BUGFIX_859814 ADD_E canvas.drawBitmap(sPrio, mPriorityX, mCoordinates.paperclipY, null); //[FEATURE]-Add-END by TSCD.chao zhang if (mStarEnabled) { // Star. canvas.drawBitmap(getStarBitmap(), mCoordinates.starX, mCoordinates.starY, sPaint); } // right-side edge effect when in tablet conversation mode and the list is not collapsed if (Utils.getDisplayListRightEdgeEffect(mTabletDevice, mListCollapsible, mConfig.getViewMode())) { final boolean isRtl = ViewUtils.isViewRtl(this); RIGHT_EDGE_TABLET.setBounds((isRtl) ? 0 : getWidth() - RIGHT_EDGE_TABLET.getIntrinsicWidth(), 0, (isRtl) ? RIGHT_EDGE_TABLET.getIntrinsicWidth() : getWidth(), getHeight()); RIGHT_EDGE_TABLET.draw(canvas); if (isActivated()) { final int w = VISIBLE_CONVERSATION_HIGHLIGHT.getIntrinsicWidth(); VISIBLE_CONVERSATION_HIGHLIGHT.setBounds((isRtl) ? getWidth() - w : 0, 0, (isRtl) ? getWidth() : w, getHeight()); VISIBLE_CONVERSATION_HIGHLIGHT.draw(canvas); } } //TS: zheng.zou 2015-09-01 EMAIL BUGFIX_539892 MOD_S if (mWillDrawDivider) { // draw the inset divider sDividerPaint.setColor(sDividerColor); final int dividerBottomY = getHeight(); final int dividerTopY = dividerBottomY - sDividerHeight; // AM: Kexue.Geng 2015-02-28 EMAIL BUGFIX_900927 MOD_S // canvas.drawRect(sDividerInset, dividerTopY, getWidth(), dividerBottomY, sDividerPaint); canvas.drawRect(mGadgetMode == ConversationItemViewCoordinates.GADGET_NONE ? 0 : sDividerInset, dividerTopY, getWidth(), dividerBottomY, sDividerPaint); // AM: Kexue.Geng 2015-02-28 EMAIL BUGFIX_900927 MOD_E } //TS: zheng.zou 2015-09-01 EMAIL BUGFIX_539892 MOD_E Utils.traceEndSection(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S //draw the status canvas.save(); drawStatus(canvas); canvas.restore(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E }
From source file:com.ifnoif.androidtestdemo.customview.VViewPager.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)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.rotate(270);/*from ww w . j ava 2s .co m*/ 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(180); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mRightEdge.setSize(height, width); needsInvalidate |= mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.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)) { if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);/*ww w . ja v a 2 s . c o m*/ 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); } } else { mLeftEdge.finish(); mRightEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }