mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 08:16:49 +00:00
Merge "Improve local color extraction handling." into sc-dev
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user