Home | History | Annotate | Download | only in util
      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 package com.android.quickstep.util;
     17 
     18 import static com.android.quickstep.util.RemoteAnimationProvider.prepareTargetsForFirstFrame;
     19 import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
     20 
     21 import android.animation.ValueAnimator;
     22 import android.animation.ValueAnimator.AnimatorUpdateListener;
     23 
     24 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
     25 import com.android.systemui.shared.system.TransactionCompat;
     26 
     27 /**
     28  * Animation listener which fades out the closing targets
     29  */
     30 public class RemoteFadeOutAnimationListener implements AnimatorUpdateListener {
     31 
     32     private final RemoteAnimationTargetSet mTarget;
     33     private boolean mFirstFrame = true;
     34 
     35     public RemoteFadeOutAnimationListener(RemoteAnimationTargetCompat[] targets) {
     36         mTarget = new RemoteAnimationTargetSet(targets, MODE_CLOSING);
     37     }
     38 
     39     @Override
     40     public void onAnimationUpdate(ValueAnimator valueAnimator) {
     41         TransactionCompat t = new TransactionCompat();
     42         if (mFirstFrame) {
     43             prepareTargetsForFirstFrame(mTarget.unfilteredApps, t, MODE_CLOSING);
     44             mFirstFrame = false;
     45         }
     46 
     47         float alpha = 1 - valueAnimator.getAnimatedFraction();
     48         for (RemoteAnimationTargetCompat app : mTarget.apps) {
     49             t.setAlpha(app.leash, alpha);
     50         }
     51         t.apply();
     52     }
     53 }
     54