List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
public void drawShape(Canvas canvas) { canvas.drawPath(shapePath, shapePathPaint); if (DEBUG) {//from w ww .ja va 2s .c o m canvas.drawPath(boundsPath, boundsPathPaint); canvas.drawCircle(medX, medY, 5, gradientHelperPaint); } }
From source file:org.telegram.ui.Cells.FeaturedStickerSetCell.java
public void setStickersSet(TLRPC.StickerSetCovered set, boolean divider, boolean unread) { boolean sameSet = set == stickersSet && wasLayout; needDivider = divider;// w w w.j a v a 2s .c o m stickersSet = set; lastUpdateTime = System.currentTimeMillis(); setWillNotDraw(!needDivider); if (currentAnimation != null) { currentAnimation.cancel(); currentAnimation = null; } textView.setText(stickersSet.set.title); if (unread) { Drawable drawable = new Drawable() { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); @Override public void draw(Canvas canvas) { paint.setColor(0xff44a8ea); canvas.drawCircle(AndroidUtilities.dp(4), AndroidUtilities.dp(5), AndroidUtilities.dp(3), paint); } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter colorFilter) { } @Override public int getOpacity() { return 0; } @Override public int getIntrinsicWidth() { return AndroidUtilities.dp(12); } @Override public int getIntrinsicHeight() { return AndroidUtilities.dp(8); } }; textView.setCompoundDrawablesWithIntrinsicBounds(LocaleController.isRTL ? null : drawable, null, LocaleController.isRTL ? drawable : null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } valueTextView.setText(LocaleController.formatPluralString("Stickers", set.set.count)); if (set.cover != null && set.cover.thumb != null && set.cover.thumb.location != null) { imageView.setImage(set.cover.thumb.location, null, "webp", null); } else if (!set.covers.isEmpty()) { imageView.setImage(set.covers.get(0).thumb.location, null, "webp", null); } if (sameSet) { boolean wasInstalled = isInstalled; if (isInstalled = StickersQuery.isStickerPackInstalled(set.set.id)) { if (!wasInstalled) { checkImage.setVisibility(VISIBLE); addButton.setClickable(false); currentAnimation = new AnimatorSet(); currentAnimation.setDuration(200); currentAnimation.playTogether(ObjectAnimator.ofFloat(addButton, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(addButton, "scaleX", 1.0f, 0.01f), ObjectAnimator.ofFloat(addButton, "scaleY", 1.0f, 0.01f), ObjectAnimator.ofFloat(checkImage, "alpha", 0.0f, 1.0f), ObjectAnimator.ofFloat(checkImage, "scaleX", 0.01f, 1.0f), ObjectAnimator.ofFloat(checkImage, "scaleY", 0.01f, 1.0f)); currentAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { if (currentAnimation != null && currentAnimation.equals(animator)) { addButton.setVisibility(INVISIBLE); } } @Override public void onAnimationCancel(Animator animator) { if (currentAnimation != null && currentAnimation.equals(animator)) { currentAnimation = null; } } }); currentAnimation.start(); } } else { if (wasInstalled) { addButton.setVisibility(VISIBLE); addButton.setClickable(true); currentAnimation = new AnimatorSet(); currentAnimation.setDuration(200); currentAnimation.playTogether(ObjectAnimator.ofFloat(checkImage, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(checkImage, "scaleX", 1.0f, 0.01f), ObjectAnimator.ofFloat(checkImage, "scaleY", 1.0f, 0.01f), ObjectAnimator.ofFloat(addButton, "alpha", 0.0f, 1.0f), ObjectAnimator.ofFloat(addButton, "scaleX", 0.01f, 1.0f), ObjectAnimator.ofFloat(addButton, "scaleY", 0.01f, 1.0f)); currentAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { if (currentAnimation != null && currentAnimation.equals(animator)) { checkImage.setVisibility(INVISIBLE); } } @Override public void onAnimationCancel(Animator animator) { if (currentAnimation != null && currentAnimation.equals(animator)) { currentAnimation = null; } } }); currentAnimation.start(); } } } else { if (isInstalled = StickersQuery.isStickerPackInstalled(set.set.id)) { addButton.setVisibility(INVISIBLE); addButton.setClickable(false); checkImage.setVisibility(VISIBLE); checkImage.setScaleX(1.0f); checkImage.setScaleY(1.0f); checkImage.setAlpha(1.0f); } else { addButton.setVisibility(VISIBLE); addButton.setClickable(true); checkImage.setVisibility(INVISIBLE); addButton.setScaleX(1.0f); addButton.setScaleY(1.0f); addButton.setAlpha(1.0f); } } }
From source file:android.support.v17.leanback.widget.SeekBar.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int radius = isFocused() ? mActiveRadius : mBarHeight / 2; canvas.drawRoundRect(mBackgroundRect, radius, radius, mBackgroundPaint); canvas.drawRoundRect(mSecondProgressRect, radius, radius, mProgressPaint); canvas.drawRoundRect(mProgressRect, radius, radius, mProgressPaint); canvas.drawCircle(mKnobx, getHeight() / 2, radius, mKnobPaint); }
From source file:com.cuelogic.android.WheelIndicatorView.java
private void drawOnlyArc(WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle, float repeatAngle, Canvas canvas) { itemArcPaint.setColor(Color.parseColor("#FF9000")); itemEndPointsPaint.setColor(Color.parseColor("#FF9000")); // Draw arc// w w w. j a v a 2s. co m canvas.drawArc(surfaceRectF, ANGLE_INIT_OFFSET, angle, false, itemArcPaint); // // Draw top circle canvas.drawCircle(minDistViewSize / 2, 0 + itemsLineWidth, itemsLineWidth, itemEndPointsPaint); int topPosition = minDistViewSize / 2 - itemsLineWidth; // Draw end circle canvas.drawCircle( (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition + itemsLineWidth), (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition + itemsLineWidth), itemsLineWidth, itemEndPointsPaint); // draw(indicatorItem, wheelBoundsRectF, repeatAngle, canvas); }
From source file:org.telegram.ui.Components.AvatarDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds();//from w w w . j a va 2 s. c o m if (bounds == null) { return; } int size = bounds.width(); paint.setColor(color); canvas.save(); canvas.translate(bounds.left, bounds.top); canvas.drawCircle(size / 2, size / 2, size / 2, paint); if (drawBrodcast && broadcastDrawable != null) { int x = (size - broadcastDrawable.getIntrinsicWidth()) / 2; int y = (size - broadcastDrawable.getIntrinsicHeight()) / 2; broadcastDrawable.setBounds(x, y, x + broadcastDrawable.getIntrinsicWidth(), y + broadcastDrawable.getIntrinsicHeight()); broadcastDrawable.draw(canvas); } else { if (textLayout != null) { canvas.translate((size - textWidth) / 2 - textLeft, (size - textHeight) / 2); textLayout.draw(canvas); } else if (drawPhoto && photoDrawable != null) { int x = (size - photoDrawable.getIntrinsicWidth()) / 2; int y = (size - photoDrawable.getIntrinsicHeight()) / 2; photoDrawable.setBounds(x, y, x + photoDrawable.getIntrinsicWidth(), y + photoDrawable.getIntrinsicHeight()); photoDrawable.draw(canvas); } } canvas.restore(); }
From source file:nuclei.ui.view.GlideImageView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mBorderRect != null && mBorderPaint != null) { if (mRadius > 0) canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mBorderPaint); else if (mCircle) canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRect.width() / 2, mBorderPaint);// ww w . j a v a 2 s. com else canvas.drawRect(mBorderRect, mBorderPaint); } }
From source file:org.stockchart.core.LegendItem.java
private void drawMarker(Canvas c, float x, float y, float r) { switch (fMarkerStyle) { case SQUARE:/*from w ww . j ava2 s. co m*/ this.TempRectF().set(x - r, y - r, x + r, y + r); getAppearance().applyFill(this.Paint(), this.TempRectF()); c.drawRect(this.TempRectF(), this.Paint()); getAppearance().applyOutline(this.Paint()); c.drawRect(this.TempRectF(), this.Paint()); break; case CIRCLE: getAppearance().applyFill(this.Paint(), this.TempRectF()); c.drawCircle(x, y, r, this.Paint()); getAppearance().applyOutline(this.Paint()); c.drawCircle(x, y, r, this.Paint()); break; } }
From source file:com.google.android.gms.samples.vision.face.facetracker.FaceGraphic.java
/** * Draws the face annotations for position on the supplied canvas. *//*www. ja v a 2 s .co m*/ @Override public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float x = translateX(face.getPosition().x + face.getWidth() / 2); float y = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint); canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint); canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint); canvas.drawText("left eye: " + String.format("%.2f", face.getIsLeftEyeOpenProbability()), x - ID_X_OFFSET * 2, y - ID_Y_OFFSET * 2, mIdPaint); try { Thread.sleep(1000); } catch (Exception e) { System.out.println("SLEEP EXCEPTION: " + e.getMessage()); } String happiness = String.format("%.2f", face.getIsSmilingProbability()); new RetrieveFeedTask().execute(happiness); // Draws a bounding box around the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = x - xOffset; float top = y - yOffset; float right = x + xOffset; float bottom = y + yOffset; canvas.drawRect(left, top, right, bottom, mBoxPaint); }
From source file:potboiler.client.PotsActivity.java
License:asdf
private void createDrawerMenu() { mMenuItems = getResources().getStringArray(R.array.menu_sections); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (LinearLayout) findViewById(R.id.left_drawer); mCommandsList = (ListView) findViewById(R.id.commands); User user = PreferenceUtils.getUser(this); ((TextView) findViewById(R.id.name)).setText(user.username); Bitmap bitmap = ImageUtils.getImageFromFile(this, FileUtils.getImagesPath(this) + user.serverId); if (bitmap != null) { /*Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); /*from w w w. j a v a 2s . com*/ BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);*/ int w = bitmap.getWidth(); int h = bitmap.getHeight(); int radius = Math.min(h / 2, w / 2); Bitmap circleBitmap = Bitmap.createBitmap(w + 8, h + 8, Bitmap.Config.ARGB_8888); Paint paint = new Paint(); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawARGB(0, 0, 0, 0); paint.setStyle(Paint.Style.FILL); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); c.drawBitmap(bitmap, 4, 4, paint); paint.setXfermode(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.WHITE); paint.setStrokeWidth(3); c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, paint); ((ImageView) findViewById(R.id.avatar)).setImageBitmap(circleBitmap); } mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent)); DrawerAdapter adapter = new DrawerAdapter(this, R.layout.item_drawer_list, R.id.title, mMenuItems); mCommandsList.setAdapter(adapter); mCommandsList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.pots, R.string.pots) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); syncActionBarArrowState(); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } public void onDrawerOpened(View drawerView) { // super.onDrawerClosed(drawerView); super.onDrawerOpened(drawerView); mDrawerToggle.setDrawerIndicatorEnabled(true); // invalidateOptionsMenu(); // mDrawerToggle.syncState(); // setRefreshMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); float xPositionOpenDrawer = mCommandsList.getWidth(); float xPositionWindowContent = (slideOffset * xPositionOpenDrawer); FrameLayout mHostFragment = (FrameLayout) findViewById(R.id.content_frame); mHostFragment.setX(xPositionWindowContent); getActionBarView().setX(xPositionWindowContent); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); getSupportFragmentManager().addOnBackStackChangedListener(mOnBackStackChangedListener); findViewById(R.id.signout).setOnClickListener(this); }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int center = getWidth() / 2; int radius = center - 8; // Draw the rings final Paint gridPaint = mGridPaint; canvas.drawCircle(center, center, radius, gridPaint); canvas.drawCircle(center, center, radius * 3 / 4, gridPaint); canvas.drawCircle(center, center, radius >> 1, gridPaint); canvas.drawCircle(center, center, radius >> 2, gridPaint); int blipRadius = (int) (mDistanceRatio * radius); final long now = SystemClock.uptimeMillis(); if (mSweepTime > 0) { // Draw the sweep. Radius is determined by how long ago it started long sweepDifference = now - mSweepTime; if (sweepDifference < 512L) { int sweepRadius = (int) (((radius + 6) * sweepDifference) >> 9); canvas.drawCircle(center, center, sweepRadius, mSweepPaint0); canvas.drawCircle(center, center, sweepRadius - 2, mSweepPaint1); canvas.drawCircle(center, center, sweepRadius - 4, mSweepPaint2); // Note when the sweep has passed the blip boolean before = sweepRadius < blipRadius; if (!before && mSweepBefore) { mSweepBefore = false;//from ww w .ja v a 2 s . c om mBlipTime = now; } } else { mSweepTime = now + 1000; mSweepBefore = true; } postInvalidate(); } // Draw horizontal and vertical lines canvas.drawLine(center, center - (radius >> 2) + 6, center, center - radius - 6, gridPaint); canvas.drawLine(center, center + (radius >> 2) - 6, center, center + radius + 6, gridPaint); canvas.drawLine(center - (radius >> 2) + 6, center, center - radius - 6, center, gridPaint); canvas.drawLine(center + (radius >> 2) - 6, center, center + radius + 6, center, gridPaint); // Draw X in the center of the screen canvas.drawLine(center - 4, center - 4, center + 4, center + 4, gridPaint); canvas.drawLine(center - 4, center + 4, center + 4, center - 4, gridPaint); if (mHaveDetected) { // Draw the blip. Alpha is based on how long ago the sweep crossed the blip long blipDifference = now - mBlipTime; gridPaint.setAlpha(255 - (int) ((128 * blipDifference) >> 10)); double bearingToTarget = mLast_bearing; double drawingAngle = Math.toRadians(bearingToTarget) - (Math.PI / 2); float cos = (float) Math.cos(drawingAngle); float sin = (float) Math.sin(drawingAngle); addText(canvas, getRatioDistanceText(0.25f), center, center + (radius >> 2)); addText(canvas, getRatioDistanceText(0.5f), center, center + (radius >> 1)); addText(canvas, getRatioDistanceText(0.75f), center, center + radius * 3 / 4); addText(canvas, getRatioDistanceText(1.0f), center, center + radius); for (Map.Entry<String, DetectedBeacon> entry : mBeacons.entrySet()) { //String key = entry.getKey(); DetectedBeacon dBeacon = entry.getValue(); System.out.println("value: " + dBeacon); // drawing the beacon if (((System.currentTimeMillis() - dBeacon.getTimeLastSeen()) / 1000 < 5)) { canvas.drawBitmap(mBlip, center + (cos * distanceToPix(dBeacon.getDistance())) - 8, center + (sin * distanceToPix(dBeacon.getDistance())) - 8, gridPaint); } } gridPaint.setAlpha(255); } }