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