1 /* 2 * Copyright (C) 2016 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.launcher3.anim; 18 19 import android.animation.Animator; 20 import android.animation.TimeInterpolator; 21 import android.util.FloatProperty; 22 import android.util.IntProperty; 23 import android.view.View; 24 25 /** 26 * Utility class for setting a property with or without animation 27 */ 28 public interface PropertySetter { 29 30 PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter() { }; 31 32 /** 33 * Sets the view alpha using the provided interpolator. 34 * Unlike {@link #setFloat}, this also updates the visibility of the view as alpha changes 35 * between zero and non-zero. 36 */ setViewAlpha(View view, float alpha, TimeInterpolator interpolator)37 default void setViewAlpha(View view, float alpha, TimeInterpolator interpolator) { 38 if (view != null) { 39 view.setAlpha(alpha); 40 AlphaUpdateListener.updateVisibility(view); 41 } 42 } 43 44 /** 45 * Sets the background color of the provided view using the provided interpolator. 46 */ setViewBackgroundColor(View view, int color, TimeInterpolator interpolator)47 default void setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) { 48 if (view != null) { 49 view.setBackgroundColor(color); 50 } 51 } 52 53 /** 54 * Updates the float property of the target using the provided interpolator 55 */ setFloat(T target, FloatProperty<T> property, float value, TimeInterpolator interpolator)56 default <T> void setFloat(T target, FloatProperty<T> property, float value, 57 TimeInterpolator interpolator) { 58 property.setValue(target, value); 59 } 60 61 /** 62 * Updates the int property of the target using the provided interpolator 63 */ setInt(T target, IntProperty<T> property, int value, TimeInterpolator interpolator)64 default <T> void setInt(T target, IntProperty<T> property, int value, 65 TimeInterpolator interpolator) { 66 property.setValue(target, value); 67 } 68 add(Animator animatorSet)69 default void add(Animator animatorSet) { 70 animatorSet.setDuration(0); 71 animatorSet.start(); 72 } 73 } 74