List of usage examples for android.graphics Canvas getHeight
public int getHeight()
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:com.forrestguice.suntimeswidget.LightMapView.java
private void drawPoint(Calendar calendar, int radius, Canvas c, Paint p) { if (calendar != null) { int w = c.getWidth(); int h = c.getHeight(); double minute = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); int x = (int) Math.round((minute / MINUTES_IN_DAY) * w); int y = h / 2; p.setStyle(Paint.Style.FILL); p.setColor(colorPointFill);//from w ww. j av a2 s . c o m c.drawCircle(x, y, radius, p); p.setStyle(Paint.Style.STROKE); p.setStrokeWidth(pointStrokeWidth); p.setColor(colorPointStroke); c.drawCircle(x, y, radius, p); } }
From source file:com.hirebuddy.util.CircleImageView.java
private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; }//from w w w . ja v a 2 s. c o m if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:me.drozdzynski.library.steppers.RoundedView.java
private void drawChecked(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_check); if (bitmap != null) { float posX = (canvas.getWidth() - bitmap.getWidth()) / 2; float posY = (canvas.getHeight() - bitmap.getHeight()) / 2; canvas.drawBitmap(bitmap, posX, posY, paint); }/*from w w w . j av a 2s . c o m*/ }
From source file:com.metinkale.prayerapp.vakit.PrefsView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); canvas.scale(0.8f, 0.8f, canvas.getWidth() / 2, canvas.getHeight() / 2); Object o = getValue();//from w w w .jav a2 s.co m boolean active = ((o instanceof Boolean) && o.equals(true)) || ((o instanceof Integer) && !o.equals(0)) || ((o instanceof String) && !((String) o).startsWith("silent")); if (mPref == Pref.Vibration2) { active = !o.equals(-1); } mPaint.setColor(active ? 0xff03A9F4 : 0xffe0e0e0); int w = getHeight(); canvas.drawCircle(w / 2, w / 2, w / 2, mPaint); int p = w / 7; mDrawable.setBounds(p, p, w - p, w - p); mDrawable.setColorFilter(active ? sCFActive : sCFInactive); mDrawable.draw(canvas); if ((mPref == Pref.Time) || (mPref == Pref.SabahTime) || (mPref == Pref.Silenter)) { int s = (Integer) getValue(); if (s != 0) { mPaint.setColor(getResources().getColor(R.color.colorPrimaryDark)); canvas.drawCircle(getWidth() * 0.78f, getHeight() * 0.78f, getWidth() / 4, mPaint); mPaint.setColor(Color.WHITE); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 5); mPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(s + "", w * 0.78f, w * 0.87f, mPaint); } } else if (mPref == Pref.Vibration2) { int s = (Integer) getValue(); String txt = ""; if (s == 0) { txt = "8"; } else if (s == 1) { txt = "1"; } mPaint.setColor(Color.BLACK); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(w / 2); mPaint.setTypeface(Typeface.DEFAULT_BOLD); if (s == 0) { canvas.rotate(90, canvas.getWidth() / 2, canvas.getHeight() / 2); canvas.drawText(txt, w / 2, (w * 2) / 3, mPaint); canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2); } else { canvas.drawText(txt, w / 2, w * 2 / 3, mPaint); } } }
From source file:pl.openrnd.multilevellistview.sample.views.LevelBeamView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (int lvl = 0; lvl <= mLevel; lvl++) { float LINE_X = mPadding + lvl * mLinesWidth; if (lvl >= 1) { LINE_X += lvl * mLinesOffset; }/* w w w . j a va 2s. c om*/ mLinePaint.setColor(getColor(getColorResIdForLevel(lvl))); canvas.drawLine(LINE_X, 0, LINE_X, canvas.getHeight(), mLinePaint); } }
From source file:ru.jango.j0widget.imagebrowser.ImageBrowserView.java
private Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) return ((BitmapDrawable) drawable).getBitmap(); int width = drawable.getIntrinsicWidth(); width = width > 0 ? width : 1;// ww w.j a v a 2 s.com int height = drawable.getIntrinsicHeight(); height = height > 0 ? height : 1; final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java
public void onDraw(Canvas canvas) { if (points.size() == 0) { return;// ww w. j av a2s . com } 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:com.abhinavjhanwar.android.egg.neko.Cat.java
@Override public void draw(@NonNull Canvas canvas) { final int hw = Math.min(canvas.getWidth(), canvas.getHeight()); if (mBitmap == null || mBitmap.getWidth() != hw || mBitmap.getHeight() != hw) { mBitmap = Bitmap.createBitmap(hw, hw, Bitmap.Config.ARGB_8888); final Canvas bitCanvas = new Canvas(mBitmap); slowDraw(bitCanvas, 0, 0, hw, hw); }/*from w ww . java2 s . c o m*/ canvas.drawBitmap(mBitmap, 0, 0, null); }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.widget.PercentageMeterView.java
@Override public void onDraw(@NonNull Canvas canvas) { if (Float.isNaN(percentage)) { return;/*from w w w .j a va 2 s . c om*/ } double number = (100 - percentage) * NUMBER_OF_BARS * PERCENT; canvas.save(); // Set each dot's diameter to half the canvas height canvas.translate( canvas.getWidth() / 2f - ((canvas.getHeight() / 2f + GUTTER_SPACE) * ((NUMBER_OF_BARS - 1) / 2f)), 0); for (double i = 0; i < NUMBER_OF_BARS; i++) { // Reset color paint.setColor(Color.LTGRAY); if (number >= 0) { if (i < 2) { // Red if number is lower than i + 1 // 2 red dots if number < 1 or 1 red dot if number > 1 if (number <= i + 1) { paint.setColor(red); } } else if (i < 4) { // Orange if number between 1 and 4 // if number == 1.5 then 1 red followed by orange dot // if number == 2.5 then 2 orange dots // if number == 3.5 then 1 orange dot if (number >= i - 1 && number <= i + 2) { paint.setColor(orange); } } else { if (number > i) { // Green if number larger than 3 but yellow if number exceeds optimum if (number > NUMBER_OF_BARS) { paint.setColor(Color.YELLOW); } else { paint.setColor(green); } } } } canvas.drawCircle(0, canvas.getHeight() / 2f, canvas.getHeight() / 4f, paint); // Position next circle canvas.translate(canvas.getHeight() / 2f + GUTTER_SPACE, 0); } canvas.restore(); super.onDraw(canvas); }