List of usage examples for android.graphics Rect exactCenterX
public final float exactCenterX()
From source file:Main.java
/** * Create round, coloured bitmap with text embedded. * @param circleColor The color to use.//from w ww. j a v a2 s. c om * @param diameterDP The diameter of the circle. * @param text The text to embed. * @return Bitmap showing a text. */ public static Bitmap generateCircleBitmap(int circleColor, float diameterDP, String text) { /** * * http://stackoverflow.com/questions/31168636/rounded-quickcontactbadge-with-text */ final int textColor = 0xffffffff; DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); float diameterPixels = diameterDP * (metrics.densityDpi / 160f); float radiusPixels = diameterPixels / 2; // Create the bitmap Bitmap output = Bitmap.createBitmap((int) diameterPixels, (int) diameterPixels, Bitmap.Config.ARGB_8888); // Create the canvas to draw on Canvas canvas = new Canvas(output); canvas.drawARGB(0, 0, 0, 0); // Draw the circle final Paint paintC = new Paint(); paintC.setAntiAlias(true); paintC.setColor(circleColor); canvas.drawCircle(radiusPixels, radiusPixels, radiusPixels, paintC); // Draw the text if (text != null && text.length() > 0) { final Paint paintT = new Paint(); paintT.setColor(textColor); paintT.setAntiAlias(true); paintT.setTextSize(radiusPixels * 2); paintT.setTypeface(Typeface.SANS_SERIF); final Rect textBounds = new Rect(); paintT.getTextBounds(text, 0, text.length(), textBounds); canvas.drawText(text, radiusPixels - textBounds.exactCenterX(), radiusPixels - textBounds.exactCenterY(), paintT); } return output; }
From source file:Main.java
/** * Draw the favicon with dominant color. * @param context Context used to create the intent. * @param favicon favicon bitmap.// w w w . ja v a2 s . c om * @param canvas Canvas that holds the favicon. */ private static void drawFaviconToCanvas(Context context, Bitmap favicon, Canvas canvas) { Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); int faviconSize = iconBounds.width() / 3; Bitmap scaledFavicon = Bitmap.createScaledBitmap(favicon, faviconSize, faviconSize, true); canvas.drawBitmap(scaledFavicon, iconBounds.exactCenterX() - scaledFavicon.getWidth() / 2.0f, iconBounds.exactCenterY() - scaledFavicon.getHeight() / 2.0f, null); }
From source file:android.support.v7.internal.widget.ListViewCompat.java
protected void positionSelectorLikeFocusCompat(int position, View sel) { // If we're changing position, update the visibility since the selector // is technically being detached from the previous selection. final Drawable selector = getSelector(); final boolean manageState = selector != null && position != INVALID_POSITION; if (manageState) { selector.setVisible(false, false); }/*from w w w. j a va 2 s .c om*/ positionSelectorCompat(position, sel); if (manageState) { final Rect bounds = mSelectorRect; final float x = bounds.exactCenterX(); final float y = bounds.exactCenterY(); selector.setVisible(getVisibility() == VISIBLE, false); DrawableCompat.setHotspot(selector, x, y); } }
From source file:com.example.waitou.rxjava.LoadingView.java
@Override protected void onDraw(Canvas canvas) { if (!mIsAnimatorCancel) { final Rect bounds = getBounds(); final int saveCount = canvas.save(); canvas.rotate(mRotation * 360, bounds.exactCenterX(), bounds.exactCenterY()); drawRing(canvas, bounds);/*from w w w . java 2 s .c om*/ canvas.restoreToCount(saveCount); } else { canvas.restore(); } }
From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.activities.MainActivity.java
private void initTransparentView() { /* Avoid displaying infographic if the home button has been pushed */ Intent intent = getIntent();//from ww w . ja va 2s.c o m displayInfographic = intent.getBooleanExtra(EXTRA_DISPLAY_INFOGRAPHIC, true); System.out.println("Display info " + displayInfographic); if (!displayInfographic) { LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer); linear.setVisibility(View.INVISIBLE); return; } /* Setup the OK button */ Button okButton = (Button) findViewById(R.id.okButton); if (okButton != null) { okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("OK button pushed"); Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_down); LinearLayout linear = (LinearLayout) findViewById(R.id.transparentLayer); linear.startAnimation(animation); linear.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getBaseContext(), "Apasa pe simbolurile din jurul tau", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); /* Display initial seek bar value */ Rect thumbRect = seekBar.getThumb().getBounds(); seekBarValue.setX(thumbRect.exactCenterX()); DecimalFormat dm = new DecimalFormat("###,###.###"); seekBarValue.setText(" " + String.valueOf(dm.format(CommManager.aroundTotalSum)) + " EURO "); seekBarValue.setVisibility(View.VISIBLE); seekBarValue.startAnimation(animationFadeIn); } }); } /* Send request to get the init data */ CommManager.requestInitData(new ICommManagerResponse() { @Override public void processResponse(JSONObject response) { MainActivity.this.receiveInitData(response); } @Override public void onErrorOccurred(String errorMsg) { Toast.makeText(MainActivity.this, "Eroare conectare la server", Toast.LENGTH_SHORT).show(); } }); }
From source file:com.mobility.android.ui.widget.MaterialProgressDrawable.java
@Override public void draw(@NonNull Canvas c) { Rect bounds = getBounds(); int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds);//from w ww . j av a2 s .c om c.restoreToCount(saveCount); }
From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java
@Override public void draw(Canvas c) { if (mShadow != null) { mShadow.getPaint().setColor(mBackgroundColor); mShadow.draw(c);// www . ja v a 2 s . co m } final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
From source file:com.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java
@Override public void draw(Canvas c) { final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(0f, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds);// w w w . j a v a2 s.com c.restoreToCount(saveCount); }
From source file:cn.spinsoft.wdq.widget.swipe.MaterialProgressDrawable.java
@Override public void draw(Canvas c) { final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds);/* w ww. j a v a2 s. c o m*/ c.restoreToCount(saveCount); }
From source file:io.plaidapp.core.ui.transitions.ReflowText.java
/** * Calculate the duration for the transition depending upon how far the text has to move. *//*from w w w .ja va 2 s . c o m*/ private long calculateDuration(@NonNull Rect startPosition, @NonNull Rect endPosition) { float distance = (float) Math.hypot(startPosition.exactCenterX() - endPosition.exactCenterX(), startPosition.exactCenterY() - endPosition.exactCenterY()); long duration = (long) (1000 * (distance / velocity)); return Math.max(minDuration, Math.min(maxDuration, duration)); }