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

Commit 4049f539 authored by Jay Aliomer's avatar Jay Aliomer Committed by Android (Google) Code Review
Browse files

Merge "Improve local color extraction handling." into sc-dev

parents ab8543e1 7fca8705
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.widget.AdapterView;
import android.widget.Advanceable;
import android.widget.RemoteViews;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;

@@ -262,6 +263,10 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView

        mIsAttachedToWindow = true;
        checkIfAutoAdvance();

        if (mLastLocationRegistered != null) {
            mColorExtractor.addLocation(List.of(mLastLocationRegistered));
        }
    }

    @Override
@@ -366,7 +371,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
        if (mTempRectF.isEmpty()) {
            return;
        }
        if (!mTempRectF.equals(mLastLocationRegistered)) {
        if (!isSameLocation(mTempRectF, mLastLocationRegistered, /* epsilon= */ 1e-6f)) {
            if (mLastLocationRegistered != null) {
                mColorExtractor.removeLocations();
            }
@@ -375,6 +380,20 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
        }
    }

    // Compare two location rectangles. Locations are always in the [0;1] range.
    private static boolean isSameLocation(@NonNull RectF rect1, @Nullable RectF rect2,
            float epsilon) {
        if (rect2 == null) return false;
        return isSameCoordinate(rect1.left, rect2.left, epsilon)
                && isSameCoordinate(rect1.right, rect2.right, epsilon)
                && isSameCoordinate(rect1.top, rect2.top, epsilon)
                && isSameCoordinate(rect1.bottom, rect2.bottom, epsilon);
    }

    private static boolean isSameCoordinate(float c1, float c2, float epsilon) {
        return Math.abs(c1 - c2) < epsilon;
    }

    @Override
    public void onColorsChanged(RectF rectF, SparseIntArray colors) {
        // setColorResources will reapply the view, which must happen in the UI thread.
@@ -391,14 +410,6 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
    protected void onWindowVisibilityChanged(int visibility) {
        super.onWindowVisibilityChanged(visibility);
        maybeRegisterAutoAdvance();

        if (visibility == View.VISIBLE) {
            if (mLastLocationRegistered != null) {
                mColorExtractor.addLocation(List.of(mLastLocationRegistered));
            }
        } else {
            mColorExtractor.removeLocations();
        }
    }

    private void checkIfAutoAdvance() {