List of usage examples for android.graphics Canvas getWidth
public int getWidth()
From source file:com.huahcoding.metrojam.BackTrackActivity.java
/** * This is where we can add markers or lines, add listeners or move the camera. In this case, we * just add a marker near Africa./*from www . j av a 2 s .c o m*/ * <p> * This should only be called once and when we are sure that {@link #mMap} is not null. */ private void setUpMap() { mMap.getUiSettings().setZoomControlsEnabled(false); // Show Lima mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chileLatLng, 15)); mMap.setOnMapLongClickListener(this); mMap.setMyLocationEnabled(true); mMap.setTrafficEnabled(true); // Instantiates a new Polyline object and adds points to define a rectangle PolylineOptions rectOptions = new PolylineOptions(); double[] route = RouteTestData.getChilePoints3(); for (int i = 0; i < route.length - 1; i += 2) { LatLng ll = new LatLng(route[i], route[i + 1]); if (i > 1) { double lat = (route[i] + route[i - 2]) / 2.0; double lng = (route[i + 1] + route[i + 1 - 2]) / 2.0; double dist = distance(route[i], route[i + 1], route[i - 2], route[i + 1 - 2]); String pretty = getPrettyDistance(dist); LatLng ll2 = new LatLng(lat, lng); String strText = pretty; Rect boundsText = new Rect(); Paint textPaint = new Paint(); textPaint.setTextSize(18); textPaint.getTextBounds(strText, 0, strText.length(), boundsText); textPaint.setColor(Color.RED); Bitmap.Config conf = Bitmap.Config.ARGB_8888; Bitmap bmpText = Bitmap.createBitmap(boundsText.width() * 3, boundsText.height(), conf); Canvas canvasText = new Canvas(bmpText); canvasText.drawText(strText, canvasText.getWidth() / 2, canvasText.getHeight(), textPaint); MarkerOptions markerOptions = new MarkerOptions().position(ll2) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1); mMap.addMarker(markerOptions); } rectOptions.add(ll); } // rectOptions. // Get back the mutable Polyline mMap.addPolyline(rectOptions); }
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 www.ja va 2 s . c o m }
From source file:org.chromium.chrome.browser.widget.MaterialProgressBar.java
private void drawRect(Canvas canvas, Paint paint, float start, float end) { if (ViewCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL) { int width = canvas.getWidth(); float rtlStart = width - end; float rtlEnd = width - start; canvas.drawRect(rtlStart, 0, rtlEnd, canvas.getHeight(), paint); } else {//from www.j a v a2 s . c o m canvas.drawRect(start, 0, end, canvas.getHeight(), paint); } }
From source file:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();/* w w w. ja v a2s . c om*/ canvas.translate(0f, imageOffset); Log.i("imageOffset", "onDraw: " + 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 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 w w .ja v 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 ww .java2s. c om*/ 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: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 ww w . j a v a 2 s .c o 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: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 . java 2 s . c om 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:com.nextgis.maplibui.formcontrol.Sign.java
@Override protected void onDraw(Canvas canvas) { if (mNotInitialized && mPreviousSignBitmap != null) canvas.drawBitmap(mPreviousSignBitmap, 0, 0, null); int posX = canvas.getWidth() - mClearImageSize - mClearBuff; mCleanImage.setBounds(posX, mClearBuff, posX + mClearImageSize, mClearImageSize + mClearBuff); mCleanImage.draw(canvas);/*from w w w . jav a 2 s . c o m*/ if (!mNotInitialized) for (Path path : mPaths) canvas.drawPath(path, mPaint); }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.widget.PercentageMeterView.java
@Override public void onDraw(@NonNull Canvas canvas) { if (Float.isNaN(percentage)) { return;//w ww . java 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); }