Search in sources :

Example 1 with BaseDragLayer

use of com.android.launcher3.views.BaseDragLayer in project android_packages_apps_Launcher3 by crdroidandroid.

the class Folder method animateOpen.

/**
 * Opens the user folder described by the specified tag. The opening of the folder
 * is animated relative to the specified View. If the View is null, no animation
 * is played.
 */
private void animateOpen(List<WorkspaceItemInfo> items, int pageNo) {
    Folder openFolder = getOpen(mActivityContext);
    if (openFolder != null && openFolder != this) {
        // Close any open folder before opening a folder.
        openFolder.close(true);
    }
    mContent.bindItems(items);
    centerAboutIcon();
    mItemsInvalidated = true;
    updateTextViewFocus();
    mIsOpen = true;
    BaseDragLayer dragLayer = mActivityContext.getDragLayer();
    // There was a one-off crash where the folder had a parent already.
    if (getParent() == null) {
        dragLayer.addView(this);
        mDragController.addDropTarget(this);
    } else {
        if (FeatureFlags.IS_STUDIO_BUILD) {
            Log.e(TAG, "Opening folder (" + this + ") which already has a parent:" + getParent());
        }
    }
    mContent.completePendingPageChanges();
    mContent.setCurrentPage(pageNo);
    // This is set to true in close(), but isn't reset to false until onDropCompleted(). This
    // leads to an inconsistent state if you drag out of the folder and drag back in without
    // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
    mDeleteFolderOnDropCompleted = false;
    cancelRunningAnimations();
    FolderAnimationManager fam = new FolderAnimationManager(this, true);
    AnimatorSet anim = fam.getAnimator();
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mFolderIcon.setIconVisible(false);
            mFolderIcon.drawLeaveBehindIfExists();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            announceAccessibilityChanges();
            mContent.setFocusOnFirstChild();
        }
    });
    // Footer animation
    if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
        int footerWidth = mContent.getDesiredWidth() - mFooter.getPaddingLeft() - mFooter.getPaddingRight();
        float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
        float translation = (footerWidth - textWidth) / 2;
        mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation);
        mPageIndicator.prepareEntryAnimation();
        // Do not update the flag if we are in drag mode. The flag will be updated, when we
        // actually drop the icon.
        final boolean updateAnimationFlag = !mDragInProgress;
        anim.addListener(new AnimatorListenerAdapter() {

            @SuppressLint("InlinedApi")
            @Override
            public void onAnimationEnd(Animator animation) {
                mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION).translationX(0).setInterpolator(AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in));
                mPageIndicator.playEntryAnimation();
                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncherDelegate.getModelWriter());
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }
    mPageIndicator.stopAllAnimations();
    startAnimation(anim);
    // Because t=0 has the folder match the folder icon, we can skip the
    // first frame and have the same movement one frame earlier.
    anim.setCurrentPlayTime(Math.min(getSingleFrameMs(getContext()), anim.getTotalDuration()));
    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
    mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SuppressLint(android.annotation.SuppressLint) AnimatorSet(android.animation.AnimatorSet) SuppressLint(android.annotation.SuppressLint)

Example 2 with BaseDragLayer

use of com.android.launcher3.views.BaseDragLayer in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskViewTouchController method reInitAnimationController.

private void reInitAnimationController(boolean goingUp) {
    if (mCurrentAnimation != null && mCurrentAnimationIsGoingUp == goingUp) {
        // No need to init
        return;
    }
    if ((goingUp && !mAllowGoingUp) || (!goingUp && !mAllowGoingDown)) {
        // Trying to re-init in an unsupported direction.
        return;
    }
    if (mCurrentAnimation != null) {
        mCurrentAnimation.setPlayFraction(0);
        mCurrentAnimation.getTarget().removeListener(this);
        mCurrentAnimation.dispatchOnCancel();
    }
    PagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler();
    mCurrentAnimationIsGoingUp = goingUp;
    BaseDragLayer dl = mActivity.getDragLayer();
    final int secondaryLayerDimension = orientationHandler.getSecondaryDimension(dl);
    long maxDuration = 2 * secondaryLayerDimension;
    int verticalFactor = orientationHandler.getTaskDragDisplacementFactor(mIsRtl);
    int secondaryTaskDimension = orientationHandler.getSecondaryDimension(mTaskBeingDragged);
    // The interpolator controlling the most prominent visual movement. We use this to determine
    // whether we passed SUCCESS_TRANSITION_PROGRESS.
    final Interpolator currentInterpolator;
    PendingAnimation pa;
    if (goingUp) {
        currentInterpolator = Interpolators.LINEAR;
        pa = mRecentsView.createTaskDismissAnimation(mTaskBeingDragged, true, /* animateTaskView */
        true, /* removeTask */
        maxDuration);
        mEndDisplacement = -secondaryTaskDimension;
    } else {
        currentInterpolator = Interpolators.ZOOM_IN;
        pa = mRecentsView.createTaskLaunchAnimation(mTaskBeingDragged, maxDuration, currentInterpolator);
        // Since the thumbnail is what is filling the screen, based the end displacement on it.
        View thumbnailView = mTaskBeingDragged.getThumbnail();
        mTempCords[1] = orientationHandler.getSecondaryDimension(thumbnailView);
        dl.getDescendantCoordRelativeToSelf(thumbnailView, mTempCords);
        mEndDisplacement = secondaryLayerDimension - mTempCords[1];
    }
    mEndDisplacement *= verticalFactor;
    mCurrentAnimation = pa.createPlaybackController();
    // Setting this interpolator doesn't affect the visual motion, but is used to determine
    // whether we successfully reached the target state in onDragEnd().
    mCurrentAnimation.getTarget().setInterpolator(currentInterpolator);
    onUserControlledAnimationCreated(mCurrentAnimation);
    mCurrentAnimation.getTarget().addListener(this);
    mCurrentAnimation.dispatchOnStart();
    mProgressMultiplier = 1 / mEndDisplacement;
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) PendingAnimation(com.android.launcher3.anim.PendingAnimation) PagedOrientationHandler(com.android.launcher3.touch.PagedOrientationHandler) Interpolator(android.view.animation.Interpolator) TaskView(com.android.quickstep.views.TaskView) View(android.view.View) RecentsView(com.android.quickstep.views.RecentsView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 3 with BaseDragLayer

use of com.android.launcher3.views.BaseDragLayer in project android_packages_apps_Launcher3 by crdroidandroid.

the class Snackbar method show.

public static void show(BaseDraggingActivity activity, int labelStringResId, int actionStringResId, Runnable onDismissed, Runnable onActionClicked) {
    closeOpenViews(activity, true, TYPE_SNACKBAR);
    Snackbar snackbar = new Snackbar(activity, null);
    // Set some properties here since inflated xml only contains the children.
    snackbar.setOrientation(HORIZONTAL);
    snackbar.setGravity(Gravity.CENTER_VERTICAL);
    Resources res = activity.getResources();
    snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
    int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
    snackbar.setPadding(padding, padding, padding, padding);
    snackbar.setBackgroundResource(R.drawable.round_rect_primary);
    snackbar.mIsOpen = true;
    BaseDragLayer dragLayer = activity.getDragLayer();
    dragLayer.addView(snackbar);
    DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
    params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
    int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
    int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
    int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
    Rect insets = activity.getDeviceProfile().getInsets();
    int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
    int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
    params.width = minWidth;
    params.setMargins(0, 0, 0, marginBottom + insets.bottom);
    TextView labelView = snackbar.findViewById(R.id.label);
    TextView actionView = snackbar.findViewById(R.id.action);
    String labelText = res.getString(labelStringResId);
    String actionText = res.getString(actionStringResId);
    int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionView.getPaint().measureText(actionText)) + labelView.getPaddingRight() + labelView.getPaddingLeft() + actionView.getPaddingRight() + actionView.getPaddingLeft() + padding * 2;
    if (totalContentWidth > params.width) {
        // The text doesn't fit in our standard width so update width to accommodate.
        if (totalContentWidth <= maxWidth) {
            params.width = totalContentWidth;
        } else {
            // One line will be cut off, fallback to 2 lines and smaller font. (This should only
            // happen in some languages if system display and font size are set to largest.)
            int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
            float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
            labelView.setLines(2);
            labelView.getLayoutParams().height = textHeight * 2;
            actionView.getLayoutParams().height = textHeight * 2;
            labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
            actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
            params.height += textHeight;
            params.width = maxWidth;
        }
    }
    labelView.setText(labelText);
    actionView.setText(actionText);
    actionView.setOnClickListener(v -> {
        if (onActionClicked != null) {
            onActionClicked.run();
        }
        snackbar.mOnDismissed = null;
        snackbar.close(true);
    });
    snackbar.mOnDismissed = onDismissed;
    snackbar.setAlpha(0);
    snackbar.setScaleX(0.8f);
    snackbar.setScaleY(0.8f);
    snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
    int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
    snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) Rect(android.graphics.Rect) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Example 4 with BaseDragLayer

use of com.android.launcher3.views.BaseDragLayer in project android_packages_apps_Launcher3 by crdroidandroid.

the class ArrowPopup method onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    // enforce contained is within screen
    BaseDragLayer dragLayer = getPopupContainer();
    Rect insets = dragLayer.getInsets();
    if (getTranslationX() + l < insets.left || getTranslationX() + r > dragLayer.getWidth() - insets.right) {
        // If we are still off screen, center horizontally too.
        mGravity |= Gravity.CENTER_HORIZONTAL;
    }
    if (Gravity.isHorizontal(mGravity)) {
        setX(dragLayer.getWidth() / 2 - getMeasuredWidth() / 2);
        mArrow.setVisibility(INVISIBLE);
    }
    if (Gravity.isVertical(mGravity)) {
        setY(dragLayer.getHeight() / 2 - getMeasuredHeight() / 2);
    }
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Rect(android.graphics.Rect)

Example 5 with BaseDragLayer

use of com.android.launcher3.views.BaseDragLayer in project android_packages_apps_Launcher3 by crdroidandroid.

the class StatefulActivity method onStop.

@Override
protected void onStop() {
    BaseDragLayer dragLayer = getDragLayer();
    final boolean wasActive = isUserActive();
    final STATE_TYPE origState = getStateManager().getState();
    final int origDragLayerChildCount = dragLayer.getChildCount();
    super.onStop();
    if (!isChangingConfigurations()) {
        getStateManager().moveToRestState();
    }
    // Workaround for b/78520668, explicitly trim memory once UI is hidden
    onTrimMemory(TRIM_MEMORY_UI_HIDDEN);
    if (wasActive) {
        // The expected condition is that this activity is stopped because the device goes to
        // sleep and the UI may have noticeable changes.
        dragLayer.post(() -> {
            if ((!getStateManager().isInStableState(origState) || // The drag layer may be animating (e.g. dismissing QSB).
            dragLayer.getAlpha() < 1 || // Maybe an ArrowPopup is closed.
            dragLayer.getChildCount() != origDragLayerChildCount)) {
                onUiChangedWhileSleeping();
            }
        });
    }
}
Also used : BaseDragLayer(com.android.launcher3.views.BaseDragLayer)

Aggregations

BaseDragLayer (com.android.launcher3.views.BaseDragLayer)6 SuppressLint (android.annotation.SuppressLint)2 Rect (android.graphics.Rect)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 Resources (android.content.res.Resources)1 View (android.view.View)1 Interpolator (android.view.animation.Interpolator)1 TextView (android.widget.TextView)1 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)1 PendingAnimation (com.android.launcher3.anim.PendingAnimation)1 DragLayer (com.android.launcher3.dragndrop.DragLayer)1 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)1 RecentsView (com.android.quickstep.views.RecentsView)1 TaskView (com.android.quickstep.views.TaskView)1