Merge "Fix preview layout crash upon screen rotation" into sc-dev
diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml
index b570464..9ac6ed0 100644
--- a/res/layout/all_apps.xml
+++ b/res/layout/all_apps.xml
@@ -36,6 +36,7 @@
         android:layout_below="@id/search_container_all_apps"
         android:clipToPadding="false"
         android:paddingTop="@dimen/all_apps_header_top_padding"
+        android:paddingBottom="@dimen/all_apps_header_bottom_padding"
         android:orientation="vertical" >
 
         <include layout="@layout/floating_header_content" />
diff --git a/res/layout/all_apps_personal_work_tabs.xml b/res/layout/all_apps_personal_work_tabs.xml
index ebb69f6..cfaa261 100644
--- a/res/layout/all_apps_personal_work_tabs.xml
+++ b/res/layout/all_apps_personal_work_tabs.xml
@@ -31,7 +31,7 @@
         android:background="@drawable/personal_work_tabs_ripple"
         android:text="@string/all_apps_personal_tab"
         android:textColor="@color/all_apps_tab_text"
-        android:textSize="16sp" />
+        android:textSize="14sp" />
 
     <Button
         android:id="@+id/tab_work"
@@ -41,5 +41,5 @@
         android:background="@drawable/personal_work_tabs_ripple"
         android:text="@string/all_apps_work_tab"
         android:textColor="@color/all_apps_tab_text"
-        android:textSize="16sp" />
+        android:textSize="14sp" />
 </com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip>
\ No newline at end of file
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index dc33ab8..92deb68 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -57,8 +57,9 @@
             <enum name="folder" value="2" />
             <enum name="widget_section" value="3" />
             <enum name="shortcut_popup" value="4" />
-            <enum name="hero_app" value="5" />
-            <enum name="taskbar" value="6" />
+            <enum name="taskbar" value="5" />
+            <enum name="search_result_tall" value="6" />
+            <enum name="search_result_small" value="7" />
         </attr>
         <attr name="centerVertically" format="boolean" />
     </declare-styleable>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f9d62a6..d065611 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -97,6 +97,7 @@
     <dimen name="all_apps_header_tab_height">48dp</dimen>
     <dimen name="all_apps_tabs_indicator_height">2dp</dimen>
     <dimen name="all_apps_header_top_padding">36dp</dimen>
+    <dimen name="all_apps_header_bottom_padding">16dp</dimen>
     <dimen name="all_apps_work_profile_tab_footer_top_padding">16dp</dimen>
     <dimen name="all_apps_work_profile_tab_footer_bottom_padding">20dp</dimen>
     <dimen name="all_apps_tabs_vertical_padding">6dp</dimen>
@@ -311,4 +312,7 @@
     <dimen name="grid_visualization_rounding_radius">22dp</dimen>
     <dimen name="grid_visualization_cell_spacing">6dp</dimen>
 
+<!-- Search results related parameters -->
+    <dimen name="search_row_icon_size">48dp</dimen>
+    <dimen name="search_row_small_icon_size">32dp</dimen>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0c389aa..86dcf4c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -315,5 +315,6 @@
 
     <style name="AddItemActivityTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
         <item name="widgetsTheme">@style/WidgetContainerTheme</item>
+        <item name="android:windowLightStatusBar">true</item>
     </style>
 </resources>
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 4f0ef12..ddbd425 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -80,8 +80,9 @@
     private static final int DISPLAY_WORKSPACE = 0;
     private static final int DISPLAY_ALL_APPS = 1;
     private static final int DISPLAY_FOLDER = 2;
-    private static final int DISPLAY_HERO_APP = 5;
-    protected static final int DISPLAY_TASKBAR = 6;
+    protected static final int DISPLAY_TASKBAR = 5;
+    private static final int DISPLAY_SEARCH_RESULT = 6;
+    private static final int DISPLAY_SEARCH_RESULT_SMALL = 7;
 
     private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
     private static final float HIGHLIGHT_SCALE = 1.16f;
@@ -187,8 +188,11 @@
             setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
             setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
             defaultIconSize = grid.folderChildIconSizePx;
-        } else if (mDisplay == DISPLAY_HERO_APP) {
-            defaultIconSize = grid.allAppsIconSizePx;
+        } else if (mDisplay == DISPLAY_SEARCH_RESULT) {
+            defaultIconSize = getResources().getDimensionPixelSize(R.dimen.search_row_icon_size);
+        } else if (mDisplay == DISPLAY_SEARCH_RESULT_SMALL) {
+            defaultIconSize = getResources().getDimensionPixelSize(
+                    R.dimen.search_row_small_icon_size);
         } else if (mDisplay == DISPLAY_TASKBAR) {
             defaultIconSize = grid.iconSizePx;
         } else {
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
index d9fb5f0..50ab422 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
@@ -41,6 +41,7 @@
 import android.widget.Advanceable;
 import android.widget.RemoteViews;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.UiThread;
 
@@ -262,6 +263,10 @@
 
         mIsAttachedToWindow = true;
         checkIfAutoAdvance();
+
+        if (mLastLocationRegistered != null) {
+            mColorExtractor.addLocation(List.of(mLastLocationRegistered));
+        }
     }
 
     @Override
@@ -366,7 +371,7 @@
         if (mTempRectF.isEmpty()) {
             return;
         }
-        if (!mTempRectF.equals(mLastLocationRegistered)) {
+        if (!isSameLocation(mTempRectF, mLastLocationRegistered, /* epsilon= */ 1e-6f)) {
             if (mLastLocationRegistered != null) {
                 mColorExtractor.removeLocations();
             }
@@ -375,6 +380,20 @@
         }
     }
 
+    // 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 @@
     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() {