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