Merge "Initial changes for handling configuration changes dynamically" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index aa23ee5..5492bbb 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -445,6 +445,10 @@
                     mAnimator.play(getClosingWindowAnimators(targets));
                     mAnimator.play(getLauncherResumeAnimation());
                     mAnimator.start();
+
+                    // Because t=0 has the app icon in its original spot, we can skip the
+                    // first frame and have the same movement one frame earlier.
+                    mAnimator.setCurrentPlayTime(REFRESH_RATE_MS);
                 });
             }
         };
@@ -457,7 +461,7 @@
         Matrix matrix = new Matrix();
         float height = mLauncher.getDeviceProfile().heightPx;
         float width = mLauncher.getDeviceProfile().widthPx;
-        float endX = Utilities.isRtl(mLauncher.getResources()) ? -width : width;
+        float endX = (Utilities.isRtl(mLauncher.getResources()) ? -width : width) * 1.16f;
 
         ValueAnimator closingAnimator = ValueAnimator.ofFloat(0, 1);
         closingAnimator.setDuration(CLOSING_TRANSITION_DURATION_MS);
@@ -472,27 +476,27 @@
 
                 float scale = getValue(1f, 0.8f, 0, 267, currentPlayTime,
                         Interpolators.AGGRESSIVE_EASE);
-                matrix.setScale(scale, scale);
 
                 float dX = getValue(0, endX, 0, 350, currentPlayTime,
                         Interpolators.AGGRESSIVE_EASE_IN_OUT);
-                float dY = (height - height * scale) / 2f;
 
                 TransactionCompat t = new TransactionCompat();
                 for (RemoteAnimationTargetCompat app : targets) {
                     if (app.mode == RemoteAnimationTargetCompat.MODE_CLOSING) {
-                        t.setAlpha(app.leash, 1f - percent);
-                        matrix.postTranslate(dX, dY);
+                        t.setAlpha(app.leash, getValue(1f, 0f, 0, 350, currentPlayTime,
+                                Interpolators.APP_CLOSE_ALPHA));
+                        matrix.setScale(scale, scale,
+                                app.sourceContainerBounds.centerX(),
+                                app.sourceContainerBounds.centerY());
+                        matrix.postTranslate(dX, 0);
                         matrix.postTranslate(app.position.x, app.position.y);
                         t.setMatrix(app.leash, matrix);
                     }
-                    // TODO: Layer should be set only once, but there is possibly a race condition
-                    // where WindowManager is also calling setLayer.
-                    int layer = app.mode == RemoteAnimationTargetCompat.MODE_CLOSING
-                            ? Integer.MAX_VALUE
-                            : app.prefixOrderIndex;
-                    t.setLayer(app.leash, layer);
                     if (isFirstFrame) {
+                        int layer = app.mode == RemoteAnimationTargetCompat.MODE_CLOSING
+                                ? Integer.MAX_VALUE
+                                : app.prefixOrderIndex;
+                        t.setLayer(app.leash, layer);
                         t.show(app.leash);
                     }
                 }
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 1d8877c..0490832 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -58,6 +58,7 @@
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.MainThreadExecutor;
 import com.android.launcher3.Utilities;
+import com.android.launcher3.model.ModelPreload;
 import com.android.launcher3.util.TraceHelper;
 import com.android.systemui.shared.recents.IOverviewProxy;
 import com.android.systemui.shared.recents.ISystemUiProxy;
@@ -195,6 +196,7 @@
         mEventQueue = new MotionEventQueue(Choreographer.getInstance(), mNoOpTouchConsumer);
         sConnected = true;
 
+        new ModelPreload().start(this);
         initBackgroundChoreographer();
     }
 
diff --git a/res/color/all_apps_work_tab_text.xml b/res/color/all_apps_work_tab_text.xml
deleted file mode 100644
index 7279bf8..0000000
--- a/res/color/all_apps_work_tab_text.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:color="@color/work_profile_color" android:state_selected="true"/>
-    <item android:color="?android:attr/textColorTertiary"/>
-</selector>
\ No newline at end of file
diff --git a/res/layout/all_apps_floating_header.xml b/res/layout/all_apps_floating_header.xml
index 166725d..c4240f8 100644
--- a/res/layout/all_apps_floating_header.xml
+++ b/res/layout/all_apps_floating_header.xml
@@ -52,7 +52,7 @@
             android:fontFamily="sans-serif-medium"
             android:text="@string/all_apps_work_tab"
             android:textAllCaps="true"
-            android:textColor="@color/all_apps_work_tab_text"
+            android:textColor="@color/all_apps_tab_text"
             android:textSize="14sp" />
     </com.android.launcher3.allapps.PersonalWorkSlidingTabStrip>
 </com.android.launcher3.allapps.FloatingHeaderView>
diff --git a/res/layout/system_shortcut_icon_only.xml b/res/layout/system_shortcut_icon_only.xml
index c59cb53..b8b5b8c 100644
--- a/res/layout/system_shortcut_icon_only.xml
+++ b/res/layout/system_shortcut_icon_only.xml
@@ -20,5 +20,6 @@
     android:layout_height="@dimen/system_shortcut_header_icon_touch_size"
     android:background="?android:attr/selectableItemBackgroundBorderless"
     android:tint="?android:attr/textColorHint"
+    android:tintMode="src_in"
     android:padding="@dimen/system_shortcut_header_icon_padding"
     android:theme="@style/PopupItem" />
diff --git a/res/layout/work_tab_footer.xml b/res/layout/work_tab_footer.xml
index dc0fdd4..21ff55e 100644
--- a/res/layout/work_tab_footer.xml
+++ b/res/layout/work_tab_footer.xml
@@ -38,8 +38,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentEnd="true"
-        android:layout_below="@id/work_footer_divider"
-        android:theme="@style/WorkModeSwitchTheme"/>
+        android:layout_below="@id/work_footer_divider"/>
 
     <TextView
         android:id="@android:id/title"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 4abdfd6..eb207af 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -38,6 +38,4 @@
 
     <color name="all_apps_bg_hand_fill">#E5E5E5</color>
     <color name="all_apps_bg_hand_fill_dark">#9AA0A6</color>
-
-    <color name="work_profile_color">#FF6D00</color>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c714841..8cc4743 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -168,8 +168,4 @@
         <item name="android:colorControlHighlight">#DFE1E5</item>
         <item name="android:colorForeground">@color/all_apps_bg_hand_fill_dark</item>
     </style>
-
-    <style name="WorkModeSwitchTheme" parent="@style/LauncherTheme">
-        <item name="android:colorAccent">@color/work_profile_color</item>
-    </style>
 </resources>
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 1b169f5..929606e 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -20,7 +20,6 @@
 import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD;
 
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -40,21 +39,18 @@
 import com.android.launcher3.compat.LauncherAppsCompat;
 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
 import com.android.launcher3.compat.UserManagerCompat;
-import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.graphics.LauncherIcons;
 import com.android.launcher3.model.AddWorkspaceItemsTask;
+import com.android.launcher3.model.BaseModelUpdateTask;
 import com.android.launcher3.model.BgDataModel;
 import com.android.launcher3.model.CacheDataUpdatedTask;
-import com.android.launcher3.model.BaseModelUpdateTask;
 import com.android.launcher3.model.LoaderResults;
 import com.android.launcher3.model.LoaderTask;
 import com.android.launcher3.model.ModelWriter;
 import com.android.launcher3.model.PackageInstallStateChangedTask;
-import com.android.launcher3.model.PackageItemInfo;
 import com.android.launcher3.model.PackageUpdatedTask;
 import com.android.launcher3.model.ShortcutsChangedTask;
 import com.android.launcher3.model.UserLockStateChangedTask;
-import com.android.launcher3.model.WidgetItem;
 import com.android.launcher3.provider.LauncherDbUtils;
 import com.android.launcher3.shortcuts.DeepShortcutManager;
 import com.android.launcher3.shortcuts.ShortcutInfoCompat;
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 19df17e..e2c0d10 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -543,7 +543,7 @@
 
     public void onScrollUpEnd() {
         if (mUsingTabs) {
-            ((PersonalWorkSlidingTabStrip) findViewById(R.id.tabs)).peekWorkTabIfNecessary();
+            ((PersonalWorkSlidingTabStrip) findViewById(R.id.tabs)).highlightWorkTabIfNecessary();
         }
     }
 
diff --git a/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java
index 393884e..05cd655 100644
--- a/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java
+++ b/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java
@@ -15,7 +15,6 @@
  */
 package com.android.launcher3.allapps;
 
-import android.animation.ValueAnimator;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.graphics.Canvas;
@@ -30,7 +29,6 @@
 import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
-import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.util.Themes;
 
 /**
@@ -39,13 +37,10 @@
 public class PersonalWorkSlidingTabStrip extends LinearLayout {
     private static final int POSITION_PERSONAL = 0;
     private static final int POSITION_WORK = 1;
-    private static final int PEEK_DURATION = 1000;
-    private static final float PEAK_OFFSET = 0.4f;
 
     private static final String KEY_SHOWED_PEEK_WORK_TAB = "showed_peek_work_tab";
 
-    private final Paint mPersonalTabIndicatorPaint;
-    private final Paint mWorkTabIndicatorPaint;
+    private final Paint mSelectedIndicatorPaint;
     private final Paint mDividerPaint;
     private final SharedPreferences mSharedPreferences;
 
@@ -55,7 +50,6 @@
     private int mIndicatorPosition = 0;
     private float mIndicatorOffset;
     private int mSelectedPosition = 0;
-    private boolean mIsRtl;
 
     public PersonalWorkSlidingTabStrip(@NonNull Context context, @Nullable AttributeSet attrs) {
         super(context, attrs);
@@ -65,15 +59,10 @@
         mSelectedIndicatorHeight =
                 getResources().getDimensionPixelSize(R.dimen.all_apps_tabs_indicator_height);
 
-        mPersonalTabIndicatorPaint = new Paint();
-        mPersonalTabIndicatorPaint.setColor(
+        mSelectedIndicatorPaint = new Paint();
+        mSelectedIndicatorPaint.setColor(
                 Themes.getAttrColor(context, android.R.attr.colorAccent));
 
-        mWorkTabIndicatorPaint = new Paint();
-        mWorkTabIndicatorPaint.setColor(getResources().getColor(R.color.work_profile_color));
-
-        mIsRtl = Utilities.isRtl(getResources());
-
         mDividerPaint = new Paint();
         mDividerPaint.setColor(Themes.getAttrColor(context, android.R.attr.colorControlHighlight));
         mDividerPaint.setStrokeWidth(
@@ -142,40 +131,26 @@
         canvas.drawLine(getPaddingLeft(), y, getWidth() - getPaddingRight(), y, mDividerPaint);
 
         final float middleX = getWidth() / 2.0f;
-        if (mIndicatorLeft <= middleX) {
-            canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight,
-                    middleX, getHeight(), getPaint(true /* firstHalf */));
-        }
-        if (mIndicatorRight > middleX) {
-            canvas.drawRect(middleX, getHeight() - mSelectedIndicatorHeight,
-                    mIndicatorRight, getHeight(), getPaint(false /* firstHalf */));
-        }
+        canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight,
+            mIndicatorRight, getHeight(), mSelectedIndicatorPaint);
     }
 
-    private Paint getPaint(boolean firstHalf) {
-        boolean isPersonal = mIsRtl ^ firstHalf;
-        return isPersonal ? mPersonalTabIndicatorPaint : mWorkTabIndicatorPaint;
-    }
-
-    public void peekWorkTabIfNecessary() {
+    public void highlightWorkTabIfNecessary() {
         if (mSharedPreferences.getBoolean(KEY_SHOWED_PEEK_WORK_TAB, false)) {
             return;
         }
         if (mIndicatorPosition != POSITION_PERSONAL) {
             return;
         }
-        peekWorkTab();
+        highlightWorkTab();
         mSharedPreferences.edit().putBoolean(KEY_SHOWED_PEEK_WORK_TAB, true).apply();
     }
 
-    private void peekWorkTab() {
-        final boolean isRtl = Utilities.isRtl(getResources());
-        ValueAnimator animator = ValueAnimator.ofFloat(0, isRtl ? 1 - PEAK_OFFSET : PEAK_OFFSET, 0);
-        animator.setDuration(PEEK_DURATION);
-        animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
-        animator.addUpdateListener(
-                animation -> updateIndicatorPosition(mIndicatorPosition,
-                        (float) animation.getAnimatedValue()));
-        animator.start();
+    private void highlightWorkTab() {
+        View v = getChildAt(POSITION_WORK);
+        v.post(() -> {
+            v.setPressed(true);
+            v.setPressed(false);
+        });
     }
 }
diff --git a/src/com/android/launcher3/anim/Interpolators.java b/src/com/android/launcher3/anim/Interpolators.java
index ee0dba6..2343654 100644
--- a/src/com/android/launcher3/anim/Interpolators.java
+++ b/src/com/android/launcher3/anim/Interpolators.java
@@ -46,6 +46,8 @@
     public static final Interpolator AGGRESSIVE_EASE = new PathInterpolator(0.2f, 0f, 0f, 1f);
     public static final Interpolator AGGRESSIVE_EASE_IN_OUT = new PathInterpolator(0.8f,0, 0.4f, 1);
 
+    public static final Interpolator APP_CLOSE_ALPHA = new PathInterpolator(0.9f, 0, 1f, 1f);
+
     public static final Interpolator OVERSHOOT_0 = new OvershootInterpolator(0);
 
     /**
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 883c33d..00dd3aa 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -54,7 +54,6 @@
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.folder.Folder;
 import com.android.launcher3.folder.FolderIconPreviewVerifier;
-import com.android.launcher3.graphics.IconNormalizer;
 import com.android.launcher3.graphics.LauncherIcons;
 import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.provider.ImportDataTask;
diff --git a/src/com/android/launcher3/model/ModelPreload.java b/src/com/android/launcher3/model/ModelPreload.java
new file mode 100644
index 0000000..6f33bed
--- /dev/null
+++ b/src/com/android/launcher3/model/ModelPreload.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.model;
+
+import android.content.Context;
+import android.support.annotation.WorkerThread;
+import android.util.Log;
+
+import com.android.launcher3.AllAppsList;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
+import com.android.launcher3.LauncherModel.ModelUpdateTask;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Utility class to preload LauncherModel
+ */
+public class ModelPreload implements ModelUpdateTask {
+
+    private static final String TAG = "ModelPreload";
+
+    private LauncherAppState mApp;
+    private LauncherModel mModel;
+    private BgDataModel mBgDataModel;
+    private AllAppsList mAllAppsList;
+
+    @Override
+    public final void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel,
+            AllAppsList allAppsList, Executor uiExecutor) {
+        mApp = app;
+        mModel = model;
+        mBgDataModel = dataModel;
+        mAllAppsList = allAppsList;
+    }
+
+    @Override
+    public final void run() {
+        if (!mModel.isModelLoaded()) {
+            Log.d(TAG, "Workspace not loaded, loading now");
+            mModel.startLoaderForResults(
+                    new LoaderResults(mApp, mBgDataModel, mAllAppsList, 0, null));
+        }
+        Log.d(TAG, "Preload completed : " + mModel.isModelLoaded());
+        onComplete(mModel.isModelLoaded());
+    }
+
+    /**
+     * Called when the task is complete
+     */
+    @WorkerThread
+    public void onComplete(boolean isSuccess) { }
+
+    public void start(Context context) {
+        LauncherAppState.getInstance(context).getModel().enqueueModelUpdateTask(this);
+    }
+}
\ No newline at end of file