• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell.common.split;
18 
19 import static android.view.WindowManager.DOCKED_INVALID;
20 
21 import static com.android.wm.shell.shared.animation.Interpolators.SLOWDOWN_INTERPOLATOR;
22 
23 import android.graphics.Point;
24 import android.graphics.Rect;
25 import android.view.WindowManager;
26 
27 /**
28  * Calculation class, used when
29  * {@link com.android.wm.shell.common.split.SplitLayout#PARALLAX_DISMISSING} is the desired parallax
30  * effect.
31  */
32 public class DismissingParallaxSpec implements ParallaxSpec {
33     @Override
getParallax(Point retreatingOut, Point advancingOut, int position, DividerSnapAlgorithm snapAlgorithm, boolean isLeftRightSplit, Rect displayBounds, Rect retreatingSurface, Rect retreatingContent, Rect advancingSurface, Rect advancingContent, int dimmingSide, boolean topLeftShrink)34     public void getParallax(Point retreatingOut, Point advancingOut, int position,
35             DividerSnapAlgorithm snapAlgorithm, boolean isLeftRightSplit, Rect displayBounds,
36             Rect retreatingSurface, Rect retreatingContent, Rect advancingSurface,
37             Rect advancingContent, int dimmingSide, boolean topLeftShrink) {
38         if (dimmingSide == DOCKED_INVALID) {
39             return;
40         }
41 
42         float progressTowardScreenEdge =
43                 Math.max(0, Math.min(snapAlgorithm.calculateDismissingFraction(position), 1f));
44         int totalDismissingDistance = 0;
45         if (position < snapAlgorithm.getFirstSplitTarget().getPosition()) {
46             totalDismissingDistance = snapAlgorithm.getDismissStartTarget().getPosition()
47                     - snapAlgorithm.getFirstSplitTarget().getPosition();
48         } else if (position > snapAlgorithm.getLastSplitTarget().getPosition()) {
49             totalDismissingDistance = snapAlgorithm.getLastSplitTarget().getPosition()
50                     - snapAlgorithm.getDismissEndTarget().getPosition();
51         }
52 
53         float parallaxFraction =
54                 calculateParallaxDismissingFraction(progressTowardScreenEdge, dimmingSide);
55         if (isLeftRightSplit) {
56             retreatingOut.x = (int) (parallaxFraction * totalDismissingDistance);
57         } else {
58             retreatingOut.y = (int) (parallaxFraction * totalDismissingDistance);
59         }
60     }
61 
62     /**
63      * @return for a specified {@code fraction}, this returns an adjusted value that simulates a
64      * slowing down parallax effect
65      */
calculateParallaxDismissingFraction(float fraction, int dockSide)66     private float calculateParallaxDismissingFraction(float fraction, int dockSide) {
67         float result = SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;
68 
69         // Less parallax at the top, just because.
70         if (dockSide == WindowManager.DOCKED_TOP) {
71             result /= 2f;
72         }
73         return result;
74     }
75 }
76