From 77475ab5505adbe96c353f560e4685e4618e7bbb Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Mon, 24 Apr 2023 18:40:22 +0100 Subject: [PATCH] Small improvements in code cleanliness Fixes mostly around potential window nullability and Kotlin style Flag: KEYBOARD_BACKLIGHT_INDICATOR Bug: 259428678 Test: KeyboardBacklightDialogScreenshotTest Change-Id: Ic1937d8bf1bed68ae1b2fb7c9edd49afb76dbc76 --- .../ui/view/KeyboardBacklightDialog.kt | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt b/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt index 2ef5e19bf382c..800e6a6af52b8 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt @@ -80,7 +80,7 @@ class KeyboardBacklightDialog( override fun onCreate(savedInstanceState: Bundle?) { setUpWindowProperties(this) - setWindowTitle() + setWindowPosition() updateResources() rootView = buildRootView() setContentView(rootView) @@ -222,24 +222,29 @@ class KeyboardBacklightDialog( } } - private fun setWindowTitle() { - val attrs = window.attributes - attrs.title = "KeyboardBacklightDialog" - attrs?.y = dialogBottomMargin - window.attributes = attrs + private fun setWindowPosition() { + window?.apply { + setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL) + this.attributes = + WindowManager.LayoutParams().apply { + copyFrom(attributes) + y = dialogBottomMargin + } + } } private fun setUpWindowProperties(dialog: Dialog) { - val window = dialog.window - window.requestFeature(Window.FEATURE_NO_TITLE) // otherwise fails while creating actionBar - window.setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL) - window.addFlags( - WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM or - WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED - ) - window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) - window.setBackgroundDrawableResource(android.R.color.transparent) - window.setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL) + dialog.window?.apply { + requestFeature(Window.FEATURE_NO_TITLE) // otherwise fails while creating actionBar + setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL) + addFlags( + WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM or + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + ) + clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + setBackgroundDrawableResource(android.R.color.transparent) + attributes.title = "KeyboardBacklightDialog" + } setCanceledOnTouchOutside(true) }