File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
lite/src/main/java/com/pengxh/kt/lite/extensions Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -218,28 +218,28 @@ fun Context.getStatusBarHeight(): Int {
218
218
*/
219
219
@Deprecated(" " , ReplaceWith (" getScreenDensity()" ))
220
220
fun Context.obtainScreenDensity (): Float {
221
- val manager = this .getSystemService( Context . WINDOW_SERVICE ) as WindowManager
221
+ val windowManager = this .getSystemService< WindowManager >() !!
222
222
val dm = DisplayMetrics ()
223
- manager .defaultDisplay.getMetrics(dm)
223
+ windowManager .defaultDisplay.getMetrics(dm)
224
224
return dm.density
225
225
}
226
226
227
- fun Context.getScreenDensity (): Int {
228
- val windowManager = this .getSystemService( Context . WINDOW_SERVICE ) as WindowManager
227
+ fun Context.getScreenDensity (): Float {
228
+ val windowManager = this .getSystemService< WindowManager >() !!
229
229
val displayMetrics = DisplayMetrics ()
230
230
val display = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
231
231
this .display
232
232
} else {
233
233
windowManager.defaultDisplay
234
234
}
235
235
if (display == null ) {
236
- return 0
236
+ return 0f
237
237
}
238
238
return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
239
- this .resources.configuration.densityDpi
239
+ this .resources.displayMetrics.density
240
240
} else {
241
241
display.getMetrics(displayMetrics)
242
- displayMetrics.density.toInt()
242
+ displayMetrics.density
243
243
}
244
244
}
245
245
You can’t perform that action at this time.
0 commit comments