1package com.xtremelabs.robolectric.shadows;
2
3import com.xtremelabs.robolectric.internal.Implementation;
4import com.xtremelabs.robolectric.internal.Implements;
5
6import android.view.View;
7
8/**
9 * Shadow for {@code View.MeasureSpec} inner class.
10 *
11 * As the implementation is very simple, it is taken from the AOSP source.
12 */
13@Implements(View.MeasureSpec.class)
14public class ShadowViewMeasureSpec {
15
16	private static final int MODE_SHIFT = 30;
17    private static final int MODE_MASK = 0x3 << MODE_SHIFT;
18
19	@Implementation
20	public static int getMode (int measureSpec) {
21		return (measureSpec & MODE_MASK);
22	}
23
24	@Implementation
25	public static int getSize (int measureSpec) {
26		return (measureSpec & ~MODE_MASK);
27	}
28
29	@Implementation
30	public static int makeMeasureSpec (int size, int mode) {
31		return size + mode;
32	}
33
34	@Implementation
35	public static String toString (int measureSpec) {
36		int mode = getMode(measureSpec);
37        int size = getSize(measureSpec);
38
39        StringBuilder sb = new StringBuilder("MeasureSpec: ");
40
41        if (mode == View.MeasureSpec.UNSPECIFIED)
42            sb.append("UNSPECIFIED ");
43        else if (mode == View.MeasureSpec.EXACTLY)
44            sb.append("EXACTLY ");
45        else if (mode == View.MeasureSpec.AT_MOST)
46            sb.append("AT_MOST ");
47        else
48            sb.append(mode).append(" ");
49
50        sb.append(size);
51        return sb.toString();
52	}
53
54}
55