List of usage examples for android.graphics Canvas getWidth
public int getWidth()
From source file:com.github.kubatatami.RoundedView.java
private void drawChecked(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_check); float posX = (canvas.getWidth() - bitmap.getWidth()) / 2; float posY = (canvas.getHeight() - bitmap.getHeight()) / 2; canvas.drawBitmap(bitmap, posX, posY, paint); }
From source file:com.github.kubatatami.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE);/*w w w .ja v a2s. c om*/ canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();//from w w w . j av a 2 s . c om canvas.translate(0f, imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.forrestguice.suntimeswidget.LightMapView.java
private void drawRect(Canvas c, Paint p) { int w = c.getWidth(); int h = c.getHeight(); c.drawRect(0, 0, w, h, p);//from www. j a v a2 s . c om }
From source file:ggikko.me.steppertest.stepper.RoundedView.java
private void drawChecked(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_check); float posX = (canvas.getWidth() - bitmap.getWidth()) / 2; float posY = (canvas.getHeight() - bitmap.getHeight()) / 2; canvas.drawBitmap(bitmap, posX, posY, paint); }
From source file:nu.yona.app.customview.graph.SpreadGraph.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); this.mCanvas = canvas; float fullWidth = canvas.getWidth(); float heightOfbar = GraphUtils.convertSizeToDeviceDependent(mContext, graphHeight); //first bar/* w w w .j a v a 2s. c o m*/ float mXStart = 0, mYStart = heightOfbar; // basically (X1, Y1) float bottom = heightOfbar; // height (distance from Y1 to Y2) mStartPoint = 0; mMiddlePoint = (fullWidth / 2); float spreadtime = fullWidth; float mPartSize = spreadtime / mNoParts; //todraw text from height float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor); //draw graphics of sun and moon Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)); float bitmapWidth = moonBitmap.getWidth() / 2; mCanvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)), mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null); float textPoint = (mMiddlePoint / 2) / 2; mCanvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw + scaleFactor, getFontStyle()); float textPoint2 = textPoint * 2 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw + scaleFactor, getFontStyle()); float textPoint3 = textPoint * 5; mCanvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint4 = textPoint * 6 + ((textPoint / 2)); mCanvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth, heightDraw + scaleFactor, getFontStyle()); float textPoint5 = textPoint * 7 + ((textPoint / 2)); mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5, bottom + (5 * scaleFactor), null); if (mListZoneSpread != null && mListZoneSpread.size() > 0) { float currentStartPos; float currentEndPos; Paint barGraphPaint = new Paint(); barGraphPaint.setStyle(Paint.Style.STROKE); barGraphPaint.setStrokeWidth(5); boolean skipThis; for (TimeZoneSpread timeZoneSpread : mListZoneSpread) { skipThis = false; currentStartPos = (float) timeZoneSpread.getIndex() * mPartSize; Path barPath = new Path(); if (timeZoneSpread.getColor() == GraphUtils.COLOR_PINK || timeZoneSpread.getColor() == GraphUtils.COLOR_BLUE) { currentEndPos = timeZoneSpread.getUsedValue(); barGraphPaint.setColor(timeZoneSpread.getColor()); } else if (timeZoneSpread.getColor() == GraphUtils.COLOR_GREEN) { if (timeZoneSpread.getUsedValue() == 15) { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BULLET_DOT); } else { currentEndPos = startEndPoint; barGraphPaint.setColor(GraphUtils.COLOR_BLUE); } } else if (timeZoneSpread.getUsedValue() != 15 && timeZoneSpread.getColor() == GraphUtils.COLOR_BULLET_LIGHT_DOT) { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); skipThis = true; } else { currentEndPos = startEndPoint; barGraphPaint.setColor(timeZoneSpread.getColor()); } if (!skipThis) { float newXPos = mXStart + currentStartPos; barPath.moveTo(newXPos + 2, mYStart); float noPartsHeight = heightOfbar / 15; barPath.lineTo(currentStartPos + 2, mYStart - (currentEndPos * noPartsHeight) - 1); canvas.drawPath(barPath, barGraphPaint); } } } }
From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Fragment rawFragment = getTargetFragment(); if (!(rawFragment instanceof DialogPreference.TargetFragment)) { throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface"); }//from www. j av a 2 s . co m final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment; final String key = getArguments().getString(ARG_KEY); if (savedInstanceState == null) { mPreference = (DialogPreference) fragment.findPreference(key); mDialogTitle = mPreference.getDialogTitle(); mPositiveButtonText = mPreference.getPositiveButtonText(); mNegativeButtonText = mPreference.getNegativeButtonText(); mDialogMessage = mPreference.getDialogMessage(); mDialogLayoutRes = mPreference.getDialogLayoutResource(); final Drawable icon = mPreference.getDialogIcon(); if (icon == null || icon instanceof BitmapDrawable) { mDialogIcon = (BitmapDrawable) icon; } else { final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.draw(canvas); mDialogIcon = new BitmapDrawable(getResources(), bitmap); } } else { mDialogTitle = savedInstanceState.getCharSequence(SAVE_STATE_TITLE); mPositiveButtonText = savedInstanceState.getCharSequence(SAVE_STATE_POSITIVE_TEXT); mNegativeButtonText = savedInstanceState.getCharSequence(SAVE_STATE_NEGATIVE_TEXT); mDialogMessage = savedInstanceState.getCharSequence(SAVE_STATE_MESSAGE); mDialogLayoutRes = savedInstanceState.getInt(SAVE_STATE_LAYOUT, 0); final Bitmap bitmap = savedInstanceState.getParcelable(SAVE_STATE_ICON); if (bitmap != null) { mDialogIcon = new BitmapDrawable(getResources(), bitmap); } } }
From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java
private void rotateArrow() { final Drawable drawable = mHeaderArrow.getDrawable(); final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);/*w ww . j a v a2s.c o m*/ final Canvas canvas = new Canvas(bitmap); canvas.save(); canvas.rotate(180.0f, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); canvas.restore(); mHeaderArrow.setImageBitmap(bitmap); }
From source file:ggikko.me.steppertest.stepper.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE);/*from ww w.jav a 2 s . c o m*/ canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:net.yanzm.actionbarprogress.MaterialIndeterminateProgressDrawable.java
@Override public void draw(Canvas canvas) { final int level = getLevel(); final float input = level / 10000f; canvas.drawColor(trackColor);// w w w. ja v a 2 s . c o m canvas.save(); canvas.translate(canvas.getWidth() / 2f, 0); canvas.scale(canvas.getWidth() / 360f, 1); paint.setColor(accentColor); { final int saveCount = canvas.save(); float translateX2 = translateInterpolator2.getInterpolation(input); canvas.translate(-197.60001f + translateX2 * 620.20002f, 0); float x = scaleInterpolator2.getInterpolation(input); float scaleX = 1.6199005127f * -Math.abs(x - 0.5f) + 0.909950256348f; rect2.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight()); canvas.drawRect(rect2, paint); canvas.restoreToCount(saveCount); } { final int saveCount = canvas.save(); float translateX1 = translateInterpolator1.getInterpolation(input); canvas.translate(-522.59998f + translateX1 * 722.19999f, 0); float x = scaleInterpolator1.getInterpolation(input); float scaleX = 1.45369842529f * -Math.abs(x - 0.5f) + 0.826849212646f; rect1.set(-144f * scaleX, 0, 144f * scaleX, canvas.getHeight()); canvas.drawRect(rect1, paint); canvas.restoreToCount(saveCount); } canvas.restore(); }