diff options
5 files changed, 197 insertions, 126 deletions
diff --git a/packages/SystemUI/res/layout/screenshot_shelf.xml b/packages/SystemUI/res/layout/screenshot_shelf.xml index 79b82bf51d8c..7adfa6ca1c29 100644 --- a/packages/SystemUI/res/layout/screenshot_shelf.xml +++ b/packages/SystemUI/res/layout/screenshot_shelf.xml @@ -20,133 +20,138 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> - <FrameLayout - android:id="@+id/actions_container_background" - android:visibility="gone" - android:layout_height="wrap_content" - android:layout_width="wrap_content" - android:elevation="4dp" - android:background="@drawable/shelf_action_chip_container_background" - android:layout_marginHorizontal="@dimen/overlay_action_container_margin_horizontal" - android:layout_marginBottom="@dimen/screenshot_shelf_vertical_margin" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintBottom_toTopOf="@id/guideline" - > - <HorizontalScrollView - android:id="@+id/actions_container" - android:layout_width="wrap_content" + <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/screenshot_static" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <FrameLayout + android:id="@+id/actions_container_background" + android:visibility="gone" android:layout_height="wrap_content" - android:layout_marginVertical="@dimen/overlay_action_container_padding_vertical" - android:layout_marginHorizontal="@dimen/overlay_action_chip_margin_start" - android:background="@drawable/shelf_action_container_clipping_shape" - android:clipToOutline="true" - android:scrollbars="none"> - <LinearLayout - android:id="@+id/screenshot_actions" + android:layout_width="wrap_content" + android:elevation="4dp" + android:background="@drawable/shelf_action_chip_container_background" + android:layout_marginHorizontal="@dimen/overlay_action_container_margin_horizontal" + android:layout_marginBottom="@dimen/screenshot_shelf_vertical_margin" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintBottom_toTopOf="@id/guideline" + > + <HorizontalScrollView + android:id="@+id/actions_container" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:showDividers="middle" - android:divider="@drawable/shelf_action_chip_divider" - android:animateLayoutChanges="true" - /> - </HorizontalScrollView> - </FrameLayout> - <View - android:id="@+id/screenshot_preview_border" - android:layout_width="0dp" - android:layout_height="0dp" - android:layout_marginStart="@dimen/overlay_action_container_margin_horizontal" - android:layout_marginTop="@dimen/overlay_border_width_neg" - android:layout_marginEnd="@dimen/overlay_border_width_neg" - android:layout_marginBottom="@dimen/screenshot_shelf_vertical_margin" - android:elevation="4dp" - android:background="@drawable/overlay_border" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@id/screenshot_preview" - app:layout_constraintEnd_toEndOf="@id/screenshot_preview" - app:layout_constraintBottom_toTopOf="@id/actions_container_background"/> - <ImageView - android:id="@+id/screenshot_preview" - android:layout_width="@dimen/overlay_x_scale" - android:layout_height="wrap_content" - android:layout_marginStart="@dimen/overlay_border_width" - android:layout_marginBottom="@dimen/overlay_border_width" - android:layout_gravity="center" - android:elevation="4dp" - android:contentDescription="@string/screenshot_edit_description" - android:scaleType="fitEnd" - android:background="@drawable/overlay_preview_background" - android:adjustViewBounds="true" - android:clickable="true" - app:layout_constraintStart_toStartOf="@id/screenshot_preview_border" - app:layout_constraintBottom_toBottomOf="@id/screenshot_preview_border"/> - <ImageView - android:id="@+id/screenshot_badge" - android:layout_width="56dp" - android:layout_height="56dp" - android:visibility="gone" - android:elevation="5dp" - app:layout_constraintBottom_toBottomOf="@id/screenshot_preview_border" - app:layout_constraintEnd_toEndOf="@id/screenshot_preview_border"/> - <FrameLayout - android:id="@+id/screenshot_dismiss_button" - android:layout_width="@dimen/overlay_dismiss_button_tappable_size" - android:layout_height="@dimen/overlay_dismiss_button_tappable_size" - android:elevation="7dp" - android:visibility="gone" - app:layout_constraintStart_toEndOf="@id/screenshot_preview" - app:layout_constraintEnd_toEndOf="@id/screenshot_preview" - app:layout_constraintTop_toTopOf="@id/screenshot_preview" - app:layout_constraintBottom_toTopOf="@id/screenshot_preview" - android:contentDescription="@string/screenshot_dismiss_description"> + android:layout_marginVertical="@dimen/overlay_action_container_padding_vertical" + android:layout_marginHorizontal="@dimen/overlay_action_chip_margin_start" + android:background="@drawable/shelf_action_container_clipping_shape" + android:clipToOutline="true" + android:scrollbars="none"> + <LinearLayout + android:id="@+id/screenshot_actions" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:showDividers="middle" + android:divider="@drawable/shelf_action_chip_divider" + android:animateLayoutChanges="true" + /> + </HorizontalScrollView> + </FrameLayout> + <View + android:id="@+id/screenshot_preview_border" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_marginStart="@dimen/overlay_action_container_margin_horizontal" + android:layout_marginTop="@dimen/overlay_border_width_neg" + android:layout_marginEnd="@dimen/overlay_border_width_neg" + android:layout_marginBottom="@dimen/screenshot_shelf_vertical_margin" + android:elevation="4dp" + android:background="@drawable/overlay_border" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/screenshot_preview" + app:layout_constraintEnd_toEndOf="@id/screenshot_preview" + app:layout_constraintBottom_toTopOf="@id/actions_container_background"/> <ImageView - android:id="@+id/screenshot_dismiss_image" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_margin="@dimen/overlay_dismiss_button_margin" - android:background="@drawable/circular_background" - android:backgroundTint="?androidprv:attr/materialColorPrimary" - android:tint="?androidprv:attr/materialColorOnPrimary" - android:padding="4dp" - android:src="@drawable/ic_close"/> - </FrameLayout> - <ImageView - android:id="@+id/screenshot_scrollable_preview" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:scaleType="matrix" - android:visibility="gone" - app:layout_constraintStart_toStartOf="@id/screenshot_preview" - app:layout_constraintTop_toTopOf="@id/screenshot_preview" - android:elevation="7dp"/> + android:id="@+id/screenshot_preview" + android:layout_width="@dimen/overlay_x_scale" + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/overlay_border_width" + android:layout_marginBottom="@dimen/overlay_border_width" + android:layout_gravity="center" + android:elevation="4dp" + android:contentDescription="@string/screenshot_edit_description" + android:scaleType="fitEnd" + android:background="@drawable/overlay_preview_background" + android:adjustViewBounds="true" + android:clickable="true" + app:layout_constraintStart_toStartOf="@id/screenshot_preview_border" + app:layout_constraintBottom_toBottomOf="@id/screenshot_preview_border"/> + <ImageView + android:id="@+id/screenshot_badge" + android:layout_width="56dp" + android:layout_height="56dp" + android:visibility="gone" + android:elevation="5dp" + app:layout_constraintBottom_toBottomOf="@id/screenshot_preview_border" + app:layout_constraintEnd_toEndOf="@id/screenshot_preview_border"/> + <FrameLayout + android:id="@+id/screenshot_dismiss_button" + android:layout_width="@dimen/overlay_dismiss_button_tappable_size" + android:layout_height="@dimen/overlay_dismiss_button_tappable_size" + android:elevation="7dp" + android:visibility="gone" + app:layout_constraintStart_toEndOf="@id/screenshot_preview" + app:layout_constraintEnd_toEndOf="@id/screenshot_preview" + app:layout_constraintTop_toTopOf="@id/screenshot_preview" + app:layout_constraintBottom_toTopOf="@id/screenshot_preview" + android:contentDescription="@string/screenshot_dismiss_description"> + <ImageView + android:id="@+id/screenshot_dismiss_image" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_margin="@dimen/overlay_dismiss_button_margin" + android:background="@drawable/circular_background" + android:backgroundTint="?androidprv:attr/materialColorPrimary" + android:tint="?androidprv:attr/materialColorOnPrimary" + android:padding="4dp" + android:src="@drawable/ic_close"/> + </FrameLayout> + <ImageView + android:id="@+id/screenshot_scrollable_preview" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:scaleType="matrix" + android:visibility="gone" + app:layout_constraintStart_toStartOf="@id/screenshot_preview" + app:layout_constraintTop_toTopOf="@id/screenshot_preview" + android:elevation="7dp"/> - <androidx.constraintlayout.widget.Guideline - android:id="@+id/guideline" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="horizontal" - app:layout_constraintGuide_end="0dp" /> + <androidx.constraintlayout.widget.Guideline + android:id="@+id/guideline" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layout_constraintGuide_end="0dp" /> - <FrameLayout - android:id="@+id/screenshot_message_container" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_marginHorizontal="@dimen/overlay_action_container_margin_horizontal" - android:layout_marginTop="4dp" - android:layout_marginBottom="@dimen/overlay_action_container_margin_bottom" - android:paddingHorizontal="@dimen/overlay_action_container_padding_end" - android:paddingVertical="@dimen/overlay_action_container_padding_vertical" - android:elevation="4dp" - android:background="@drawable/action_chip_container_background" - android:visibility="gone" - app:layout_constraintTop_toBottomOf="@id/guideline" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintWidth_max="450dp" - app:layout_constraintHorizontal_bias="0"> - <include layout="@layout/screenshot_work_profile_first_run" /> - <include layout="@layout/screenshot_detection_notice" /> - </FrameLayout> + <FrameLayout + android:id="@+id/screenshot_message_container" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginHorizontal="@dimen/overlay_action_container_margin_horizontal" + android:layout_marginTop="4dp" + android:layout_marginBottom="@dimen/overlay_action_container_margin_bottom" + android:paddingHorizontal="@dimen/overlay_action_container_padding_end" + android:paddingVertical="@dimen/overlay_action_container_padding_vertical" + android:elevation="4dp" + android:background="@drawable/action_chip_container_background" + android:visibility="gone" + app:layout_constraintTop_toBottomOf="@id/guideline" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintWidth_max="450dp" + app:layout_constraintHorizontal_bias="0"> + <include layout="@layout/screenshot_work_profile_first_run" /> + <include layout="@layout/screenshot_detection_notice" /> + </FrameLayout> + </androidx.constraintlayout.widget.ConstraintLayout> <ImageView android:id="@+id/screenshot_flash" android:layout_width="match_parent" diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt index 52ae973992a4..9b754f3271a7 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt @@ -87,6 +87,7 @@ constructor( onDismissalRequested = { event, velocity -> requestDismissal(event, velocity) }, onDismissalCancelled = { animationController.getSwipeReturnAnimation().start() } ) + view.updateInsets(windowManager.currentWindowMetrics.windowInsets) addPredictiveBackListener { requestDismissal(SCREENSHOT_DISMISSED_OTHER) } setOnKeyListener { requestDismissal(SCREENSHOT_DISMISSED_OTHER) } debugLog(DEBUG_WINDOW) { "adding OnComputeInternalInsetsListener" } @@ -112,7 +113,9 @@ constructor( isPendingSharedTransition = false viewModel.reset() } - override fun updateInsets(insets: WindowInsets) {} + override fun updateInsets(insets: WindowInsets) { + view.updateInsets(insets) + } override fun updateOrientation(insets: WindowInsets) {} override fun createScreenshotDropInAnimation(screenRect: Rect, showFlash: Boolean): Animator { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotAnimationController.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotAnimationController.kt index 2e4473e75ed0..4eceb176fcd2 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotAnimationController.kt @@ -25,6 +25,7 @@ import android.graphics.Rect import android.util.MathUtils import android.view.View import android.view.animation.AnimationUtils +import android.widget.ImageView import androidx.core.animation.doOnEnd import androidx.core.animation.doOnStart import com.android.systemui.res.R @@ -34,7 +35,7 @@ import kotlin.math.sign class ScreenshotAnimationController(private val view: ScreenshotShelfView) { private var animator: Animator? = null - private val screenshotPreview = view.requireViewById<View>(R.id.screenshot_preview) + private val screenshotPreview = view.requireViewById<ImageView>(R.id.screenshot_preview) private val flashView = view.requireViewById<View>(R.id.screenshot_flash) private val actionContainer = view.requireViewById<View>(R.id.actions_container_background) private val fastOutSlowIn = diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt index f9af4b93bf15..4437bf533353 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt @@ -17,20 +17,25 @@ package com.android.systemui.screenshot.ui import android.content.Context +import android.content.res.Configuration import android.graphics.Insets import android.graphics.Rect import android.graphics.Region import android.util.AttributeSet import android.view.MotionEvent import android.view.View +import android.view.ViewGroup +import android.view.WindowInsets +import android.widget.FrameLayout import android.widget.ImageView -import androidx.constraintlayout.widget.ConstraintLayout import com.android.systemui.res.R import com.android.systemui.screenshot.FloatingWindowUtil +import kotlin.math.max class ScreenshotShelfView(context: Context, attrs: AttributeSet? = null) : - ConstraintLayout(context, attrs) { + FrameLayout(context, attrs) { lateinit var screenshotPreview: ImageView + private lateinit var screenshotStatic: ViewGroup var onTouchInterceptListener: ((MotionEvent) -> Boolean)? = null private val displayMetrics = context.resources.displayMetrics @@ -43,6 +48,7 @@ class ScreenshotShelfView(context: Context, attrs: AttributeSet? = null) : // Get focus so that the key events go to the layout. isFocusableInTouchMode = true screenshotPreview = requireViewById(R.id.screenshot_preview) + screenshotStatic = requireViewById(R.id.screenshot_static) actionsContainerBackground = requireViewById(R.id.actions_container_background) dismissButton = requireViewById(R.id.screenshot_dismiss_button) } @@ -66,6 +72,40 @@ class ScreenshotShelfView(context: Context, attrs: AttributeSet? = null) : return region } + fun updateInsets(insets: WindowInsets) { + val orientation = mContext.resources.configuration.orientation + val inPortrait = orientation == Configuration.ORIENTATION_PORTRAIT + val p = screenshotStatic.layoutParams as LayoutParams + val cutout = insets.displayCutout + val navBarInsets = insets.getInsets(WindowInsets.Type.navigationBars()) + if (cutout == null) { + p.setMargins(0, 0, 0, navBarInsets.bottom) + } else { + val waterfall = cutout.waterfallInsets + if (inPortrait) { + p.setMargins( + waterfall.left, + max(cutout.safeInsetTop.toDouble(), waterfall.top.toDouble()).toInt(), + waterfall.right, + max( + cutout.safeInsetBottom.toDouble(), + max(navBarInsets.bottom.toDouble(), waterfall.bottom.toDouble()) + ) + .toInt() + ) + } else { + p.setMargins( + max(cutout.safeInsetLeft.toDouble(), waterfall.left.toDouble()).toInt(), + waterfall.top, + max(cutout.safeInsetRight.toDouble(), waterfall.right.toDouble()).toInt(), + max(navBarInsets.bottom.toDouble(), waterfall.bottom.toDouble()).toInt() + ) + } + } + screenshotStatic.layoutParams = p + screenshotStatic.requestLayout() + } + private fun getSwipeRegion(): Region { val swipeRegion = Region() val padding = FloatingWindowUtil.dpToPx(displayMetrics, -1 * TOUCH_PADDING_DP).toInt() diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt index 3376b8c84826..734a530efea7 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/binder/ScreenshotShelfViewBinder.kt @@ -16,8 +16,11 @@ package com.android.systemui.screenshot.ui.binder +import android.graphics.Bitmap import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup +import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout import androidx.lifecycle.Lifecycle @@ -68,7 +71,7 @@ object ScreenshotShelfViewBinder { launch { viewModel.preview.collect { bitmap -> if (bitmap != null) { - previewView.setImageBitmap(bitmap) + setScreenshotBitmap(previewView, bitmap) previewView.visibility = View.VISIBLE previewBorder.visibility = View.VISIBLE } else { @@ -128,4 +131,23 @@ object ScreenshotShelfViewBinder { } } } + + private fun setScreenshotBitmap(screenshotPreview: ImageView, bitmap: Bitmap) { + screenshotPreview.setImageBitmap(bitmap) + val hasPortraitAspectRatio = bitmap.width < bitmap.height + val fixedSize = screenshotPreview.resources.getDimensionPixelSize(R.dimen.overlay_x_scale) + val params: ViewGroup.LayoutParams = screenshotPreview.layoutParams + if (hasPortraitAspectRatio) { + params.width = fixedSize + params.height = FrameLayout.LayoutParams.WRAP_CONTENT + screenshotPreview.scaleType = ImageView.ScaleType.FIT_START + } else { + params.width = FrameLayout.LayoutParams.WRAP_CONTENT + params.height = fixedSize + screenshotPreview.scaleType = ImageView.ScaleType.FIT_END + } + + screenshotPreview.layoutParams = params + screenshotPreview.requestLayout() + } } |