Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.systemui.statusbar.notification; |
| 18 | |
| 19 | import android.util.FloatProperty; |
| 20 | import android.util.Property; |
| 21 | import android.view.View; |
| 22 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 23 | import com.android.systemui.R; |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 24 | |
| 25 | import java.util.function.BiConsumer; |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 26 | import java.util.function.Function; |
| 27 | |
| 28 | /** |
| 29 | * An animatable property of a view. Used with {@link PropertyAnimator} |
| 30 | */ |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 31 | public abstract class AnimatableProperty { |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 32 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 33 | public static final AnimatableProperty X = AnimatableProperty.from(View.X, |
| 34 | R.id.x_animator_tag, R.id.x_animator_tag_start_value, R.id.x_animator_tag_end_value); |
| 35 | public static final AnimatableProperty Y = AnimatableProperty.from(View.Y, |
| 36 | R.id.y_animator_tag, R.id.y_animator_tag_start_value, R.id.y_animator_tag_end_value); |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 37 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 38 | public abstract int getAnimationStartTag(); |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 39 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 40 | public abstract int getAnimationEndTag(); |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 41 | |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 42 | public abstract int getAnimatorTag(); |
| 43 | |
| 44 | public abstract Property getProperty(); |
| 45 | |
| 46 | public static <T extends View> AnimatableProperty from(String name, BiConsumer<T, Float> setter, |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 47 | Function<T, Float> getter, int animatorTag, int startValueTag, int endValueTag) { |
| 48 | Property<T, Float> property = new FloatProperty<T>(name) { |
| 49 | |
| 50 | @Override |
| 51 | public Float get(T object) { |
| 52 | return getter.apply(object); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void setValue(T object, float value) { |
| 57 | setter.accept(object, value); |
| 58 | } |
| 59 | }; |
| 60 | return new AnimatableProperty() { |
| 61 | @Override |
| 62 | public int getAnimationStartTag() { |
| 63 | return startValueTag; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public int getAnimationEndTag() { |
| 68 | return endValueTag; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public int getAnimatorTag() { |
| 73 | return animatorTag; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Property getProperty() { |
| 78 | return property; |
| 79 | } |
| 80 | }; |
| 81 | } |
Lucas Dupin | 60661a6 | 2018-04-12 10:50:13 -0700 | [diff] [blame] | 82 | |
| 83 | public static <T extends View> AnimatableProperty from(Property<T, Float> property, |
| 84 | int animatorTag, int startValueTag, int endValueTag) { |
| 85 | return new AnimatableProperty() { |
| 86 | @Override |
| 87 | public int getAnimationStartTag() { |
| 88 | return startValueTag; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public int getAnimationEndTag() { |
| 93 | return endValueTag; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int getAnimatorTag() { |
| 98 | return animatorTag; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public Property getProperty() { |
| 103 | return property; |
| 104 | } |
| 105 | }; |
| 106 | } |
Selim Cinek | 0228a25 | 2017-11-10 17:47:27 -0800 | [diff] [blame] | 107 | } |