List of usage examples for android.graphics Canvas drawText
public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint)
From source file:com.wanikani.androidnotifier.graph.TYPlot.java
/** * Draws the grinds on the canvas. Since they are "over" the plot, this * method should be called last/*from w ww . j a v a2 s.co m*/ * @param canvas the canvas */ protected void drawGrid(Canvas canvas) { float f, dateLabelBaseline, levelupBaseline; Map<Integer, Pager.Marker> markers; Pager.Marker marker; int d, lo, hi, ascent; DateFormat df; String s; Calendar cal; canvas.drawLine(meas.plotArea.left, meas.plotArea.bottom, meas.plotArea.right, meas.plotArea.bottom, pas.axisPaint); f = vp.getRelPosition(0); lo = vp.leftmostDay(); hi = vp.rightmostDay(); cal = taxis.dayToCalendar(lo); markers = pager.dsource.getMarkers(); ascent = (int) pas.dateLabels.getFontMetrics().ascent; dateLabelBaseline = meas.plotArea.bottom - ascent + meas.tickSize / 2; levelupBaseline = meas.plotArea.top - meas.tickSize / 2; for (d = meas.yaxisGrid; vp.getY(d) >= meas.plotArea.top; d += meas.yaxisGrid) canvas.drawLine(meas.plotArea.left, vp.getY(d), meas.plotArea.right, vp.getY(d), pas.gridPaint); for (d = lo; d <= hi; d++) { f = vp.getRelPosition(d); if (d == 0 || d == taxis.today) canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.axisPaint); else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.gridPaint); if (cal.get(Calendar.DAY_OF_MONTH) == 1) { df = cal.get(Calendar.MONTH) == Calendar.JANUARY ? janf : datef; s = df.format(cal.getTime()); canvas.drawLine(f, meas.plotArea.bottom - meas.tickSize / 2, f, meas.plotArea.bottom + meas.tickSize / 2, pas.axisPaint); canvas.drawText(s, f, dateLabelBaseline, pas.dateLabels); } marker = markers.get(d); if (marker != null) { pas.levelup.setColor(marker.color); canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.levelup); canvas.drawText(marker.name, f, levelupBaseline, pas.levelup); } cal.add(Calendar.DATE, 1); } }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override protected void onDraw(Canvas canvas) { float x = (getRight() - getLeft()) / 2; float y = mCurrentScrollOffset; if (mVirtualButtonPressedDrawable != null && mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { if (mDecrementVirtualButtonPressed) { mVirtualButtonPressedDrawable.setState(PRESSED_STATE_SET); mVirtualButtonPressedDrawable.setBounds(0, 0, getRight(), mTopSelectionDividerTop); mVirtualButtonPressedDrawable.draw(canvas); }/* w w w. j ava 2 s . c o m*/ if (mIncrementVirtualButtonPressed) { mVirtualButtonPressedDrawable.setState(PRESSED_STATE_SET); mVirtualButtonPressedDrawable.setBounds(0, mBottomSelectionDividerBottom, getRight(), getBottom()); mVirtualButtonPressedDrawable.draw(canvas); } } // draw the selector wheel int[] selectorIndices = mSelectorIndices; for (int i = 0; i < selectorIndices.length; i++) { int selectorIndex = selectorIndices[i]; String scrollSelectorValue = mSelectorIndexToStringCache.get(selectorIndex); // Do not draw the middle item if input is visible since the input // is shown only if the wheel is static and it covers the middle // item. Otherwise, if the user starts editing the text via the // IME he may see a dimmed version of the old value intermixed // with the new one. if (i != SELECTOR_MIDDLE_ITEM_INDEX || mInputText.getVisibility() != VISIBLE) { canvas.drawText(scrollSelectorValue, x, y, mSelectorWheelPaint); } y += mSelectorElementHeight; } // draw the selection dividers if (mSelectionDivider != null) { // draw the top divider int topOfTopDivider = mTopSelectionDividerTop; int bottomOfTopDivider = topOfTopDivider + mSelectionDividerHeight; mSelectionDivider.setBounds(0, topOfTopDivider, getRight(), bottomOfTopDivider); mSelectionDivider.draw(canvas); // draw the bottom divider int bottomOfBottomDivider = mBottomSelectionDividerBottom; int topOfBottomDivider = bottomOfBottomDivider - mSelectionDividerHeight; mSelectionDivider.setBounds(0, topOfBottomDivider, getRight(), bottomOfBottomDivider); mSelectionDivider.draw(canvas); } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * /*w ww. java 2s. c om*/ * * @param canvas */ private void drawText(Canvas canvas) { float x = getPaddingLeft() + itemWidth / 2; int y = getHeight() - getPaddingBottom() - indicatorHeight - underLineHeight; int position = 0; for (String text : tabs) { canvas.save(); mTextPaint.setColor(textColorNormal); mTextPaint.setTextAlign(Align.LEFT); mTextPaint.setTextSize(textSize); if (showTextGradient) { if (position == nextPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, textSizeOffset)); } else if (position == currectPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, 1 - textSizeOffset)); } else { mTextPaint.setColor(textColorNormal); } } if (showTextScale) { if (position == nextPager) { canvas.translate(x - mTextPaint.measureText(text) * (1 + textSizeOffset * magnification) / 2, y - textTop); canvas.scale(1 + textSizeOffset * magnification, 1 + textSizeOffset * magnification); } else if (position == currectPager) { canvas.translate( x - mTextPaint.measureText(text) * (1 + (1 - textSizeOffset) * magnification) / 2, y - textTop); canvas.scale(1 + (1 - textSizeOffset) * magnification, 1 + (1 - textSizeOffset) * magnification); } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); canvas.scale(1, 1); } } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); } canvas.drawText(text, 0, 0, mTextPaint); x += itemWidth + intervalWidth; position++; canvas.restore(); } }
From source file:org.mdc.chess.ChessBoard.java
private void drawDecorations(Canvas canvas) { if (decorations == null) { return;/*from ww w . j a va2 s. c o m*/ } long decorated = 0; for (SquareDecoration sd : decorations) { int sq = sd.sq; if ((sd.sq < 0) || (sd.sq >= 64)) { continue; } if (((1L << sq) & decorated) != 0) { continue; } decorated |= 1L << sq; int xCrd = getXCrd(Position.getX(sq)); int yCrd = getYCrd(Position.getY(sq)); String s = null; int wdl = sd.tbData.wdl; int num = (sd.tbData.score + 1) / 2; switch (sd.tbData.type) { case DTM: if (wdl > 0) { s = "+" + String.valueOf(num); } else if (wdl < 0) { s = "-" + String.valueOf(num); } else { s = "0"; } break; case DTZ: if (wdl > 0) { s = "W" + String.valueOf(num); } else if (wdl < 0) { s = "L" + String.valueOf(num); } else { s = "0"; } break; case WDL: if (wdl > 0) { s = "W"; } else if (wdl < 0) { s = "L"; } else { s = "0"; } break; case NONE: break; } if (s != null) { Rect bounds = new Rect(); decorationPaint.getTextBounds(s, 0, s.length(), bounds); xCrd += (sqSize - (bounds.left + bounds.right)) / 2; yCrd += (sqSize - (bounds.top + bounds.bottom)) / 2; canvas.drawText(s, xCrd, yCrd, decorationPaint); } } }
From source file:com.cssweb.android.view.PriceView.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1);/*w w w . j a va2s .c om*/ this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY + DY / 4, endX, DY + DY / 4, tPaint); canvas.drawLine(startX, DY * 6 + DY / 4, endX, DY * 6 + DY / 4, tPaint); canvas.drawLine(startX, DY * 11 + DY / 4, endX, DY * 11 + DY / 4, tPaint); canvas.drawLine(startX, DY * 16 + DY / 4, endX, DY * 16 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); canvas.translate(0, DY); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); if (jo.getDouble("wb") < 0) paint.setColor(GlobalColor.colorPriceDown); else if (jo.getDouble("wb") > 0) paint.setColor(GlobalColor.colorpriceUp); else paint.setColor(GlobalColor.colorPriceEqual); if (jo.getInt("tp") == 1) canvas.drawText("", x, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, 0); 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"), false), x - tips, y, paint); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { double temp2 = jo.getDouble("sjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); //paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(str, x, y, paint); if (i != 1) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 5; i >= 1; i--) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint); if (i != 1) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width / 2, -DY * 4); paint.setTextAlign(Paint.Align.RIGHT); for (int i = 1; i <= 5; i++) { double temp2 = jo.getDouble("bjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); for (int i = 1; i <= 5; i++) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint); if (i != 5) canvas.translate(0, DY); } canvas.translate(-width, DY); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); int syjd = jo.getInt("syjd"); switch (syjd) { case 1: canvas.drawText("()", x + tips, y, paint); break; case 2: canvas.drawText("()", x + tips, y, paint); break; case 3: canvas.drawText("()", x + tips, y, paint); break; case 4: canvas.drawText("()", x + tips, y, paint); break; default: canvas.drawText("()", x + tips, y, paint); break; } canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.drawText(Utils.dataFormation(zjcj, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp")); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit, jo.getInt("tp")); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x, y, paint); canvas.translate(0, -DY * 7); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) canvas.drawText("", x + tips, y, paint); else canvas.drawText("PE()", x + tips, y, paint); canvas.translate(width / 2, -DY * 7); paint.setTextAlign(Paint.Align.RIGHT); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); 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("gb"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) { canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint); } else { canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.example.test2969mediabrowser.UnderlinePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;//ww w .j a v a 2 s .com } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } final int width = getWidth(); int height = getHeight(); final int paddingLeft = getPaddingLeft(); final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count); final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset); final float right = left + pageWidth; final float top = getPaddingTop(); final float bottom = getHeight() - getPaddingBottom(); // canvas.drawRect(left, top, right, bottom, mPaint); //===================================add by joe 20150918 start============ // mPath.reset(); mPath.moveTo(0, height * 4 / 5); mPath.lineTo(width, height * 4 / 5); mPath.lineTo(width, height); mPath.lineTo(0, height); mPath.close(); mPaint.setColor(Color.BLACK); canvas.drawPath(mPath, mPaint); // mPath.reset(); mPath.moveTo(left + 50, height * 5 / 6); mPath.lineTo(right - 50, height * 5 / 6); mPath.lineTo(right - 50, height); mPath.lineTo(left + 50, height); mPath.close();//#ff3b8eb9 canvas.drawPath(mPath, mPaintFooterLine); //?text mPaintText.setColor(getResources().getColor(R.color.blue_select)); mPaintText.setTextSize(22); FontMetricsInt fontMetrics = mPaintText.getFontMetricsInt(); Rect targetRect = new Rect((int) left, (int) top, (int) right, (int) (height * 4 / 5)); int baseline = targetRect.top + (targetRect.bottom - targetRect.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top; // ?drawTexttargetRect.centerX() mPaintText.setTextAlign(Paint.Align.CENTER); String tittle = (mCurrentPage + 1) + " / " + mViewPager.getAdapter().getCount(); canvas.drawText(tittle, (left + right - tittle.length()) / 2, height * 3 / 5, mPaintText); //===================================add by joe 20150918 end================== }
From source file:com.bytebit.classicbyte.ScreenMainMenu.java
public void draw(Canvas c) { this.parent.standard_paint.setColor(Color.WHITE); for (int i = 0; i != 9; i++) { for (int k = 0; k != 10; k++) { c.drawBitmap(TextureManager.getBitmap(3), k * (this.parent.renderer.width / 10), (i + 1) * (this.parent.renderer.width / 10), this.parent.standard_paint); }/*from w w w . j av a2s .c om*/ } if (this.menu_current_tab == 1) { Rect bounds = new Rect(); String g; for (int k = 0; k != this.server_list_name.size(); k++) { if (k >= this.server_list_name.size()) { break; } if ((this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset) >= 0 && (this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset) <= this.parent.renderer.height) { this.parent.standard_paint.setColor(Color.WHITE); this.parent.standard_paint.setTextSize(this.parent.renderer.width * 0.04F); c.drawBitmap(TextureManager.getBitmap(10), (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2, this.parent.renderer.width * 0.02F + this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset, this.parent.standard_paint); g = this.server_list_name.get(k); this.parent.standard_paint.getTextBounds(this.server_list_name.get(k), 0, this.server_list_name.get(k).length(), bounds); if (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) { while (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) { this.parent.standard_paint.getTextBounds(g + " ..", 0, (g + " ..").length(), bounds); g = g.substring(0, g.length() - 1); } g = g + " .."; } c.drawText(g, (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2 + this.parent.renderer.width * 0.02F, this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset, this.parent.standard_paint); this.parent.standard_paint.setColor(Color.YELLOW); this.parent.standard_paint.getTextBounds(this.server_list_online_data.get(k), 0, this.server_list_online_data.get(k).length(), bounds); c.drawText(this.server_list_online_data.get(k), this.parent.renderer.width - (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2 - this.parent.renderer.width * 0.02F - bounds.width(), this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset, this.parent.standard_paint); } } c.drawBitmap( TextureManager.getBitmap(26), 0, TextureManager.getBitmap(2).getHeight() + TextureManager.getBitmap(22).getHeight() + this.scrollbar_offset, this.parent.standard_paint); if (this.menu_button_highlighted == 3) { c.drawBitmap(TextureManager.getBitmap(25), 0, TextureManager.getBitmap(2).getHeight(), this.parent.standard_paint); } else { c.drawBitmap(TextureManager.getBitmap(24), 0, TextureManager.getBitmap(2).getHeight(), this.parent.standard_paint); } if (this.menu_button_highlighted == 4) { c.drawBitmap(TextureManager.getBitmap(23), 0, this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(), this.parent.standard_paint); } else { c.drawBitmap(TextureManager.getBitmap(22), 0, this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(), this.parent.standard_paint); } } if (this.menu_current_tab == 2) { Rect bounds = new Rect(); this.parent.standard_paint.setColor(Color.WHITE); this.parent.standard_paint.setTextSize(this.parent.renderer.height * 0.25F); this.parent.standard_paint.getTextBounds("Nothing here", 0, "Nothing here".length(), bounds); c.drawText("Nothing here", (this.parent.renderer.width - bounds.width()) / 2, this.parent.renderer.height * 0.5F, this.parent.standard_paint); } for (int k = 0; k != 10; k++) { c.drawBitmap(TextureManager.getBitmap(2), k * TextureManager.getBitmap(2).getWidth(), 0, this.parent.standard_paint); } c.drawBitmap(TextureManager.getBitmap(4), this.parent.renderer.width * 0.05F, 0, this.parent.standard_paint); if (this.menu_button_highlighted == 1) { c.drawBitmap(TextureManager.getBitmap(8), this.parent.renderer.width * 0.1F * 6.5F, this.parent.renderer.width * 0.01F, this.parent.standard_paint); } else { c.drawBitmap(TextureManager.getBitmap(7), this.parent.renderer.width * 0.1F * 6.5F, this.parent.renderer.width * 0.01F, this.parent.standard_paint); } if (this.menu_button_highlighted == 2) { c.drawBitmap(TextureManager.getBitmap(6), this.parent.renderer.width * 0.1F * 8.75F, this.parent.renderer.width * 0.01F, this.parent.standard_paint); } else { c.drawBitmap(TextureManager.getBitmap(5), this.parent.renderer.width * 0.1F * 8.75F, this.parent.renderer.width * 0.01F, this.parent.standard_paint); } //c.drawBitmap(TextureManager.getBitmap(9), this.parent.renderer.width-TextureManager.getBitmap(9).getWidth(), this.parent.renderer.height-TextureManager.getBitmap(9).getHeight(), this.parent.standard_paint); }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * /*from www . j a va2 s .c o m*/ * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawText(Canvas canvas, int position, int itemWidth, int itemHeight) { if (getItemText(position) == null) return; String text = getItemText(position).toString(); if (text.length() <= 0) return; mTextPaint.setTextSize(mTextSize); if (mTextColor == null) { mTextPaint.setColor(DEFAULT_TEXT_COLOR); } else { final int normalColor = mTextColor.getDefaultColor(); final int selectedColor = mTextColor.getColorForState(SELECTED_STATE_SET, normalColor); if (position == mNextPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, mOffset)); } else if (position == mCurrentPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, 1 - mOffset)); } else { mTextPaint.setColor(normalColor); } } final float centerX = ViewCompat.getPaddingStart(this) + (itemWidth + getIntervalWidth()) * ((float) position + 0.5f); final float centerY = getPaddingTop() + itemHeight * 0.5f; float scale; if (position == mNextPager) { scale = 1 + (mTextScale - 1) * mOffset; } else if (position == mCurrentPager) { scale = 1 + (mTextScale - 1) * (1 - mOffset); } else { scale = 1; } canvas.save(); canvas.translate(centerX, centerY + mTextDesc); if (scale != 1) { canvas.scale(scale, scale, 0, -mTextDesc); } canvas.drawText(text, 0, 0, mTextPaint); canvas.restore(); }
From source file:com.icloud.listenbook.base.view.viewpagerindicator.FixedTitlePageIndicator.java
private void onDrawIsFixedTitle(Canvas canvas) { // //from w ww . j a v a 2 s. c om bounds = calculateFixedAllBounds(mPaintText); // final int count = mViewPager.getAdapter().getCount(); final float unitNum = (count > 3 ? 4f : count); final float halfWidth = getWidth() / 2f; final float unitWidth = getWidth() / unitNum; final int left = getLeft(); final int width = getWidth(); final int height = getHeight(); final int right = left + width; int page = mCurrentPage; float offsetPercent; if (mCurrentOffset <= halfWidth) { offsetPercent = 1.0f * mCurrentOffset / width; } else { page += 1; offsetPercent = 1.0f * (width - mCurrentOffset) / width; } final float mOffset = unitWidth * (1.0f * mCurrentOffset / width); final boolean currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE); final boolean currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE); final float selectedPercent = (0.5f - offsetPercent) / 0.5f; // RectF curPageBound = bounds.get(mCurrentPage); final float curPageW = curPageBound.right - curPageBound.left; // Now draw views for (int i = 0; i < count; i++) { // Get the title RectF bound = bounds.get(i); // Only if one side is visible if ((bound.left > left && bound.left < right) || (bound.right > left && bound.right < right)) { final boolean currentPage = (i == page); // Only set bold if we are within bounds mPaintText.setFakeBoldText(currentPage && currentBold && mBoldText); // Draw text as unselected mPaintText.setColor(mColorText); canvas.drawText(mTitleProvider.getPageTitle(i).toString(), bound.left, bound.bottom + mTopPadding, mPaintText); // if (currentPage && currentSelected) { mPaintText.setColor(mColorSelected); mPaintText.setAlpha((int) ((mColorSelected >>> 24) * selectedPercent)); canvas.drawText(mTitleProvider.getPageTitle(i).toString(), bound.left, bound.bottom + mTopPadding, mPaintText); } } } // mPath = new Path(); mPath.moveTo(0, height - mFooterLineHeight / 2f); mPath.lineTo(width, height - mFooterLineHeight / 2f); mPath.close(); canvas.drawPath(mPath, mPaintFooterLine); switch (mFooterIndicatorStyle) { case Triangle: { float TriangleLetf = curPageBound.left + +(curPageBound.right - curPageBound.left) / 2; TriangleLetf += mOffset; mPath = new Path(); mPath.moveTo(TriangleLetf, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.lineTo(TriangleLetf + mFooterIndicatorHeight, height - mFooterLineHeight); mPath.lineTo(TriangleLetf - mFooterIndicatorHeight, height - mFooterLineHeight); mPath.close(); mPaintFooterIndicator.setAlpha((int) (0xFF * selectedPercent)); canvas.drawPath(mPath, mPaintFooterIndicator); mPaintFooterIndicator.setAlpha(0xFF); break; } case Underline: { int index = (int) (curPageBound.left / unitWidth); final float TriangleLetf = unitWidth * index + mOffset + mFooterIndicatorUnderlinePadding; final float TriangleRight = unitWidth * index + mOffset + unitWidth - mFooterIndicatorUnderlinePadding; mPath = new Path(); mPath.moveTo(TriangleLetf, height - mFooterLineHeight); mPath.lineTo(TriangleRight, height - mFooterLineHeight); mPath.lineTo(TriangleRight, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.lineTo(TriangleLetf, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.close(); mPaintFooterIndicator.setAlpha((int) (0xFF * selectedPercent)); canvas.drawPath(mPath, mPaintFooterIndicator); mPaintFooterIndicator.setAlpha(0xFF); break; } } }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Draws the month days./* w ww .j ava2s . co m*/ */ private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int rowHeight = mDayHeight; final int colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; int rowCenter = headerHeight + rowHeight / 2; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (ViewCompatUtils.isLayoutRtl(this)) { colCenterRtl = mPaddedWidth - colCenter; } else { colCenterRtl = colCenter; } int state = 0; final boolean isDayEnabled = isDayEnabled(day); final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { state = VIEW_STATE_SELECTED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { state = VIEW_STATE_PRESSED; if (isDayEnabled) { // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; final int dayTextColor; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { final int[] stateSet = buildState(isDayEnabled, state); dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } p.setColor(dayTextColor); canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p); col++; if (col == DAYS_IN_WEEK) { col = 0; rowCenter += rowHeight; } } }