Example usage for android.graphics Rect Rect

List of usage examples for android.graphics Rect Rect

Introduction

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

Prototype

public Rect() 

Source Link

Document

Create a new empty Rect.

Usage

From source file:com.example.android.camera.CameraActivity.java

private List<Rect> getFaces() {
    List<Rect> found = new ArrayList<Rect>();

    for (Face face : mPreview.faces) {
        if (face.score < 100)
            continue;

        Rect rect = new Rect();
        RectF rectf = new RectF();

        rectf.set(face.rect);/*w w w. j  av a2s.c  o  m*/
        mViewFinderView.dumpRect(rectf, "before");
        matrix.mapRect(rectf);
        mViewFinderView.dumpRect(rectf, "after");

        float adj = (rectf.bottom - rectf.top - rectf.right + rectf.left) / 2;
        rectf.set(rectf.left - adj, rectf.top, rectf.right + adj, rectf.bottom);
        mViewFinderView.dumpRect(rectf, "Squared");

        if (rectf.left < 0) {
            rectf.set(0, rectf.top, rectf.right - rectf.left, rectf.bottom);
            Log.d("face Adjust", "Left");
        } else if (rectf.right > pWidth) {
            rectf.set(rectf.left - rectf.right + pWidth, rectf.top, pWidth, rectf.bottom);
            Log.d("face Adjust", "Right");
        }

        if (rectf.top < 0) {
            rectf.set(rectf.left, 0, rectf.right, rectf.bottom - rectf.top);
            Log.d("face Adjust", "Top");
        } else if (rectf.bottom > pHeight) {
            rectf.set(rectf.left, rectf.top - rectf.bottom + pHeight, rectf.right, pHeight);
            Log.d("face Adjust", "Bottom");
        }

        mViewFinderView.dumpRect(rectf, "Shift Adjusted");
        rectf.round(rect);
        found.add(rect);
    }

    return found;
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

private boolean isViewVisible(HorizontalScrollView scrollView, View view) {
    Rect scrollBounds = new Rect();
    scrollView.getDrawingRect(scrollBounds);
    float vLeft = view.getLeft();
    float vRight = view.getWidth() + vLeft;
    return scrollBounds.left < vLeft && scrollBounds.right > vRight;
}

From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

private int getMaxAvailableHeight(View anchor, int yOffset, boolean ignoreBottomDecorations) {
    final Rect displayFrame = new Rect();
    anchor.getWindowVisibleDisplayFrame(displayFrame);

    final int[] anchorPos = new int[2];
    anchor.getLocationOnScreen(anchorPos);

    int bottomEdge = displayFrame.bottom;
    if (ignoreBottomDecorations) {
        Resources res = anchor.getContext().getResources();
        bottomEdge = res.getDisplayMetrics().heightPixels;
    }/* w  w  w  .  ja  v  a  2 s.com*/
    final int distanceToBottom = bottomEdge - (anchorPos[1] + anchor.getHeight()) - yOffset;
    final int distanceToTop = anchorPos[1] - displayFrame.top + yOffset;

    // anchorPos[1] is distance from anchor to top of screen
    int returnedHeight = Math.max(distanceToBottom, distanceToTop);
    if (mPopup.getBackground() != null) {
        mPopup.getBackground().getPadding(mTempRect);
        returnedHeight -= mTempRect.top + mTempRect.bottom;
    }

    return returnedHeight;
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void addAudioRects() {
    for (AudioAreaHolder holder : mAudioAreas) {
        // convert grid-based coordinates to image-based coordinates, accounting for image rotation/inversion by
        // making sure to use the min/max values of each coordinate
        Rect rect = holder.serverRect;//from w w w. j  a va 2  s  .  co m
        PointF leftTop = QRImageParser.getImagePosition(mImageParameters, new PointF(rect.left, rect.top));
        PointF rightBottom = QRImageParser.getImagePosition(mImageParameters,
                new PointF(rect.right, rect.bottom));
        RectF displayRect = new RectF(Math.min(leftTop.x, rightBottom.x), Math.min(leftTop.y, rightBottom.y),
                Math.max(rightBottom.x, leftTop.x), Math.max(leftTop.y, rightBottom.y));
        Rect imageRect = new Rect();
        displayRect.roundOut(imageRect);

        holder.setImageRect(imageRect);
        mImageView.addAudioAreaRect(imageRect);
    }
}

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

private void scrollTo(final View view) {

    final Rect scrollBounds = new Rect();
    scrollContainer.getHitRect(scrollBounds);

    scrollBounds.set(scrollBounds.left, scrollBounds.top, scrollBounds.right, scrollBounds.bottom - 200);

    view.getLocalVisibleRect(scrollBounds);

    if (scrollBounds.height() >= view.getHeight()) {
        return; // no scroll need
    }/*  w w w  . java  2 s .  c  o  m*/

    // Determine where to set the scroll-to to by measuring the distance from the top of the scroll view
    // to the control to focus on by summing the "top" position of each view in the hierarchy.
    int yDistanceToControlsView = 0;
    View parentView = (View) view.getParent();
    while (true) {
        if (parentView.equals(scrollContainer)) {
            break;
        }
        yDistanceToControlsView += parentView.getTop();
        parentView = (View) parentView.getParent();
    }

    // Compute the final position value for the top and bottom of the control in the scroll view.
    final int topInScrollView = yDistanceToControlsView + view.getTop();
    final int bottomInScrollView = yDistanceToControlsView + view.getBottom();

    // Post the scroll action to happen on the scrollView with the UI thread.
    scrollContainer.post(new Runnable() {
        @Override
        public void run() {
            int height = view.getHeight();
            scrollContainer.smoothScrollTo(0, topInScrollView); //((topInScrollView + bottomInScrollView) / 2) - height);
            view.requestFocus();
        }
    });
}

From source file:com.test.hwautotest.emmagee.service.EmmageeService.java

private void offsetTouch() {
    View rootView = viFloatingWindow.getRootView();
    Rect r = new Rect();
    rootView.getWindowVisibleDisplayFrame(r);
    statusBarHeight = r.top;
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void reveal(View sourceView, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(themeClearAccent);
    groupOverlay.add(revealView);//from  ww w .j a v  a  2  s .  co  m

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    alphaAnimator.addListener(listener);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.appfeel.cordova.admob.AdMobAds.java

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * /*ww  w  . java2 s.  c  o  m*/
 * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input
 *          parameters.
 * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see
 *         if an ad was successfully retrieved.
 */
private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) {
    if (adView == null) {
        return new PluginResult(Status.ERROR, "adView is null, call createBannerView first.");
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (show == isBannerVisible) {
                // no change

            } else if (show) {
                if (adView.getParent() != null) {
                    ((ViewGroup) adView.getParent()).removeView(adView);
                }

                if (isBannerOverlap) {
                    RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                    if (isOffsetStatusBar) {
                        int titleBarHeight = 0;
                        Rect rectangle = new Rect();
                        Window window = AdMobAds.this.cordova.getActivity().getWindow();
                        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);

                        if (isBannerAtTop) {
                            if (rectangle.top == 0) {
                                int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                                titleBarHeight = contentViewTop - rectangle.top;
                            }
                            params2.topMargin = titleBarHeight;

                        } else {
                            if (rectangle.top > 0) {
                                int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT)
                                        .getBottom();
                                titleBarHeight = contentViewBottom - rectangle.bottom;
                            }
                            params2.bottomMargin = titleBarHeight;
                        }

                    } else if (isBannerAtTop) {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                    } else {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    }

                    if (adViewLayout == null) {
                        adViewLayout = new RelativeLayout(cordova.getActivity());
                        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                                RelativeLayout.LayoutParams.MATCH_PARENT,
                                RelativeLayout.LayoutParams.MATCH_PARENT);
                        if (CORDOVA_4) {
                            ((ViewGroup) webView.getView().getParent()).addView(adViewLayout, params);
                        } else {
                            ((ViewGroup) webView).addView(adViewLayout, params);
                        }
                    }
                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    if (CORDOVA_4) {
                        ViewGroup wvParentView = (ViewGroup) webView.getView().getParent();

                        if (parentView == null) {
                            parentView = new LinearLayout(webView.getContext());
                        }

                        if (wvParentView != null && wvParentView != parentView) {
                            wvParentView.removeView(webView.getView());
                            ((LinearLayout) parentView).setOrientation(LinearLayout.VERTICAL);
                            parentView.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
                            webView.getView().setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                            ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));
                            parentView.addView(webView.getView());
                            cordova.getActivity().setContentView(parentView);
                        }

                    } else {
                        parentView = (ViewGroup) ((ViewGroup) webView).getParent();
                    }

                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                    parentView.requestLayout();

                }

                adView.setVisibility(View.VISIBLE);
                isBannerVisible = true;

            } else {
                adView.setVisibility(View.GONE);
                isBannerVisible = false;
            }

            if (callbackContext != null) {
                callbackContext.success();
            }
        }
    });
    return null;
}

From source file:com.jomendezdev.cordova.admob.AdMobAds.java

/**
 * Parses the show ad input parameters and runs the show ad action on the UI thread.
 * /*from   w w w  . j  ava 2 s .  c  o  m*/
 * @param inputs The JSONArray representing input parameters. This function expects the first object in the array to be a JSONObject with the input
 *          parameters.
 * @return A PluginResult representing whether or not an ad was requested succcessfully. Listen for onReceiveAd() and onFailedToReceiveAd() callbacks to see
 *         if an ad was successfully retrieved.
 */
private PluginResult executeShowBannerAd(final boolean show, final CallbackContext callbackContext) {
    if (adView == null) {
        return new PluginResult(Status.ERROR, "adView is null, call createBannerView first.");
    }

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (show == isBannerVisible) {
                // no change

            } else if (show) {
                if (adView.getParent() != null) {
                    ((ViewGroup) adView.getParent()).removeView(adView);
                }

                if (isBannerOverlap) {
                    RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                    if (isOffsetStatusBar) {
                        int titleBarHeight = 0;
                        Rect rectangle = new Rect();
                        Window window = AdMobAds.this.cordova.getActivity().getWindow();
                        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);

                        if (isBannerAtTop) {
                            if (rectangle.top == 0) {
                                int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                                titleBarHeight = contentViewTop - rectangle.top;
                            }
                            params2.topMargin = titleBarHeight;

                        } else {
                            if (rectangle.top > 0) {
                                int contentViewBottom = window.findViewById(Window.ID_ANDROID_CONTENT)
                                        .getBottom();
                                titleBarHeight = contentViewBottom - rectangle.bottom;
                            }
                            params2.bottomMargin = titleBarHeight;
                        }

                    } else if (isBannerAtTop) {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_TOP);

                    } else {
                        params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    }

                    adViewLayout.addView(adView, params2);
                    adViewLayout.bringToFront();

                } else {
                    ViewGroup parentView = (ViewGroup) webView.getParent();
                    if (isBannerAtTop) {
                        parentView.addView(adView, 0);
                    } else {
                        parentView.addView(adView);
                    }
                    parentView.bringToFront();
                }

                adView.setVisibility(View.VISIBLE);
                isBannerVisible = true;

            } else {
                adView.setVisibility(View.GONE);
                isBannerVisible = false;
            }

            if (callbackContext != null) {
                callbackContext.success();
            }
        }
    });
    return null;
}

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

public Rect estimateItemPosition(CellLayout cl, ItemInfo pendingInfo, int hCell, int vCell, int hSpan,
        int vSpan) {
    Rect r = new Rect();
    cl.cellToRect(hCell, vCell, hSpan, vSpan, r);
    return r;//from  w  ww.  ja va2 s. c o  m
}