List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:com.yek.keyboard.keyboards.views.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick * the target candidate./* w w w.ja v a 2s . c o m*/ */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; final int height = getHeight(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2; final int count = mSuggestions.size(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final boolean typedWordValid = mTypedWordValid; int x = 0; for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; final int wordLength = suggestion.length(); paint.setColor(mColorNormal); if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); // existsAutoCompletion = true; } else if (i != 0 || (wordLength == 1 && count > 1)) { // HACK: even if i == 0, we use mColorOther when this // suggestion's length is 1 and // there are multiple suggestions, such as the default // punctuation list. paint.setColor(mColorOther); } // now that we set the typeFace, we can measure int wordWidth; if ((wordWidth = mWordWidth[i]) == 0) { float textWidth = paint.measureText(suggestion, 0, wordLength); // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2); wordWidth = (int) (textWidth + mXGap * 2); mWordWidth[i] = wordWidth; } mWordX[i] = x; if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) { if (canvas != null && !mShowingAddToDictionary) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedString = suggestion; mSelectedIndex = i; } if (canvas != null) { // (+)This is the trick to get RTL/LTR text correct if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) { final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2; canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint); } else { final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2; // no matter what: StaticLayout float textX = x + (wordWidth / 2) - mXGap; float textY = y - bgPadding.bottom - bgPadding.top; canvas.translate(textX, textY); mTextPaint.setTypeface(paint.getTypeface()); mTextPaint.setColor(paint.getColor()); StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth, Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); suggestionText.draw(canvas); canvas.translate(-textX, -textY); } // (-) paint.setColor(mColorOther); canvas.translate(x + wordWidth, 0); // Draw a divider unless it's after the hint //or the last suggested word if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) { canvas.translate(0, dividerYOffset); mDivider.draw(canvas); canvas.translate(0, -dividerYOffset); } canvas.translate(-x - wordWidth, 0); } paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) return;//from ww w. ja v a 2 s . c o m canvas.save(); if (image != null) { if (mShowOriginalDirection == 0) { if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { mShowOriginalDirection = UNVEIL_VERTICAL; } else { mShowOriginalDirection = UNVEIL_HORIZONTAL; } } int px = 0; int py = 0; if (mShowOriginalDirection == UNVEIL_VERTICAL) { px = mImageBounds.width(); py = mTouch.y - mImageBounds.top; } else { px = mTouch.x - mImageBounds.left; py = mImageBounds.height(); if (showsOriginal) { px = mImageBounds.width(); } } Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py); if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { if (mTouchDown.x - mTouch.x > 0) { d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py); } } else { if (mTouchDown.y - mTouch.y > 0) { d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom); } } canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); if (mShowOriginalDirection == UNVEIL_VERTICAL) { canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint); } else { canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint); } Rect bounds = new Rect(); paint.setAntiAlias(true); paint.setTextSize(mOriginalTextSize); paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); paint.setColor(Color.WHITE); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); }
From source file:android.support.wear.widget.drawer.PageIndicatorView.java
private void updateDotPaint(Paint dotPaint, Paint shadowPaint, float baseRadius, float shadowRadius, int color, int shadowColor) { float radius = baseRadius + shadowRadius; float shadowStart = baseRadius / radius; Shader gradient = new RadialGradient(0, 0, radius, new int[] { shadowColor, shadowColor, Color.TRANSPARENT }, new float[] { 0f, shadowStart, 1f }, TileMode.CLAMP);// www . j a va 2s. c o m shadowPaint.setShader(gradient); dotPaint.setColor(color); dotPaint.setStyle(Style.FILL); }
From source file:com.tiange.hz.wheelview.widget.WheelView.java
private void drawMask(Canvas canvas) { int center = getHeight() / 2; int offset = (int) (getItemHeight() / 2 * 1.2); /*int maskA = Color.alpha(wheelBackgroundColor); int maskR = Color.red(wheelBackgroundColor); int maskG = Color.green(wheelBackgroundColor); int maskB = Color.blue(wheelBackgroundColor);*/ int wheelUnSelectedMaskColor = Color.argb((int) (255 * wheelUnselectedMaskAlphaRate), 255, 255, 255); Paint paint = new Paint(); paint.setColor(wheelUnSelectedMaskColor); canvas.drawRect(0, 0, getWidth(), center - offset - 1, paint); canvas.drawRect(0, center + offset + 1, getWidth(), getHeight(), paint); }
From source file:com.yk.notification.util.BitmapUtil.java
/** * //from w ww . j a v a 2 s. c o m * * @param bitmap * ?Bitmap * @param roundPx * ? * @return Bitmap */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:com.mukesh.OtpView.java
private void drawHint(Canvas canvas, int i) { Paint paint = getPaintByIndex(i); paint.setColor(getCurrentHintTextColor()); if (rtlTextDirection) { int reversedPosition = otpViewItemCount - i; int reversedCharPosition = reversedPosition - getHint().length(); if (reversedCharPosition <= 0) { drawTextAtBox(canvas, paint, getHint(), Math.abs(reversedCharPosition)); }// ww w . j a v a 2s. c o m } else { drawTextAtBox(canvas, paint, getHint(), i); } }
From source file:nu.yona.app.customview.graph.TimeFrameGraph.java
/** * Chart value pre./* w ww. j a v a2s . c o m*/ * * @param mListZoneSpread the m list zone spread */ public void chartValuePre(List<TimeZoneSpread> mListZoneSpread) { position = 0; this.mListZoneSpread = mListZoneSpread; graphDataList = new ArrayList<>(); fullWidth = getWidth(); height = scaleFactor * GraphUtils.HEIGHT_BAR; //first bar left = 0; top = 0; // basically (X1, Y1) right = fullWidth; // width (distance from X1 to X2) bottom = top + height; // height (distance from Y1 to Y2) mStartPoint = 0; mMiddlePoint = (fullWidth / 2); float spreadtime = fullWidth; mPartSize = spreadtime / NO_PARTS; minValue = mPartSize / MIN_PER_PARTS; if (mListZoneSpread != null && mListZoneSpread.size() > 0) { currentStartPos = 0; currentEndPos = 0; for (int i = 0; i < (mListZoneSpread.size() - 1); i++) { Paint mZonePaint = new Paint(); mZonePaint.setStrokeWidth(1); if (currentStartPos == 0) { currentStartPos = mListZoneSpread.get(i).getIndex() * mPartSize; } else { if (mListZoneSpread.get(i).getIndex() == mListZoneSpread.get(i - 1).getIndex()) { currentStartPos = (mListZoneSpread.get(i).getIndex() * mPartSize) + (minValue * mListZoneSpread.get(i - 1).getUsedValue()); } else { currentStartPos = mListZoneSpread.get(i).getIndex() * mPartSize; } } currentEndPos = (minValue * mListZoneSpread.get(i).getUsedValue()) + currentStartPos; mZonePaint.setColor(mListZoneSpread.get(i).getColor()); GraphData newGraphData = new GraphData(currentStartPos, currentEndPos, mZonePaint); /*graphDataList.add(newGraphData);*/ udpateGraphData(newGraphData, i); startAnimation(); } } }
From source file:com.mukesh.OtpView.java
private void drawText(Canvas canvas, int i) { Paint paint = getPaintByIndex(i); paint.setColor(getCurrentTextColor()); if (rtlTextDirection) { int reversedPosition = otpViewItemCount - i; int reversedCharPosition; if (getText() == null) { reversedCharPosition = reversedPosition; } else {// ww w. j a va 2 s. c o m reversedCharPosition = reversedPosition - getText().length(); } if (reversedCharPosition <= 0 && getText() != null) { drawTextAtBox(canvas, paint, getText(), Math.abs(reversedCharPosition)); } } else if (getText() != null) { drawTextAtBox(canvas, paint, getText(), i); } }
From source file:com.tiange.hz.wheelview.widget.WheelView.java
/** * Draws rect for current value// w w w.j av a 2s. c om * @param canvas the canvas for drawing */ private void drawCenterRect(Canvas canvas) { int center = getHeight() / 2; int offset = (int) (getItemHeight() / 2 * 1.2); if (centerDrawable != null) { centerDrawable.setBounds(0, center - offset, getWidth(), center + offset); centerDrawable.draw(canvas); } //dip2px if (wheelForegroundColor != Color.TRANSPARENT) { Paint paint = new Paint(); paint.setColor(wheelForegroundColor); paint.setStyle(Paint.Style.FILL); canvas.drawRect(new Rect(0, center - offset, getWidth(), center + offset), paint); } if (wheelForeDividerColor != Color.TRANSPARENT) { //wheelForeDividerWidth== Paint paint = new Paint(); paint.setColor(wheelForeDividerColor); canvas.drawLine(0, center - offset, getWidth(), center - offset, paint); canvas.drawLine(0, center + offset, getWidth(), center + offset, paint); } }
From source file:com.example.angel.parkpanda.MainActivity.java
public Bitmap drawTextToBitmap(int gResId, String gText) { Resources resources = getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*ww w . ja v a 2 s . com*/ bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.rgb(0, 0, 0)); paint.setTextSize((int) (15 * scale)); paint.setShadowLayer(1f, 0f, 1f, Color.BLACK); Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2 - 10; canvas.drawText(gText, x, y, paint); return bitmap; }