1/*
2 * Copyright (C) 2012 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 android.support.v4.view;
18
19import android.animation.ValueAnimator;
20import android.graphics.Matrix;
21import android.graphics.Paint;
22import android.view.View;
23import android.view.ViewParent;
24
25class ViewCompatHC {
26    static long getFrameTime() {
27        return ValueAnimator.getFrameDelay();
28    }
29
30    public static float getAlpha(View view) {
31        return view.getAlpha();
32    }
33
34    public static void setLayerType(View view, int layerType, Paint paint) {
35        view.setLayerType(layerType, paint);
36    }
37
38    public static int getLayerType(View view) {
39        return view.getLayerType();
40    }
41
42    public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
43        return View.resolveSizeAndState(size, measureSpec, childMeasuredState);
44    }
45
46    public static int getMeasuredWidthAndState(View view) {
47        return view.getMeasuredWidthAndState();
48    }
49
50    public static int getMeasuredHeightAndState(View view) {
51        return view.getMeasuredHeightAndState();
52    }
53
54    public static int getMeasuredState(View view) {
55        return view.getMeasuredState();
56    }
57
58    public static float getTranslationX(View view) {
59        return view.getTranslationX();
60    }
61
62    public static float getTranslationY(View view) {
63        return view.getTranslationY();
64    }
65
66    public static float getX(View view) {
67        return view.getX();
68    }
69
70    public static float getY(View view) {
71        return view.getY();
72    }
73
74    public static float getRotation(View view) {
75        return view.getRotation();
76    }
77
78    public static float getRotationX(View view) {
79        return view.getRotationX();
80    }
81
82    public static float getRotationY(View view) {
83        return view.getRotationY();
84    }
85
86    public static float getScaleX(View view) {
87        return view.getScaleX();
88    }
89
90    public static float getScaleY(View view) {
91        return view.getScaleY();
92    }
93
94    public static void setTranslationX(View view, float value) {
95        view.setTranslationX(value);
96    }
97
98    public static void setTranslationY(View view, float value) {
99        view.setTranslationY(value);
100    }
101
102    public static Matrix getMatrix(View view) {
103        return view.getMatrix();
104    }
105
106    public static void setAlpha(View view, float value) {
107        view.setAlpha(value);
108    }
109
110    public static void setX(View view, float value) {
111        view.setX(value);
112    }
113
114    public static void setY(View view, float value) {
115        view.setY(value);
116    }
117
118    public static void setRotation(View view, float value) {
119        view.setRotation(value);
120    }
121
122    public static void setRotationX(View view, float value) {
123        view.setRotationX(value);
124    }
125
126    public static void setRotationY(View view, float value) {
127        view.setRotationY(value);
128    }
129
130    public static void setScaleX(View view, float value) {
131        view.setScaleX(value);
132    }
133
134    public static void setScaleY(View view, float value) {
135        view.setScaleY(value);
136    }
137
138    public static void setPivotX(View view, float value) {
139        view.setPivotX(value);
140    }
141
142    public static void setPivotY(View view, float value) {
143        view.setPivotY(value);
144    }
145
146    public static float getPivotX(View view) {
147        return view.getPivotX();
148    }
149
150    public static float getPivotY(View view) {
151        return view.getPivotY();
152    }
153
154    public static void jumpDrawablesToCurrentState(View view) {
155        view.jumpDrawablesToCurrentState();
156    }
157
158    public static void setSaveFromParentEnabled(View view, boolean enabled) {
159        view.setSaveFromParentEnabled(enabled);
160    }
161
162    public static void setActivated(View view, boolean activated) {
163        view.setActivated(activated);
164    }
165
166    public static int combineMeasuredStates(int curState, int newState) {
167        return View.combineMeasuredStates(curState, newState);
168    }
169
170    static void offsetTopAndBottom(View view, int offset) {
171        view.offsetTopAndBottom(offset);
172        tickleInvalidationFlag(view);
173
174        ViewParent parent = view.getParent();
175        if (parent instanceof View) {
176            tickleInvalidationFlag((View) parent);
177        }
178    }
179
180    static void offsetLeftAndRight(View view, int offset) {
181        view.offsetLeftAndRight(offset);
182        tickleInvalidationFlag(view);
183
184        ViewParent parent = view.getParent();
185        if (parent instanceof View) {
186            tickleInvalidationFlag((View) parent);
187        }
188    }
189
190    private static void tickleInvalidationFlag(View view) {
191        final float y = view.getTranslationY();
192        view.setTranslationY(y + 1);
193        view.setTranslationY(y);
194    }
195}
196