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

Commit c4cbf4e3 authored by Florence Yang's avatar Florence Yang Committed by Automerger Merge Worker
Browse files

Merge "Fix RegionSampler crashes" into tm-qpr-dev am: 63afdb25 am:...

Merge "Fix RegionSampler crashes" into tm-qpr-dev am: 63afdb25 am: ca3c7f2d am: 82cacb96 am: 47a8bf19

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21733197



Change-Id: I9486cde3dd2e21916dea38e901d98a58ddaa1529
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents ea2e5a50 47a8bf19
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -91,6 +91,22 @@ constructor(
        val sampledRegion = calculateSampledRegion(sampledView)
        val sampledRegion = calculateSampledRegion(sampledView)
        val regions = ArrayList<RectF>()
        val regions = ArrayList<RectF>()
        val sampledRegionWithOffset = convertBounds(sampledRegion)
        val sampledRegionWithOffset = convertBounds(sampledRegion)

        if (
            sampledRegionWithOffset.left < 0.0 ||
                sampledRegionWithOffset.right > 1.0 ||
                sampledRegionWithOffset.top < 0.0 ||
                sampledRegionWithOffset.bottom > 1.0
        ) {
            android.util.Log.e(
                "RegionSampler",
                "view out of bounds: $sampledRegion | " +
                    "screen width: ${displaySize.x}, screen height: ${displaySize.y}",
                Exception()
            )
            return
        }

        regions.add(sampledRegionWithOffset)
        regions.add(sampledRegionWithOffset)


        wallpaperManager?.removeOnColorsChangedListener(this)
        wallpaperManager?.removeOnColorsChangedListener(this)
+9 −29
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import android.content.Intent
import android.content.Intent
import android.content.IntentFilter
import android.content.IntentFilter
import android.content.res.Resources
import android.content.res.Resources
import android.graphics.Rect
import android.text.format.DateFormat
import android.text.format.DateFormat
import android.util.TypedValue
import android.util.TypedValue
import android.view.View
import android.view.View
@@ -119,10 +120,6 @@ constructor(


    private val mLayoutChangedListener =
    private val mLayoutChangedListener =
        object : View.OnLayoutChangeListener {
        object : View.OnLayoutChangeListener {
            private var currentSmallClockView: View? = null
            private var currentLargeClockView: View? = null
            private var currentSmallClockLocation = IntArray(2)
            private var currentLargeClockLocation = IntArray(2)


            override fun onLayoutChange(
            override fun onLayoutChange(
                view: View?,
                view: View?,
@@ -135,6 +132,8 @@ constructor(
                oldRight: Int,
                oldRight: Int,
                oldBottom: Int
                oldBottom: Int
            ) {
            ) {
                view?.removeOnLayoutChangeListener(this)

                val parent = (view?.parent) as FrameLayout
                val parent = (view?.parent) as FrameLayout


                // don't pass in negative bounds when clocks are in transition state
                // don't pass in negative bounds when clocks are in transition state
@@ -142,34 +141,15 @@ constructor(
                    return
                    return
                }
                }


                // SMALL CLOCK
                val currentViewRect = Rect(left, top, right, bottom)
                if (parent.id == R.id.lockscreen_clock_view) {
                val oldViewRect = Rect(oldLeft, oldTop, oldRight, oldBottom)
                    // view bounds have changed due to clock size changing (i.e. different character

                    // widths)
                if (currentViewRect.width() != oldViewRect.width() ||
                    // AND/OR the view has been translated when transitioning between small and
                    currentViewRect.height() != oldViewRect.height()) {
                    // large clock
                    if (
                        view != currentSmallClockView ||
                            !view.locationOnScreen.contentEquals(currentSmallClockLocation)
                    ) {
                        currentSmallClockView = view
                        currentSmallClockLocation = view.locationOnScreen
                        updateRegionSampler(view)
                    }
                }
                // LARGE CLOCK
                else if (parent.id == R.id.lockscreen_clock_view_large) {
                    if (
                        view != currentLargeClockView ||
                            !view.locationOnScreen.contentEquals(currentLargeClockLocation)
                    ) {
                        currentLargeClockView = view
                        currentLargeClockLocation = view.locationOnScreen
                    updateRegionSampler(view)
                    updateRegionSampler(view)
                }
                }
            }
            }
        }
        }
        }


    private fun updateColors() {
    private fun updateColors() {
        val wallpaperManager = WallpaperManager.getInstance(context)
        val wallpaperManager = WallpaperManager.getInstance(context)
+4 −2
Original line number Original line Diff line number Diff line
@@ -501,10 +501,12 @@ constructor(


    private fun updateTextColorFromRegionSampler() {
    private fun updateTextColorFromRegionSampler() {
        smartspaceViews.forEach {
        smartspaceViews.forEach {
            val textColor = regionSamplers.getValue(it).currentForegroundColor()
            val textColor = regionSamplers.get(it)?.currentForegroundColor()
            if (textColor != null) {
                it.setPrimaryTextColor(textColor)
                it.setPrimaryTextColor(textColor)
            }
            }
        }
        }
    }


    private fun updateTextColorFromWallpaper() {
    private fun updateTextColorFromWallpaper() {
        val wallpaperManager = WallpaperManager.getInstance(context)
        val wallpaperManager = WallpaperManager.getInstance(context)