1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.systemui.statusbar.notification;
import android.util.FloatProperty;
import android.util.Property;
import android.view.View;
import com.android.systemui.R;
import java.util.function.BiConsumer;
import java.util.function.Function;
/**
* An animatable property of a view. Used with {@link PropertyAnimator}
*/
public abstract class AnimatableProperty {
public static final AnimatableProperty X = AnimatableProperty.from(View.X,
R.id.x_animator_tag, R.id.x_animator_tag_start_value, R.id.x_animator_tag_end_value);
public static final AnimatableProperty Y = AnimatableProperty.from(View.Y,
R.id.y_animator_tag, R.id.y_animator_tag_start_value, R.id.y_animator_tag_end_value);
public static final AnimatableProperty TRANSLATION_X = AnimatableProperty.from(
View.TRANSLATION_X, R.id.x_animator_tag, R.id.x_animator_tag_start_value,
R.id.x_animator_tag_end_value);
public static final AnimatableProperty SCALE_X = AnimatableProperty.from(
View.SCALE_X, R.id.scale_x_animator_tag, R.id.scale_x_animator_start_value_tag,
R.id.scale_x_animator_end_value_tag);
public static final AnimatableProperty SCALE_Y = AnimatableProperty.from(
View.SCALE_Y, R.id.scale_y_animator_tag, R.id.scale_y_animator_start_value_tag,
R.id.scale_y_animator_end_value_tag);
/**
* Similar to X, however this doesn't allow for any other modifications other than from this
* property. When using X, it's possible that the view is laid out during the animation,
* which could break the continuity
*/
public static final AnimatableProperty ABSOLUTE_X = AnimatableProperty.from(
new FloatProperty<View>("ViewAbsoluteX") {
@Override
public void setValue(View view, float value) {
view.setTag(R.id.absolute_x_current_value, value);
View.X.set(view, value);
}
@Override
public Float get(View view) {
Object tag = view.getTag(R.id.absolute_x_current_value);
if (tag instanceof Float) {
return (Float) tag;
}
return View.X.get(view);
}
},
R.id.absolute_x_animator_tag,
R.id.absolute_x_animator_start_tag,
R.id.absolute_x_animator_end_tag);
/**
* Similar to Y, however this doesn't allow for any other modifications other than from this
* property. When using X, it's possible that the view is laid out during the animation,
* which could break the continuity
*/
public static final AnimatableProperty ABSOLUTE_Y = AnimatableProperty.from(
new FloatProperty<View>("ViewAbsoluteY") {
@Override
public void setValue(View view, float value) {
view.setTag(R.id.absolute_y_current_value, value);
View.Y.set(view, value);
}
@Override
public Float get(View view) {
Object tag = view.getTag(R.id.absolute_y_current_value);
if (tag instanceof Float) {
return (Float) tag;
}
return View.Y.get(view);
}
},
R.id.absolute_y_animator_tag,
R.id.absolute_y_animator_start_tag,
R.id.absolute_y_animator_end_tag);
public static final AnimatableProperty WIDTH = AnimatableProperty.from(
new FloatProperty<View>("ViewWidth") {
@Override
public void setValue(View view, float value) {
view.setTag(R.id.view_width_current_value, value);
view.setRight((int) (view.getLeft() + value));
}
@Override
public Float get(View view) {
Object tag = view.getTag(R.id.view_width_current_value);
if (tag instanceof Float) {
return (Float) tag;
}
return (float) view.getWidth();
}
},
R.id.view_width_animator_tag,
R.id.view_width_animator_start_tag,
R.id.view_width_animator_end_tag);
public static final AnimatableProperty HEIGHT = AnimatableProperty.from(
new FloatProperty<View>("ViewHeight") {
@Override
public void setValue(View view, float value) {
view.setTag(R.id.view_height_current_value, value);
view.setBottom((int) (view.getTop() + value));
}
@Override
public Float get(View view) {
Object tag = view.getTag(R.id.view_height_current_value);
if (tag instanceof Float) {
return (Float) tag;
}
return (float) view.getHeight();
}
},
R.id.view_height_animator_tag,
R.id.view_height_animator_start_tag,
R.id.view_height_animator_end_tag);
public abstract int getAnimationStartTag();
public abstract int getAnimationEndTag();
public abstract int getAnimatorTag();
public abstract Property getProperty();
public static <T extends View> AnimatableProperty from(String name, BiConsumer<T, Float> setter,
Function<T, Float> getter, int animatorTag, int startValueTag, int endValueTag) {
Property<T, Float> property = new FloatProperty<T>(name) {
@Override
public Float get(T object) {
return getter.apply(object);
}
@Override
public void setValue(T object, float value) {
setter.accept(object, value);
}
};
return new AnimatableProperty() {
@Override
public int getAnimationStartTag() {
return startValueTag;
}
@Override
public int getAnimationEndTag() {
return endValueTag;
}
@Override
public int getAnimatorTag() {
return animatorTag;
}
@Override
public Property getProperty() {
return property;
}
};
}
public static <T extends View> AnimatableProperty from(Property<T, Float> property,
int animatorTag, int startValueTag, int endValueTag) {
return new AnimatableProperty() {
@Override
public int getAnimationStartTag() {
return startValueTag;
}
@Override
public int getAnimationEndTag() {
return endValueTag;
}
@Override
public int getAnimatorTag() {
return animatorTag;
}
@Override
public Property getProperty() {
return property;
}
};
}
}
|