List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKPrice(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/* w ww . j ava2 s. c o m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wb")<0) // paint.setColor(GlobalColor.colorPriceDown); // else if(jo.getDouble("wb")>0) // paint.setColor(GlobalColor.colorpriceUp); // else // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 3); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); // canvas.drawText("", x, y, paint); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); // canvas.translate(0, DY); // canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 3); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wc")<0) { // paint.setColor(GlobalColor.colorPriceDown); // canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint); // } // else if(jo.getDouble("wc")>0) { // paint.setColor(GlobalColor.colorpriceUp); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } // else { // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); // paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.dongdong.wheel.WheelView.java
/** * Draws items// ww w .j av a2s. c o m * * @param canvas the canvas for drawing */ private void drawItems(Canvas canvas) { canvas.save(); int top = mItemsLayout.getLineTop(1); canvas.translate(0, -top + mScrollingOffset); mItemsPaint.setColor(ITEMS_TEXT_COLOR); mItemsPaint.drawableState = getDrawableState(); mItemsLayout.draw(canvas); canvas.restore(); }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (stickyWrapper != null) { int pLeft = getListPaddingLeft(); int pTop = getListPaddingTop(); View view = stickyWrapper.view; int headerTop = view.getTop(); pLeft += stickyWrapper.additionalIndent; // draw child canvas.save();//from w ww. j av a2s. c om int clipHeight = view.getHeight() + (shadowDrawable == null ? 0 : shadowHeight); canvas.clipRect(pLeft, pTop, pLeft + view.getWidth() - 2 * stickyWrapper.additionalIndent, pTop + clipHeight); canvas.translate(pLeft - stickyWrapper.additionalIndent, pTop - headerTop); drawChild(canvas, stickyWrapper.view, getDrawingTime()); if (shadowDrawable != null) { shadowDrawable.setBounds(stickyWrapper.view.getLeft(), stickyWrapper.view.getBottom(), stickyWrapper.view.getRight(), stickyWrapper.view.getBottom() + shadowHeight); shadowDrawable.draw(canvas); } canvas.restore(); } }
From source file:com.cssweb.android.view.FinanceMini.java
private void drawQihuo(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*w w w. j a v a 2 s. co m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); // canvas.translate(0, DY); // canvas.drawText(" ", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint); // canvas.translate(0, DY); // canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); canvas.translate(0, -DY * 4); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); // canvas.translate(0, DY); // canvas.drawText(" ", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(width / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint); // paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.dat.complexrecyclerviewdemo.recyclerviewinsidecardviewdemo.StickyHeaderDecoration.java
/** * {@inheritDoc}//from ww w. java 2 s.c o m */ @Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = mAdapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top - 4); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
From source file:ca.barrenechea.widget.recyclerview.decoration.StickyHeaderDecoration.java
/** * {@inheritDoc}/*from w w w. j a va 2s . c o m*/ */ @Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { final int count = parent.getChildCount(); long previousHeaderId = -1; for (int layoutPos = 0; layoutPos < count; layoutPos++) { final View child = parent.getChildAt(layoutPos); final int adapterPos = parent.getChildAdapterPosition(child); if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) { long headerId = mAdapter.getHeaderId(adapterPos); if (headerId != previousHeaderId) { previousHeaderId = headerId; View header = getHeader(parent, adapterPos).itemView; canvas.save(); final int left = child.getLeft(); final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos); canvas.translate(left, top); header.setTranslationX(left); header.setTranslationY(top); header.draw(canvas); canvas.restore(); } } } }
From source file:com.android.launcher3.folder.FolderIcon.java
private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { canvas.save();/* w w w . j av a2 s . c o m*/ canvas.translate(params.transX, params.transY); canvas.scale(params.scale, params.scale); Drawable d = params.drawable; if (d != null) { mOldBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); if (d instanceof FastBitmapDrawable) { FastBitmapDrawable fd = (FastBitmapDrawable) d; float oldBrightness = fd.getBrightness(); fd.setBrightness(params.overlayAlpha); d.draw(canvas); fd.setBrightness(oldBrightness); } else { d.setColorFilter(Color.argb((int) (params.overlayAlpha * 255), 255, 255, 255), PorterDuff.Mode.SRC_ATOP); d.draw(canvas); d.clearColorFilter(); } d.setBounds(mOldBounds); } canvas.restore(); }
From source file:com.dm.xz.views.PinnedSectionListView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mPinnedSection != null) { // prepare variables int pLeft = getListPaddingLeft(); int pTop = getListPaddingTop(); View view = mPinnedSection.view; // draw child canvas.save();/*from w w w.jav a2s. c o m*/ int clipHeight = view.getHeight() + (mShadowDrawable == null ? 0 : Math.min(mShadowHeight, mSectionsDistanceY)); canvas.clipRect(pLeft, pTop, pLeft + view.getWidth(), pTop + clipHeight); canvas.translate(pLeft, pTop + mTranslateY); drawChild(canvas, mPinnedSection.view, getDrawingTime()); if (mShadowDrawable != null && mSectionsDistanceY > 0) { mShadowDrawable.setBounds(mPinnedSection.view.getLeft(), mPinnedSection.view.getBottom(), mPinnedSection.view.getRight(), mPinnedSection.view.getBottom() + mShadowHeight); mShadowDrawable.draw(canvas); } canvas.restore(); } }
From source file:com.evilduck.piano.views.instrument.PianoView.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)) { if (!leftEdgeEffect.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);//from w ww . j a v a 2s . com canvas.translate(-height + getPaddingTop(), 0); leftEdgeEffect.setSize(height, width); needsInvalidate |= leftEdgeEffect.draw(canvas); canvas.restoreToCount(restoreCount); } if (!rightEdgeEffect.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -width); rightEdgeEffect.setSize(height, width); needsInvalidate |= rightEdgeEffect.draw(canvas); canvas.restoreToCount(restoreCount); } } else { leftEdgeEffect.finish(); rightEdgeEffect.finish(); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:org.telegram.ui.Cells.ContextLinkCell.java
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save();/* w ww .ja va 2s . c om*/ canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(DESCRIPTION_TEXT_COLOR/*0xff8a8a8a*/); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (linkLayout != null) { descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY); linkLayout.draw(canvas); canvas.restore(); } if (!mediaWebpage) { if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) { radialProgress.setProgressColor(buttonPressed ? Theme.MSG_IN_AUDIO_SELECTED_PROGRESS_COLOR : Theme.MSG_IN_AUDIO_PROGRESS_COLOR); radialProgress.draw(canvas); } else if (inlineResult != null && inlineResult.type.equals("file")) { int w = Theme.inlineDocDrawable.getIntrinsicWidth(); int h = Theme.inlineDocDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineDocDrawable.setBounds(x, y, x + w, y + h); Theme.inlineDocDrawable.draw(canvas); } else if (inlineResult != null && (inlineResult.type.equals("audio") || inlineResult.type.equals("voice"))) { int w = Theme.inlineAudioDrawable.getIntrinsicWidth(); int h = Theme.inlineAudioDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineAudioDrawable.setBounds(x, y, x + w, y + h); Theme.inlineAudioDrawable.draw(canvas); } else if (inlineResult != null && (inlineResult.type.equals("venue") || inlineResult.type.equals("geo"))) { int w = Theme.inlineLocationDrawable.getIntrinsicWidth(); int h = Theme.inlineLocationDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2; int y = linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint); Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h); Theme.inlineLocationDrawable.draw(canvas); } else { letterDrawable.draw(canvas); } } else { if (inlineResult != null && (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) { int w = Theme.inlineLocationDrawable.getIntrinsicWidth(); int h = Theme.inlineLocationDrawable.getIntrinsicHeight(); int x = linkImageView.getImageX() + (linkImageView.getImageWidth() - w) / 2; int y = linkImageView.getImageY() + (linkImageView.getImageHeight() - h) / 2; canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + linkImageView.getImageWidth(), linkImageView.getImageY() + linkImageView.getImageHeight(), LetterDrawable.paint); Theme.inlineLocationDrawable.setBounds(x, y, x + w, y + h); Theme.inlineLocationDrawable.draw(canvas); } } if (drawLinkImageView) { canvas.save(); if (scaled && scale != 0.8f || !scaled && scale != 1.0f) { long newTime = System.currentTimeMillis(); long dt = (newTime - lastUpdateTime); lastUpdateTime = newTime; if (scaled && scale != 0.8f) { scale -= dt / 400.0f; if (scale < 0.8f) { scale = 0.8f; } } else { scale += dt / 400.0f; if (scale > 1.0f) { scale = 1.0f; } } invalidate(); } canvas.scale(scale, scale, getMeasuredWidth() / 2, getMeasuredHeight() / 2); linkImageView.draw(canvas); canvas.restore(); } if (mediaWebpage && (documentAttachType == DOCUMENT_ATTACH_TYPE_PHOTO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF)) { radialProgress.setProgressColor(0xffffffff); radialProgress.draw(canvas); } if (needDivider && !mediaWebpage) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, paint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, paint); } } if (needShadow && shadowDrawable != null) { shadowDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(3)); shadowDrawable.draw(canvas); } }