Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0942e4c2 authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Set shelf screenshot landscape size and window insets" into 24D1-dev

parents b2188616 0aa11826
Loading
Loading
Loading
Loading
+126 −121
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <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"
@@ -147,6 +151,7 @@
            <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"
+4 −1
Original line number Diff line number Diff line
@@ -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 {
+2 −1
Original line number Diff line number Diff line
@@ -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 =
+42 −2
Original line number Diff line number Diff line
@@ -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()
+23 −1
Original line number Diff line number Diff line
@@ -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()
    }
}