1 /*
2  * Copyright (C) 2017 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.systemui.statusbar.notification;
18 
19 import android.view.View;
20 
21 import com.android.systemui.statusbar.CrossFadeHelper;
22 import com.android.systemui.statusbar.TransformableView;
23 import com.android.systemui.statusbar.ViewTransformationHelper;
24 
25 /**
26  * A custom transformation that modifies the interpolator
27  */
28 public abstract class CustomInterpolatorTransformation
29         extends ViewTransformationHelper.CustomTransformation {
30 
31     private final int mViewType;
32 
CustomInterpolatorTransformation(int viewType)33     public CustomInterpolatorTransformation(int viewType) {
34         mViewType = viewType;
35     }
36 
37     @Override
transformTo(TransformState ownState, TransformableView notification, float transformationAmount)38     public boolean transformTo(TransformState ownState, TransformableView notification,
39             float transformationAmount) {
40         if (!hasCustomTransformation()) {
41             return false;
42         }
43         TransformState otherState = notification.getCurrentState(mViewType);
44         if (otherState == null) {
45             return false;
46         }
47         View view = ownState.getTransformedView();
48         CrossFadeHelper.fadeOut(view, transformationAmount);
49         ownState.transformViewFullyTo(otherState, this, transformationAmount);
50         otherState.recycle();
51         return true;
52     }
53 
hasCustomTransformation()54     protected boolean hasCustomTransformation() {
55         return true;
56     }
57 
58     @Override
transformFrom(TransformState ownState, TransformableView notification, float transformationAmount)59     public boolean transformFrom(TransformState ownState,
60             TransformableView notification, float transformationAmount) {
61         if (!hasCustomTransformation()) {
62             return false;
63         }
64         TransformState otherState = notification.getCurrentState(mViewType);
65         if (otherState == null) {
66             return false;
67         }
68         View view = ownState.getTransformedView();
69         CrossFadeHelper.fadeIn(view, transformationAmount, true /* remap */);
70         ownState.transformViewFullyFrom(otherState, this, transformationAmount);
71         otherState.recycle();
72         return true;
73     }
74 }
75