• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.graphics.PixelFormat;
4 import android.util.DisplayMetrics;
5 import android.view.Display;
6 import android.view.Surface;
7 import com.xtremelabs.robolectric.internal.Implementation;
8 import com.xtremelabs.robolectric.internal.Implements;
9 
10 /**
11  * A shadow for Display with some reasonable defaults
12  */
13 @SuppressWarnings({"UnusedDeclaration"})
14 @Implements(Display.class)
15 public class ShadowDisplay {
16     private int displayId;
17     private int width = 480;
18     private int height = 800;
19     private float density = 1.5f;
20     private int densityDpi = DisplayMetrics.DENSITY_HIGH;
21     private float xdpi = 240.0f;
22     private float ydpi = 240.0f;
23     private float scaledDensity = 1.0f;
24     private float refreshRate = 60.0f;
25     private int rotation = Surface.ROTATION_0;
26     private int pixelFormat = PixelFormat.RGBA_4444;
27 
28     @Implementation
getHeight()29     public int getHeight() {
30         return height;
31     }
32 
33     @Implementation
getMetrics(DisplayMetrics outMetrics)34     public void getMetrics(DisplayMetrics outMetrics) {
35         outMetrics.density = density;
36         outMetrics.densityDpi = densityDpi;
37         outMetrics.scaledDensity = scaledDensity;
38         outMetrics.widthPixels = width;
39         outMetrics.heightPixels = height;
40         outMetrics.xdpi = xdpi;
41         outMetrics.ydpi = ydpi;
42     }
43 
44     @Implementation
getWidth()45     public int getWidth() {
46         return width;
47     }
48 
49     @Implementation
getDisplayId()50     public int getDisplayId() {
51         return displayId;
52     }
53 
54     @Implementation
getRefreshRate()55     public float getRefreshRate() {
56         return refreshRate;
57     }
58 
59     @Implementation
getRotation()60     public int getRotation() {
61         return rotation;
62     }
63 
64     @Implementation
getPixelFormat()65     public int getPixelFormat() {
66         return pixelFormat;
67     }
68 
getDensity()69     public float getDensity() {
70         return density;
71     }
72 
setDensity(float density)73     public void setDensity(float density) {
74         this.density = density;
75     }
76 
getDensityDpi()77     public int getDensityDpi() {
78         return densityDpi;
79     }
80 
setDensityDpi(int densityDpi)81     public void setDensityDpi(int densityDpi) {
82         this.densityDpi = densityDpi;
83     }
84 
getXdpi()85     public float getXdpi() {
86         return xdpi;
87     }
88 
setXdpi(float xdpi)89     public void setXdpi(float xdpi) {
90         this.xdpi = xdpi;
91     }
92 
getYdpi()93     public float getYdpi() {
94         return ydpi;
95     }
96 
setYdpi(float ydpi)97     public void setYdpi(float ydpi) {
98         this.ydpi = ydpi;
99     }
100 
getScaledDensity()101     public float getScaledDensity() {
102         return scaledDensity;
103     }
104 
setScaledDensity(float scaledDensity)105     public void setScaledDensity(float scaledDensity) {
106         this.scaledDensity = scaledDensity;
107     }
108 
setDisplayId(int displayId)109     public void setDisplayId(int displayId) {
110         this.displayId = displayId;
111     }
112 
setWidth(int width)113     public void setWidth(int width) {
114         this.width = width;
115     }
116 
setHeight(int height)117     public void setHeight(int height) {
118         this.height = height;
119     }
120 
setRefreshRate(float refreshRate)121     public void setRefreshRate(float refreshRate) {
122         this.refreshRate = refreshRate;
123     }
124 
setRotation(int rotation)125     public void setRotation(int rotation) {
126         this.rotation = rotation;
127     }
128 
setPixelFormat(int pixelFormat)129     public void setPixelFormat(int pixelFormat) {
130         this.pixelFormat = pixelFormat;
131     }
132 
133 }
134