1 |
|
2 |
|
3 | export const MODE_SHIFT = 30;
|
4 | export const MODE_MASK = 0x3 << MODE_SHIFT;
|
5 | export const UNSPECIFIED = 0 << MODE_SHIFT;
|
6 | export const EXACTLY = 1 << MODE_SHIFT;
|
7 | export const AT_MOST = 2 << MODE_SHIFT;
|
8 | export const MEASURED_HEIGHT_STATE_SHIFT = 0x00000010;
|
9 | export const MEASURED_STATE_TOO_SMALL = 0x01000000;
|
10 | export const MEASURED_STATE_MASK = 0xff000000;
|
11 | export const MEASURED_SIZE_MASK = 0x00ffffff;
|
12 | export function getMode(mode) {
|
13 | switch (mode) {
|
14 | case EXACTLY:
|
15 | return 'Exact';
|
16 | case AT_MOST:
|
17 | return 'AtMost';
|
18 | default:
|
19 | return 'Unspecified';
|
20 | }
|
21 | }
|
22 | export function getMeasureSpecMode(spec) {
|
23 | return spec & MODE_MASK;
|
24 | }
|
25 | export function getMeasureSpecSize(spec) {
|
26 | return spec & ~MODE_MASK;
|
27 | }
|
28 | export function measureSpecToString(measureSpec) {
|
29 | const mode = getMeasureSpecMode(measureSpec);
|
30 | const size = getMeasureSpecSize(measureSpec);
|
31 | let text = 'MeasureSpec: ';
|
32 | if (mode === UNSPECIFIED) {
|
33 | text += 'UNSPECIFIED ';
|
34 | }
|
35 | else if (mode === EXACTLY) {
|
36 | text += 'EXACTLY ';
|
37 | }
|
38 | else if (mode === AT_MOST) {
|
39 | text += 'AT_MOST ';
|
40 | }
|
41 | text += size;
|
42 | return text;
|
43 | }
|
44 | export function round(value) {
|
45 | const res = Math.floor(value + 0.5);
|
46 | if (res !== 0) {
|
47 | return res;
|
48 | }
|
49 | else if (value === 0) {
|
50 | return 0;
|
51 | }
|
52 | else if (value > 0) {
|
53 | return 1;
|
54 | }
|
55 | return -1;
|
56 | }
|
57 |
|
\ | No newline at end of file |