diff options
| author | 2024-10-09 11:51:57 +0000 | |
|---|---|---|
| committer | 2024-10-09 11:51:57 +0000 | |
| commit | 8e6b0c4b31eb783d261ed002b9cf3c71bcd15949 (patch) | |
| tree | d84202ff4f77eeee5226b50b8493d4e69d31ed0f | |
| parent | 376f16b1a863368ebe89ad561076a67175a682dc (diff) | |
| parent | afad30814f3d514a3d981cce595896dc9325eb03 (diff) | |
Merge "Fixed status bar hover state height" into main
2 files changed, 77 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt index bef552ce7769..ff7c14308fcb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt @@ -151,7 +151,11 @@ private constructor( startSideContainer = mView.requireViewById(R.id.status_bar_start_side_content) startSideContainer.setOnHoverListener( - statusOverlayHoverListenerFactory.createDarkAwareListener(startSideContainer) + statusOverlayHoverListenerFactory.createDarkAwareListener( + startSideContainer, + topHoverMargin = 6, + bottomHoverMargin = 6, + ) ) startSideContainer.setOnTouchListener(iconsOnTouchListener) } @@ -210,7 +214,7 @@ private constructor( event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL centralSurfaces.setInteracting( WINDOW_STATUS_BAR, - !upOrCancel || shadeController.isExpandedVisible + !upOrCancel || shadeController.isExpandedVisible, ) } } @@ -247,7 +251,7 @@ private constructor( String.format( "onTouchForwardedFromStatusBar: panel disabled, " + "ignoring touch at (${event.x.toInt()},${event.y.toInt()})" - ) + ), ) } return false @@ -266,7 +270,7 @@ private constructor( if (!shadeViewController.isViewEnabled) { shadeLogger.logMotionEvent( event, - "onTouchForwardedFromStatusBar: panel view disabled" + "onTouchForwardedFromStatusBar: panel view disabled", ) return true } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusOverlayHoverListener.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusOverlayHoverListener.kt index 640ec281e162..c40822d71952 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusOverlayHoverListener.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusOverlayHoverListener.kt @@ -20,6 +20,7 @@ import android.content.res.Configuration import android.content.res.Resources import android.graphics.Color import android.graphics.drawable.PaintDrawable +import android.util.TypedValue import android.view.MotionEvent import android.view.View import android.view.View.OnHoverListener @@ -27,10 +28,10 @@ import androidx.annotation.ColorInt import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle -import com.android.systemui.res.R import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.plugins.DarkIconDispatcher +import com.android.systemui.res.R import com.android.systemui.statusbar.phone.SysuiDarkIconDispatcher.DarkChange import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener @@ -65,6 +66,26 @@ constructor( createDarkAwareListener(view, darkIconDispatcher.darkChangeFlow()) /** + * Creates listener using [DarkIconDispatcher] to determine light or dark color of the overlay + * Also sets margins for hover background relative to view bounds + */ + fun createDarkAwareListener( + view: View, + leftHoverMargin: Int = 0, + rightHoverMargin: Int = 0, + topHoverMargin: Int = 0, + bottomHoverMargin: Int = 0, + ) = + createDarkAwareListener( + view, + darkIconDispatcher.darkChangeFlow(), + leftHoverMargin, + rightHoverMargin, + topHoverMargin, + bottomHoverMargin, + ) + + /** * Creates listener using provided [DarkChange] producer to determine light or dark color of the * overlay */ @@ -76,6 +97,25 @@ constructor( darkFlow.map { toHoverTheme(view, it) }, ) + private fun createDarkAwareListener( + view: View, + darkFlow: StateFlow<DarkChange>, + leftHoverMargin: Int = 0, + rightHoverMargin: Int = 0, + topHoverMargin: Int = 0, + bottomHoverMargin: Int = 0, + ) = + StatusOverlayHoverListener( + view, + configurationController, + resources, + darkFlow.map { toHoverTheme(view, it) }, + leftHoverMargin, + rightHoverMargin, + topHoverMargin, + bottomHoverMargin, + ) + private fun toHoverTheme(view: View, darkChange: DarkChange): HoverTheme { val calculatedTint = DarkIconDispatcher.getTint(darkChange.areas, view, darkChange.tint) // currently calculated tint is either white or some shade of black. @@ -91,7 +131,7 @@ constructor( */ enum class HoverTheme { LIGHT, - DARK + DARK, } /** @@ -103,11 +143,19 @@ class StatusOverlayHoverListener( configurationController: ConfigurationController, private val resources: Resources, private val themeFlow: Flow<HoverTheme>, + private val leftHoverMargin: Int = 0, + private val rightHoverMargin: Int = 0, + private val topHoverMargin: Int = 0, + private val bottomHoverMargin: Int = 0, ) : OnHoverListener { @ColorInt private var darkColor: Int = 0 @ColorInt private var lightColor: Int = 0 private var cornerRadius = 0f + private var leftHoverMarginInPx: Int = 0 + private var rightHoverMarginInPx: Int = 0 + private var topHoverMarginInPx: Int = 0 + private var bottomHoverMarginInPx: Int = 0 private var lastTheme = HoverTheme.LIGHT @@ -138,7 +186,12 @@ class StatusOverlayHoverListener( val drawable = PaintDrawable(backgroundColor).apply { setCornerRadius(cornerRadius) - setBounds(0, 0, v.width, v.height) + setBounds( + /*left = */ 0 + leftHoverMarginInPx, + /*top = */ 0 + topHoverMarginInPx, + /*right = */ v.width - rightHoverMarginInPx, + /*bottom = */ v.height - bottomHoverMarginInPx, + ) } v.overlay.add(drawable) } else if (event.action == MotionEvent.ACTION_HOVER_EXIT) { @@ -151,5 +204,18 @@ class StatusOverlayHoverListener( lightColor = resources.getColor(R.color.status_bar_icons_hover_color_light) darkColor = resources.getColor(R.color.status_bar_icons_hover_color_dark) cornerRadius = resources.getDimension(R.dimen.status_icons_hover_state_background_radius) + leftHoverMarginInPx = leftHoverMargin.dpToPx(resources) + rightHoverMarginInPx = rightHoverMargin.dpToPx(resources) + topHoverMarginInPx = topHoverMargin.dpToPx(resources) + bottomHoverMarginInPx = bottomHoverMargin.dpToPx(resources) + } + + private fun Int.dpToPx(resources: Resources): Int { + return TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + toFloat(), + resources.displayMetrics, + ) + .toInt() } } |