Merge "Fixing wrong check for grid migration" into ub-launcher3-master
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index e3c6965..8aeab87 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -29,6 +29,7 @@
 
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.config.ProviderConfig;
+import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.util.Thunk;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -187,6 +188,23 @@
         }
     }
 
+    public void dumpDisplayInfo(Context context) {
+        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+        Display display = wm.getDefaultDisplay();
+        DisplayMetrics dm = new DisplayMetrics();
+        display.getMetrics(dm);
+
+        Point smallestSize = new Point();
+        Point largestSize = new Point();
+        display.getCurrentSizeRange(smallestSize, largestSize);
+
+        FileLog.e("DisplayInfo", "Default Density: " + DisplayMetrics.DENSITY_DEFAULT);
+        FileLog.e("DisplayInfo", "Density: " + dm.densityDpi);
+        FileLog.e("DisplayInfo", "Smallest size: " + smallestSize);
+        FileLog.e("DisplayInfo", "Largest size: " + largestSize);
+        FileLog.e("DisplayInfo", "minWidth/Height DPS: " + minWidthDps + ", " + minHeightDps);
+    }
+
     ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles(Context context) {
         ArrayList<InvariantDeviceProfile> profiles = new ArrayList<>();
         try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 55c3703..e0e53a6 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -28,6 +28,7 @@
 import com.android.launcher3.compat.UserManagerCompat;
 import com.android.launcher3.config.ProviderConfig;
 import com.android.launcher3.dynamicui.ExtractionUtils;
+import com.android.launcher3.model.GridSizeMigrationTask;
 import com.android.launcher3.util.ConfigMonitor;
 import com.android.launcher3.util.Preconditions;
 import com.android.launcher3.util.TestingUtils;
@@ -53,6 +54,8 @@
         if (INSTANCE == null) {
             if (Looper.myLooper() == Looper.getMainLooper()) {
                 INSTANCE = new LauncherAppState(context.getApplicationContext());
+                GridSizeMigrationTask.logDeviceProfileIfChanged(
+                        INSTANCE.getInvariantDeviceProfile(), context);
             } else {
                 try {
                     return new MainThreadExecutor().submit(new Callable<LauncherAppState>() {
diff --git a/src/com/android/launcher3/dynamicui/ColorExtractionService.java b/src/com/android/launcher3/dynamicui/ColorExtractionService.java
index 1a127dc..f94d442 100644
--- a/src/com/android/launcher3/dynamicui/ColorExtractionService.java
+++ b/src/com/android/launcher3/dynamicui/ColorExtractionService.java
@@ -98,7 +98,7 @@
                 if (bitmap != null) {
                     return Palette.from(bitmap).clearFilters().generate();
                 }
-            } catch (IOException e) {
+            } catch (IOException | NullPointerException e) {
                 Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
             }
         }
@@ -129,7 +129,7 @@
                 if (bitmap != null) {
                     return Palette.from(bitmap).clearFilters().generate();
                 }
-            } catch (IOException e) {
+            } catch (IOException | NullPointerException e) {
                 Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
             }
         }
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index 221798b..e50b912 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -27,6 +27,7 @@
 import com.android.launcher3.compat.AppWidgetManagerCompat;
 import com.android.launcher3.compat.PackageInstallerCompat;
 import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.util.GridOccupancy;
 import com.android.launcher3.util.LongArrayMap;
 
@@ -889,6 +890,23 @@
                 .apply();
     }
 
+    public static void logDeviceProfileIfChanged(InvariantDeviceProfile idp, Context context) {
+        SharedPreferences prefs = Utilities.getPrefs(context);
+        String gridSizeString = getPointString(idp.numColumns, idp.numRows);
+
+        int oldHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numHotseatIcons);
+        String oldSize = prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString);
+        if (gridSizeString.equals(oldSize) && idp.numHotseatIcons == oldHotseatCount) {
+            // Skip if workspace and hotseat sizes have not changed.
+            return;
+        }
+
+        FileLog.e(TAG, "Grid size changed" + gridSizeString);
+        FileLog.e(TAG, "   oldSize: " + oldSize + "  , hotseat: " + oldHotseatCount);
+        FileLog.e(TAG, "   newSize: " + gridSizeString + "  , hotseat: " + idp.numHotseatIcons);
+        idp.dumpDisplayInfo(context);
+    }
+
     /**
      * Migrates the workspace and hotseat in case their sizes changed.
      * @return false if the migration failed.
diff --git a/src/com/android/launcher3/notification/NotificationItemView.java b/src/com/android/launcher3/notification/NotificationItemView.java
index 639447d..c9b3940 100644
--- a/src/com/android/launcher3/notification/NotificationItemView.java
+++ b/src/com/android/launcher3/notification/NotificationItemView.java
@@ -83,12 +83,20 @@
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
+        if (mMainView.getNotificationInfo() == null) {
+            // The notification hasn't been populated yet.
+            return false;
+        }
         getParent().requestDisallowInterceptTouchEvent(true);
         return mSwipeHelper.onInterceptTouchEvent(ev);
     }
 
     @Override
     public boolean onTouchEvent(MotionEvent ev) {
+        if (mMainView.getNotificationInfo() == null) {
+            // The notification hasn't been populated yet.
+            return false;
+        }
         return mSwipeHelper.onTouchEvent(ev) || super.onTouchEvent(ev);
     }
 
diff --git a/src/com/android/launcher3/notification/NotificationMainView.java b/src/com/android/launcher3/notification/NotificationMainView.java
index 6677c2f..a05fef3 100644
--- a/src/com/android/launcher3/notification/NotificationMainView.java
+++ b/src/com/android/launcher3/notification/NotificationMainView.java
@@ -18,8 +18,11 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorSet;
+import android.animation.ArgbEvaluator;
+import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
@@ -39,10 +42,13 @@
  */
 public class NotificationMainView extends LinearLayout implements SwipeHelper.Callback {
 
+    private final ArgbEvaluator mArgbEvaluator = new ArgbEvaluator();
+
     private NotificationInfo mNotificationInfo;
     private TextView mTitleView;
     private TextView mTextView;
     private IconPalette mIconPalette;
+    private ColorDrawable mColorBackground;
 
     public NotificationMainView(Context context) {
         this(context, null, 0);
@@ -65,7 +71,8 @@
     }
 
     public void applyColors(IconPalette iconPalette) {
-        setBackgroundColor(iconPalette.backgroundColor);
+        mColorBackground = new ColorDrawable(iconPalette.backgroundColor);
+        setBackground(mColorBackground);
         mIconPalette = iconPalette;
     }
 
@@ -81,7 +88,7 @@
         if (animate) {
             mTitleView.setAlpha(0);
             mTextView.setAlpha(0);
-            setBackgroundColor(mIconPalette.secondaryColor);
+            mColorBackground.setColor(mIconPalette.secondaryColor);
         }
         mNotificationInfo = mainNotification;
         mTitleView.setText(mNotificationInfo.title);
@@ -97,14 +104,8 @@
             AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
             Animator textFade = new LauncherViewPropertyAnimator(mTextView).alpha(1);
             Animator titleFade = new LauncherViewPropertyAnimator(mTitleView).alpha(1);
-            ValueAnimator colorChange = ValueAnimator.ofArgb(mIconPalette.secondaryColor,
-                    mIconPalette.backgroundColor);
-            colorChange.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
-                @Override
-                public void onAnimationUpdate(ValueAnimator valueAnimator) {
-                    setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
-                }
-            });
+            ValueAnimator colorChange = ObjectAnimator.ofObject(mColorBackground, "color",
+                    mArgbEvaluator, mIconPalette.secondaryColor, mIconPalette.backgroundColor);
             animation.playTogether(textFade, titleFade, colorChange);
             animation.setDuration(150);
             animation.start();