Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

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

Prototype

public final int width() 

Source Link

Usage

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

private void drawSun(Canvas canvas, float pct) {

    // Draw the dots
    canvas.drawCircle(mBezier1x, mBezier1y, mDotRadius, mDotPaint);
    canvas.drawCircle(mBezier4x, mBezier4y, mDotRadius, mDotPaint);

    // calculate the center point of the sun image
    float x = bezierInterpolation(pct, mBezier1x, mBezier2x, mBezier3x, mBezier4x);
    float y = bezierInterpolation(pct, mBezier1y, mBezier2y, mBezier3y, mBezier4y);

    Rect sunBounds = mSunImage.getBounds();

    x -= sunBounds.width() / 2;
    y -= sunBounds.height() / 2;/*from w w  w  .j  av  a2 s  .  co  m*/

    // if we are in rtl, we still want to show the image normally
    // so flip it back
    canvas.translate(x, y);
    if (mIsRtl) {
        canvas.save();
        canvas.scale(-1, 1, sunBounds.centerX(), sunBounds.centerY());
    }
    // draw the sun image
    mSunImage.draw(canvas);
    // restore the flip again
    if (mIsRtl) {
        canvas.restore();
    }
    canvas.translate(-x, -y);

}

From source file:org.liberty.android.fantastischmemo.downloader.google.GoogleOAuth2AccessCodeRetrievalFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final View v = inflater.inflate(R.layout.oauth_login_layout, container, false);
    final WebView webview = (WebView) v.findViewById(R.id.login_page);
    final View loadingText = v.findViewById(R.id.auth_page_load_text);
    final View progressDialog = v.findViewById(R.id.auth_page_load_progress);
    final LinearLayout ll = (LinearLayout) v.findViewById(R.id.ll);

    // We have to set up the dialog's webview size manually or the webview will be zero size.
    // This should be a bug of Android.
    Rect displayRectangle = new Rect();
    Window window = mActivity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

    ll.setMinimumWidth((int) (displayRectangle.width() * 0.9f));
    ll.setMinimumHeight((int) (displayRectangle.height() * 0.8f));

    webview.getSettings().setJavaScriptEnabled(true);
    try {//from   ww w .j  ava  2 s  . c  o m
        String uri = String.format(
                "https://accounts.google.com/o/oauth2/auth?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s",
                URLEncoder.encode(AMEnv.GOOGLE_CLIENT_ID, "UTF-8"), URLEncoder.encode("code", "UTF-8"),
                URLEncoder.encode(AMEnv.GOOGLE_REDIRECT_URI, "UTF-8"),
                URLEncoder.encode(AMEnv.GDRIVE_SCOPE, "UTF-8"));
        webview.loadUrl(uri);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // This is workaround to show input on some android version.
    webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        private boolean authenticated = false;

        @Override
        public void onPageFinished(WebView view, String url) {
            loadingText.setVisibility(View.GONE);
            progressDialog.setVisibility(View.GONE);
            webview.setVisibility(View.VISIBLE);
            if (authenticated == true) {
                return;
            }
            String code = getAuthCodeFromUrl(url);
            String error = getErrorFromUrl(url);
            if (error != null) {
                authCodeReceiveListener.onAuthCodeError(error);
                authenticated = true;
                dismiss();
            }
            if (code != null) {
                authenticated = true;
                authCodeReceiveListener.onAuthCodeReceived(code);
                dismiss();
            }
        }
    });
    return v;
}

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size));

    Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());

    RectF bounds = new RectF(areaRect);

    bounds.right = paint.measureText(text, 0, text.length());

    bounds.bottom = paint.descent() - paint.ascent();

    bounds.left += (areaRect.width() - bounds.right) / 2.0f;
    bounds.top += (areaRect.height() - bounds.bottom) / 2.0f;

    paint.setColor(Color.WHITE);//w  w  w  .  jav  a2 s  .  c  o m
    canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint);
}

From source file:org.srr.dev.view.refreshlayout.SwipeProgressBar.java

private boolean draw(Canvas canvas, boolean first) {
    Rect bounds = mBounds;
    final int width = bounds.width();
    final int cx = bounds.centerX();
    final int cy = bounds.centerY();
    boolean drawTriggerWhileFinishing = false;
    boolean drawAgain = false;
    int restoreCount = canvas.save();
    canvas.clipRect(bounds);/*from w w w  . ja va 2 s. c  o m*/

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't re-post.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return false;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            if (SUPPORT_CLIP_RECT_DIFFERENCE) {
                mClipRect.set(cx - clearRadius, bounds.top, cx + clearRadius, bounds.bottom);
                canvas.clipRect(mClipRect, Region.Op.DIFFERENCE);
            } else {
                if (first) {
                    // First time left
                    drawAgain = true;
                    mClipRect.set(bounds.left, bounds.top, cx - clearRadius, bounds.bottom);
                } else {
                    // Second time right
                    mClipRect.set(cx + clearRadius, bounds.top, bounds.right, bounds.bottom);
                }
                canvas.clipRect(mClipRect);
            }
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(bounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
    return drawAgain;
}

From source file:com.hippo.refreshlayout.SwipeProgressBar.java

private boolean draw(Canvas canvas, boolean first) {
    Rect bounds = mBounds;
    final int width = bounds.width();
    final int cx = bounds.centerX();
    final int cy = bounds.centerY();
    final int colors = mColors.length;
    boolean drawTriggerWhileFinishing = false;
    boolean drawAgain = false;
    int restoreCount = canvas.save();
    canvas.clipRect(bounds);/*w  ww.j  a  v a2s .c  o m*/

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % mAnimationDuration;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS_PER_COLOR;
        float rawProgress = (elapsed / (mAnimationDuration / (float) colors));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return false;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            if (SUPPORT_CLIP_RECT_DIFFERENCE) {
                mClipRect.set(cx - clearRadius, bounds.top, cx + clearRadius, bounds.bottom);
                canvas.clipRect(mClipRect, Region.Op.DIFFERENCE);
            } else {
                if (first) {
                    // First time left
                    drawAgain = true;
                    mClipRect.set(bounds.left, bounds.top, cx - clearRadius, bounds.bottom);
                } else {
                    // Second time right
                    mClipRect.set(cx + clearRadius, bounds.top, bounds.right, bounds.bottom);
                }
                canvas.clipRect(mClipRect);
            }
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColors[0]);
        } else {
            int index = colors - 1;
            float left = 0.0f;
            float right = 1.0f;
            for (int i = 0; i < colors; ++i) {
                if ((rawProgress >= left && rawProgress < right) || i == colors - 1) {
                    canvas.drawColor(mColors[index]);
                    break;
                }
                index = (index + 1) % colors;
                left += 1.0f;
                right += 1.0f;
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if (colors > 1) {
            if ((rawProgress >= 0.0f && rawProgress <= 1.0f)) {
                float pct = (rawProgress + 1.0f) / 2;
                drawCircle(canvas, cx, cy, mColors[0], pct);
            }
            float left = 0.0f;
            float right = 2.0f;
            for (int i = 1; i < colors; ++i) {
                if (rawProgress >= left && rawProgress <= right) {
                    float pct = (rawProgress - i + 1.0f) / 2;
                    drawCircle(canvas, cx, cy, mColors[i], pct);
                }
                left += 1.0f;
                right += 1.0f;
            }
            if ((rawProgress >= colors - 1.0f && rawProgress <= colors)) {
                float pct = (rawProgress - colors + 1.0f) / 2;
                drawCircle(canvas, cx, cy, mColors[0], pct);
            }
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(bounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
    return drawAgain;
}

From source file:com.iutiao.sdk.views.PasswordEditText.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mDrawableSide == null) {
        return super.onTouchEvent(event);
    }/*from   w w  w  .  j  a v a  2s  .c  om*/
    final Rect bounds = mDrawableSide.getBounds();
    final int x = (int) event.getRawX(); // ?

    int iconX = (int) getTopRightCorner().x;

    // Icon?
    int leftIcon = iconX - bounds.width();

    Log.e(TAG, "x: " + x + ", leftIcon: " + leftIcon);

    // Icon?, ??
    if (x >= leftIcon) {
        togglePasswordIconVisibility(); // ???
        event.setAction(MotionEvent.ACTION_CANCEL);
        return false;
    }
    return super.onTouchEvent(event);
}

From source file:org.telegram.ui.Components.AvatarDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    if (bounds == null) {
        return;//from w  ww. j a v a 2 s. c  o  m
    }
    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:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();/*from www .ja va  2s .c  om*/
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[] { halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize,
            cornerSize };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}

From source file:com.github.andrewlord1990.materialandroid.component.textfield.PasswordEditText.java

private boolean isTouchEventWithinToggle(MotionEvent event) {
    int xPosition = (int) event.getX();
    Rect bounds = getDrawables()[2].getBounds();
    boolean withinIconLeftToRight = isLeftToRight() && (xPosition >= getWidth() - bounds.width());
    boolean withinIconRightToLeft = !isLeftToRight() && (xPosition <= bounds.width());
    return withinIconLeftToRight || withinIconRightToLeft;
}

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

@Override
protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    if (mBounds == null) {
        mBounds = new Rect();
    }//w ww  . j a  v a 2  s. co  m
    int size = Math.min(bounds.height(), bounds.width());
    mBounds.left = bounds.centerX() - size / 2;
    mBounds.right = mBounds.left + size;
    mBounds.top = bounds.centerY() - size / 2;
    mBounds.bottom = mBounds.top + size;
    configureBounds();
}