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:cc.flydev.launcher.Workspace.java

/** Return a rect that has the cellWidth/cellHeight (left, top), and
 * widthGap/heightGap (right, bottom) */
static Rect getCellLayoutMetrics(Launcher launcher, int orientation) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    Resources res = launcher.getResources();
    Display display = launcher.getWindowManager().getDefaultDisplay();
    Point smallestSize = new Point();
    Point largestSize = new Point();
    display.getCurrentSizeRange(smallestSize, largestSize);
    int countX = (int) grid.numColumns;
    int countY = (int) grid.numRows;
    int constrainedLongEdge = largestSize.y;
    int constrainedShortEdge = smallestSize.y;
    if (orientation == CellLayout.LANDSCAPE) {
        if (mLandscapeCellLayoutMetrics == null) {
            Rect padding = grid.getWorkspacePadding(CellLayout.LANDSCAPE);
            int width = constrainedLongEdge - padding.left - padding.right;
            int height = constrainedShortEdge - padding.top - padding.bottom;
            mLandscapeCellLayoutMetrics = new Rect();
            mLandscapeCellLayoutMetrics.set(grid.calculateCellWidth(width, countX),
                    grid.calculateCellHeight(height, countY), 0, 0);
        }/*from  ww w . ja  v  a 2 s.  c o m*/
        return mLandscapeCellLayoutMetrics;
    } else if (orientation == CellLayout.PORTRAIT) {
        if (mPortraitCellLayoutMetrics == null) {
            Rect padding = grid.getWorkspacePadding(CellLayout.PORTRAIT);
            int width = constrainedShortEdge - padding.left - padding.right;
            int height = constrainedLongEdge - padding.top - padding.bottom;
            mPortraitCellLayoutMetrics = new Rect();
            mPortraitCellLayoutMetrics.set(grid.calculateCellWidth(width, countX),
                    grid.calculateCellHeight(height, countY), 0, 0);
        }
        return mPortraitCellLayoutMetrics;
    }
    return null;
}

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

boolean isPointInSelfOverHotseat(int x, int y, Rect r) {
    if (r == null) {
        r = new Rect();
    }/*from   www . j a v  a2  s . c o  m*/
    mTempPt[0] = x;
    mTempPt[1] = y;
    mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    r = grid.getHotseatRect();
    if (r.contains(mTempPt[0], mTempPt[1])) {
        return true;
    }
    return false;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static int inferStatusBarHeight(final Activity activity) {
    final Window w = activity.getWindow();
    final View decorView = w.getDecorView();
    final Rect rect = new Rect();
    decorView.getWindowVisibleDisplayFrame(rect);
    return rect.top;
}

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

public void onDragOver(DragObject d) {
    // Skip drag over events while we are dragging over side pages
    if (mInScrollArea || mIsSwitchingState || mState == State.SMALL)
        return;/*from w  ww.  j a  v  a 2 s . c o  m*/

    Rect r = new Rect();
    CellLayout layout = null;
    ItemInfo item = (ItemInfo) d.dragInfo;

    // Ensure that we have proper spans for the item that we are dropping
    if (item.spanX < 0 || item.spanY < 0)
        throw new RuntimeException("Improper spans found");
    mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView,
            mDragViewVisualCenter);

    final View child = (mDragInfo == null) ? null : mDragInfo.cell;
    // Identify whether we have dragged over a side page
    if (isSmall()) {
        if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) {
            if (isPointInSelfOverHotseat(d.x, d.y, r)) {
                layout = mLauncher.getHotseat().getLayout();
            }
        }
        if (layout == null) {
            layout = findMatchingPageForDragOver(d.dragView, d.x, d.y, false);
        }
        if (layout != mDragTargetLayout) {
            setCurrentDropLayout(layout);
            setCurrentDragOverlappingLayout(layout);

            boolean isInSpringLoadedMode = (mState == State.SPRING_LOADED);
            if (isInSpringLoadedMode) {
                if (mLauncher.isHotseatLayout(layout)) {
                    mSpringLoadedDragController.cancel();
                } else {
                    mSpringLoadedDragController.setAlarm(mDragTargetLayout);
                }
            }
        }
    } else {
        // Test to see if we are over the hotseat otherwise just use the current page
        if (mLauncher.getHotseat() != null && !isDragWidget(d)) {
            if (isPointInSelfOverHotseat(d.x, d.y, r)) {
                layout = mLauncher.getHotseat().getLayout();
            }
        }
        if (layout == null) {
            layout = getCurrentDropLayout();
        }
        if (layout != mDragTargetLayout) {
            setCurrentDropLayout(layout);
            setCurrentDragOverlappingLayout(layout);
        }
    }

    // Handle the drag over
    if (mDragTargetLayout != null) {
        // We want the point to be mapped to the dragTarget.
        if (mLauncher.isHotseatLayout(mDragTargetLayout)) {
            mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
        } else {
            mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null);
        }

        ItemInfo info = (ItemInfo) d.dragInfo;

        int minSpanX = item.spanX;
        int minSpanY = item.spanY;
        if (item.minSpanX > 0 && item.minSpanY > 0) {
            minSpanX = item.minSpanX;
            minSpanY = item.minSpanY;
        }

        mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX,
                minSpanY, mDragTargetLayout, mTargetCell);
        int reorderX = mTargetCell[0];
        int reorderY = mTargetCell[1];

        setCurrentDropOverCell(mTargetCell[0], mTargetCell[1]);

        float targetCellDistance = mDragTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0],
                mDragViewVisualCenter[1], mTargetCell);

        final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);

        manageFolderFeedback(info, mDragTargetLayout, mTargetCell, targetCellDistance, dragOverView);

        boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied(
                (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX, item.spanY, child,
                mTargetCell);

        if (!nearestDropOccupied) {
            mDragTargetLayout.visualizeDropLocation(child, mDragOutline, (int) mDragViewVisualCenter[0],
                    (int) mDragViewVisualCenter[1], mTargetCell[0], mTargetCell[1], item.spanX, item.spanY,
                    false, d.dragView.getDragVisualizeOffset(), d.dragView.getDragRegion());
        } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER)
                && !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX || mLastReorderY != reorderY)) {

            // Otherwise, if we aren't adding to or creating a folder and there's no pending
            // reorder, then we schedule a reorder
            ReorderAlarmListener listener = new ReorderAlarmListener(mDragViewVisualCenter, minSpanX, minSpanY,
                    item.spanX, item.spanY, d.dragView, child);
            mReorderAlarm.setOnAlarmListener(listener);
            mReorderAlarm.setAlarm(REORDER_TIMEOUT);
        }

        if (mDragMode == DRAG_MODE_CREATE_FOLDER || mDragMode == DRAG_MODE_ADD_TO_FOLDER
                || !nearestDropOccupied) {
            if (mDragTargetLayout != null) {
                mDragTargetLayout.revertTempState();
            }
        }
    }
}

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

public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView,
        final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) {
    Rect from = new Rect();
    mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);

    int[] finalPos = new int[2];
    float scaleXY[] = new float[2];
    boolean scalePreview = !(info instanceof PendingAddShortcutInfo);
    getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, external,
            scalePreview);//from  w ww .jav  a2  s  . c  o  m

    Resources res = mLauncher.getResources();
    int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;

    // In the case where we've prebound the widget, we remove it from the DragLayer
    if (finalView instanceof AppWidgetHostView && external) {
        Log.d(TAG, "6557954 Animate widget drop, final view is appWidgetHostView");
        mLauncher.getDragLayer().removeView(finalView);
    }
    if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) {
        Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView);
        dragView.setCrossFadeBitmap(crossFadeBitmap);
        dragView.crossFade((int) (duration * 0.8f));
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && external) {
        scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
    }

    DragLayer dragLayer = mLauncher.getDragLayer();
    if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) {
        mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f,
                DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
    } else {
        int endStyle;
        if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) {
            endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE;
        } else {
            endStyle = DragLayer.ANIMATION_END_DISAPPEAR;
            ;
        }

        Runnable onComplete = new Runnable() {
            @Override
            public void run() {
                if (finalView != null) {
                    finalView.setVisibility(VISIBLE);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
            }
        };
        dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], finalPos[1], 1, 1, 1,
                scaleXY[0], scaleXY[1], onComplete, endStyle, duration, this);
    }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private Point getSpanCoordinates(View widget, ClickableURLSpan span) {
    TextView parentTextView = (TextView) widget;

    Rect parentTextViewRect = new Rect();

    // Initialize values for the computing of clickedText position
    SpannableString completeText = (SpannableString) (parentTextView).getText();
    Layout textViewLayout = parentTextView.getLayout();

    int startOffsetOfClickedText = completeText.getSpanStart(span);
    int endOffsetOfClickedText = completeText.getSpanEnd(span);
    double startXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(startOffsetOfClickedText);
    double endXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(endOffsetOfClickedText);

    // Get the rectangle of the clicked text
    int currentLineStartOffset = textViewLayout.getLineForOffset(startOffsetOfClickedText);
    int currentLineEndOffset = textViewLayout.getLineForOffset(endOffsetOfClickedText);
    boolean keywordIsInMultiLine = currentLineStartOffset != currentLineEndOffset;
    textViewLayout.getLineBounds(currentLineStartOffset, parentTextViewRect);

    // Update the rectangle position to his real position on screen
    int[] parentTextViewLocation = { 0, 0 };
    parentTextView.getLocationOnScreen(parentTextViewLocation);

    double parentTextViewTopAndBottomOffset = (parentTextViewLocation[1] - parentTextView.getScrollY()
            + parentTextView.getCompoundPaddingTop());

    Rect windowRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(windowRect);
    parentTextViewTopAndBottomOffset -= windowRect.top;

    parentTextViewRect.top += parentTextViewTopAndBottomOffset;
    parentTextViewRect.bottom += parentTextViewTopAndBottomOffset;

    parentTextViewRect.left += (parentTextViewLocation[0] + startXCoordinatesOfClickedText
            + parentTextView.getCompoundPaddingLeft() - parentTextView.getScrollX());
    parentTextViewRect.right = (int) (parentTextViewRect.left + endXCoordinatesOfClickedText
            - startXCoordinatesOfClickedText);

    int x = (parentTextViewRect.left + parentTextViewRect.right) / 2;
    int y = (parentTextViewRect.top + parentTextViewRect.bottom) / 2;
    if (keywordIsInMultiLine) {
        x = parentTextViewRect.left;//from  w ww  .  ja v  a 2 s . c om
    }

    return new Point(x, y);
}

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

@Override
public boolean onEnterScrollArea(int x, int y, int direction) {
    // Ignore the scroll area if we are dragging over the hot seat
    boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext());
    if (mLauncher.getHotseat() != null && isPortrait) {
        Rect r = new Rect();
        mLauncher.getHotseat().getHitRect(r);
        if (r.contains(x, y)) {
            return false;
        }// w  w  w  . ja  va2 s  . co  m
    }

    boolean result = false;
    if (!isSmall() && !mIsSwitchingState && getOpenFolder() == null) {
        mInScrollArea = true;

        final int page = getNextPage() + (direction == DragController.SCROLL_LEFT ? -1 : 1);
        // We always want to exit the current layout to ensure parity of enter / exit
        setCurrentDropLayout(null);

        if (0 <= page && page < getChildCount()) {
            // Ensure that we are not dragging over to the custom content screen
            if (getScreenIdForPageIndex(page) == CUSTOM_CONTENT_SCREEN_ID) {
                return false;
            }

            CellLayout layout = (CellLayout) getChildAt(page);
            setCurrentDragOverlappingLayout(layout);

            // Workspace is responsible for drawing the edge glow on adjacent pages,
            // so we need to redraw the workspace when this may have changed.
            invalidate();
            result = true;
        }
    }
    return result;
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

/**
 *  ?  ? ?//w  w w .  j a  va2s.co  m
 * @param itemPosition ? ? (?)   listView
 * @param isTablet true, ?   (??   ? ??)
 * @param coordinates   ??
 */
private void showPostPopupDialog(final int itemPosition, final boolean isTablet, final Point coordinates,
        final String refererPost) {
    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);
    final int measuredWidth = isTablet ? adapter.measureViewWidth(itemPosition) : -1; //? ??  ? 
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    final Rect activityWindowRect;
    final int dlgWindowWidth;
    final int dlgWindowHeight;
    if (isTablet) {
        activityWindowRect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(activityWindowRect);
        dlgWindowWidth = Math.max(coordinates.x, activityWindowRect.width() - coordinates.x);
        dlgWindowHeight = Math.max(coordinates.y, activityWindowRect.height() - coordinates.y);
        tmpDlg.getWindow().setLayout(dlgWindowWidth, dlgWindowHeight);
    } else {
        activityWindowRect = null;
        dlgWindowWidth = -1;
        dlgWindowHeight = -1;
    }
    tmpDlg.show();

    Runnable next = new Runnable() {
        @SuppressLint("RtlHardcoded")
        @Override
        public void run() {
            int dlgWidth = tmpV.getWidth();
            int dlgHeight = tmpV.getHeight();
            tmpDlg.hide();
            tmpDlg.cancel();
            int newWidth = isTablet ? Math.min(measuredWidth, dlgWidth) : dlgWidth;

            View view = adapter.getView(itemPosition, null, null, newWidth, refererPost);
            view.setBackgroundColor(bgColor);
            //Logger.d(TAG, "measured: "+view.findViewById(R.id.post_frame_main).getMeasuredWidth()+
            //        "x"+view.findViewById(R.id.post_frame_main).getMeasuredHeight());

            Dialog dialog = new Dialog(activity);
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(view);
            if (isTablet) {
                view.findViewById(R.id.post_frame_main).measure(
                        MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                int newWindowWidth = dlgWindowWidth - dlgWidth + newWidth;
                int newWindowHeight = dlgWindowHeight - dlgHeight
                        + Math.min(view.findViewById(R.id.post_frame_main).getMeasuredHeight(), dlgHeight);
                dialog.getWindow().setLayout(newWindowWidth, newWindowHeight);
                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                if (coordinates.x > activityWindowRect.width() - coordinates.x
                        && coordinates.x + newWindowWidth > activityWindowRect.width()) {
                    params.x = activityWindowRect.width() - coordinates.x;
                    params.gravity = Gravity.RIGHT;
                } else {
                    params.x = coordinates.x;
                    params.gravity = Gravity.LEFT;
                }
                if (coordinates.y > activityWindowRect.height() - coordinates.y
                        && coordinates.y + newWindowHeight > activityWindowRect.height()) {
                    params.y = activityWindowRect.height() - coordinates.y;
                    params.gravity |= Gravity.BOTTOM;
                } else {
                    params.y = coordinates.y;
                    params.gravity |= Gravity.TOP;
                }
                dialog.getWindow().setAttributes(params);

                //     
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    CompatibilityImpl.setDimAmount(dialog.getWindow(), 0.1f);
                } else {
                    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                }
            }
            dialog.show();
            dialogs.add(dialog);
        }
    };

    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void showMenuItemToast(final View v, final CharSequence text) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    v.getLocationOnScreen(screenPos);/*ww  w  .  j  a v a  2 s.c o m*/
    v.getWindowVisibleDisplayFrame(displayFrame);
    final int height = v.getHeight();
    final int midy = screenPos[1] + height / 2;
    showMenuItemToast(v, text, midy >= displayFrame.height());
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void showMenuItemToast(final View v, final CharSequence text, final boolean isBottomBar) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    v.getLocationOnScreen(screenPos);/*from  w  w w  . jav  a 2  s  .  c om*/
    v.getWindowVisibleDisplayFrame(displayFrame);
    final int width = v.getWidth();
    final int height = v.getHeight();
    final int screenWidth = v.getResources().getDisplayMetrics().widthPixels;
    final Toast cheatSheet = Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT);
    if (isBottomBar) {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    } else {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height);
    }
    cheatSheet.show();
}