Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87e546da authored by Liran Binyamin's avatar Liran Binyamin Committed by Android (Google) Code Review
Browse files

Merge "Fix fling to dismiss behavior" into main

parents 30299ac0 cdf9a815
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.bubbles.animation;
import static android.view.View.LAYOUT_DIRECTION_RTL;

import static com.android.wm.shell.bubbles.BubblePositioner.NUM_VISIBLE_WHEN_RESTING;
import static com.android.wm.shell.bubbles.animation.FlingToDismissUtils.getFlingToDismissTargetWidth;

import android.content.res.Resources;
import android.graphics.Path;
@@ -375,6 +376,9 @@ public class ExpandedAnimationController
        mMagnetizedBubbleDraggingOut.setMagnetListener(listener);
        mMagnetizedBubbleDraggingOut.setHapticsEnabled(true);
        mMagnetizedBubbleDraggingOut.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY);
        int screenWidthPx = mLayout.getContext().getResources().getDisplayMetrics().widthPixels;
        mMagnetizedBubbleDraggingOut.setFlingToTargetWidthPercent(
                getFlingToDismissTargetWidth(screenWidthPx));
    }

    private void springBubbleTo(View bubble, float x, float y) {
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.bubbles.animation

/** Utils related to the fling to dismiss animation. */
object FlingToDismissUtils {

    /** The target width surrounding the dismiss target on a small width screen, e.g. phone. */
    private const val FLING_TO_DISMISS_TARGET_WIDTH_SMALL = 3f
    /**
     * The target width surrounding the dismiss target on a medium width screen, e.g. tablet in
     * portrait.
     */
    private const val FLING_TO_DISMISS_TARGET_WIDTH_MEDIUM = 4.5f
    /**
     * The target width surrounding the dismiss target on a large width screen, e.g. tablet in
     * landscape.
     */
    private const val FLING_TO_DISMISS_TARGET_WIDTH_LARGE = 6f

    /** Returns the dismiss target width for the specified [screenWidthPx]. */
    @JvmStatic
    fun getFlingToDismissTargetWidth(screenWidthPx: Int) = when {
        screenWidthPx >= 2000 -> FLING_TO_DISMISS_TARGET_WIDTH_LARGE
        screenWidthPx >= 1500 -> FLING_TO_DISMISS_TARGET_WIDTH_MEDIUM
        else -> FLING_TO_DISMISS_TARGET_WIDTH_SMALL
    }
}
+12 −17
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.bubbles.animation;

import static com.android.wm.shell.bubbles.BubblePositioner.NUM_VISIBLE_WHEN_RESTING;
import static com.android.wm.shell.bubbles.animation.FlingToDismissUtils.getFlingToDismissTargetWidth;

import android.content.ContentResolver;
import android.content.res.Resources;
@@ -851,6 +852,15 @@ public class StackAnimationController extends
        if (mLayout != null) {
            Resources res = mLayout.getContext().getResources();
            mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
            updateFlingToDismissTargetWidth();
        }
    }

    private void updateFlingToDismissTargetWidth() {
        if (mLayout != null && mMagnetizedStack != null) {
            int screenWidthPx = mLayout.getResources().getDisplayMetrics().widthPixels;
            mMagnetizedStack.setFlingToTargetWidthPercent(
                    getFlingToDismissTargetWidth(screenWidthPx));
        }
    }

@@ -1022,23 +1032,8 @@ public class StackAnimationController extends
            };
            mMagnetizedStack.setHapticsEnabled(true);
            mMagnetizedStack.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY);
            updateFlingToDismissTargetWidth();
        }

        final ContentResolver contentResolver = mLayout.getContext().getContentResolver();
        final float minVelocity = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_fling_min_velocity",
                mMagnetizedStack.getFlingToTargetMinVelocity() /* default */);
        final float maxVelocity = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_stick_max_velocity",
                mMagnetizedStack.getStickToTargetMaxXVelocity() /* default */);
        final float targetWidth = Settings.Secure.getFloat(contentResolver,
                "bubble_dismiss_target_width_percent",
                mMagnetizedStack.getFlingToTargetWidthPercent() /* default */);

        mMagnetizedStack.setFlingToTargetMinVelocity(minVelocity);
        mMagnetizedStack.setStickToTargetMaxXVelocity(maxVelocity);
        mMagnetizedStack.setFlingToTargetWidthPercent(targetWidth);

        return mMagnetizedStack;
    }

@@ -1053,7 +1048,7 @@ public class StackAnimationController extends
     * property directly to move the first bubble and cause the stack to 'follow' to the new
     * location.
     *
     * This could also be achieved by simply animating the first bubble view and adding an update
     * <p>This could also be achieved by simply animating the first bubble view and adding an update
     * listener to dispatch movement to the rest of the stack. However, this would require
     * duplication of logic in that update handler - it's simpler to keep all logic contained in the
     * {@link #moveFirstBubbleWithStackFollowing} method.