• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 android.view;
18 
19 import android.animation.Animator;
20 import android.animation.AnimatorListenerAdapter;
21 import android.graphics.RenderNode;
22 
23 import androidx.annotation.NonNull;
24 
25 /**
26  * Maps a View to a RenderNode's AnimationHost
27  *
28  * @hide
29  */
30 public class ViewAnimationHostBridge extends AnimatorListenerAdapter
31         implements RenderNode.AnimationHost {
32     private final View mView;
33 
34     /**
35      * @param view the View to bridge to an AnimationHost
36      */
ViewAnimationHostBridge(View view)37     public ViewAnimationHostBridge(View view) {
38         mView = view;
39     }
40 
41     @Override
registerAnimatingRenderNode(RenderNode renderNode, Animator animator)42     public void registerAnimatingRenderNode(RenderNode renderNode, Animator animator) {
43         mView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(renderNode);
44         animator.addListener(this);
45     }
46 
47     @Override
registerVectorDrawableAnimator(NativeVectorDrawableAnimator animator)48     public void registerVectorDrawableAnimator(NativeVectorDrawableAnimator animator) {
49         mView.mAttachInfo.mViewRootImpl.registerVectorDrawableAnimator(animator);
50         animator.setThreadedRendererAnimatorListener(this);
51     }
52 
53     @Override
isAttached()54     public boolean isAttached() {
55         return mView.mAttachInfo != null;
56     }
57 
58     @Override
onAnimationStart(@onNull Animator animation)59     public void onAnimationStart(@NonNull Animator animation) {
60         ViewRootImpl viewRoot = mView.getViewRootImpl();
61         if (viewRoot != null) {
62             viewRoot.addThreadedRendererView(mView);
63         }
64     }
65 
66     @Override
onAnimationEnd(@onNull Animator animation)67     public void onAnimationEnd(@NonNull Animator animation) {
68         ViewRootImpl viewRoot = mView.getViewRootImpl();
69         if (viewRoot != null) {
70             viewRoot.removeThreadedRendererView(mView);
71         }
72     }
73 }
74