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.zyk.launcher.Workspace.java

public void onExternalDragStartedWithItem(View v) {
    // Compose a drag bitmap with the view scaled to the icon size
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    int iconSize = grid.iconSizePx;
    int bmpWidth = v.getMeasuredWidth();
    int bmpHeight = v.getMeasuredHeight();

    // If this is a text view, use its drawable instead
    if (v instanceof TextView) {
        TextView tv = (TextView) v;//from  w  ww. ja v a2s .c o  m
        Drawable d = tv.getCompoundDrawables()[1];
        Rect bounds = Utils.getDrawableBounds(d);
        bmpWidth = bounds.width();
        bmpHeight = bounds.height();
    }

    // Compose the bitmap to create the icon from
    Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
    mCanvas.setBitmap(b);
    Utils.drawDragView(v, mCanvas, 0);
    mCanvas.setBitmap(null);

    // The outline is used to visualize where the item will land if dropped
    mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true);
}

From source file:cc.flydev.launcher.Workspace.java

private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout,
        ItemInfo info, int[] targetCell, boolean external, boolean scale) {
    // Now we animate the dragView, (ie. the widget or shortcut preview) into its final
    // location and size on the home screen.
    int spanX = info.spanX;
    int spanY = info.spanY;

    Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY);
    loc[0] = r.left;/*from w w w. jav  a 2 s  .  c o m*/
    loc[1] = r.top;

    setFinalTransitionTransform(layout);
    float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true);
    resetTransitionTransform(layout);

    float dragViewScaleX;
    float dragViewScaleY;
    if (scale) {
        dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
        dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
    } else {
        dragViewScaleX = 1f;
        dragViewScaleY = 1f;
    }

    // The animation will scale the dragView about its center, so we need to center about
    // the final location.
    loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2;
    loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

    scaleXY[0] = dragViewScaleX * cellLayoutScale;
    scaleXY[1] = dragViewScaleY * cellLayoutScale;
}

From source file:com.skytree.epubtest.BookViewActivity.java

@Override
public void draw(Canvas canvas) {
    int lvl = getLevel();
    Rect b = getBounds();
    float x = (float) b.width() * (float) lvl / 10000.0f;
    float y = (b.height() - mPaint.getStrokeWidth()) / 2;
    mPaint.setStyle(Paint.Style.FILL);
    for (int cx = 10; cx < b.width(); cx += 30) {
        float cr = (float) ((float) (cx - 10) / (float) (b.width() - 10)) * 100;
        if (cr <= this.value) {
            mPaint.setColor(color);/*from  w  ww. j a v a2s  .  c  o  m*/
            if (color != inactiveColor) {
                canvas.drawCircle(cx, y, 6, mPaint);
            } else {
                canvas.drawCircle(cx, y, 4, mPaint);
            }

        } else {
            mPaint.setColor(inactiveColor);
            canvas.drawCircle(cx, y, 4, mPaint);
        }

    }
}

From source file:com.android.launcher3.Launcher.java

private Bundle getActivityLaunchOptions(View v) {
    if (Utilities.ATLEAST_MARSHMALLOW) {
        int left = 0, top = 0;
        int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
        if (v instanceof TextView) {
            // Launch from center of icon, not entire view
            Drawable icon = Workspace.getTextViewIcon((TextView) v);
            if (icon != null) {
                Rect bounds = icon.getBounds();
                left = (width - bounds.width()) / 2;
                top = v.getPaddingTop();
                width = bounds.width();/* w  ww .  ja  v a2 s  .c o m*/
                height = bounds.height();
            }
        }
        return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle();
    } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
        // On L devices, we use the device default slide-up transition.
        // On L MR1 devices, we use a custom version of the slide-up transition which
        // doesn't have the delay present in the device default.
        return ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim).toBundle();
    }
    return null;
}

From source file:com.example.launcher3.Workspace.java

private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout,
        ItemInfo info, int[] targetCell, boolean external, boolean scale) {
    // Now we animate the dragView, (ie. the widget or shortcut preview)
    // into its final
    // location and size on the home screen.
    int spanX = info.spanX;
    int spanY = info.spanY;

    Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY);
    loc[0] = r.left;/*from w ww.  j av  a  2 s.c o  m*/
    loc[1] = r.top;

    setFinalTransitionTransform(layout);
    float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true);
    resetTransitionTransform(layout);

    float dragViewScaleX;
    float dragViewScaleY;
    if (scale) {
        dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
        dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
    } else {
        dragViewScaleX = 1f;
        dragViewScaleY = 1f;
    }

    // The animation will scale the dragView about its center, so we need to
    // center about
    // the final location.
    loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2;
    loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

    scaleXY[0] = dragViewScaleX * cellLayoutScale;
    scaleXY[1] = dragViewScaleY * cellLayoutScale;
}

From source file:com.skytree.epubtest.BookViewActivity.java

@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();
    mPaint.setColor(mColor);//w w w.  j a v  a 2  s. c  o m
    mPaint.setStrokeWidth(mStrokeWidth);
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawLine(0, b.height() / 2 + b.height() * 0.1f, b.width(), b.height() / 2 + b.height() * .1f,
            mPaint);
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, DragView dragView, CellLayout layout,
        ItemInfoBean info, int[] targetCell, boolean external, boolean scale) {
    // Now we animate the dragView, (ie. the widget or shortcut preview)
    // into its final
    // location and size on the home screen.
    int spanX = info.spanX;
    int spanY = info.spanY;

    Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY);
    loc[0] = r.left;//from w  w  w.j a va 2s .  co  m
    loc[1] = r.top;

    setFinalTransitionTransform(layout);
    float cellLayoutScale = mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true);
    resetTransitionTransform(layout);

    float dragViewScaleX;
    float dragViewScaleY;
    if (scale) {
        dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth();
        dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight();
    } else {
        dragViewScaleX = 1f;
        dragViewScaleY = 1f;
    }

    // The animation will scale the dragView about its center, so we need to
    // center about
    // the final location.
    loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2;
    loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2;

    scaleXY[0] = dragViewScaleX * cellLayoutScale;
    scaleXY[1] = dragViewScaleY * cellLayoutScale;
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

private boolean startActivity(View v, Intent intent, Object tag) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/* w  ww. ja v  a  2s.co  m*/
        // Only launch using the new animation if the shortcut has not opted out (this is a
        // private contract between launcher and may be ignored in the future).
        boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
        UserManagerCompat userManager = UserManagerCompat.getInstance(this);

        UserHandleCompat user = null;
        if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
            long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
            user = userManager.getUserForSerialNumber(serialNumber);
        }

        Bundle optsBundle = null;
        if (useLaunchAnimation) {
            ActivityOptions opts = null;
            if (sClipRevealMethod != null) {
                // TODO: call method directly when Launcher3 can depend on M APIs
                int left = 0, top = 0;
                int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
                if (v instanceof TextView) {
                    // Launch from center of icon, not entire view
                    Drawable icon = Workspace.getTextViewIcon((TextView) v);
                    if (icon != null) {
                        Rect bounds = icon.getBounds();
                        left = (width - bounds.width()) / 2;
                        top = v.getPaddingTop();
                        width = bounds.width();
                        height = bounds.height();
                    }
                }
                try {
                    opts = (ActivityOptions) sClipRevealMethod.invoke(null, v, left, top, width, height);
                } catch (IllegalAccessException e) {
                    Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
                    sClipRevealMethod = null;
                } catch (InvocationTargetException e) {
                    Log.d(TAG, "Could not call makeClipRevealAnimation: " + e);
                    sClipRevealMethod = null;
                }
            }
            if (opts == null && !Utilities.isLmpOrAbove()) {
                // Below L, we use a scale up animation
                opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(),
                        v.getMeasuredHeight());
            } else if (opts == null && Utilities.isLmpMR1()) {
                // On L devices, we use the device default slide-up transition.
                // On L MR1 devices, we a custom version of the slide-up transition which
                // doesn't have the delay present in the device default.
                opts = ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim);
            }
            optsBundle = opts != null ? opts.toBundle() : null;
        }

        if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            // TODO Component can be null when shortcuts are supported for secondary user
            launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(),
                    optsBundle);
        }
        return true;
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent
                + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e);
    }
    return false;
}

From source file:com.appunite.list.HorizontalListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }//from ww  w .j  ava 2s. c om
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToTop = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToTop);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getLeft();
        invalidate();
    }
    return scroll;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectLeftWithinChild = rect.left;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectLeftWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }//from   ww  w .  j av a 2s  .  com
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.right < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToLeft = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToLeft);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getTop();
        invalidate();
    }
    return scroll;
}