blob: 75b41ca3e162eabbaa198d5f6406146bb1ce3211 [file] [log] [blame]
Selim Cinek0228a252017-11-10 17:47:27 -08001/*
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
17package com.android.systemui.statusbar.notification;
18
19import android.util.FloatProperty;
20import android.util.Property;
21import android.view.View;
22
Lucas Dupin60661a62018-04-12 10:50:13 -070023import com.android.systemui.R;
Selim Cinek0228a252017-11-10 17:47:27 -080024
25import java.util.function.BiConsumer;
Selim Cinek0228a252017-11-10 17:47:27 -080026import java.util.function.Function;
27
28/**
29 * An animatable property of a view. Used with {@link PropertyAnimator}
30 */
Lucas Dupin60661a62018-04-12 10:50:13 -070031public abstract class AnimatableProperty {
Selim Cinek0228a252017-11-10 17:47:27 -080032
Lucas Dupin60661a62018-04-12 10:50:13 -070033 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 Cinek0228a252017-11-10 17:47:27 -080037
Lucas Dupin60661a62018-04-12 10:50:13 -070038 public abstract int getAnimationStartTag();
Selim Cinek0228a252017-11-10 17:47:27 -080039
Lucas Dupin60661a62018-04-12 10:50:13 -070040 public abstract int getAnimationEndTag();
Selim Cinek0228a252017-11-10 17:47:27 -080041
Lucas Dupin60661a62018-04-12 10:50:13 -070042 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 Cinek0228a252017-11-10 17:47:27 -080047 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 Dupin60661a62018-04-12 10:50:13 -070082
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 Cinek0228a252017-11-10 17:47:27 -0800107}