Loading src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +20 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -262,6 +263,10 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView mIsAttachedToWindow = true; checkIfAutoAdvance(); if (mLastLocationRegistered != null) { mColorExtractor.addLocation(List.of(mLastLocationRegistered)); } } @Override Loading Loading @@ -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(); } Loading @@ -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. Loading @@ -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() { Loading Loading
src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +20 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -262,6 +263,10 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView mIsAttachedToWindow = true; checkIfAutoAdvance(); if (mLastLocationRegistered != null) { mColorExtractor.addLocation(List.of(mLastLocationRegistered)); } } @Override Loading Loading @@ -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(); } Loading @@ -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. Loading @@ -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() { Loading