Merge "Reusing LayoutListener instead of creating a new one everytime" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index 46886c9..cb5152a 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -443,7 +443,16 @@
private void playIconAnimators(AnimatorSet appOpenAnimator, View v, Rect windowTargetBounds,
boolean toggleVisibility) {
final boolean isBubbleTextView = v instanceof BubbleTextView;
- mFloatingView = new View(mLauncher);
+ if (mFloatingView == null) {
+ mFloatingView = new View(mLauncher);
+ } else {
+ mFloatingView.setTranslationX(0);
+ mFloatingView.setTranslationY(0);
+ mFloatingView.setScaleX(1);
+ mFloatingView.setScaleY(1);
+ mFloatingView.setAlpha(1);
+ mFloatingView.setBackground(null);
+ }
if (isBubbleTextView && v.getTag() instanceof ItemInfoWithIcon ) {
// Create a copy of the app icon
mFloatingView.setBackground(DrawableFactory.INSTANCE.get(mLauncher)
@@ -481,19 +490,17 @@
: viewLocationLeft;
LayoutParams lp = new LayoutParams(rect.width(), rect.height());
lp.ignoreInsets = true;
- lp.setMarginStart(viewLocationStart);
+ lp.leftMargin = viewLocationStart;
lp.topMargin = viewLocationTop;
mFloatingView.setLayoutParams(lp);
// Set the properties here already to make sure they'are available when running the first
// animation frame.
- mFloatingView.setLeft(viewLocationLeft);
- mFloatingView.setTop(viewLocationTop);
- mFloatingView.setRight(viewLocationLeft + rect.width());
- mFloatingView.setBottom(viewLocationTop + rect.height());
+ mFloatingView.layout(viewLocationLeft, viewLocationTop,
+ viewLocationLeft + rect.width(), viewLocationTop + rect.height());
// Swap the two views in place.
- ((ViewGroup) mDragLayer.getParent()).addView(mFloatingView);
+ ((ViewGroup) mDragLayer.getParent()).getOverlay().add(mFloatingView);
if (toggleVisibility) {
v.setVisibility(View.INVISIBLE);
}
@@ -562,7 +569,7 @@
((BubbleTextView) v).setStayPressed(false);
}
v.setVisibility(View.VISIBLE);
- ((ViewGroup) mDragLayer.getParent()).removeView(mFloatingView);
+ ((ViewGroup) mDragLayer.getParent()).getOverlay().remove(mFloatingView);
}
});
}
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 610ef04..fd4585b 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -422,7 +422,9 @@
mSyncTransactionApplier = applier;
});
mRecentsView.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
- updateFinalShift();
+ if (!mBgLongSwipeMode) {
+ updateFinalShift();
+ }
});
mRecentsView.setRecentsAnimationWrapper(mRecentsAnimationWrapper);
mRecentsView.setClipAnimationHelper(mClipAnimationHelper);
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index e2e02dd..4cfd8cb 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -17,6 +17,7 @@
package com.android.quickstep.views;
import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS;
+import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_ICON_PARAMS;
import static com.android.launcher3.anim.Interpolators.ACCEL;
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
@@ -69,6 +70,7 @@
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
+import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -105,7 +107,8 @@
*/
@TargetApi(Build.VERSION_CODES.P)
public abstract class RecentsView<T extends BaseActivity> extends PagedView implements Insettable,
- TaskThumbnailCache.HighResLoadingState.HighResLoadingStateChangedCallback {
+ TaskThumbnailCache.HighResLoadingState.HighResLoadingStateChangedCallback,
+ InvariantDeviceProfile.OnIDPChangeListener {
private static final String TAG = RecentsView.class.getSimpleName();
@@ -151,6 +154,8 @@
// Keeps track of the previously known visible tasks for purposes of loading/unloading task data
private final SparseBooleanArray mHasVisibleTaskData = new SparseBooleanArray();
+ private final InvariantDeviceProfile mIdp;
+
/**
* TODO: Call reloadIdNeeded in onTaskStackChanged.
*/
@@ -293,6 +298,8 @@
mActivity = (T) BaseActivity.fromContext(context);
mQuickScrubController = new QuickScrubController(mActivity, this);
mModel = RecentsModel.INSTANCE.get(context);
+ mIdp = InvariantDeviceProfile.INSTANCE.get(context);
+
mClearAllButton = (ClearAllButton) LayoutInflater.from(context)
.inflate(R.layout.overview_clear_all_button, this, false);
mClearAllButton.setOnClickListener(this::dismissAllTasks);
@@ -335,6 +342,15 @@
}
@Override
+ public void onIdpChanged(int changeFlags, InvariantDeviceProfile idp) {
+ if ((changeFlags & CHANGE_FLAG_ICON_PARAMS) == 0) {
+ return;
+ }
+ mModel.getIconCache().clear();
+ reset();
+ }
+
+ @Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
updateTaskStackListenerState();
@@ -342,6 +358,7 @@
mActivity.addMultiWindowModeChangedListener(mMultiWindowModeChangedListener);
ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
mSyncTransactionApplier = new SyncRtSurfaceTransactionApplierCompat(this);
+ mIdp.addOnChangeListener(this);
}
@Override
@@ -352,6 +369,7 @@
mActivity.removeMultiWindowModeChangedListener(mMultiWindowModeChangedListener);
ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
mSyncTransactionApplier = null;
+ mIdp.removeOnChangeListener(this);
}
@Override
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 5c842a5..3c0ef79 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -30,12 +30,16 @@
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.SparseArray;
+import android.util.TypedValue;
import android.util.Xml;
import android.view.Display;
import android.view.WindowManager;
import com.android.launcher3.util.ConfigMonitor;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.MainThreadInitializedObject;
+import com.android.launcher3.util.Themes;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -44,6 +48,7 @@
import java.util.ArrayList;
import java.util.Collections;
+import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
public class InvariantDeviceProfile {
@@ -91,6 +96,8 @@
public int fillResIconDpi;
public float iconTextSize;
+ private SparseArray<TypedValue> mExtraAttrs;
+
/**
* Number of icons inside the hotseat area.
*/
@@ -122,6 +129,7 @@
numHotseatIcons = p.numHotseatIcons;
defaultLayoutId = p.defaultLayoutId;
demoModeLayoutId = p.demoModeLayoutId;
+ mExtraAttrs = p.mExtraAttrs;
}
@TargetApi(23)
@@ -171,6 +179,8 @@
demoModeLayoutId = closestProfile.demoModeLayoutId;
numFolderRows = closestProfile.numFolderRows;
numFolderColumns = closestProfile.numFolderColumns;
+ mExtraAttrs = closestProfile.extraAttrs;
+
if (!closestProfile.name.equals(gridName)) {
Utilities.getPrefs(context).edit()
.putString(KEY_IDP_GRID_NAME, closestProfile.name).apply();
@@ -210,10 +220,19 @@
}
}
+ @Nullable
+ public TypedValue getAttrValue(int attr) {
+ return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
+ }
+
public void addOnChangeListener(OnIDPChangeListener listener) {
mChangeListeners.add(listener);
}
+ public void removeOnChangeListener(OnIDPChangeListener listener) {
+ mChangeListeners.remove(listener);
+ }
+
private void killProcess(Context context) {
Log.e("ConfigMonitor", "restarting launcher");
android.os.Process.killProcess(android.os.Process.myPid());
@@ -436,6 +455,8 @@
private final int defaultLayoutId;
private final int demoModeLayoutId;
+ private final SparseArray<TypedValue> extraAttrs;
+
GridOption(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.GridDisplayOption);
@@ -454,6 +475,9 @@
numFolderColumns = a.getInt(
R.styleable.GridDisplayOption_numFolderColumns, numColumns);
a.recycle();
+
+ extraAttrs = Themes.createValueMap(context, attrs,
+ IntArray.wrap(R.styleable.GridDisplayOption));
}
}
diff --git a/src/com/android/launcher3/folder/FolderShape.java b/src/com/android/launcher3/folder/FolderShape.java
index f7cdb77..4b06dda 100644
--- a/src/com/android/launcher3/folder/FolderShape.java
+++ b/src/com/android/launcher3/folder/FolderShape.java
@@ -49,6 +49,7 @@
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.Themes;
import org.xmlpull.v1.XmlPullParser;
@@ -387,6 +388,8 @@
final int depth = parser.getDepth();
int[] radiusAttr = new int[] {R.attr.folderIconRadius};
+ IntArray keysToIgnore = new IntArray(0);
+
while (((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
@@ -396,7 +399,7 @@
FolderShape shape = getShapeDefinition(parser.getName(), a.getFloat(0, 1));
a.recycle();
- shape.mAttrs = Themes.createValueMap(context, attrs);
+ shape.mAttrs = Themes.createValueMap(context, attrs, keysToIgnore);
result.add(shape);
}
}
diff --git a/src/com/android/launcher3/util/Themes.java b/src/com/android/launcher3/util/Themes.java
index e3ab1a5..675e2f4 100644
--- a/src/com/android/launcher3/util/Themes.java
+++ b/src/com/android/launcher3/util/Themes.java
@@ -112,16 +112,19 @@
* Creates a map for attribute-name to value for all the values in {@param attrs} which can be
* held in memory for later use.
*/
- public static SparseArray<TypedValue> createValueMap(Context context, AttributeSet attrSet) {
+ public static SparseArray<TypedValue> createValueMap(Context context, AttributeSet attrSet,
+ IntArray keysToIgnore) {
int count = attrSet.getAttributeCount();
- int[] attrNames = new int[count];
+ IntArray attrNameArray = new IntArray(count);
for (int i = 0; i < count; i++) {
- attrNames[i] = attrSet.getAttributeNameResource(i);
+ attrNameArray.add(attrSet.getAttributeNameResource(i));
}
+ attrNameArray.removeAllValues(keysToIgnore);
- SparseArray<TypedValue> result = new SparseArray<>(count);
+ int[] attrNames = attrNameArray.toArray();
+ SparseArray<TypedValue> result = new SparseArray<>(attrNames.length);
TypedArray ta = context.obtainStyledAttributes(attrSet, attrNames);
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < attrNames.length; i++) {
TypedValue tv = new TypedValue();
ta.getValue(i, tv);
result.put(attrNames[i], tv);