Debian Codegraph @

core/java/com/android/internal/policy/ClipRectTBAnimation.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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.internal.policy;
18
19 import android.graphics.Rect;
20 import android.view.animation.ClipRectAnimation;
21 import android.view.animation.Interpolator;
22 import android.view.animation.Transformation;
23
24 /**
25 * Special case of ClipRectAnimation that animates only the top/bottom
26 * dimensions of the clip, picking up the other dimensions from whatever is
27 * set on the transform already. In addition to that, information about a vertical translation
28 * animation can be specified so this animation simulates as the clip would be applied after instead
29 * of before applying the translation.
30 */
31 public class ClipRectTBAnimation extends ClipRectAnimation {
32
33 private final int mFromTranslateY;
34 private final int mToTranslateY;
35 private final Interpolator mTranslateInterpolator;
36 private float mNormalizedTime;
37
38 /**
39 * Constructor. Passes in 0 for Left/Right parameters of ClipRectAnimation
40 */
41 public ClipRectTBAnimation(int fromT, int fromB, int toT, int toB,
42 int fromTranslateY, int toTranslateY, Interpolator translateInterpolator) {
43 super(0, fromT, 0, fromB, 0, toT, 0, toB);
44 mFromTranslateY = fromTranslateY;
45 mToTranslateY = toTranslateY;
46 mTranslateInterpolator = translateInterpolator;
47 }
48
49 @Override
50 public boolean getTransformation(long currentTime, Transformation outTransformation) {
51
52 // Hack: Because translation animation has a different interpolator, we need to duplicate
53 // code from Animation here and use it to calculate/store the uninterpolated normalized
54 // time.
55 final long startOffset = getStartOffset();
56 final long duration = getDuration();
57 float normalizedTime;
58 if (duration != 0) {
59 normalizedTime = ((float) (currentTime - (getStartTime() + startOffset))) /
60 (float) duration;
61 } else {
62 // time is a step-change with a zero duration
63 normalizedTime = currentTime < getStartTime() ? 0.0f : 1.0f;
64 }
65 mNormalizedTime = normalizedTime;
66 return super.getTransformation(currentTime, outTransformation);
67 }
68
69 /**
70 * Calculates and sets clip rect on given transformation. It uses existing values
71 * on the Transformation for Left/Right clip parameters.
72 */
73 @Override
74 protected void applyTransformation(float it, Transformation tr) {
75 float translationT = mTranslateInterpolator.getInterpolation(mNormalizedTime);
76 int translation =
77 (int) (mFromTranslateY + (mToTranslateY - mFromTranslateY) * translationT);
78 Rect oldClipRect = tr.getClipRect();
79 tr.setClipRect(oldClipRect.left,
80 mFromRect.top - translation + (int) ((mToRect.top - mFromRect.top) * it),
81 oldClipRect.right,
82 mFromRect.bottom - translation + (int) ((mToRect.bottom - mFromRect.bottom) * it));
83 }
84
85 }