MCPcopy Create free account
hub / github.com/golang/mobile / windowConfigRead

Function windowConfigRead

app/android.go:185–239  ·  view source on GitHub ↗
(activity *C.ANativeActivity)

Source from the content-addressed store, hash-verified

183}
184
185func windowConfigRead(activity *C.ANativeActivity) windowConfig {
186 aconfig := C.AConfiguration_new()
187 C.AConfiguration_fromAssetManager(aconfig, activity.assetManager)
188 orient := C.AConfiguration_getOrientation(aconfig)
189 density := C.AConfiguration_getDensity(aconfig)
190 C.AConfiguration_delete(aconfig)
191
192 // Calculate the screen resolution. This value is approximate. For example,
193 // a physical resolution of 200 DPI may be quantized to one of the
194 // ACONFIGURATION_DENSITY_XXX values such as 160 or 240.
195 //
196 // A more accurate DPI could possibly be calculated from
197 // https://developer.android.com/reference/android/util/DisplayMetrics.html#xdpi
198 // but this does not appear to be accessible via the NDK. In any case, the
199 // hardware might not even provide a more accurate number, as the system
200 // does not apparently use the reported value. See golang.org/issue/13366
201 // for a discussion.
202 var dpi int
203 switch density {
204 case C.ACONFIGURATION_DENSITY_DEFAULT:
205 dpi = 160
206 case C.ACONFIGURATION_DENSITY_LOW,
207 C.ACONFIGURATION_DENSITY_MEDIUM,
208 213, // C.ACONFIGURATION_DENSITY_TV
209 C.ACONFIGURATION_DENSITY_HIGH,
210 320, // ACONFIGURATION_DENSITY_XHIGH
211 480, // ACONFIGURATION_DENSITY_XXHIGH
212 640: // ACONFIGURATION_DENSITY_XXXHIGH
213 dpi = int(density)
214 case C.ACONFIGURATION_DENSITY_NONE:
215 log.Print("android device reports no screen density")
216 dpi = 72
217 default:
218 log.Printf("android device reports unknown density: %d", density)
219 // All we can do is guess.
220 if density > 0 {
221 dpi = int(density)
222 } else {
223 dpi = 72
224 }
225 }
226
227 o := size.OrientationUnknown
228 switch orient {
229 case C.ACONFIGURATION_ORIENTATION_PORT:
230 o = size.OrientationPortrait
231 case C.ACONFIGURATION_ORIENTATION_LAND:
232 o = size.OrientationLandscape
233 }
234
235 return windowConfig{
236 orientation: o,
237 pixelsPerPt: float32(dpi) / 72,
238 }
239}
240
241//export onConfigurationChanged
242func onConfigurationChanged(activity *C.ANativeActivity) {

Callers 2

onCreateFunction · 0.85
onConfigurationChangedFunction · 0.85

Calls 1

PrintfMethod · 0.80

Tested by

no test coverage detected