Example usage for android.graphics Rect inset

List of usage examples for android.graphics Rect inset

Introduction

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

Prototype

public void inset(int dx, int dy) 

Source Link

Document

Inset the rectangle by (dx,dy).

Usage

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/***
 * ?/*from   www. j  a v a 2 s  . c o  m*/
 * **/
private void animateDragged() {
    if (mLastDragged >= 0) {
        final View v = getChildAt(mLastDragged);

        final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        r.inset(-r.width() / 20, -r.height() / 20);
        v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
        v.layout(r.left, r.top, r.right, r.bottom);

        AnimationSet animSet = new AnimationSet(true);
        ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
        scale.setDuration(ANIMATION_DURATION);
        AlphaAnimation alpha = new AlphaAnimation(1, .5f);
        alpha.setDuration(ANIMATION_DURATION);

        animSet.addAnimation(scale);
        animSet.addAnimation(alpha);
        animSet.setFillEnabled(true);
        animSet.setFillAfter(true);

        v.clearAnimation();
        v.startAnimation(animSet);
    }
}

From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java

/**
 * ?/*from w  ww .j a v  a2  s  .  com*/
 * */
private int getTargetByXY(int x, int y) {
    // ?
    final int position = getPositionByXY(x, y);
    if (position < 0) {
        return -1;
    }
    // ?
    final Rect r = getRectByPosition(position);
    final int page = position / mPageSize;
    // ?? ??
    r.inset(r.width() / 4, r.height() / 4);
    // ??
    r.offset(-getWidth() * page, 0);
    // ?? ?
    if (!r.contains(x, y)) {
        return -1;
    }
    return position;
}

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

private static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);/*from w  ww.j  av a 2  s. co m*/
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    if (d instanceof PreloadIconDrawable) {
        int inset = -((PreloadIconDrawable) d).getOutset();
        bounds.inset(inset, inset);
    }
    return bounds;
}