Search in sources :

Example 26 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DragController method startDrag.

/**
     * Starts a drag.
     *
     * @param b The bitmap to display as the drag image.  It will be re-scaled to the
     *          enlarged size.
     * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
     * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
     * @param source An object representing where the drag originated
     * @param dragInfo The data associated with the object that is being dragged
     * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
     *        {@link #DRAG_ACTION_COPY}
     * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
     *          Makes dragging feel more precise, e.g. you can clip out a transparent border
     */
public void startDrag(Bitmap b, int dragLayerX, int dragLayerY, DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion, float initialDragViewScale) {
    if (PROFILE_DRAWING_DURING_DRAG) {
        android.os.Debug.startMethodTracing("Launcher");
    }
    // Hide soft keyboard, if visible
    if (mInputMethodManager == null) {
        mInputMethodManager = (InputMethodManager) mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
    }
    mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
    for (DragListener listener : mListeners) {
        listener.onDragStart(source, dragInfo, dragAction);
    }
    final int registrationX = mMotionDownX - dragLayerX;
    final int registrationY = mMotionDownY - dragLayerY;
    final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
    final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
    mDragging = true;
    mDragObject = new DropTarget.DragObject();
    mDragObject.dragComplete = false;
    mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
    mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
    mDragObject.dragSource = source;
    mDragObject.dragInfo = dragInfo;
    final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX, registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale);
    if (dragOffset != null) {
        dragView.setDragVisualizeOffset(new Point(dragOffset));
    }
    if (dragRegion != null) {
        dragView.setDragRegion(new Rect(dragRegion));
    }
    mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    dragView.show(mMotionDownX, mMotionDownY);
    handleMoveEvent(mMotionDownX, mMotionDownY);
}
Also used : Rect(android.graphics.Rect) Point(android.graphics.Point) Point(android.graphics.Point)

Example 27 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DragLayer method handleTouchDown.

private boolean handleTouchDown(MotionEvent ev, boolean intercept) {
    Rect hitRect = new Rect();
    int x = (int) ev.getX();
    int y = (int) ev.getY();
    for (AppWidgetResizeFrame child : mResizeFrames) {
        child.getHitRect(hitRect);
        if (hitRect.contains(x, y)) {
            if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) {
                mCurrentResizeFrame = child;
                mXDown = x;
                mYDown = y;
                requestDisallowInterceptTouchEvent(true);
                return true;
            }
        }
    }
    Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
    if (currentFolder != null && !mLauncher.isFolderClingVisible() && intercept) {
        if (currentFolder.isEditingName()) {
            if (!isEventOverFolderTextRegion(currentFolder, ev)) {
                currentFolder.dismissEditingName();
                return true;
            }
        }
        getDescendantRectRelativeToSelf(currentFolder, hitRect);
        if (!isEventOverFolder(currentFolder, ev)) {
            mLauncher.closeFolder();
            return true;
        }
    }
    return false;
}
Also used : Rect(android.graphics.Rect)

Example 28 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DragLayer method animateViewIntoPosition.

public void animateViewIntoPosition(DragView dragView, final int[] pos, float alpha, float scaleX, float scaleY, int animationEndStyle, Runnable onFinishRunnable, int duration) {
    Rect r = new Rect();
    getViewRectRelativeToSelf(dragView, r);
    final int fromX = r.left;
    final int fromY = r.top;
    animateViewIntoPosition(dragView, fromX, fromY, pos[0], pos[1], alpha, 1, 1, scaleX, scaleY, onFinishRunnable, animationEndStyle, duration, null);
}
Also used : Rect(android.graphics.Rect)

Example 29 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DynamicGrid method updateFromConfiguration.

void updateFromConfiguration(Resources resources, int wPx, int hPx, int awPx, int ahPx) {
    isLandscape = (resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
    isTablet = resources.getBoolean(R.bool.is_tablet);
    isLargeTablet = resources.getBoolean(R.bool.is_large_tablet);
    widthPx = wPx;
    heightPx = hPx;
    availableWidthPx = awPx;
    availableHeightPx = ahPx;
    Rect padding = getWorkspacePadding(isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
    int pageIndicatorOffset = resources.getDimensionPixelSize(R.dimen.apps_customize_page_indicator_offset);
    if (isLandscape) {
        allAppsNumRows = (availableHeightPx - pageIndicatorOffset - 4 * edgeMarginPx) / (iconSizePx + iconTextSizePx + 2 * edgeMarginPx);
    } else {
        allAppsNumRows = (int) numRows + 1;
    }
    allAppsNumCols = (availableWidthPx - padding.left - padding.right - 2 * edgeMarginPx) / (iconSizePx + 2 * edgeMarginPx);
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint)

Example 30 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DynamicGrid method getWorkspacePadding.

Rect getWorkspacePadding(int orientation) {
    Rect padding = new Rect();
    if (orientation == CellLayout.LANDSCAPE && transposeLayoutWithOrientation) {
        // Pad the left and right of the workspace with search/hotseat bar sizes
        padding.set(searchBarSpaceHeightPx, edgeMarginPx, hotseatBarHeightPx, edgeMarginPx);
    } else {
        if (isTablet()) {
            // Pad the left and right of the workspace to ensure consistent spacing
            // between all icons
            int width = (orientation == CellLayout.LANDSCAPE) ? Math.max(widthPx, heightPx) : Math.min(widthPx, heightPx);
            // XXX: If the icon size changes across orientations, we will have to take
            //      that into account here too.
            int gap = (int) ((width - 2 * edgeMarginPx - (numColumns * cellWidthPx)) / (2 * (numColumns + 1)));
            padding.set(edgeMarginPx + gap, searchBarSpaceHeightPx, edgeMarginPx + gap, hotseatBarHeightPx + pageIndicatorHeightPx);
        } else {
            // Pad the top and bottom of the workspace with search/hotseat bar sizes
            padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, searchBarSpaceHeightPx, desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right, hotseatBarHeightPx + pageIndicatorHeightPx);
        }
    }
    return padding;
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint)

Aggregations

Rect (android.graphics.Rect)3823 Paint (android.graphics.Paint)791 View (android.view.View)533 Point (android.graphics.Point)470 Bitmap (android.graphics.Bitmap)333 Canvas (android.graphics.Canvas)255 Drawable (android.graphics.drawable.Drawable)203 RectF (android.graphics.RectF)176 Resources (android.content.res.Resources)101 Matrix (android.graphics.Matrix)99 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 TextPaint (android.text.TextPaint)94 RemoteException (android.os.RemoteException)93 ViewGroup (android.view.ViewGroup)89 TextView (android.widget.TextView)87 ArrayList (java.util.ArrayList)87 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)84 BitmapDrawable (android.graphics.drawable.BitmapDrawable)82 SuppressLint (android.annotation.SuppressLint)77 ImageView (android.widget.ImageView)70