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.unkonw.testapp.libs.view.indicator.CirclePageIndicatorOfHuaLong.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;// ww w . j a va 2s .c o m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } float ft = mPaintText.getTextSize() - 3; mPaintText.setColor(0xffffffff); //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { // canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); canvas.drawRect(dX, dY, dX + ft, dY - ft, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { // canvas.drawCircle(dX, dY, mRadius, mPaintStroke); canvas.drawRect(dX, dY, dX + ft, dY - ft, mPaintStroke); } canvas.drawText(String.valueOf(iLoop + 1), dX, dY, mPaintText); } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } // canvas.drawCircle(dX, dY, mRadius, mPaintFill); mPaintText.setColor(0xffffffff); canvas.drawRect(dX, dY, dX + ft, dY - ft, mPaintFill); canvas.drawText(String.valueOf(mCurrentPage + 1), dX, dY, mPaintText); }
From source file:com.viewsforandroid.foundry.sample.indicators.NumericPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;//from w ww . j a va2 s .co m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // mCurrentPage is -1 on first start and after orientation changed. If // so, retrieve the correct index from viewpager. if (mCurrentPage == -1 && mViewPager != null) { mCurrentPage = mViewPager.getCurrentItem(); } // Handle the first time we draw the view, when onMeasure has not been // called yet if (mTextFirstPart == null) { updateText(); } // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing // the page // number itself, because of the animated effect in which the current // page fades // out and the next one fades in. In order to implement this effect we // are forced to // draw the text in four "chunks": the first part ("Page "), the current // page // number ("1"), the next page number ("2"), and the last part // (" of 20"). // To implement the fade in and fade out animations we simply change the // alpha // of the page number text, relative to the view pager scroll final float currentPageWeight = 1 - mPageOffset; final float nextPageWeight = mPageOffset; final float firstPartWidth = mPaintText.measureText(mTextFirstPart); final String currentPageNumber = Integer.toString(mCurrentPage + 1); final String nextPageNumber = Integer.toString(mCurrentPage + 2); final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber); final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber); final float pageNumberWidth = currentPageWeight * currentPageNumberWidth + nextPageWeight * nextPageNumberWidth; final float lastPartWidth = mPaintText.measureText(mTextLastPart); final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth; float currentX = (getWidth() - totalWidth) / 2; canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText); currentX += firstPartWidth; final float pageNumberCenterX = currentX + pageNumberWidth / 2; final int startAlpha = Color.alpha(mColorPageNumberText); final int endAlpha = 0; final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha); canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha); canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); currentX += pageNumberWidth; canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText); // Draw the "start" and "end" buttons if (mShowStartEndButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mStartDown) { canvas.drawRect(mRectStart, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mEndDown) { canvas.drawRect(mRectEnd, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } // Draw the "next" and "previous" buttons if (mShowChangePageButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mPreviousDown) { canvas.drawRect(mRectPrevious, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mNextDown) { canvas.drawRect(mRectNext, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2, mRectPreviousText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } }
From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java
public void onDraw(Canvas canvas) { if (points.size() == 0) { return;//from w ww . j a v a2 s.c o m } Path path = new Path(); int height = canvas.getHeight(); int width = canvas.getWidth(); for (Point point : points) { point.x = point.percentageX * width + 60; // Log.i("scaleFactor", " : " + scaleFactor); //Log.i("percent", " : " + percent); point.y = (float) ((1 - point.percentageY * scaleFactor) * height * 0.7 + 30); } if (points.size() > 1) { //calcuate x/y based on size of canvas for (int i = 0; i < points.size(); i++) { if (i >= 0) { Point point = points.get(i); // Log.i("dx",point.x + " - " + point.y ); if (i == 0) { Point next = points.get(i + 1); point.dx = ((next.x - point.x) / 5); point.dy = ((next.y - point.y) / 5); } else if (i == points.size() - 1) { Point prev = points.get(i - 1); point.dx = ((point.x - prev.x) / 5); point.dy = ((point.y - prev.y) / 5); } else { Point next = points.get(i + 1); Point prev = points.get(i - 1); point.dx = ((next.x - prev.x) / 5); point.dy = ((next.y - prev.y) / 5); } } } } if (points.size() > 0) { path.moveTo(0, (float) (canvas.getHeight() * 0.8)); path.lineTo(0, points.get(0).y); } boolean first = true; for (int i = 0; i < points.size(); i++) { Point point = points.get(i); if (first) { first = false; path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy, point.x, point.y); } else { Point prev = points.get(i - 1); // Log.i("Draw", point.dx + " " + point.dy); path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x, point.y); } } path.lineTo(width, (float) (height * 0.8)); path.lineTo(width, (float) (height * 0.9)); path.lineTo(0, (float) (height * 0.9)); canvas.drawPath(path, mGraphPaint); canvas.drawRect(0, (float) (height * 0.9), width, height, mGraphPaint); double Kp1Height = (1 - 0.6666666) * height;//points.get(points.size()-1).y; canvas.drawRect(0, (float) Kp1Height, width, (float) Kp1Height + 1, paintG1Line); canvas.drawText("G1", 2, (float) Kp1Height, paintTxt); int detlaY = 15; for (Point p : points) { int val = (int) Math.round(9 * p.percentageY); //if last element if (points.indexOf(p) == points.size() - 1) { //Log.i("last", p.toString()); // canvas.drawText(val + "", p.x-150,p.y - detlaY, paintTxt); } else { canvas.drawText(val + "", p.x - 10, p.y - detlaY, paintTxt); } //Log.i("point", p.toString()); } // Log.i("Lenght", points.size() + " "); }
From source file:connect.app.com.connect.calendar.SimpleMonthView.java
/** * Draws the month days./*from www . j av a 2 s . c o 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 = colCenter; // if (isLayoutRtl()) { // colCenterRtl = mPaddedWidth - colCenter; // } else { // colCenterRtl = colCenter; // } int stateMask = 0; final boolean isDayEnabled = isDayEnabled(day); // if (isDayEnabled) { // stateMask |= StateSet.VIEW_STATE_ENABLED; // } final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { // stateMask |= StateSet.VIEW_STATE_ACTIVATED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { // stateMask |= StateSet.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; int dayTextColor = 0; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { // final int[] stateSet = StateSet.get(stateMask); // 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; } } }
From source file:com.cssweb.android.view.TrendView.java
private void drawWin(Canvas canvas) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1);//from ww w . j a v a 2s.c om mpaint = new Paint(); mpaint.setTypeface(Typeface.DEFAULT_BOLD); mpaint.setAntiAlias(true); mpaint.setTextAlign(Paint.Align.LEFT); mpaint.setStyle(Paint.Style.STROKE); mpaint.setTextSize(dTextSize); /** * ? */ closeLeft = Utils.dataFormation(high, stockdigit); closeRight = "00.00%"; LSpace = (int) (Math.max(mpaint.measureText(closeLeft), mpaint.measureText(closeRight))); //??? //RSpace = (int)(paint.measureText(closeRight) + 10); RSpace = 0; axisLabelHeight = Font.getFontHeight(dTextSize); graphicsQuoteWidth = width - LSpace - RSpace; SPACE = graphicsQuoteWidth / MINUTES; topTitleHeight = axisLabelHeight; graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight; price_row_num = 2;//(int)graphicsQuoteHeight/3/25; volume_row_num = price_row_num; price_row_height = graphicsQuoteHeight / price_row_num / 3; volume_row_height = price_row_height; calc_zf(); title1 = ":"; title7 = ":"; title8 = ""; title2 = ""; mpaint.setColor(GlobalColor.colorLabelName); canvas.drawText(title7 + title8, LSpace, axisLabelHeight - 5, mpaint); canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint); canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint); if (isZs()) { if (close == 0) close = 1000; } else { if (close == 0) close = 1; } low = Math.min(low, close); //upPrice = close * (1+max_zf); //downPrice = close * (1-max_zf); paint.setColor(GlobalColor.clrLine); canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); // upQuoteX = LSpace; upQuoteY = topTitleHeight; upQuoteWidth = (int) graphicsQuoteWidth; upQuoteHeight = price_row_num * price_row_height; for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } else Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } // downQuoteX = LSpace; downQuoteY = topTitleHeight + upQuoteHeight; downQuoteWidth = (int) graphicsQuoteWidth; downQuoteHeight = upQuoteHeight; paint.setColor(GlobalColor.clrLine); for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint); } else Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint); } // ?? volumeX = LSpace; volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight; volumeWidth = (int) graphicsQuoteWidth; volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight; volume_row_height = volumeHeight / volume_row_num; paint.setColor(GlobalColor.clrLine); for (int i = 0; i <= volume_row_num; i++) { if (i == 0) { canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } else { if (i != volume_row_num) Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } else Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } // canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); }
From source file:com.manuelpeinado.numericpageindicator.NumericPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from w ww . j ava 2 s. c o m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // mCurrentPage is -1 on first start and after orientation changed. If // so, retrieve the correct index from viewpager. if (mCurrentPage == -1 && mViewPager != null) { mCurrentPage = mViewPager.getCurrentItem(); } // Handle the first time we draw the view, when onMeasure has not been // called yet if (mTextFirstPart == null) { updateText(); } // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing // the page // number itself, because of the animated effect in which the current // page fades // out and the next one fades in. In order to implement this effect we // are forced to // draw the text in four "chunks": the first part ("Page "), the current // page // number ("1"), the next page number ("2"), and the last part // (" of 20"). // To implement the fade in and fade out animations we simply change the // alpha // of the page number text, relative to the view pager scroll final float currentPageWeight = 1 - mPageOffset; final float nextPageWeight = mPageOffset; final float firstPartWidth = mPaintText.measureText(mTextFirstPart); final String currentPageNumber = Integer.toString(mCurrentPage + 1); final String nextPageNumber = Integer.toString(mCurrentPage + 2); final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber); final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber); final float pageNumberWidth = currentPageWeight * currentPageNumberWidth + nextPageWeight * nextPageNumberWidth; final float lastPartWidth = mPaintText.measureText(mTextLastPart); final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth; float currentX = (getWidth() - totalWidth) / 2; canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText); currentX += firstPartWidth; final float pageNumberCenterX = currentX + pageNumberWidth / 2; final int startAlpha = Color.alpha(mColorPageNumberText); final int endAlpha = 0; final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha); canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha); canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); currentX += pageNumberWidth; canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText); // Draw the "start" and "end" buttons if (mShowStartEndButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mStartDown) { canvas.drawRect(mRectStart, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mEndDown) { canvas.drawRect(mRectEnd, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } if (!mShowImagesForPageControls) { canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom, mPaintText); } else if (mStartButtonImage != null) { canvas.drawBitmap(mStartButtonImage, mRectStart.centerX() - mStartButtonImage.getWidth() / 2, mRectStart.centerY() - mStartButtonImage.getHeight() / 2, mPaintText); } mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } if (!mShowImagesForPageControls) { canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom, mPaintText); } else if (mEndButtonImage != null) { canvas.drawBitmap(mEndButtonImage, mRectEnd.centerX() - mEndButtonImage.getWidth() / 2, mRectEnd.centerY() - mEndButtonImage.getHeight() / 2, mPaintText); } mPaintText.setAlpha(Color.alpha(mColorText)); } } // Draw the "next" and "previous" buttons if (mShowChangePageButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mPreviousDown) { canvas.drawRect(mRectPrevious, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mNextDown) { canvas.drawRect(mRectNext, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } if (!mShowImagesForPageControls) { canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2, mRectPreviousText.bottom, mPaintText); } else if (mPreviousButtonImage != null) { canvas.drawBitmap(mPreviousButtonImage, mRectPrevious.centerX() - mPreviousButtonImage.getWidth() / 2, mRectPrevious.centerY() - mPreviousButtonImage.getHeight() / 2, mPaintText); } mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } if (!mShowImagesForPageControls) { canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom, mPaintText); } else if (mNextButtonImage != null) { canvas.drawBitmap(mNextButtonImage, mRectNext.centerX() - mNextButtonImage.getWidth() / 2, mRectNext.centerY() - mNextButtonImage.getHeight() / 2, mPaintText); } mPaintText.setAlpha(Color.alpha(mColorText)); } } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
private void drawDayHeader(String dayStr, int day, String dateNumStr, Canvas canvas, Paint p) { int x;//from w ww . ja v a 2 s. c o m p.setAntiAlias(true); int todayIndex = mTodayJulianDay - mFirstJulianDay; // Draw day of the month if (mNumDays > 1) { float y = DAY_HEADER_HEIGHT - DAY_HEADER_BOTTOM_MARGIN; // Draw day of the month x = computeDayLeftPosition(day + 1) - DAY_HEADER_RIGHT_MARGIN; p.setTextAlign(Align.RIGHT); p.setTextSize(DATE_HEADER_FONT_SIZE); p.setTypeface(todayIndex == day ? mBold : Typeface.DEFAULT); canvas.drawText(dateNumStr, x, y, p); // Draw day of the week x -= p.measureText(" " + dateNumStr); p.setTextSize(DAY_HEADER_FONT_SIZE); p.setTypeface(Typeface.DEFAULT); canvas.drawText(dayStr, x, y, p); } else { float y = DAY_HEADER_HEIGHT - DAY_HEADER_ONE_DAY_BOTTOM_MARGIN; p.setTextAlign(Align.LEFT); // Draw day of the week x = computeDayLeftPosition(day) + DAY_HEADER_ONE_DAY_LEFT_MARGIN; x = x + ((mCellWidth - mDateStrWidthLong) / 2); p.setTextSize(DAY_HEADER_FONT_SIZE); p.setTypeface(Typeface.DEFAULT); canvas.drawText(dayStr, x, y, p); // Draw day of the month x += p.measureText(dayStr) + DAY_HEADER_ONE_DAY_RIGHT_MARGIN; p.setTextSize(DATE_HEADER_FONT_SIZE); p.setTypeface(todayIndex == day ? mBold : Typeface.DEFAULT); canvas.drawText(dateNumStr, x, y, p); } }
From source file:com.eveningoutpost.dexdrip.Home.java
private void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false;/*from www . ja v a 2 s .c o m*/ chart = (LineChartView) findViewById(R.id.chart); if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams(); params.topMargin = 130; chart.setLayoutParams(params); } chart.setBackgroundColor(getCol(X.color_home_chart_background)); chart.setZoomType(ZoomType.HORIZONTAL); //Transmitter Battery Level final Sensor sensor = Sensor.currentSensor(); if (sensor != null && sensor.latest_battery_level != 0 && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW && !prefs.getBoolean("disable_battery_warning", false)) { Drawable background = new Drawable() { @Override public void draw(Canvas canvas) { DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics(); int px = (int) (30 * (metrics.densityDpi / 160f)); Paint paint = new Paint(); paint.setTextSize(px); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#FFFFAA")); paint.setStyle(Paint.Style.STROKE); paint.setAlpha(100); canvas.drawText(getString(R.string.transmitter_battery), 10, chart.getHeight() / 3 - (int) (1.2 * px), paint); if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) { paint.setTextSize((int) (px * 1.5)); canvas.drawText(getString(R.string.very_low), 10, chart.getHeight() / 3, paint); } else { canvas.drawText(getString(R.string.low), 10, chart.getHeight() / 3, paint); } } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getOpacity() { return 0; // TODO Which pixel format should this be? } }; chart.setBackground(background); } previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(mActivity)); previewChart.setBackgroundColor(getCol(X.color_home_chart_background)); previewChart.setZoomType(ZoomType.HORIZONTAL); previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData())); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); if (small_height) { previewChart.setVisibility(View.GONE); // quick test Viewport moveViewPort = new Viewport(chart.getMaximumViewport()); float tempwidth = (float) moveViewPort.width() / 4; holdViewport.left = moveViewPort.right - tempwidth; holdViewport.right = moveViewPort.right + (moveViewPort.width() / 24); holdViewport.top = moveViewPort.top; holdViewport.bottom = moveViewPort.bottom; chart.setCurrentViewport(holdViewport); previewChart.setCurrentViewport(holdViewport); } else { previewChart.setVisibility(View.VISIBLE); } if (insulinset || glucoseset || carbsset || timeset) { if (chart != null) { chart.setAlpha((float) 0.10); // TODO also set buttons alpha } } }
From source file:com.journeyapps.barcodescanner.WXViewfinderView.java
@SuppressLint("DrawAllocation") @Override/*from w w w. j a v a 2s .c o m*/ public void onDraw(Canvas canvas) { refreshSizes(); if (framingRect == null || previewFramingRect == null) { return; } Rect frame = framingRect; Rect previewFrame = previewFramingRect; int width = canvas.getWidth(); int height = canvas.getHeight(); maskPaint.setColor(maskColor); canvas.drawRect(0, 0, width, frame.top, maskPaint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint); canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint); //drawable the border canvas.drawRect(frame.left + 1, frame.top + 1, frame.right, frame.bottom, borderPaint); int halfWidth = (int) (cornerWidth / 2); //draw four corner Path corner1 = new Path(); corner1.moveTo(frame.left, frame.top + cornerLength); corner1.lineTo(frame.left, frame.top); corner1.lineTo(frame.left + cornerLength, frame.top); Matrix translate1 = new Matrix(); translate1.setTranslate(halfWidth, halfWidth); corner1.transform(translate1); canvas.drawPath(corner1, cornerPaint); Path corner2 = new Path(); corner2.moveTo(frame.right + 1 - cornerLength, frame.top); corner2.lineTo(frame.right + 1, frame.top); corner2.lineTo(frame.right + 1, frame.top + cornerLength); Matrix translate2 = new Matrix(); translate2.setTranslate(-halfWidth, halfWidth); corner2.transform(translate2); canvas.drawPath(corner2, cornerPaint); Path corner3 = new Path(); corner3.moveTo(frame.left, frame.bottom + 1 - cornerLength); corner3.lineTo(frame.left, frame.bottom + 1); corner3.lineTo(frame.left + cornerLength, frame.bottom + 1); Matrix translate3 = new Matrix(); translate3.setTranslate(halfWidth, -halfWidth); corner3.transform(translate3); canvas.drawPath(corner3, cornerPaint); Path corner4 = new Path(); corner4.moveTo(frame.right + 1 - cornerLength, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1); corner4.lineTo(frame.right + 1, frame.bottom + 1 - cornerLength); Matrix translate4 = new Matrix(); translate4.setTranslate(-halfWidth, -halfWidth); corner4.transform(translate4); canvas.drawPath(corner4, cornerPaint); offset += speed; if (offset >= frame.bottom - frame.top) { offset = 0; } Rect rect = new Rect(); rect.left = frame.left + 1 + laserPadding; rect.top = frame.top + 1 + offset; rect.right = frame.right - laserPadding; rect.bottom = frame.top + 1 + offset + 3; Bitmap laserBitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.scan_laser, null)).getBitmap(); canvas.drawBitmap(laserBitmap, null, rect, linePaint); textPaint.setTextAlign(Paint.Align.CENTER); canvas.drawText(statusText, (frame.right + frame.left) / 2, frame.bottom + statusTextPadding + statusTextSize, textPaint); postInvalidateDelayed(animationDelay, frame.left, frame.top, frame.right, frame.bottom); }