Search in sources :

Example 91 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class FloatingIconView method update.

/**
 * Positions this view to match the size and location of {@param rect}.
 * @param alpha The alpha to set this view.
 * @param progress A value from [0, 1] that represents the animation progress.
 * @param shapeProgressStart The progress value at which to start the shape reveal.
 * @param cornerRadius The corner radius of {@param rect}.
 */
public void update(RectF rect, float alpha, float progress, float shapeProgressStart, float cornerRadius, boolean isOpening) {
    setAlpha(alpha);
    LayoutParams lp = (LayoutParams) getLayoutParams();
    float dX = mIsRtl ? rect.left - (mLauncher.getDeviceProfile().widthPx - lp.getMarginStart() - lp.width) : rect.left - lp.getMarginStart();
    float dY = rect.top - lp.topMargin;
    setTranslationX(dX);
    setTranslationY(dY);
    float minSize = Math.min(lp.width, lp.height);
    float scaleX = rect.width() / minSize;
    float scaleY = rect.height() / minSize;
    float scale = Math.max(1f, Math.min(scaleX, scaleY));
    setPivotX(0);
    setPivotY(0);
    setScaleX(scale);
    setScaleY(scale);
    // shapeRevealProgress = 1 when progress = shapeProgressStart + SHAPE_PROGRESS_DURATION
    float toMax = isOpening ? 1 / SHAPE_PROGRESS_DURATION : 1f;
    float shapeRevealProgress = Utilities.boundToRange(mapToRange(Math.max(shapeProgressStart, progress), shapeProgressStart, 1f, 0, toMax, LINEAR), 0, 1);
    if (mIsVerticalBarLayout) {
        mOutline.right = (int) (rect.width() / scale);
    } else {
        mOutline.bottom = (int) (rect.height() / scale);
    }
    mTaskCornerRadius = cornerRadius / scale;
    if (mIsAdaptiveIcon) {
        if (!isOpening && progress >= shapeProgressStart) {
            if (mRevealAnimator == null) {
                mRevealAnimator = (ValueAnimator) IconShape.getShape().createRevealAnimator(this, mStartRevealRect, mOutline, mTaskCornerRadius, !isOpening);
                mRevealAnimator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mRevealAnimator = null;
                    }
                });
                mRevealAnimator.start();
                // We pause here so we can set the current fraction ourselves.
                mRevealAnimator.pause();
            }
            mRevealAnimator.setCurrentFraction(shapeRevealProgress);
        }
        float drawableScale = (mIsVerticalBarLayout ? mOutline.width() : mOutline.height()) / minSize;
        setBackgroundDrawableBounds(drawableScale);
        if (isOpening) {
            // Center align foreground
            int height = mFinalDrawableBounds.height();
            int width = mFinalDrawableBounds.width();
            int diffY = mIsVerticalBarLayout ? 0 : (int) (((height * drawableScale) - height) / 2);
            int diffX = mIsVerticalBarLayout ? (int) (((width * drawableScale) - width) / 2) : 0;
            sTmpRect.set(mFinalDrawableBounds);
            sTmpRect.offset(diffX, diffY);
            mForeground.setBounds(sTmpRect);
        } else {
            // Spring the foreground relative to the icon's movement within the DragLayer.
            int diffX = (int) (dX / mLauncher.getDeviceProfile().availableWidthPx * FG_TRANS_X_FACTOR);
            int diffY = (int) (dY / mLauncher.getDeviceProfile().availableHeightPx * FG_TRANS_Y_FACTOR);
            mFgSpringX.animateToFinalPosition(diffX);
            mFgSpringY.animateToFinalPosition(diffY);
        }
    }
    invalidate();
    invalidateOutline();
}
Also used : LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 92 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class QsbBlockerView method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mView != null && mState == 2) {
        Launcher launcher = OmegaUtilsKt.getLauncherOrNull(getContext());
        int size;
        if (launcher != null) {
            DeviceProfile deviceProfile = launcher.getDeviceProfile();
            if (launcher.useVerticalBarLayout()) {
                size = ((MeasureSpec.getSize(widthMeasureSpec) / deviceProfile.inv.numColumns) - deviceProfile.iconSizePx) / 2;
            } else {
                size = 0;
            }
        } else {
            size = getResources().getDimensionPixelSize(R.dimen.smartspace_preview_widget_margin);
        }
        LayoutParams layoutParams = (LayoutParams) mView.getLayoutParams();
        layoutParams.leftMargin = layoutParams.rightMargin = size;
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Launcher(com.android.launcher3.Launcher) Paint(android.graphics.Paint)

Example 93 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class FolderAnimationManager method addPreviewItemAnimators.

/**
 * Animate the items on the current page.
 */
private void addPreviewItemAnimators(AnimatorSet animatorSet, final float folderScale, int previewItemOffsetX, int previewItemOffsetY) {
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    boolean isOnFirstPage = mFolder.mContent.getCurrentPage() == 0;
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(isOnFirstPage ? 0 : mFolder.mContent.getCurrentPage());
    final int numItemsInPreview = itemsInPreview.size();
    final int numItemsInFirstPagePreview = isOnFirstPage ? numItemsInPreview : MAX_NUM_ITEMS_IN_PREVIEW;
    TimeInterpolator previewItemInterpolator = getPreviewItemInterpolator();
    ShortcutAndWidgetContainer cwc = mContent.getPageAt(0).getShortcutsAndWidgets();
    for (int i = 0; i < numItemsInPreview; ++i) {
        final BubbleTextView btv = itemsInPreview.get(i);
        CellLayout.LayoutParams btvLp = (CellLayout.LayoutParams) btv.getLayoutParams();
        // Calculate the final values in the LayoutParams.
        btvLp.isLockedToGrid = true;
        cwc.setupLp(btv);
        // Match scale of icons in the preview of the items on the first page.
        float previewScale = rule.scaleForItem(numItemsInFirstPagePreview);
        float previewSize = rule.getIconSize() * previewScale;
        float iconScale = previewSize / itemsInPreview.get(i).getIconSize();
        final float initialScale = iconScale / folderScale;
        final float finalScale = 1f;
        float scale = mIsOpening ? initialScale : finalScale;
        btv.setScaleX(scale);
        btv.setScaleY(scale);
        // Match positions of the icons in the folder with their positions in the preview
        rule.computePreviewItemDrawingParams(i, numItemsInFirstPagePreview, mTmpParams);
        // The PreviewLayoutRule assumes that the icon size takes up the entire width so we
        // offset by the actual size.
        int iconOffsetX = (int) ((btvLp.width - btv.getIconSize()) * iconScale) / 2;
        final int previewPosX = (int) ((mTmpParams.transX - iconOffsetX + previewItemOffsetX) / folderScale);
        final int previewPosY = (int) ((mTmpParams.transY + previewItemOffsetY) / folderScale);
        final float xDistance = previewPosX - btvLp.x;
        final float yDistance = previewPosY - btvLp.y;
        Animator translationX = getAnimator(btv, View.TRANSLATION_X, xDistance, 0f);
        translationX.setInterpolator(previewItemInterpolator);
        play(animatorSet, translationX);
        Animator translationY = getAnimator(btv, View.TRANSLATION_Y, yDistance, 0f);
        translationY.setInterpolator(previewItemInterpolator);
        play(animatorSet, translationY);
        Animator scaleAnimator = getAnimator(btv, SCALE_PROPERTY, initialScale, finalScale);
        scaleAnimator.setInterpolator(previewItemInterpolator);
        play(animatorSet, scaleAnimator);
        if (mFolder.getItemCount() > MAX_NUM_ITEMS_IN_PREVIEW) {
            // These delays allows the preview items to move as part of the Folder's motion,
            // and its only necessary for large folders because of differing interpolators.
            int delay = mIsOpening ? mDelay : mDelay * 2;
            if (mIsOpening) {
                translationX.setStartDelay(delay);
                translationY.setStartDelay(delay);
                scaleAnimator.setStartDelay(delay);
            }
            translationX.setDuration(translationX.getDuration() - delay);
            translationY.setDuration(translationY.getDuration() - delay);
            scaleAnimator.setDuration(scaleAnimator.getDuration() - delay);
        }
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                // Necessary to initialize values here because of the start delay.
                if (mIsOpening) {
                    btv.setTranslationX(xDistance);
                    btv.setTranslationY(yDistance);
                    btv.setScaleX(initialScale);
                    btv.setScaleY(initialScale);
                }
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                btv.setTranslationX(0.0f);
                btv.setTranslationY(0.0f);
                btv.setScaleX(1f);
                btv.setScaleY(1f);
            }
        });
    }
}
Also used : ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) TimeInterpolator(android.animation.TimeInterpolator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 94 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project android_packages_apps_Trebuchet by LineageOS.

the class FloatingSurfaceView method updateIconLocation.

private void updateIconLocation() {
    if (mContract == null) {
        return;
    }
    View icon = mLauncher.getWorkspace().getFirstMatchForAppClose(mContract.componentName.getPackageName(), mContract.user);
    boolean iconChanged = mIcon != icon;
    if (iconChanged) {
        setCurrentIconVisible(true);
        mIcon = icon;
        setCurrentIconVisible(false);
    }
    if (icon != null && icon.isAttachedToWindow()) {
        getLocationBoundsForView(mLauncher, icon, false, mTmpPosition, mIconBounds);
        if (!mTmpPosition.equals(mIconPosition)) {
            mIconPosition.set(mTmpPosition);
            sendIconInfo();
            LayoutParams lp = (LayoutParams) mSurfaceView.getLayoutParams();
            lp.width = Math.round(mIconPosition.width());
            lp.height = Math.round(mIconPosition.height());
            lp.leftMargin = Math.round(mIconPosition.left);
            lp.topMargin = Math.round(mIconPosition.top);
        }
    }
    if (iconChanged && !mIconBounds.isEmpty()) {
        // Record the icon display
        setCurrentIconVisible(true);
        Canvas c = mPicture.beginRecording(mIconBounds.width(), mIconBounds.height());
        c.translate(-mIconBounds.left, -mIconBounds.top);
        mIcon.draw(c);
        mPicture.endRecording();
        setCurrentIconVisible(false);
        drawOnSurface();
    }
}
Also used : Canvas(android.graphics.Canvas) SurfaceView(android.view.SurfaceView) FloatingIconView.getLocationBoundsForView(com.android.launcher3.views.FloatingIconView.getLocationBoundsForView) View(android.view.View) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 95 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project android_packages_apps_Trebuchet by LineageOS.

the class TaskView method setOrientationState.

public void setOrientationState(RecentsOrientedState orientationState) {
    PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
    boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
    LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
    int thumbnailPadding = (int) getResources().getDimension(R.dimen.task_thumbnail_top_margin);
    LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();
    switch(orientationHandler.getRotation()) {
        case ROTATION_90:
            iconParams.gravity = (isRtl ? START : END) | CENTER_VERTICAL;
            iconParams.rightMargin = -thumbnailPadding;
            iconParams.leftMargin = 0;
            iconParams.topMargin = snapshotParams.topMargin / 2;
            break;
        case ROTATION_180:
            iconParams.gravity = BOTTOM | CENTER_HORIZONTAL;
            iconParams.bottomMargin = -thumbnailPadding;
            iconParams.leftMargin = iconParams.topMargin = iconParams.rightMargin = 0;
            break;
        case ROTATION_270:
            iconParams.gravity = (isRtl ? END : START) | CENTER_VERTICAL;
            iconParams.leftMargin = -thumbnailPadding;
            iconParams.rightMargin = 0;
            iconParams.topMargin = snapshotParams.topMargin / 2;
            break;
        case Surface.ROTATION_0:
        default:
            iconParams.gravity = TOP | CENTER_HORIZONTAL;
            iconParams.leftMargin = iconParams.topMargin = iconParams.rightMargin = 0;
            break;
    }
    mIconView.setLayoutParams(iconParams);
    mIconView.setRotation(orientationHandler.getDegreesRotated());
    if (mMenuView != null) {
        mMenuView.onRotationChanged();
    }
}
Also used : PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler)

Aggregations

View (android.view.View)79 SuppressLint (android.annotation.SuppressLint)61 Paint (android.graphics.Paint)59 Point (android.graphics.Point)58 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)49 DraggableView (com.android.launcher3.dragndrop.DraggableView)40 CellAndSpan (com.android.launcher3.util.CellAndSpan)35 Rect (android.graphics.Rect)23 BubbleTextView (com.android.launcher3.BubbleTextView)21 ItemInfo (com.android.launcher3.model.data.ItemInfo)17 Animator (android.animation.Animator)16 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)16 ObjectAnimator (android.animation.ObjectAnimator)15 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)15 FrameLayout (android.widget.FrameLayout)13 DeviceProfile (com.android.launcher3.DeviceProfile)13 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)10 ValueAnimator (android.animation.ValueAnimator)9 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)8 TimeInterpolator (android.animation.TimeInterpolator)7