1/* 2 * Copyright (C) 2015 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 17package com.android.tv.ui; 18 19import android.animation.Animator; 20import android.animation.AnimatorListenerAdapter; 21import android.view.View; 22 23/** 24 * An AnimatorListenerAdapter subclass that conveniently sets the layer type to hardware during the 25 * animation. 26 */ 27public class HardwareLayerAnimatorListenerAdapter extends AnimatorListenerAdapter { 28 private final View mView; 29 private boolean mLayerTypeChanged; 30 31 public HardwareLayerAnimatorListenerAdapter(View view) { 32 mView = view; 33 } 34 35 @Override 36 public void onAnimationStart(Animator animator) { 37 if (mView.hasOverlappingRendering() && mView.getLayerType() == View.LAYER_TYPE_NONE) { 38 mLayerTypeChanged = true; 39 mView.setLayerType(View.LAYER_TYPE_HARDWARE, null); 40 } 41 } 42 43 @Override 44 public void onAnimationEnd(Animator animator) { 45 if (mLayerTypeChanged) { 46 mLayerTypeChanged = false; 47 mView.setLayerType(View.LAYER_TYPE_NONE, null); 48 } 49 } 50} 51