Search in sources :

Example 6 with Rect

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

the class Folder method getContentAreaHeight.

private int getContentAreaHeight() {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
    int maxContentAreaHeight = grid.availableHeightPx - 4 * grid.edgeMarginPx - workspacePadding.top - workspacePadding.bottom - getPaddingTop() - getPaddingBottom() - mFolderNameHeight;
    return Math.min(maxContentAreaHeight, mContent.getDesiredHeight());
}
Also used : Rect(android.graphics.Rect)

Example 7 with Rect

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

the class Folder method centerAboutIcon.

private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height = getFolderHeight();
    float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
    int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    int currentPage = mLauncher.getWorkspace().getNextPage();
    // In case the workspace is scrolling, we need to use the final scroll to compute
    // the folders bounds.
    mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
    ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
    // We reset the workspaces scroll
    mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
    // We need to bound the folder to the currently visible CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) {
        // Center the folder if it is full (on phones only)
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= bounds.width()) {
        // If the folder doesn't fit within the bounds, center it about the desired bounds
        left = bounds.left + (bounds.width() - width) / 2;
    }
    if (height >= bounds.height()) {
        top = bounds.top + (bounds.height() - height) / 2;
    }
    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));
    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}
Also used : Rect(android.graphics.Rect)

Example 8 with Rect

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

the class FolderIcon method onDrop.

private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect, float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable, DragObject d) {
    item.cellX = -1;
    item.cellY = -1;
    // will not have a view to animate
    if (animateView != null) {
        DragLayer dragLayer = mLauncher.getDragLayer();
        Rect from = new Rect();
        dragLayer.getViewRectRelativeToSelf(animateView, from);
        Rect to = finalRect;
        if (to == null) {
            to = new Rect();
            Workspace workspace = mLauncher.getWorkspace();
            // Set cellLayout and this to it's final state to compute final animation locations
            workspace.setFinalTransitionTransform((CellLayout) getParent().getParent());
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
            // Finished computing final animation locations, restore current state
            setScaleX(scaleX);
            setScaleY(scaleY);
            workspace.resetTransitionTransform((CellLayout) getParent().getParent());
        }
        int[] center = new int[2];
        float scale = getLocalCenterForIndex(index, center);
        center[0] = (int) Math.round(scaleRelativeToDragLayer * center[0]);
        center[1] = (int) Math.round(scaleRelativeToDragLayer * center[1]);
        to.offset(center[0] - animateView.getMeasuredWidth() / 2, center[1] - animateView.getMeasuredHeight() / 2);
        float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;
        float finalScale = scale * scaleRelativeToDragLayer;
        dragLayer.animateView(animateView, from, to, finalAlpha, 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2), new AccelerateInterpolator(2), postAnimationRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
        addItem(item);
        mHiddenItems.add(item);
        mFolder.hideItem(item);
        postDelayed(new Runnable() {

            public void run() {
                mHiddenItems.remove(item);
                mFolder.showItem(item);
                invalidate();
            }
        }, DROP_IN_ANIMATION_DURATION);
    } else {
        addItem(item);
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Rect(android.graphics.Rect) AccelerateInterpolator(android.view.animation.AccelerateInterpolator)

Example 9 with Rect

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

the class LauncherTransitionable method startSearch.

/**
     * Indicates that we want global search for this activity by setting the globalSearch
     * argument for {@link #startSearch} to true.
     */
@Override
public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, boolean globalSearch) {
    showWorkspace(true);
    if (initialQuery == null) {
        // Use any text typed in the launcher as the initial query
        initialQuery = getTypedText();
    }
    if (appSearchData == null) {
        appSearchData = new Bundle();
        appSearchData.putString("source", "launcher-search");
    }
    Rect sourceBounds = new Rect();
    if (mSearchDropTargetBar != null) {
        sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
    }
    startSearch(initialQuery, selectInitialQuery, appSearchData, sourceBounds);
}
Also used : Rect(android.graphics.Rect) Bundle(android.os.Bundle)

Example 10 with Rect

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

the class LauncherTransitionable method getSpanForWidget.

static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, int minHeight) {
    Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
    // We want to account for the extra amount of padding that we are adding to the widget
    // to ensure that it gets the full amount of space that it has requested
    int requiredWidth = minWidth + padding.left + padding.right;
    int requiredHeight = minHeight + padding.top + padding.bottom;
    return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
}
Also used : Rect(android.graphics.Rect) Point(android.graphics.Point)

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