1 /*
2  * Copyright (C) 2020 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.car.notification.headsup.animationhelper;
18 
19 import android.animation.AnimatorInflater;
20 import android.animation.AnimatorSet;
21 import android.animation.ObjectAnimator;
22 import android.content.Context;
23 import android.view.View;
24 
25 import com.android.car.notification.R;
26 
27 /** Sample AnimationHelper that animates the notification fading in from the top of the screen. */
28 public class CarHeadsUpNotificationTopAnimationHelper implements
29         HeadsUpNotificationAnimationHelper {
30 
31     @Override
getAnimateInAnimator(Context context, View view)32     public AnimatorSet getAnimateInAnimator(Context context, View view) {
33         AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(
34                 context, R.animator.heads_up_notification_transition_in);
35         ObjectAnimator objectAnimator = (ObjectAnimator) animatorSet.getChildAnimations().get(0);
36         objectAnimator.setFloatValues(getHUNFinalPosition());
37         return animatorSet;
38     }
39 
40     @Override
getAnimateOutAnimator(Context context, View view)41     public AnimatorSet getAnimateOutAnimator(Context context, View view) {
42         return (AnimatorSet) AnimatorInflater.loadAnimator(
43                 context, R.animator.heads_up_notification_transition_out);
44     }
45 
46     @Override
resetHUNPosition(View view)47     public void resetHUNPosition(View view) {
48         view.setY(getHUNInitialPosition(view));
49         view.setAlpha(0);
50     }
51 
getHUNInitialPosition(View view)52     private float getHUNInitialPosition(View view) {
53         return -1 * view.getHeight();
54     }
55 
getHUNFinalPosition()56     private float getHUNFinalPosition() {
57         return 0f;
58     }
59 }
60