Example usage for android.graphics Rect exactCenterY

List of usage examples for android.graphics Rect exactCenterY

Introduction

In this page you can find the example usage for android.graphics Rect exactCenterY.

Prototype

public final float exactCenterY() 

Source Link

Usage

From source file:Main.java

/**
 * Create round, coloured bitmap with text embedded.
 * @param circleColor The color to use./*w ww  .  jav a2 s  .  c o m*/
 * @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./*from w  w  w. j a  v a 2s.  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);
    }/* ww  w.  ja v  a 2 s  .  c  o m*/

    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 ww  . ja v  a  2 s . com*/
        canvas.restoreToCount(saveCount);
    } else {
        canvas.restore();
    }
}

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);//  w  w  w . ja va 2  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);//ww  w . j a  v a 2s .  com
    }

    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);/*  ww w. j  a v a2  s.  c o m*/
    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);//from   w w  w .ja  v a  2s  .  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.
 *///w  ww  .j  a v  a2 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));
}

From source file:com.breakout.main.GameState.java

/**
 * Renders debug features.//from  w w w  .  j  av a 2  s .  c  o  m
 * <p>
 * This function is allowed to violate the "don't allocate objects" rule.
 */
void drawDebugStuff() {

    // Draw a red outline rectangle around the ball.  This shows the area that was
    // examined for collisions during the "coarse" pass.
    OutlineAlignedRect.prepareToDraw();
    mDebugCollisionRect.draw();
    OutlineAlignedRect.finishedDrawing();

    // Draw the entire message texture so we can see what it looks like.
    if (true) {
        int textureWidth = mTextRes.getTextureWidth();
        int textureHeight = mTextRes.getTextureHeight();
        float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / textureWidth;

        // Draw an orange rect around the texture.
        OutlineAlignedRect outline = new OutlineAlignedRect();
        outline.setPosition(ARENA_WIDTH / 2, ARENA_HEIGHT / 2);
        outline.setScale(textureWidth * scale + 2, textureHeight * scale + 2);
        outline.setColor(1.0f, 0.65f, 0.0f);
        OutlineAlignedRect.prepareToDraw();
        outline.draw();
        OutlineAlignedRect.finishedDrawing();

        // Draw the full texture.  Note you can set the background to opaque white in
        // TextResources to see what the drop shadow looks like.
        Rect boundsRect = new Rect(0, 0, textureWidth, textureHeight);
        TexturedAlignedRect msgBox = mGameStatusMessages;
        msgBox.setTextureCoords(boundsRect);
        msgBox.setScale(textureWidth * scale, textureHeight * scale);
        TexturedAlignedRect.prepareToDraw();
        msgBox.draw();
        TexturedAlignedRect.finishedDrawing();

        // Draw a rectangle around each individual text item.  We draw a different one each
        // time to get a flicker effect, so it doesn't fully obscure the text.
        if (true) {
            outline.setColor(1.0f, 1.0f, 1.0f);
            int stringNum = mDebugFramedString;
            mDebugFramedString = (mDebugFramedString + 1) % TextResources.getNumStrings();
            boundsRect = mTextRes.getTextureRect(stringNum);
            // The bounds rect is in bitmap coordinates, with (0,0) in the top left.  Translate
            // it to an offset from the center of the bitmap, and find the center of the rect.
            float boundsCenterX = boundsRect.exactCenterX() - (textureWidth / 2);
            float boundsCenterY = boundsRect.exactCenterY() - (textureHeight / 2);
            // Now scale it to arena coordinates, using the same scale factor we used to
            // draw the texture with all the messages, and translate it to the center of
            // the arena.  We need to invert Y to match GL conventions.
            boundsCenterX = ARENA_WIDTH / 2 + (boundsCenterX * scale);
            boundsCenterY = ARENA_HEIGHT / 2 - (boundsCenterY * scale);
            // Set the values and draw the rect.
            outline.setPosition(boundsCenterX, boundsCenterY);
            outline.setScale(boundsRect.width() * scale, boundsRect.height() * scale);
            OutlineAlignedRect.prepareToDraw();
            outline.draw();
            OutlineAlignedRect.finishedDrawing();
        }
    }
}