public void draw(Canvas canvas, MapView mapv, boolean shadow) { int cZoom = mapView.getZoomLevel(); GeoPoint kpGP = parceToGP(r.getString(R.string.kpiPoint)); // Log.i(TAG, "Zoom=" + cZoom); if (cZoom > mZoomMin) { GeoPoint[] kpiZone0 = parceToGPAr(r.getStringArray(R.array.kpiZone0)); Paint mPaint = new Paint(); mPaint.setDither(true); mPaint.setColor(0xff0962f5); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(2); drawFigure(mPaint, canvas, shadow, kpiZone0); if (cZoom > mZoomMax) { super.draw(canvas, mapv, false); int i; Point p = new Point(); Paint tPaint = new Paint(); tPaint.setDither(true); tPaint.setColor(Color.BLACK); tPaint.setStyle(Paint.Style.FILL); tPaint.setFakeBoldText(true); tPaint.setTextAlign(Align.CENTER); tPaint.setTextSize(14); for (mapItem item : itemAr) { projection.toPixels(item.gp, p); canvas.drawText(item.index, p.x, p.y, tPaint); } } else { // Draw only KPI Area int i; Point p = new Point(); Paint tPaint = new Paint(); tPaint.setDither(true); tPaint.setColor(0xff0962f5); tPaint.setStyle(Paint.Style.FILL); tPaint.setFakeBoldText(true); tPaint.setTextAlign(Align.CENTER); tPaint.setTextSize(18); projection.toPixels(kpGP, p); canvas.drawText("KPI", p.x, p.y, tPaint); canvas.drawBitmap( kpiIcon, p.x - kpiIcon.getWidth() / 2, p.y - kpiIcon.getHeight() / 2, null); } } else { Point p = new Point(); projection.toPixels(kpGP, p); canvas.drawBitmap( kpiIcon, p.x - kpiIcon.getWidth() / 2, p.y - kpiIcon.getHeight() / 2, null); } }
/** * Sets up the text and style properties for painting. Override this if you want to use a * different paint. */ protected void initView() { mMonthTitlePaint = new Paint(); mMonthTitlePaint.setFakeBoldText(true); mMonthTitlePaint.setAntiAlias(true); mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE); mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD)); mMonthTitlePaint.setColor(mDayTextColor); mMonthTitlePaint.setTextAlign(Align.CENTER); mMonthTitlePaint.setStyle(Style.FILL); mSelectedCirclePaint = new Paint(); mSelectedCirclePaint.setFakeBoldText(true); mSelectedCirclePaint.setAntiAlias(true); mSelectedCirclePaint.setColor(mTodayNumberColor); mSelectedCirclePaint.setTextAlign(Align.CENTER); mSelectedCirclePaint.setStyle(Style.FILL); mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA); mMonthDayLabelPaint = new Paint(); mMonthDayLabelPaint.setAntiAlias(true); mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE); mMonthDayLabelPaint.setColor(mMonthDayTextColor); mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(), "Roboto-Medium")); mMonthDayLabelPaint.setStyle(Style.FILL); mMonthDayLabelPaint.setTextAlign(Align.CENTER); mMonthDayLabelPaint.setFakeBoldText(true); mMonthNumPaint = new Paint(); mMonthNumPaint.setAntiAlias(true); mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE); mMonthNumPaint.setStyle(Style.FILL); mMonthNumPaint.setTextAlign(Align.CENTER); mMonthNumPaint.setFakeBoldText(false); }
@Override protected void onDraw(final Canvas canvas) { if (recycled) return; final int canvasSave = canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); canvas.scale(scale, scale); canvas.drawBitmap(genBackgroundBitmap, 0, 0, bitmapPaint); final boolean drawSignal = signalMin != null && signalMax != null; if (drawSignal) { signalTextPaint.setTextAlign(Align.LEFT); canvas.drawText( String.format("– %s", signalText), coordFW(9, relW), coordFH(130, relH), signalTextPaint); signalTextPaint.setTextAlign(Align.RIGHT); canvas.drawText( Integer.toString(signalMin), coordFW(72, relW), coordFH(195, relH), signalTextPaint); canvas.drawText( Integer.toString(signalMax), coordFW(72, relW), coordFH(58, relH), signalTextPaint); } canvas.drawBitmap(gridBitmap, gridX, gridY, bitmapPaint); final int canvasSave2 = canvas.save(); canvas.translate(graphX, graphY); for (final GraphService graph : graphs) graph.draw(canvas); canvas.restoreToCount(canvasSave2); canvas.restoreToCount(canvasSave); }
public NormalBatteryMeterDrawable(Resources res, boolean horizontal) { super(); mHorizontal = horizontal; mDisposed = false; mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mFramePaint.setColor(res.getColor(R.color.batterymeter_frame_color)); mFramePaint.setDither(true); mFramePaint.setStrokeWidth(0); mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE); mFramePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBatteryPaint.setDither(true); mBatteryPaint.setStrokeWidth(0); mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE); mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(res.getColor(R.color.batterymeter_bolt_color)); Typeface font = Typeface.create("sans-serif-condensed", Typeface.BOLD); mTextPaint.setTypeface(font); mTextPaint.setTextAlign(Paint.Align.CENTER); mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mWarningTextPaint.setColor(mColors[1]); font = Typeface.create("sans-serif", Typeface.BOLD); mWarningTextPaint.setTypeface(font); mWarningTextPaint.setTextAlign(Paint.Align.CENTER); mBoltPaint = new Paint(); mBoltPaint.setAntiAlias(true); mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color)); mBoltPoints = loadBoltPoints(res); }
public DrawView(Context context) { super(context); axisPaint.setDither(true); axisPaint.setStyle(Paint.Style.STROKE); axisPaint.setStrokeJoin(Paint.Join.ROUND); axisPaint.setStrokeCap(Paint.Cap.ROUND); axisPaint.setColor(getContext().getResources().getColor(R.color.text)); axisPaint.setStrokeWidth(strokeWidth); withPaint.setDither(true); withPaint.setStyle(Paint.Style.STROKE); withPaint.setStrokeJoin(Paint.Join.ROUND); withPaint.setStrokeCap(Paint.Cap.ROUND); withPaint.setColor(getContext().getResources().getColor(R.color.with)); withPaint.setStrokeWidth(strokeWidth); withTextPaint.setColor(getContext().getResources().getColor(R.color.with)); withTextPaint.setTextSize(TEXT_SIZE); withTextPaint.setTextAlign(Align.RIGHT); withoutPaint.setDither(true); withoutPaint.setStyle(Paint.Style.STROKE); withoutPaint.setStrokeJoin(Paint.Join.ROUND); withoutPaint.setStrokeCap(Paint.Cap.ROUND); withoutPaint.setColor(getContext().getResources().getColor(R.color.without)); withoutPaint.setStrokeWidth(strokeWidth); withoutTextPaint.setColor(getContext().getResources().getColor(R.color.without)); withoutTextPaint.setTextSize(TEXT_SIZE); withoutTextPaint.setTextAlign(Align.RIGHT); textPaint.setColor(getContext().getResources().getColor(R.color.text)); textPaint.setTextSize(TEXT_SIZE); }
private void init() { circlePickedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); circleUnPickPaint = new Paint(Paint.ANTI_ALIAS_FLAG); linePickedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); linePickedPaint.setStrokeWidth(5); lineUnPickPaint = new Paint(Paint.ANTI_ALIAS_FLAG); lineUnPickPaint.setStrokeWidth(5); stepTextPaint = new Paint(); stepTextPaint.setStrokeWidth(3); stepTextPaint.setTextSize(textSize); stepTextPaint.setTextAlign(Paint.Align.LEFT); descPaint = new Paint(); descPaint.setStrokeWidth(3); descPaint.setTextSize(descSize); descPaint.setTextAlign(Paint.Align.LEFT); linePickedPaint.setColor(pickedColor); circlePickedPaint.setColor(pickedColor); circleUnPickPaint.setColor(unPickColor); lineUnPickPaint.setColor(unPickColor); stepTextPaint.setColor(stepTextColor); descPaint.setColor(descColor); }
private void init(Context context, CreditsParams p) { Paint paintPerson = new Paint(); paintPerson.setAntiAlias(true); paintPerson.setStrokeWidth(5); paintPerson.setStrokeCap(Paint.Cap.ROUND); paintPerson.setTextSize(p.getTextSizeDefault()); paintPerson.setTypeface(p.getTypefaceDefault()); paintPerson.setColor(p.getColorDefault()); paintPerson.setTextAlign(Paint.Align.CENTER); Person.setPaint(paintPerson); Person.setSpacings(p.getSpacingBeforeDefault(), p.getSpacingAfterDefault()); Paint paintCategory = new Paint(); paintCategory.setAntiAlias(true); paintCategory.setStrokeWidth(5); paintCategory.setStrokeCap(Paint.Cap.ROUND); paintCategory.setTextSize(p.getTextSizeCategory()); paintCategory.setTypeface(p.getTypefaceCategory()); paintCategory.setColor(p.getColorCategory()); paintCategory.setTextAlign(Paint.Align.CENTER); Category.setPaint(paintCategory); Category.setSpacings(p.getSpacingBeforeCategory(), p.getSpacingAfterCategory()); credits.add(new Person(context.getString(p.getAppNameRes()))); credits.add(new Category(context.getString(p.getAppVersionRes()))); loadFromResources(credits, p.getArrayCreditsRes()); mBackground = BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundRes()); mBackgroundLandscape = BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundLandscapeRes()); }
private void drawAxis(Canvas canvas) { mPaint.setAntiAlias(true); // draw y axis mPaint.setColor(yAxisColor); mPaint.setStrokeWidth(yAxisScale); canvas.drawLine(yAxisXPosition, yAxisStartYPosition, yAxisXPosition, yAxisEndYPosition, mPaint); // draw x axis mPaint.setColor(xAxisColor); mPaint.setStrokeWidth(xAxisScale); canvas.drawLine(xAxisStartXPosition, xAxisYPosition, xAxisEndXPosition, xAxisYPosition, mPaint); // draw average line int y = (int) (averageWithdrawal / maximumWithdrawal * (yAxisEndYPosition - yAxisStartYPosition)); y = yAxisEndYPosition - 1 - y; canvas.drawLine(yAxisXPosition, y, xAxisEndXPosition, y, mPaint); textPaint.setAntiAlias(true); textPaint.setTypeface(Typeface.SERIF); textPaint.setColor(Color.BLACK); // draw the second title textPaint.setTextAlign(Paint.Align.LEFT); textPaint.setTextSize(titleSecondSize); canvas.drawText(averageText, titleSecondSize, titleSecondY, textPaint); // draw the y axis valus textPaint.setTextAlign(Paint.Align.RIGHT); textPaint.setTextSize(yPaintScale); int x = yAxisXPosition - 2 * yAxisScale; y = yAxisEndYPosition; for (int i = 0, count = yValues.size(); i < count; i++) { canvas.drawText(yValues.get(i), x, y, textPaint); y -= yCellLength; } // draw the x axis values textPaint.setTextAlign(Paint.Align.LEFT); textPaint.setTextSize(xPaintScale); x = yAxisXPosition + xCellLength; for (int count = dataList.size(), i = count - 1; i >= 0; i--) { // draw the vertical line canvas.drawLine(x, yAxisStartYPosition, x, yAxisEndYPosition, mPaint); mpath.reset(); String temp = convertDateFormat(dataList.get(i).getLastUpdate()); String[] strs = temp.split(" "); mpath.moveTo(x - yPaintScale / 2, yAxisEndYPosition + 2 * yPaintScale); mpath.lineTo(x + 3 * yPaintScale, yAxisEndYPosition); canvas.drawTextOnPath(strs[0], mpath, 0, 0, textPaint); canvas.drawTextOnPath(strs[1], mpath, 0, yPaintScale, textPaint); x += xCellLength; } }
/** @param canvas */ private void drawCornerTextsAndTrack(Canvas canvas) { /* * Misc text in the information text location on the view like GPS status, * Maps status, and point destination/destination bearing, altitude, ... * Add shadows for better viewing */ mPaint.setShadowLayer(SHADOW, SHADOW, SHADOW, Color.BLACK); mPaint.setColor(Color.WHITE); mPaint.setTextAlign(Align.LEFT); /* * Speed */ canvas.drawText( "" + Math.round(mGpsParams.getSpeed()) + "kt", 0, getHeight() / mTextDiv, mPaint); /* * Altitude */ canvas.drawText( "" + Math.round(mGpsParams.getAltitude()) + "ft", 0, getHeight() - mFontHeight, mPaint); mPaint.setTextAlign(Align.RIGHT); /* * Heading */ canvas.drawText( "" + Math.round(mGpsParams.getBearing()) + '\u00B0', getWidth(), getHeight() - mFontHeight, mPaint); /* * Status/destination top right */ if (mErrorStatus != null) { mPaint.setColor(Color.RED); canvas.drawText(mErrorStatus, getWidth(), getHeight() / mTextDiv * 2, mPaint); } /* * Point above error status */ mPaint.setColor(Color.WHITE); if (mPoint != null) { canvas.drawText(mPoint, getWidth(), getHeight() / mTextDiv, mPaint); } else if (mDestination != null) { canvas.drawText(mDestination.toString(), getWidth(), getHeight() / mTextDiv, mPaint); if (mDestination.isFound() && mPref.isTrackEnabled() && (!mPref.isSimulationMode())) { if (null != mTrackShape) { mPaint.setColor(Color.MAGENTA); mPaint.setStrokeWidth(4); mTrackShape.drawShape(canvas, mOrigin, mScale, mMovement, mPaint, mFace); } } } }
public SimpleGraphView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Resources res = context.getResources(); bitmapPaint = new Paint(); bitmapPaint.setFilterBitmap(true); final Bitmap backgroundBitmap = BitmapFactory.decodeResource(res, R.drawable.test_box_small); width = backgroundBitmap.getWidth(); height = backgroundBitmap.getHeight(); genBackgroundBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(genBackgroundBitmap); // canvas.drawBitmap(backgroundBitmap, 0, 0, bitmapPaint); if (!isInEditMode()) backgroundBitmap.recycle(); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setTextSize(coordFH(15, relH)); paint.setColor(Color.parseColor("#C8ffffff")); paint.setTextAlign(Align.LEFT); canvas.drawText("0", coordFW(88, relW), coordFH(220, relH), paint); paint.setTextAlign(Align.RIGHT); canvas.drawText("8", coordFW(567, relW), coordFH(220, relH), paint); paint.setTextAlign(Align.CENTER); canvas.drawText("sec", coordFW(326, relW), coordFH(220, relH), paint); paint.setTextAlign(Align.LEFT); paint.setColor(Color.parseColor("#C800f940")); canvas.drawText( String.format("– %s", res.getString(R.string.test_mbps)), coordFW(9, relW), coordFH(110, relH), paint); paint.setTextAlign(Align.RIGHT); canvas.drawText("0", coordFW(72, relW), coordFH(220, relH), paint); canvas.drawText("100", coordFW(72, relW), coordFH(38, relH), paint); gridBitmap = BitmapFactory.decodeResource(res, R.drawable.test_grid); gridX = coordFW(55, relW); gridY = coordFH(16, relH); graphX = coordFW(80, relW); graphY = coordFH(16, relH); graphWidth = coordW(493, relW); graphHeight = coordH(183, relH); graphStrokeWidth = coordFW(4, relW); signalTextPaint = new Paint(); signalTextPaint.setAntiAlias(true); signalTextPaint.setTypeface(Typeface.DEFAULT_BOLD); signalTextPaint.setTextSize(coordFH(15, relH)); signalTextPaint.setColor(Color.parseColor("#C8f8a000")); signalText = res.getString(R.string.test_dbm); }
/** 画下面的两个按钮 */ public void drawBottomButton(Canvas canvas) { Paint paint = new Paint(); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(getResources().getDimension(R.dimen.pt_size)); paint.setAntiAlias(true); paint.setTypeface(Typeface.MONOSPACE); // paint.setARGB(255, 189, 189, 189); paint.setColor(Color.GRAY); Paint p2 = new Paint(); p2.setTextAlign(Paint.Align.CENTER); p2.setTextSize(getResources().getDimension(R.dimen.pt_size)); p2.setAntiAlias(true); p2.setTypeface(Typeface.MONOSPACE); p2.setColor(Color.BLACK); canvas.drawLine( 0, SetImagePasswordActivity.screenHeight / 10 * 8, SetImagePasswordActivity.screenWidth, SetImagePasswordActivity.screenHeight / 10 * 8, paint); canvas.drawLine( SetImagePasswordActivity.screenWidth / 2, SetImagePasswordActivity.screenHeight / 10 * 8, SetImagePasswordActivity.screenWidth / 2, SetImagePasswordActivity.screenHeight, paint); if (leftBtpress) { Log.e("tag", "drawleftBtbg"); canvas.drawRect(leftRect, paint); // canvas.drawRect(0, SetImagePasswordActivity.screenHeight-90, // SetImagePasswordActivity.screenWidth/2, SetImagePasswordActivity.screenHeight, paint); } if (rightBtpress && rightBtClikable) { Log.e("tag", "drawrightBtbg"); canvas.drawRect(rightRect, paint); } canvas.drawText( leftButtonText, SetImagePasswordActivity.screenWidth / 4, SetImagePasswordActivity.screenHeight / 10 * 9, p2); if (rightBtClikable) { canvas.drawText( rightButtonText, SetImagePasswordActivity.screenWidth / 4 * 3, SetImagePasswordActivity.screenHeight / 10 * 9, p2); } else { canvas.drawText( rightButtonText, SetImagePasswordActivity.screenWidth / 4 * 3, SetImagePasswordActivity.screenHeight / 10 * 9, paint); } }
/** * Draws this {@link TextDrawable} on the given {@link Canvas}. * * @param canvas A {@link Canvas}. */ @Override public void draw(final Canvas canvas) { if (mText != null) { final Rect bounds = getBounds(); int x = bounds.left; int y = bounds.top; mFillPaint.getTextBounds(mText, 0, mText.length(), mTextBounds); switch (mHorizontalAlignment) { case LEFT: { break; } case CENTER: { x += (bounds.width() - mTextBounds.width()) / 2; break; } case RIGHT: { x = bounds.right - mTextBounds.width(); break; } } switch (mVerticalAlignment) { case TOP: { y += mTextBounds.height(); break; } case CENTER: { y += (bounds.height() + mTextBounds.height()) / 2; break; } case BOTTOM: { y = bounds.bottom; break; } } mFillPaint.setAntiAlias(mAntialized); mFillPaint.setTextAlign(mHorizontalAlignment.getPaintAlign()); canvas.drawText(mText, x, y, mFillPaint); if (mStroked) { mStrokePaint.setAntiAlias(mAntialized); mStrokePaint.setTextAlign(mHorizontalAlignment.getPaintAlign()); canvas.drawText(mText, x, y, mStrokePaint); } } }
// Creates icons for markers public Bitmap create_marker_icon(String AcColorX, String MarkerName, float GraphicsScaleFactor) { int w = (int) (34 * GraphicsScaleFactor); // 24 int h = (int) (54 * GraphicsScaleFactor); Bitmap.Config conf = Bitmap.Config.ARGB_4444; // see other conf types Bitmap bmp = Bitmap.createBitmap( w, h, conf); // this creates a MUTABLE bitmapAircraftData[IndexOfAc].AC_Color Canvas canvas = new Canvas(bmp); Paint p = new Paint(); p.setColor(get_color(AcColorX)); p.setStyle(Paint.Style.FILL); p.setAntiAlias(true); Path MarkerPath = new Path(); MarkerPath.moveTo((w / 2), (6 * h / 16)); // point 1 MarkerPath.lineTo((7 * w / 16), (5 * h / 16)); // point 2 MarkerPath.lineTo((2 * w / 8), (5 * h / 16)); // point 3 MarkerPath.lineTo((2 * w / 8), (2)); // point 4 (2*h/8) MarkerPath.lineTo((6 * w / 8), (2)); // point 5 MarkerPath.lineTo((6 * w / 8), (5 * h / 16)); // point 6 MarkerPath.lineTo((9 * w / 16), (5 * h / 16)); // point 7 MarkerPath.close(); // border canvas.drawPath(MarkerPath, p); Paint black = new Paint(); black.setColor(Color.BLACK); black.setStyle(Paint.Style.STROKE); black.setStrokeWidth(2f); black.setAntiAlias(true); canvas.drawPath(MarkerPath, black); // Text black.setTextAlign(Paint.Align.CENTER); black.setStrokeWidth(3f * GraphicsScaleFactor); black.setTextSize(8f * GraphicsScaleFactor); // for DEBUG // canvas.drawRect(0,0,w,h,black); p.setStyle(Paint.Style.STROKE); p.setTextAlign(Paint.Align.CENTER); p.setTextSize(8f * GraphicsScaleFactor); p.setStrokeWidth(1f * GraphicsScaleFactor); canvas.drawText(MarkerName, (w / 2), (7 * h / 32), black); canvas.drawText(MarkerName, (w / 2), (7 * h / 32), p); return bmp; }
/** 初始化各项数值 */ private void init() { paintHL.setColor(Color.WHITE); paintHL.setTextSize(25); paintHL.setAntiAlias(true); // 消除锯齿 paintHL.setTextAlign(Paint.Align.CENTER); // 设置文本对齐方式 paint.setColor(Color.GRAY); paint.setTextSize(25); paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); }
protected void onDraw(Canvas canvas) { paint.setColor(Color.YELLOW); paint.setTypeface(font); paint.setTextSize(28); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("Esto seria una prueba de fuente", canvas.getWidth() / 2, 100, paint); String text = "Esto es otra prueba copada de fuente!"; paint.setColor(Color.WHITE); paint.setTextSize(18); paint.setTextAlign(Paint.Align.LEFT); paint.getTextBounds(text, 0, text.length(), bounds); canvas.drawText(text, canvas.getWidth() - bounds.width(), 140, paint); invalidate(); }
private void initPainter() { digitPaint = new Paint(); digitPaint.setAntiAlias(true); digitPaint.setTextSize(textSize); digitPaint.setColor(color); digitPaint.setTypeface(typeface); digitPaint.setTextAlign(Paint.Align.CENTER); textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setTextSize(textSize / 3); textPaint.setColor(color); textPaint.setTypeface(typeface); textPaint.setTextAlign(Paint.Align.CENTER); }
/** * @param cluster a cluster to be rendered for this marker. * @param markerIconBmps icon set for marker. * @param screenDensity screen density. */ public ClusterMarker(GeoClusterer.GeoCluster cluster, List<MarkerBitmap> markerIconBmps, float screenDensity) { this.cluster = cluster; this.markerIconBmps = markerIconBmps; center = this.cluster.getLocation(); geoItems = this.cluster.getItemsOfCluster(); this.screenDensity = screenDensity; paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setAntiAlias(true); paint.setColor(Color.rgb(220, 220, 80)); paint.setTextSize(TXTSIZE * this.screenDensity); paint.setTextAlign(Paint.Align.CENTER); paint.setTypeface(Typeface.DEFAULT_BOLD); Paint.FontMetrics metrics = paint.getFontMetrics(); txtHeightOffset = (int) ((metrics.bottom + metrics.ascent) / 2.0f); /* check if we have selected item in cluster */ selItem = 0; for (int i = 0; i < geoItems.size(); i++) { if (geoItems.get(i).isSelected()) { selItem = i; selected = true; } } setMarkerBitmap(); }
private void generateASCIIFont(AsyncTask task) { String ascii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; Paint p = new Paint(); p.setTextAlign(Align.CENTER); Typeface tf = Fonts.getTypeface(configuration.getModel()); p.setTypeface(tf); p.setTextScaleX(1.0f); p.setColor(configuration.getCharacterColorAsRGB()); p.setAntiAlias(true); setFontSize(p); int xPos = trsCharWidth / 2; int yPos = (int) ((trsCharHeight / 2) - ((p.descent() + p.ascent()) / 2)); for (int i = 0; i < ascii.length(); i++) { if (task.isCancelled()) { return; } Bitmap b = Bitmap.createBitmap(trsCharWidth, trsCharHeight, Bitmap.Config.RGB_565); Canvas c = new Canvas(b); c.drawColor(configuration.getScreenColorAsRGB()); c.drawText(ascii.substring(i, i + 1), xPos, yPos, p); font[i + 32] = b; } // Use space for all other characters for (int i = 0; i < font.length; i++) { if (font[i] == null) { font[i] = font[32]; } } }
@Override protected void onElementDraw(Canvas canvas) { // set transparent background canvas.drawColor(Color.TRANSPARENT); paint.setTextSize(getPercent(getWidth(), 30)); paint.setTextAlign(Paint.Align.CENTER); paint.setStrokeWidth(getDefaultStrokeWidth()); paint.setColor(isPressed() ? pressedColor : getDefaultColor()); paint.setStyle(Paint.Style.STROKE); canvas.drawRect( paint.getStrokeWidth(), paint.getStrokeWidth(), getWidth() - paint.getStrokeWidth(), getHeight() - paint.getStrokeWidth(), paint); if (icon != -1) { Drawable d = getResources().getDrawable(icon); d.setBounds(5, 5, getWidth() - 5, getHeight() - 5); d.draw(canvas); } else { paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeWidth(getDefaultStrokeWidth() / 2); canvas.drawText(text, getPercent(getWidth(), 50), getPercent(getHeight(), 63), paint); } }
public CircleBatteryMeterDrawable(Resources res) { super(); mDisposed = false; mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setColor(res.getColor(R.color.status_bar_clock_color)); Typeface font = Typeface.create("sans-serif-condensed", Typeface.NORMAL); mTextPaint.setTypeface(font); mTextPaint.setTextAlign(Paint.Align.CENTER); mFrontPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mFrontPaint.setStrokeCap(Paint.Cap.BUTT); mFrontPaint.setDither(true); mFrontPaint.setStrokeWidth(0); mFrontPaint.setStyle(Paint.Style.STROKE); mFrontPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP)); mBackPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBackPaint.setColor(res.getColor(R.color.batterymeter_frame_color)); mBackPaint.setStrokeCap(Paint.Cap.BUTT); mBackPaint.setDither(true); mBackPaint.setStrokeWidth(0); mBackPaint.setStyle(Paint.Style.STROKE); mBackPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR)); mBoltPaint = new Paint(); mBoltPaint.setAntiAlias(true); mBoltPaint.setColor(getColorForLevel(50)); mBoltPoints = loadBoltPoints(res); }
private void drawSections(Canvas canvas) { if (mSections == null || mSections.length == 0) return; resetPaint(); final int length = mSections.length; // 字母的宽度 final float width = getWidth() - mIndexBarSides * 2; final float height = (getHeight() - ((length + 1) * mAlphabetPadding)) / length; for (int i = 0; i < length; i++) { final float l = mIndexBarSides; final float t = (i + 1) * mAlphabetPadding + i * height; final float r = l + width; final float b = t + height; RectF targetRect = new RectF(l, t, r, b); paint.setColor(mAlphabetTextColor); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(mAlphabetTextSize); Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt(); float baseline = targetRect.top + (targetRect.bottom - targetRect.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top; canvas.drawText(mSections[i], targetRect.centerX(), baseline, paint); } }
private void init(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleTextView); mText = typedArray.getString(R.styleable.CircleTextView_Text); mTextColor = typedArray.getColor(R.styleable.CircleTextView_TextColor, Color.WHITE); mCircleColor = typedArray.getColor(R.styleable.CircleTextView_CircleColor, Color.BLACK); mTextSize = typedArray.getDimension(R.styleable.CircleTextView_TextSize, 30); boolean isRandomColor = typedArray.getBoolean(R.styleable.CircleTextView_RandomColor, true); typedArray.recycle(); mCirclePaint = new Paint(); mCirclePaint.setAntiAlias(true); if (isRandomColor) mCirclePaint.setColor(getRandomColor()); else mCirclePaint.setColor(mCircleColor); mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); mTextPaint.setColor(mTextColor); mTextPaint.setTextSize(mTextSize); mTextPaint.setTextAlign(Paint.Align.CENTER); Paint.FontMetrics fm = mTextPaint.getFontMetrics(); offY = (fm.bottom - fm.top) / 2 - fm.bottom; if (mText == null || mText.length() == 0) mText = "无"; if (mText.length() > 1) mText = mText.substring(0, 1); }
public TimeBar(Context context, Listener listener) { super(context); this.listener = Utils.checkNotNull(listener); showTimes = true; showScrubber = true; progressBar = new Rect(); playedBar = new Rect(); progressPaint = new Paint(); progressPaint.setColor(0xFF808080); playedPaint = new Paint(); playedPaint.setColor(0xFFFFFFFF); DisplayMetrics metrics = context.getResources().getDisplayMetrics(); float textSizeInPx = metrics.density * TEXT_SIZE_IN_DP; timeTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); timeTextPaint.setColor(0xFFCECECE); timeTextPaint.setTextSize(textSizeInPx); timeTextPaint.setTextAlign(Paint.Align.CENTER); timeBounds = new Rect(); timeTextPaint.getTextBounds("0:00:00", 0, 7, timeBounds); scrubber = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_knob); scrubberPadding = (int) (metrics.density * SCRUBBER_PADDING_IN_DP); vPaddingInPx = (int) (metrics.density * V_PADDING_IN_DP); }
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawColor(Color.BLACK); Paint textPaint = new Paint(); textPaint.setARGB(50, 254, 100, 45); textPaint.setTextAlign(Align.CENTER); textPaint.setTextSize(50); textPaint.setTypeface(font); canvas.drawText("Ajith is ..", canvas.getWidth() / 2, 200, textPaint); canvas.drawBitmap(star, (canvas.getWidth() / 2), y, null); if (y < canvas.getHeight()) { y += 10; } else { y = 0; } Rect middlRect = new Rect(); middlRect.set(0, 400, canvas.getWidth(), 550); Paint ourBlue = new Paint(); ourBlue.setColor(Color.BLUE); canvas.drawRect(middlRect, ourBlue); invalidate(); }
private TextDrawable(Builder builder) { super(builder.shape); // shape properties shape = builder.shape; height = builder.height; width = builder.width; radius = builder.radius; // text and color text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text; color = builder.color; // text paint settings fontSize = builder.fontSize; textPaint = new Paint(); textPaint.setColor(builder.textColor); textPaint.setAntiAlias(true); textPaint.setFakeBoldText(builder.isBold); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(builder.font); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setStrokeWidth(builder.borderThickness); // border paint settings borderThickness = builder.borderThickness; borderPaint = new Paint(); borderPaint.setColor(getDarkerShade(color)); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderThickness); // drawable paint color Paint paint = getPaint(); paint.setColor(color); }
private void initPaintTools() { mSatValPaint = new Paint(); mSatValTrackerPaint = new Paint(); mHuePaint = new Paint(); mHueTrackerPaint = new Paint(); mAlphaPaint = new Paint(); mAlphaTextPaint = new Paint(); mBorderPaint = new Paint(); mSatValTrackerPaint.setStyle(Style.STROKE); mSatValTrackerPaint.setStrokeWidth(2f * mDensity); mSatValTrackerPaint.setAntiAlias(true); mHueTrackerPaint.setColor(mSliderTrackerColor); mHueTrackerPaint.setStyle(Style.STROKE); mHueTrackerPaint.setStrokeWidth(2f * mDensity); mHueTrackerPaint.setAntiAlias(true); mAlphaTextPaint.setColor(0xff1c1c1c); mAlphaTextPaint.setTextSize(14f * mDensity); mAlphaTextPaint.setAntiAlias(true); mAlphaTextPaint.setTextAlign(Align.CENTER); mAlphaTextPaint.setFakeBoldText(true); }
public ArtifactDrawable(Context context, Kind kind, String text) { this.context = context; if (kind == Kind.IMAGE) { this.kind = Kind.OPERATION; this.text = "\u273f"; } else { this.kind = kind; this.text = text; } if (kind == Kind.MODULE || kind == Kind.OPERATION || kind == Kind.SOUND || kind == Kind.CONTINUOUS_OPERATION || kind == Kind.IMAGE) { rect = new RectF(); } if (kind == Kind.PROPERTY || kind == Kind.TUTORIAL || kind == Kind.SOUND) { path = new Path(); } if (kind == Kind.CLASSIFIER) { paint.setTypeface(Typeface.DEFAULT_BOLD); } paint.setTextAlign(Paint.Align.CENTER); paint.setAntiAlias(true); setEnabled(true); }
private void initView() { float length = 0; if (mMeasureHeigth >= mMeasureWidth) { length = mMeasureWidth; } else { length = mMeasureHeigth; } mCircleXY = length / 2; mRadius = (float) (length * 0.5 / 2); mCirclePaint = new Paint(); mCirclePaint.setAntiAlias(true); mCirclePaint.setColor(getResources().getColor(android.R.color.holo_blue_bright)); mArcRectF = new RectF( (float) (length * 0.1), (float) (length * 0.1), (float) (length * 0.9), (float) (length * 0.9)); mSweepAngle = (mSweepValue / 100f) * 360f; mArcPaint = new Paint(); mArcPaint.setAntiAlias(true); mArcPaint.setColor(getResources().getColor(android.R.color.holo_blue_bright)); mArcPaint.setStrokeWidth((float) (length * 0.1)); mArcPaint.setStyle(Paint.Style.STROKE); mShowText = setShowText(); mShowTextSize = setShowTextSize(); mTextPaint = new Paint(); mTextPaint.setTextSize(mShowTextSize); mTextPaint.setTextAlign(Paint.Align.CENTER); }
public ClockView(Context context, AttributeSet attrs) { super(context, attrs); mCalendar = Calendar.getInstance(); mPaintLine = new Paint(); mPaintLine.setColor(Color.BLUE); mPaintLine.setStrokeWidth(10); mPaintCircle = new Paint(); mPaintCircle.setColor(Color.GREEN); // 设置颜色 mPaintCircle.setStrokeWidth(10); // 设置线宽 mPaintCircle.setAntiAlias(true); // 设置是否抗锯齿 mPaintCircle.setStyle(Paint.Style.STROKE); // 设置绘制风格 mPaintText = new Paint(); mPaintText.setColor(Color.BLUE); mPaintText.setStrokeWidth(10); mPaintText.setTextAlign(Paint.Align.CENTER); mPaintText.setTextSize(40); mPaintHour = new Paint(); mPaintHour.setStrokeWidth(20); mPaintHour.setColor(Color.BLUE); mPaintMinute = new Paint(); mPaintMinute.setStrokeWidth(15); mPaintMinute.setColor(Color.BLUE); mPaintSec = new Paint(); mPaintSec.setStrokeWidth(10); mPaintSec.setColor(Color.BLUE); // handler.sendEmptyMessage(NEED_INVALIDATE);//向handler发送一个消息,让它开启重绘 }
/** * Generates bitmap used for drawing button. * * @param radius Radius of button in pixels. */ @Override void generateBitmap() { super.generateBitmap(); // Size and shape buttonShape.setShape(new OvalShape()); buttonShape.setBounds( new Rect(PADDING, PADDING, (int) radius * 2 - PADDING, (int) radius * 2 - PADDING)); // Create button bitmap and render shape buttonBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444); Canvas handleCanvas = new Canvas(buttonBitmap); buttonShape.getPaint().set(parent.fillPaint); buttonShape.draw(handleCanvas); // Set text style textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setColor(Color.BLACK); // Set size (one character has a standard design, more has dynamic size) if (label.length() == 1) textPaint.setTextSize(radius); else textPaint.setTextSize(radius / label.length() * 2.5f); // Set paint to clear text from button textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); // Render the button handleCanvas.drawText(label, radius, radius + (textPaint.getTextSize() * .33333f), textPaint); }