Merge "[PS] Add emphasized interpolators when clicking the PS tile to scroll to bottom." into main
diff --git a/quickstep/res/layout/icon_app_chip_view.xml b/quickstep/res/layout/icon_app_chip_view.xml
index fa9fd2b..b7acb70 100644
--- a/quickstep/res/layout/icon_app_chip_view.xml
+++ b/quickstep/res/layout/icon_app_chip_view.xml
@@ -60,9 +60,8 @@
android:maxLines="1"
android:ellipsize="end"
android:textAlignment="viewStart"
- android:textColor="?androidprv:attr/materialColorOnSurface"
- android:textSize="@dimen/task_thumbnail_icon_menu_text_size"
- android:importantForAccessibility="no" />
+ android:importantForAccessibility="no"
+ style="@style/IconAppChipMenuTextStyle" />
<TextView
android:id="@+id/icon_text_expanded"
@@ -72,9 +71,8 @@
android:maxLines="1"
android:ellipsize="end"
android:textAlignment="viewStart"
- android:textColor="?androidprv:attr/materialColorOnSurface"
- android:textSize="@dimen/task_thumbnail_icon_menu_text_size"
- android:importantForAccessibility="no" />
+ android:importantForAccessibility="no"
+ style="@style/IconAppChipMenuTextStyle" />
<ImageView
android:id="@+id/icon_arrow"
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index 295074a..079f01b 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -55,7 +55,7 @@
<!-- The max width of the icon menu text -->
<dimen name="task_thumbnail_icon_menu_text_max_width">118dp</dimen>
<!-- The size of the icon menu text -->
- <dimen name="task_thumbnail_icon_menu_text_size">16sp</dimen>
+ <dimen name="task_thumbnail_icon_menu_text_size">14sp</dimen>
<!-- The max width of the thumbnail icon menu background -->
<dimen name="task_thumbnail_icon_menu_background_max_width">164dp</dimen>
<!-- The height of the thumbnail icon menu -->
diff --git a/quickstep/res/values/styles.xml b/quickstep/res/values/styles.xml
index fc03704..ae62c26 100644
--- a/quickstep/res/values/styles.xml
+++ b/quickstep/res/values/styles.xml
@@ -303,4 +303,12 @@
<item name="arrowTipBackground">?androidprv:attr/materialColorSurfaceContainer</item>
<item name="arrowTipTextColor">?androidprv:attr/materialColorOnSurface</item>
</style>
+
+ <style name="IconAppChipMenuTextStyle">
+ <item name="android:fontFamily">google-sans-text-medium</item>
+ <item name="android:textSize">@dimen/task_thumbnail_icon_menu_text_size</item>
+ <item name="android:textColor">?androidprv:attr/materialColorOnSurface</item>
+ <item name="android:letterSpacing">0.025</item>
+ <item name="android:lineHeight">20sp</item>
+ </style>
</resources>
diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
index 0ef4541..3514447 100644
--- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
@@ -26,6 +26,7 @@
import static com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_NAVBAR_UNIFICATION;
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.SYSUI_SURFACE_PROGRESS_INDEX;
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneButtonNavMode;
+import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BACK;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME;
@@ -380,10 +381,12 @@
int navButtonSize = mContext.getResources().getDimensionPixelSize(
R.dimen.taskbar_nav_buttons_size);
boolean isRtl = Utilities.isRtl(mContext.getResources());
- mPropertyHolders.add(new StatePropertyHolder(
- mBackButton, flags -> (flags & FLAG_ONLY_BACK_FOR_BOUNCER_VISIBLE) != 0
- || (flags & FLAG_KEYGUARD_VISIBLE) != 0,
- VIEW_TRANSLATE_X, navButtonSize * (isRtl ? -2 : 2), 0));
+ if (!isPhoneMode(mContext.getDeviceProfile())) {
+ mPropertyHolders.add(new StatePropertyHolder(
+ mBackButton, flags -> (flags & FLAG_ONLY_BACK_FOR_BOUNCER_VISIBLE) != 0
+ || (flags & FLAG_KEYGUARD_VISIBLE) != 0,
+ VIEW_TRANSLATE_X, navButtonSize * (isRtl ? -2 : 2), 0));
+ }
// home button
mHomeButton = addButton(R.drawable.ic_sysbar_home, BUTTON_HOME, navContainer,
diff --git a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayDragLayer.java b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayDragLayer.java
index e742a3d..432d272 100644
--- a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayDragLayer.java
+++ b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayDragLayer.java
@@ -118,6 +118,15 @@
topView.onBackInvoked();
return true;
}
+ } else if (event.getAction() == KeyEvent.ACTION_DOWN
+ && event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) {
+ // Ignore escape if pressed in conjunction with any modifier keys. Close each
+ // floating view one at a time for each key press.
+ AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mActivity);
+ if (topView != null) {
+ topView.close(/* animate= */ true);
+ return true;
+ }
}
return super.dispatchKeyEvent(event);
}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java b/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java
index 2064fe2..110ca16 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/PredictedAppIcon.java
@@ -44,13 +44,13 @@
import androidx.core.graphics.ColorUtils;
-import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatorListeners;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
+import com.android.launcher3.celllayout.DelegatedCellDrawing;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.IconNormalizer;
@@ -418,7 +418,7 @@
/**
* Draws Predicted Icon outline on cell layout
*/
- public static class PredictedIconOutlineDrawing extends CellLayout.DelegatedCellDrawing {
+ public static class PredictedIconOutlineDrawing extends DelegatedCellDrawing {
private final PredictedAppIcon mIcon;
private final Paint mOutlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
index 165ed80..5b0c8c3 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
@@ -480,7 +480,11 @@
@Override
public void onDestroy() {
- mAppTransitionManager.onActivityDestroyed();
+ if (mAppTransitionManager != null) {
+ mAppTransitionManager.onActivityDestroyed();
+ }
+ mAppTransitionManager = null;
+
if (mUnfoldTransitionProgressProvider != null) {
SystemUiProxy.INSTANCE.get(this).setUnfoldAnimationListener(null);
mUnfoldTransitionProgressProvider.destroy();
diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/QuickstepAtomicAnimationFactory.java b/quickstep/src/com/android/launcher3/uioverrides/states/QuickstepAtomicAnimationFactory.java
index e7b285a..6651c73 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/states/QuickstepAtomicAnimationFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/states/QuickstepAtomicAnimationFactory.java
@@ -55,12 +55,14 @@
import static com.android.quickstep.views.RecentsView.RECENTS_SCALE_PROPERTY;
import android.animation.ValueAnimator;
+import android.util.Log;
import com.android.launcher3.CellLayout;
import com.android.launcher3.Hotseat;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Workspace;
import com.android.launcher3.states.StateAnimationConfig;
+import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.touch.AllAppsSwipeController;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.DisplayController;
@@ -94,6 +96,8 @@
@Override
public void prepareForAtomicAnimation(LauncherState fromState, LauncherState toState,
StateAnimationConfig config) {
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "creating animation fromState: "
+ + fromState + " toState: " + toState);
RecentsView overview = mActivity.getOverviewPanel();
if ((fromState == OVERVIEW || fromState == OVERVIEW_SPLIT_SELECT) && toState == NORMAL) {
overview.switchToScreenshot(() ->
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 8313e09..d7ff59e 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -855,7 +855,9 @@
if (windowInsets.isVisible(WindowInsets.Type.ime())) {
return result;
}
- buildAnimationController();
+ if (mGestureState.getEndTarget() == null) {
+ buildAnimationController();
+ }
// Reapply the current shift to ensure it takes new insets into account, e.g. when long
// pressing to stash taskbar without moving the finger.
onCurrentShiftUpdated();
@@ -1223,12 +1225,12 @@
: null;
ActiveGestureLog.INSTANCE.addLog(
new ActiveGestureLog.CompoundString("calculateEndTarget: velocities=(x=")
- .append(Float.toString(dpiFromPx(velocityPxPerMs.x)))
+ .append(dpiFromPx(velocityPxPerMs.x))
.append("dp/ms, y=")
- .append(Float.toString(dpiFromPx(velocityPxPerMs.y)))
+ .append(dpiFromPx(velocityPxPerMs.y))
.append("dp/ms), angle=")
- .append(Double.toString(Math.toDegrees(Math.atan2(
- -velocityPxPerMs.y, velocityPxPerMs.x)))), gestureEvent);
+ .append(Math.toDegrees(Math.atan2(
+ -velocityPxPerMs.y, velocityPxPerMs.x))), gestureEvent);
if (mGestureState.isHandlingAtomicEvent()) {
// Button mode, this is only used to go to recents.
diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java
index 95ce406..35fa539 100644
--- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java
+++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java
@@ -238,6 +238,12 @@
if (toState == MODAL_TASK) {
setOverviewSelectEnabled(true);
}
+
+ // Set border after select mode changes to avoid showing border during state transition
+ if (!toState.overviewUi() || toState == MODAL_TASK) {
+ setTaskBorderEnabled(false);
+ }
+
setFreezeViewVisibility(true);
}
@@ -253,6 +259,11 @@
if (finalState != MODAL_TASK) {
setOverviewSelectEnabled(false);
}
+
+ if (finalState.overviewUi() && finalState != MODAL_TASK) {
+ setTaskBorderEnabled(true);
+ }
+
if (finalState != OVERVIEW_SPLIT_SELECT) {
if (FeatureFlags.enableSplitContextually()) {
mSplitSelectStateController.resetState();
diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
index ac6c274..2aa9240 100644
--- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
+++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
@@ -32,6 +32,7 @@
import static com.android.systemui.shared.system.SysUiStatsLog.LAUNCHER_UICHANGED__DST_STATE__OVERVIEW;
import android.content.Context;
+import android.text.TextUtils;
import android.util.Log;
import android.util.StatsEvent;
import android.view.View;
@@ -227,6 +228,7 @@
private Optional<Integer> mCardinality = Optional.empty();
private int mInputType = SysUiStatsLog.LAUNCHER_UICHANGED__INPUT_TYPE__UNKNOWN;
private Optional<Integer> mFeatures = Optional.empty();
+ private Optional<String> mPackageName = Optional.empty();
StatsCompatLogger(Context context, ActivityContext activityContext) {
mContext = context;
@@ -332,6 +334,12 @@
}
@Override
+ public StatsLogger withPackageName(@Nullable String packageName) {
+ mPackageName = Optional.ofNullable(packageName);
+ return this;
+ }
+
+ @Override
public void log(EventEnum event) {
if (!Utilities.ATLEAST_R) {
return;
@@ -431,6 +439,7 @@
int srcState = mSrcState;
int dstState = mDstState;
int inputType = mInputType;
+ String packageName = mPackageName.orElseGet(() -> getPackageName(atomInfo));
if (IS_VERBOSE) {
String name = (event instanceof Enum) ? ((Enum) event).name() :
event.getId() + "";
@@ -448,6 +457,9 @@
if (atomInfo.hasContainerInfo()) {
logStringBuilder.append("\n").append(atomInfo);
}
+ if (!TextUtils.isEmpty(packageName)) {
+ logStringBuilder.append(String.format("\nPackage name: %s", packageName));
+ }
Log.d(TAG, logStringBuilder.toString());
}
@@ -472,7 +484,7 @@
atomInfo.getItemCase().getNumber() /* target_id */,
instanceId.getId() /* instance_id TODO */,
0 /* uid TODO */,
- getPackageName(atomInfo) /* package_name */,
+ packageName /* package_name */,
getComponentName(atomInfo) /* component_name */,
getGridX(atomInfo, false) /* grid_x */,
getGridY(atomInfo, false) /* grid_y */,
diff --git a/quickstep/src/com/android/quickstep/util/ActiveGestureLog.java b/quickstep/src/com/android/quickstep/util/ActiveGestureLog.java
index 6f4b6cb..278ca56 100644
--- a/quickstep/src/com/android/quickstep/util/ActiveGestureLog.java
+++ b/quickstep/src/com/android/quickstep/util/ActiveGestureLog.java
@@ -18,6 +18,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import com.android.launcher3.util.Preconditions;
+
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -43,14 +45,6 @@
*/
public static final String INTENT_EXTRA_LOG_TRACE_ID = "INTENT_EXTRA_LOG_TRACE_ID";
- private static final int TYPE_ONE_OFF = 0;
- private static final int TYPE_FLOAT = 1;
- private static final int TYPE_INTEGER = 2;
- private static final int TYPE_BOOL_TRUE = 3;
- private static final int TYPE_BOOL_FALSE = 4;
- private static final int TYPE_COMPOUND_STRING = 5;
- private static final int TYPE_GESTURE_EVENT = 6;
-
private final EventLog[] logs;
private int nextIndex;
private int mCurrentLogId = 100;
@@ -67,9 +61,12 @@
* execution.
*/
public void trackEvent(@Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- addLog(TYPE_GESTURE_EVENT, "", 0, CompoundString.NO_OP, gestureEvent);
+ addLog(CompoundString.NO_OP, gestureEvent);
}
+ /**
+ * Adds a log to be printed at log-dump-time.
+ */
public void addLog(String event) {
addLog(event, null);
}
@@ -82,54 +79,35 @@
addLog(event, extras, null);
}
- public void addLog(CompoundString compoundString) {
- if (compoundString == CompoundString.NO_OP) return;
- addLog(TYPE_COMPOUND_STRING, "", 0, compoundString, null);
- }
-
- public void addLog(
- CompoundString compoundString,
- @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- if (compoundString == CompoundString.NO_OP) {
- trackEvent(gestureEvent);
- return;
- }
- addLog(TYPE_COMPOUND_STRING, "", 0, compoundString, gestureEvent);
- }
-
/**
- * Adds a log and track the associated event for error detection.
+ * Adds a log to be printed at log-dump-time and track the associated event for error detection.
*
* @param gestureEvent GestureEvent representing the event being logged.
*/
public void addLog(
String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- addLog(TYPE_ONE_OFF, event, 0, CompoundString.NO_OP, gestureEvent);
+ addLog(new CompoundString(event), gestureEvent);
}
public void addLog(
String event,
int extras,
@Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- addLog(TYPE_INTEGER, event, extras, CompoundString.NO_OP, gestureEvent);
+ addLog(new CompoundString(event).append(": ").append(extras), gestureEvent);
}
public void addLog(
String event,
boolean extras,
@Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- addLog(
- extras ? TYPE_BOOL_TRUE : TYPE_BOOL_FALSE,
- event,
- 0,
- CompoundString.NO_OP,
- gestureEvent);
+ addLog(new CompoundString(event).append(": ").append(extras), gestureEvent);
}
- private void addLog(
- int type,
- String event,
- float extras,
+ public void addLog(CompoundString compoundString) {
+ addLog(compoundString, null);
+ }
+
+ public void addLog(
CompoundString compoundString,
@Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
EventLog lastEventLog = logs[(nextIndex + logs.length - 1) % logs.length];
@@ -137,7 +115,7 @@
EventLog eventLog = new EventLog(mCurrentLogId, mIsFullyGesturalNavMode);
EventEntry eventEntry = new EventEntry();
- eventEntry.update(type, event, extras, compoundString, gestureEvent);
+ eventEntry.update(compoundString, gestureEvent);
eventLog.eventEntries.add(eventEntry);
logs[nextIndex] = eventLog;
nextIndex = (nextIndex + 1) % logs.length;
@@ -146,17 +124,17 @@
// Update the last EventLog
List<EventEntry> lastEventEntries = lastEventLog.eventEntries;
- EventEntry lastEntry = lastEventEntries.size() > 0
+ EventEntry lastEntry = !lastEventEntries.isEmpty()
? lastEventEntries.get(lastEventEntries.size() - 1) : null;
// Update the last EventEntry if it's a duplicate
- if (isEntrySame(lastEntry, type, event, extras, compoundString, gestureEvent)) {
+ if (isEntrySame(lastEntry, compoundString, gestureEvent)) {
lastEntry.duplicateCount++;
return;
}
EventEntry eventEntry = new EventEntry();
- eventEntry.update(type, event, extras, compoundString, gestureEvent);
+ eventEntry.update(compoundString, gestureEvent);
lastEventEntries.add(eventEntry);
}
@@ -181,30 +159,14 @@
writer.println(prefix + "\tLogs for logId: " + eventLog.logId);
for (EventEntry eventEntry : eventLog.eventEntries) {
+ if (eventEntry.mCompoundString.mIsNoOp) {
+ continue;
+ }
date.setTime(eventEntry.time);
- StringBuilder msg = new StringBuilder(prefix + "\t\t").append(sdf.format(date))
- .append(eventEntry.event);
- switch (eventEntry.type) {
- case TYPE_BOOL_FALSE:
- msg.append(": false");
- break;
- case TYPE_BOOL_TRUE:
- msg.append(": true");
- break;
- case TYPE_FLOAT:
- msg.append(": ").append(eventEntry.extras);
- break;
- case TYPE_INTEGER:
- msg.append(": ").append((int) eventEntry.extras);
- break;
- case TYPE_COMPOUND_STRING:
- msg.append(eventEntry.mCompoundString);
- break;
- case TYPE_GESTURE_EVENT:
- continue;
- default: // fall out
- }
+ StringBuilder msg = new StringBuilder(prefix + "\t\t")
+ .append(sdf.format(date))
+ .append(eventEntry.mCompoundString);
if (eventEntry.duplicateCount > 0) {
msg.append(" & ").append(eventEntry.duplicateCount).append(" similar events");
}
@@ -232,15 +194,9 @@
private boolean isEntrySame(
EventEntry entry,
- int type,
- String event,
- float extras,
CompoundString compoundString,
ActiveGestureErrorDetector.GestureEvent gestureEvent) {
return entry != null
- && entry.type == type
- && entry.event.equals(event)
- && Float.compare(entry.extras, extras) == 0
&& entry.mCompoundString.equals(compoundString)
&& entry.gestureEvent == gestureEvent;
}
@@ -248,9 +204,6 @@
/** A single event entry. */
protected static class EventEntry {
- private int type;
- private String event;
- private float extras;
@NonNull private CompoundString mCompoundString;
private ActiveGestureErrorDetector.GestureEvent gestureEvent;
private long time;
@@ -264,14 +217,8 @@
}
private void update(
- int type,
- String event,
- float extras,
@NonNull CompoundString compoundString,
ActiveGestureErrorDetector.GestureEvent gestureEvent) {
- this.type = type;
- this.event = event;
- this.extras = extras;
this.mCompoundString = compoundString;
this.gestureEvent = gestureEvent;
time = System.currentTimeMillis();
@@ -302,6 +249,7 @@
public static final CompoundString NO_OP = new CompoundString();
private final List<String> mSubstrings;
+ private final List<Object> mArgs;
private final boolean mIsNoOp;
@@ -313,10 +261,12 @@
mIsNoOp = substring == null;
if (mIsNoOp) {
mSubstrings = null;
+ mArgs = null;
return;
}
mSubstrings = new ArrayList<>();
mSubstrings.add(substring);
+ mArgs = new ArrayList<>();
}
public CompoundString append(CompoundString substring) {
@@ -338,19 +288,41 @@
}
public CompoundString append(int num) {
- if (mIsNoOp) {
- return this;
- }
- mSubstrings.add(Integer.toString(num));
+ mArgs.add(num);
- return this;
+ return append("%d");
+ }
+
+ public CompoundString append(float num) {
+ mArgs.add(num);
+
+ return append("%.2f");
+ }
+
+ public CompoundString append(double num) {
+ mArgs.add(num);
+
+ return append("%.2f");
+ }
+
+ public CompoundString append(boolean bool) {
+ mArgs.add(bool);
+
+ return append("%b");
+ }
+
+ public Object[] getArgs() {
+ return mArgs.toArray();
}
@Override
public String toString() {
- if (mIsNoOp) {
- return "ERROR: cannot use No-Op compound string";
- }
+ return String.format(toUnformattedString(), getArgs());
+ }
+
+ public String toUnformattedString() {
+ Preconditions.assertTrue(!mIsNoOp);
+
StringBuilder sb = new StringBuilder();
for (String substring : mSubstrings) {
sb.append(substring);
diff --git a/quickstep/src/com/android/quickstep/util/TaskKeyByLastActiveTimeCache.java b/quickstep/src/com/android/quickstep/util/TaskKeyByLastActiveTimeCache.java
index 79ca076..21c9e09 100644
--- a/quickstep/src/com/android/quickstep/util/TaskKeyByLastActiveTimeCache.java
+++ b/quickstep/src/com/android/quickstep/util/TaskKeyByLastActiveTimeCache.java
@@ -44,7 +44,7 @@
private final PriorityQueue<Task.TaskKey> mQueue;
public TaskKeyByLastActiveTimeCache(int maxSize) {
- mMap = new HashMap(maxSize);
+ mMap = new HashMap(0);
mQueue = new PriorityQueue<>(Comparator.comparingLong(t -> t.lastActiveTime));
mMaxSize = new AtomicInteger(maxSize);
}
@@ -106,7 +106,8 @@
}
/**
- * Adds an entry to the cache, optionally evicting the last accessed entry
+ * Adds an entry to the cache, optionally evicting the last accessed entry excluding the newly
+ * added entry
*/
@Override
public final synchronized void put(Task.TaskKey key, V value) {
@@ -117,9 +118,9 @@
mQueue.remove(entry.mKey);
}
+ removeExcessIfNeeded(mMaxSize.get() - 1);
mMap.put(key.id, new Entry<>(key, value));
mQueue.add(key);
- removeExcessIfNeeded();
} else {
Log.e(TAG, "Unexpected null key or value: " + key + ", " + value);
}
@@ -143,11 +144,11 @@
@Override
public synchronized void updateCacheSizeAndRemoveExcess(int cacheSize) {
mMaxSize.compareAndSet(mMaxSize.get(), cacheSize);
- removeExcessIfNeeded();
+ removeExcessIfNeeded(mMaxSize.get());
}
- private synchronized void removeExcessIfNeeded() {
- while (mQueue.size() > mMaxSize.get() && !mQueue.isEmpty()) {
+ private synchronized void removeExcessIfNeeded(int maxSize) {
+ while (mQueue.size() > maxSize && !mQueue.isEmpty()) {
Task.TaskKey key = mQueue.poll();
mMap.remove(key.id);
}
diff --git a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
index 92ffcd0..efc0a35 100644
--- a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
@@ -319,7 +319,7 @@
// Fade in the placeholder view during Normal > OverviewSplitSelect
if (mSplitPlaceholderView.getAlpha() == 0) {
- mSplitPlaceholderView.getIconView().setAlpha(0);
+ mSplitPlaceholderView.getIconView().setContentAlpha(0);
fadeInSplitPlaceholder(animation, timings);
}
diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
index 8559b37..dd201af 100644
--- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
@@ -436,7 +436,7 @@
super.setIconsAndBannersTransitionProgress(progress, invert);
// Value set by super call
float scale = mIconView.getAlpha();
- mIconView2.setAlpha(scale);
+ mIconView2.setContentAlpha(scale);
mDigitalWellBeingToast2.updateBannerOffset(1f - scale);
}
diff --git a/quickstep/src/com/android/quickstep/views/IconAppChipView.java b/quickstep/src/com/android/quickstep/views/IconAppChipView.java
index b14b917..ee09c4d 100644
--- a/quickstep/src/com/android/quickstep/views/IconAppChipView.java
+++ b/quickstep/src/com/android/quickstep/views/IconAppChipView.java
@@ -40,6 +40,7 @@
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.touch.PagedOrientationHandler;
+import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.views.ActivityContext;
import com.android.quickstep.util.RecentsOrientedState;
@@ -51,6 +52,12 @@
private static final int MENU_BACKGROUND_REVEAL_DURATION = 417;
private static final int MENU_BACKGROUND_HIDE_DURATION = 333;
+ private static final int NUM_ALPHA_CHANNELS = 2;
+ private static final int INDEX_CONTENT_ALPHA = 0;
+ private static final int INDEX_COLOR_FILTER_ALPHA = 1;
+
+ private final MultiValueAlpha mMultiValueAlpha;
+
private IconView mIconView;
// Two textview so we can ellipsize the collapsed view and crossfade on expand to the full name.
private TextView mIconTextCollapsedView;
@@ -98,6 +105,8 @@
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Resources res = getResources();
+ mMultiValueAlpha = new MultiValueAlpha(this, NUM_ALPHA_CHANNELS);
+ mMultiValueAlpha.setUpdateVisibility(/* updateVisibility= */ true);
// Menu dimensions
mMaxMenuWidth = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_menu_max_width);
@@ -286,7 +295,13 @@
@Override
public void setIconColorTint(int color, float amount) {
// RecentsView's COLOR_TINT animates between 0 and 0.5f, we want to hide the app chip menu.
- setAlpha(Utilities.mapToRange(amount, 0f, 0.5f, 1f, 0f, LINEAR));
+ float colorTintAlpha = Utilities.mapToRange(amount, 0f, 0.5f, 1f, 0f, LINEAR);
+ mMultiValueAlpha.get(INDEX_COLOR_FILTER_ALPHA).setValue(colorTintAlpha);
+ }
+
+ @Override
+ public void setContentAlpha(float alpha) {
+ mMultiValueAlpha.get(INDEX_CONTENT_ALPHA).setValue(alpha);
}
@Override
diff --git a/quickstep/src/com/android/quickstep/views/IconView.java b/quickstep/src/com/android/quickstep/views/IconView.java
index 64caba7..a4bda7f 100644
--- a/quickstep/src/com/android/quickstep/views/IconView.java
+++ b/quickstep/src/com/android/quickstep/views/IconView.java
@@ -144,6 +144,11 @@
}
@Override
+ public void setContentAlpha(float alpha) {
+ setAlpha(alpha);
+ }
+
+ @Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
if (alpha > 0) {
diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
index a265146..5b5d0de 100644
--- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
@@ -16,7 +16,6 @@
package com.android.quickstep.views;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
-
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.CLEAR_ALL_BUTTON;
import static com.android.launcher3.LauncherState.EDIT_MODE;
@@ -31,6 +30,7 @@
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.MotionEvent;
import androidx.annotation.Nullable;
@@ -44,6 +44,7 @@
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.statemanager.StateManager.StateListener;
+import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.PendingSplitSelectInfo;
import com.android.launcher3.util.SplitConfigurationOptions;
@@ -144,6 +145,12 @@
if (toState == OVERVIEW_MODAL_TASK) {
setOverviewSelectEnabled(true);
}
+
+ // Set border after select mode changes to avoid showing border during state transition
+ if (!toState.overviewUi || toState == OVERVIEW_MODAL_TASK) {
+ setTaskBorderEnabled(false);
+ }
+
setFreezeViewVisibility(true);
if (mActivity.getDesktopVisibilityController() != null) {
mActivity.getDesktopVisibilityController().onLauncherStateChanged(toState);
@@ -164,6 +171,10 @@
setOverviewSelectEnabled(false);
}
+ if (finalState.overviewUi && finalState != OVERVIEW_MODAL_TASK) {
+ setTaskBorderEnabled(true);
+ }
+
if (isOverlayEnabled) {
runActionOnRemoteHandles(remoteTargetHandle ->
remoteTargetHandle.getTaskViewSimulator().setDrawsBelowRecents(true));
@@ -173,6 +184,8 @@
@Override
public void setOverviewStateEnabled(boolean enabled) {
super.setOverviewStateEnabled(enabled);
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "overview state enabled state has changed: "
+ + enabled);
if (enabled) {
LauncherState state = mActivity.getStateManager().getState();
boolean hasClearAllButton = (state.getVisibleElements(mActivity)
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index f55dce9..22a5064 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1410,6 +1410,17 @@
}
/**
+ * Enable or disable showing border on hover and focus change on task views
+ */
+ public void setTaskBorderEnabled(boolean enabled) {
+ int taskCount = getTaskViewCount();
+ for (int i = 0; i < taskCount; i++) {
+ TaskView taskView = requireTaskViewAt(i);
+ taskView.setBorderEnabled(enabled);
+ }
+ }
+
+ /**
* Whether the Clear All button is hidden or fully visible. Used to determine if center
* displayed page is a task or the Clear All button.
*
diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java
index ab51a70..af4f402 100644
--- a/quickstep/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskView.java
@@ -408,6 +408,7 @@
new TaskIdAttributeContainer[2];
private boolean mShowScreenshot;
+ private boolean mBorderEnabled;
// The current background requests to load the task thumbnail and icon
@Nullable
@@ -439,8 +440,15 @@
this(context, attrs, defStyleAttr, 0);
}
- public TaskView(
- Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ public TaskView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ this(context, attrs, defStyleAttr, defStyleRes, null, null);
+ }
+
+ @VisibleForTesting
+ public TaskView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
+ int defStyleRes, BorderAnimator focusBorderAnimator,
+ BorderAnimator hoverBorderAnimator) {
super(context, attrs, defStyleAttr, defStyleRes);
mActivity = StatefulActivity.fromContext(context);
setOnClickListener(this::onClick);
@@ -457,28 +465,35 @@
TypedArray styledAttrs = context.obtainStyledAttributes(
attrs, R.styleable.TaskView, defStyleAttr, defStyleRes);
- mFocusBorderAnimator = keyboardFocusHighlightEnabled
- ? BorderAnimator.createSimpleBorderAnimator(
- /* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
- /* borderWidthPx= */ context.getResources().getDimensionPixelSize(
- R.dimen.keyboard_quick_switch_border_width),
- /* boundsBuilder= */ this::updateBorderBounds,
- /* targetView= */ this,
- /* borderColor= */ styledAttrs.getColor(
- R.styleable.TaskView_focusBorderColor, DEFAULT_BORDER_COLOR))
- : null;
+ if (focusBorderAnimator != null) {
+ mFocusBorderAnimator = focusBorderAnimator;
+ } else {
+ mFocusBorderAnimator = keyboardFocusHighlightEnabled
+ ? BorderAnimator.createSimpleBorderAnimator(
+ /* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
+ /* borderWidthPx= */ context.getResources().getDimensionPixelSize(
+ R.dimen.keyboard_quick_switch_border_width),
+ /* boundsBuilder= */ this::updateBorderBounds,
+ /* targetView= */ this,
+ /* borderColor= */ styledAttrs.getColor(
+ R.styleable.TaskView_focusBorderColor, DEFAULT_BORDER_COLOR))
+ : null;
+ }
- mHoverBorderAnimator = cursorHoverStatesEnabled
- ? BorderAnimator.createSimpleBorderAnimator(
- /* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
- /* borderWidthPx= */ context.getResources().getDimensionPixelSize(
- R.dimen.task_hover_border_width),
- /* boundsBuilder= */ this::updateBorderBounds,
- /* targetView= */ this,
- /* borderColor= */ styledAttrs.getColor(
- R.styleable.TaskView_hoverBorderColor, DEFAULT_BORDER_COLOR))
- : null;
-
+ if (hoverBorderAnimator != null) {
+ mHoverBorderAnimator = hoverBorderAnimator;
+ } else {
+ mHoverBorderAnimator = cursorHoverStatesEnabled
+ ? BorderAnimator.createSimpleBorderAnimator(
+ /* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
+ /* borderWidthPx= */ context.getResources().getDimensionPixelSize(
+ R.dimen.task_hover_border_width),
+ /* boundsBuilder= */ this::updateBorderBounds,
+ /* targetView= */ this,
+ /* borderColor= */ styledAttrs.getColor(
+ R.styleable.TaskView_hoverBorderColor, DEFAULT_BORDER_COLOR))
+ : null;
+ }
styledAttrs.recycle();
}
@@ -538,24 +553,25 @@
}
@Override
- protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+ @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
+ public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
- if (mFocusBorderAnimator != null) {
+ if (mFocusBorderAnimator != null && mBorderEnabled) {
mFocusBorderAnimator.setBorderVisibility(gainFocus, /* animated= */ true);
}
}
@Override
public boolean onHoverEvent(MotionEvent event) {
- if (mHoverBorderAnimator != null) {
+ if (mHoverBorderAnimator != null && mBorderEnabled) {
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_ENTER:
- mHoverBorderAnimator.setBorderVisibility(
- /* visible= */ true, /* animated= */ true);
+ mHoverBorderAnimator.setBorderVisibility(/* visible= */ true, /* animated= */
+ true);
break;
case MotionEvent.ACTION_HOVER_EXIT:
- mHoverBorderAnimator.setBorderVisibility(
- /* visible= */ false, /* animated= */ true);
+ mHoverBorderAnimator.setBorderVisibility(/* visible= */ false, /* animated= */
+ true);
break;
default:
break;
@@ -564,6 +580,24 @@
return super.onHoverEvent(event);
}
+ /**
+ * Enable or disable showing border on hover and focus change
+ */
+ public void setBorderEnabled(boolean enabled) {
+ mBorderEnabled = enabled;
+ // Set the animation correctly in case it misses the hover/focus event during state
+ // transition
+ if (mHoverBorderAnimator != null) {
+ mHoverBorderAnimator.setBorderVisibility(/* visible= */
+ enabled && isHovered(), /* animated= */ true);
+ }
+
+ if (mFocusBorderAnimator != null) {
+ mFocusBorderAnimator.setBorderVisibility(/* visible= */
+ enabled && isFocused(), /* animated= */true);
+ }
+ }
+
@Override
public boolean onInterceptHoverEvent(MotionEvent event) {
if (enableCursorHoverStates()) {
@@ -630,7 +664,7 @@
return;
}
mModalness = modalness;
- mIconView.setAlpha(1 - modalness);
+ mIconView.setContentAlpha(1 - modalness);
mDigitalWellBeingToast.updateBannerOffset(modalness);
}
@@ -1253,7 +1287,7 @@
float upperClamp = invert ? 1 : iconScalePercentage;
float scale = Interpolators.clampToProgress(FAST_OUT_SLOW_IN, lowerClamp, upperClamp)
.getInterpolation(progress);
- mIconView.setAlpha(scale);
+ mIconView.setContentAlpha(scale);
mDigitalWellBeingToast.updateBannerOffset(1f - scale);
}
@@ -1327,6 +1361,7 @@
mSnapshotView.setThumbnail(mTask, null);
setOverlayEnabled(false);
onTaskListVisibilityChanged(false);
+ mBorderEnabled = false;
}
public float getTaskCornerRadius() {
diff --git a/quickstep/src/com/android/quickstep/views/TaskViewIcon.java b/quickstep/src/com/android/quickstep/views/TaskViewIcon.java
index b4f21be..4e82725 100644
--- a/quickstep/src/com/android/quickstep/views/TaskViewIcon.java
+++ b/quickstep/src/com/android/quickstep/views/TaskViewIcon.java
@@ -40,7 +40,7 @@
/**
* Sets the opacity of the view.
*/
- void setAlpha(float alpha);
+ void setContentAlpha(float alpha);
/**
* Returns this icon view's drawable.
diff --git a/quickstep/tests/src/com/android/quickstep/AbstractTaplTestsTaskbar.java b/quickstep/tests/src/com/android/quickstep/AbstractTaplTestsTaskbar.java
index ba9ae67..fc757b4 100644
--- a/quickstep/tests/src/com/android/quickstep/AbstractTaplTestsTaskbar.java
+++ b/quickstep/tests/src/com/android/quickstep/AbstractTaplTestsTaskbar.java
@@ -25,7 +25,6 @@
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.Taskbar;
import com.android.launcher3.ui.AbstractLauncherUiTest;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.LauncherLayoutBuilder;
import com.android.launcher3.util.TestUtil;
@@ -55,7 +54,7 @@
"com.google.android.apps.nexuslauncher.tests",
"com.android.launcher3.testcomponent.BaseTestingActivity");
mLauncherLayout = TestUtil.setLauncherDefaultLayout(mTargetContext, layoutBuilder);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
startAppFast(CALCULATOR_APP_PACKAGE);
mLauncher.enableBlockTimeout(true);
mLauncher.showTaskbarIfHidden();
diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
index a89eab5..85440e9 100644
--- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
+++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
@@ -22,7 +22,7 @@
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.launcher3.ui.TaplTestsLauncher3;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.rule.TestStabilityRule.Stability;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
@@ -40,7 +40,7 @@
@Before
public void setUp() throws Exception {
super.setUp();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
// b/143488140
mLauncher.goHome();
// Start an activity where the gestures start.
@@ -49,6 +49,8 @@
@Test
@NavigationModeSwitch
+ // Stress tests are long. We permanently demote them from presubmit to match the presubmit SLO.
+ @Stability(flavors = LOCAL | PLATFORM_POSTSUBMIT)
public void testStressPressHome() {
for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
// Destroy Launcher activity.
@@ -61,7 +63,8 @@
@Test
@NavigationModeSwitch
- @Stability(flavors = LOCAL | PLATFORM_POSTSUBMIT) // b/187761685
+ // Stress tests are long. We permanently demote them from presubmit to match the presubmit SLO.
+ @Stability(flavors = LOCAL | PLATFORM_POSTSUBMIT)
public void testStressSwipeToOverview() {
for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
// Destroy Launcher activity.
diff --git a/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java b/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java
index c4c95bc..3f806d1 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java
@@ -15,7 +15,7 @@
*/
package com.android.quickstep;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT;
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsKeyboardQuickSwitch.java b/quickstep/tests/src/com/android/quickstep/TaplTestsKeyboardQuickSwitch.java
index 74f37a4..829e54b 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsKeyboardQuickSwitch.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsKeyboardQuickSwitch.java
@@ -22,7 +22,7 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.launcher3.tapl.KeyboardQuickSwitch;
-import com.android.launcher3.ui.TaplTestsLauncher3;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import org.junit.Assume;
import org.junit.Test;
@@ -56,7 +56,7 @@
public void setUp() throws Exception {
Assume.assumeTrue(mLauncher.isTablet());
super.setUp();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
startAppFast(CALCULATOR_APP_PACKAGE);
startTestActivity(2);
}
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
index 8e142c3..b3cc215 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
@@ -45,8 +45,8 @@
import com.android.launcher3.tapl.Overview;
import com.android.launcher3.tapl.OverviewActions;
import com.android.launcher3.tapl.OverviewTask;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
import com.android.launcher3.util.rule.TestStabilityRule;
@@ -72,7 +72,7 @@
@Before
public void setUp() throws Exception {
super.setUp();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
executeOnLauncher(launcher -> {
RecentsView recentsView = launcher.getOverviewPanel();
recentsView.getPagedViewOrientedState().forceAllowRotationForTesting(true);
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java b/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java
index 234fe63..1e33635 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java
@@ -32,15 +32,14 @@
import com.android.launcher3.tapl.Overview;
import com.android.launcher3.tapl.Taskbar;
import com.android.launcher3.tapl.TaskbarAppIcon;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.quickstep.TaskbarModeSwitchRule.TaskbarModeSwitch;
import com.android.wm.shell.Flags;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,7 +57,7 @@
@Before
public void setUp() throws Exception {
super.setUp();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
if (mLauncher.isTablet()) {
mLauncher.enableBlockTimeout(true);
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsTrackpad.java b/quickstep/tests/src/com/android/quickstep/TaplTestsTrackpad.java
index 907dbcc..0eec8b7 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsTrackpad.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsTrackpad.java
@@ -19,7 +19,6 @@
import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
@@ -32,8 +31,8 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
import com.android.launcher3.tapl.Workspace;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
import org.junit.After;
@@ -51,7 +50,7 @@
@Before
public void setUp() throws Exception {
super.setUp();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
}
@After
diff --git a/quickstep/tests/src/com/android/quickstep/TaskViewTest.java b/quickstep/tests/src/com/android/quickstep/TaskViewTest.java
new file mode 100644
index 0000000..d744194
--- /dev/null
+++ b/quickstep/tests/src/com/android/quickstep/TaskViewTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2023 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.quickstep;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.pm.ApplicationInfo;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.Rect;
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.launcher3.statemanager.StatefulActivity;
+import com.android.quickstep.util.BorderAnimator;
+import com.android.quickstep.views.TaskView;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+public class TaskViewTest {
+
+ @Mock
+ private StatefulActivity mContext;
+ @Mock
+ private Resources mResource;
+ @Mock
+ private BorderAnimator mHoverAnimator;
+ @Mock
+ private BorderAnimator mFocusAnimator;
+ private TaskView mTaskView;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ when(mResource.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
+ when(mResource.getConfiguration()).thenReturn(new Configuration());
+
+ when(mContext.getResources()).thenReturn(mResource);
+ when(mContext.getTheme()).thenReturn(mock(Resources.Theme.class));
+ when(mContext.getApplicationInfo()).thenReturn(mock(ApplicationInfo.class));
+ when(mContext.obtainStyledAttributes(any(), any(), anyInt(), anyInt())).thenReturn(
+ mock(TypedArray.class));
+
+ mTaskView = new TaskView(mContext, null, 0, 0, mFocusAnimator, mHoverAnimator);
+ }
+
+ @Test
+ public void notShowBorderOnBorderDisabled() {
+ mTaskView.setBorderEnabled(/* enabled= */ false);
+ MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0.0f, 0.0f, 0);
+ mTaskView.onHoverEvent(MotionEvent.obtain(event));
+ verify(mHoverAnimator, never()).setBorderVisibility(/* visible= */ true, /* animated= */
+ true);
+
+ mTaskView.onFocusChanged(false, 0, new Rect());
+ verify(mFocusAnimator, never()).setBorderVisibility(/* visible= */ true, /* animated= */
+ true);
+ }
+
+ @Test
+ public void showBorderOnBorderEnabled() {
+ mTaskView.setBorderEnabled(/* enabled= */ true);
+ MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0.0f, 0.0f, 0);
+ mTaskView.onHoverEvent(MotionEvent.obtain(event));
+ verify(mHoverAnimator, times(1)).setBorderVisibility(/* visible= */ true, /* animated= */
+ true);
+ mTaskView.onFocusChanged(true, 0, new Rect());
+ verify(mFocusAnimator, times(1)).setBorderVisibility(/* visible= */ true, /* animated= */
+ true);
+ }
+
+ @Test
+ public void hideBorderOnBorderDisabled() {
+ mTaskView.setBorderEnabled(/* enabled= */ false);
+ verify(mHoverAnimator, times(1)).setBorderVisibility(/* visible= */ false, /* animated= */
+ true);
+ verify(mFocusAnimator, times(1)).setBorderVisibility(/* visible= */ false, /* animated= */
+ true);
+ }
+
+ @Test
+ public void notShowBorderByDefault() {
+ MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_ENTER, 0.0f, 0.0f, 0);
+ mTaskView.onHoverEvent(MotionEvent.obtain(event));
+ verify(mHoverAnimator, never()).setBorderVisibility(/* visible= */ false, /* animated= */
+ true);
+ mTaskView.onFocusChanged(true, 0, new Rect());
+ verify(mHoverAnimator, never()).setBorderVisibility(/* visible= */ false, /* animated= */
+ true);
+ }
+}
diff --git a/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java b/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
index 8cc8487..2318f54 100644
--- a/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
+++ b/quickstep/tests/src/com/android/quickstep/ViewInflationDuringSwipeUp.java
@@ -56,7 +56,7 @@
import com.android.launcher3.testcomponent.ListViewService;
import com.android.launcher3.testcomponent.ListViewService.SimpleViewsFactory;
import com.android.launcher3.testcomponent.TestCommandReceiver;
-import com.android.launcher3.ui.TaplTestsLauncher3;
+import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.Executors;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
@@ -102,7 +102,7 @@
// is started only after starting another app.
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
mModel = LauncherAppState.getInstance(mTargetContext).getModel();
Executors.MODEL_EXECUTOR.submit(mModel.getModelDbController()::createEmptyDB).get();
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 3682830..8d84c90 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -164,7 +164,19 @@
<!-- numFolderRows & numFolderColumns defaults to numRows & numColumns, if not specified -->
<attr name="numFolderRows" format="integer" />
+ <!-- defaults to numFolderRows, if not specified -->
+ <attr name="numFolderRowsLandscape" format="integer" />
+ <!-- defaults to numFolderRows, if not specified -->
+ <attr name="numFolderRowsTwoPanelLandscape" format="integer" />
+ <!-- defaults to numFolderRows, if not specified -->
+ <attr name="numFolderRowsTwoPanelPortrait" format="integer" />
<attr name="numFolderColumns" format="integer" />
+ <!-- defaults to numFolderColumns, if not specified -->
+ <attr name="numFolderColumnsLandscape" format="integer" />
+ <!-- defaults to numFolderColumns, if not specified -->
+ <attr name="numFolderColumnsTwoPanelLandscape" format="integer" />
+ <!-- defaults to numFolderColumns, if not specified -->
+ <attr name="numFolderColumnsTwoPanelPortrait" format="integer" />
<!-- Support attributes in FolderStyle -->
<attr name="folderStyle" format="reference" />
@@ -220,6 +232,14 @@
Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
<attr name="hotseatSpecsId" format="reference" />
<attr name="hotseatSpecsTwoPanelId" format="reference" />
+ <!-- File that contains the specs for workspace icon and text size.
+ Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
+ <attr name="workspaceCellSpecsId" format="reference" />
+ <attr name="workspaceCellSpecsTwoPanelId" format="reference" />
+ <!-- File that contains the specs for all apps icon and text size.
+ Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
+ <attr name="allAppsCellSpecsId" format="reference" />
+ <attr name="allAppsCellSpecsTwoPanelId" format="reference" />
<!-- By default all categories are enabled -->
<attr name="deviceCategory" format="integer">
@@ -292,6 +312,11 @@
<attr name="maxAvailableSize" />
</declare-styleable>
+ <declare-styleable name="CellSpec">
+ <attr name="dimensionType" />
+ <attr name="maxAvailableSize" />
+ </declare-styleable>
+
<declare-styleable name="SizeSpec">
<attr name="fixedSize" format="dimension" />
<attr name="ofAvailableSpace" format="float" />
diff --git a/res/values/config.xml b/res/values/config.xml
index 4b15a6b..154312a 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -228,6 +228,10 @@
<dimen name="iconSize60dp">66dp</dimen>
<dimen name="iconSize66dp">72dp</dimen>
<dimen name="iconSize72dp">79dp</dimen>
+ <dimen name="iconSize82dp">90dp</dimen>
+ <dimen name="iconSize110dp">121dp</dimen>
+ <dimen name="iconSize144dp">158dp</dimen>
+
<!-- Icon size steps in dp -->
<integer-array name="icon_size_steps">
@@ -240,6 +244,9 @@
<item>@dimen/iconSize60dp</item>
<item>@dimen/iconSize66dp</item>
<item>@dimen/iconSize72dp</item>
+ <item>@dimen/iconSize82dp</item>
+ <item>@dimen/iconSize110dp</item>
+ <item>@dimen/iconSize144dp</item>
</integer-array>
<dimen name="minimum_icon_label_size">8sp</dimen>
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 1a0f2cf..7257d86 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -67,7 +67,10 @@
import com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
import com.android.launcher3.celllayout.CellPosMapper.CellPos;
+import com.android.launcher3.celllayout.DelegatedCellDrawing;
+import com.android.launcher3.celllayout.ItemConfiguration;
import com.android.launcher3.celllayout.ReorderAlgorithm;
+import com.android.launcher3.celllayout.ViewCluster;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.PreviewBackground;
@@ -86,7 +89,6 @@
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Stack;
@@ -1434,9 +1436,8 @@
View child = mShortcutsAndWidgets.getChildAt(i);
if (child == dragView) continue;
CellAndSpan c = solution.map.get(child);
- boolean skip = mode == ReorderPreviewAnimation.MODE_HINT && solution.intersectingViews
- != null && !solution.intersectingViews.contains(child);
-
+ boolean skip = mode == ReorderPreviewAnimation.MODE_HINT
+ && !solution.intersectingViews.contains(child);
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
if (c != null && !skip && (child instanceof Reorderable)) {
@@ -1832,7 +1833,7 @@
private boolean pushViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop,
int[] direction, View dragView, ItemConfiguration currentState) {
- ViewCluster cluster = new ViewCluster(views, currentState);
+ ViewCluster cluster = new ViewCluster(this, views, currentState);
Rect clusterRect = cluster.getBoundingRect();
int whichEdge;
int pushDistance;
@@ -1924,191 +1925,6 @@
return foundSolution;
}
- /**
- * This helper class defines a cluster of views. It helps with defining complex edges
- * of the cluster and determining how those edges interact with other views. The edges
- * essentially define a fine-grained boundary around the cluster of views -- like a more
- * precise version of a bounding box.
- */
- private class ViewCluster {
- final static int LEFT = 1 << 0;
- final static int TOP = 1 << 1;
- final static int RIGHT = 1 << 2;
- final static int BOTTOM = 1 << 3;
-
- final ArrayList<View> views;
- final ItemConfiguration config;
- final Rect boundingRect = new Rect();
-
- final int[] leftEdge = new int[mCountY];
- final int[] rightEdge = new int[mCountY];
- final int[] topEdge = new int[mCountX];
- final int[] bottomEdge = new int[mCountX];
- int dirtyEdges;
- boolean boundingRectDirty;
-
- @SuppressWarnings("unchecked")
- public ViewCluster(ArrayList<View> views, ItemConfiguration config) {
- this.views = (ArrayList<View>) views.clone();
- this.config = config;
- resetEdges();
- }
-
- void resetEdges() {
- for (int i = 0; i < mCountX; i++) {
- topEdge[i] = -1;
- bottomEdge[i] = -1;
- }
- for (int i = 0; i < mCountY; i++) {
- leftEdge[i] = -1;
- rightEdge[i] = -1;
- }
- dirtyEdges = LEFT | TOP | RIGHT | BOTTOM;
- boundingRectDirty = true;
- }
-
- void computeEdge(int which) {
- int count = views.size();
- for (int i = 0; i < count; i++) {
- CellAndSpan cs = config.map.get(views.get(i));
- switch (which) {
- case LEFT:
- int left = cs.cellX;
- for (int j = cs.cellY; j < cs.cellY + cs.spanY; j++) {
- if (left < leftEdge[j] || leftEdge[j] < 0) {
- leftEdge[j] = left;
- }
- }
- break;
- case RIGHT:
- int right = cs.cellX + cs.spanX;
- for (int j = cs.cellY; j < cs.cellY + cs.spanY; j++) {
- if (right > rightEdge[j]) {
- rightEdge[j] = right;
- }
- }
- break;
- case TOP:
- int top = cs.cellY;
- for (int j = cs.cellX; j < cs.cellX + cs.spanX; j++) {
- if (top < topEdge[j] || topEdge[j] < 0) {
- topEdge[j] = top;
- }
- }
- break;
- case BOTTOM:
- int bottom = cs.cellY + cs.spanY;
- for (int j = cs.cellX; j < cs.cellX + cs.spanX; j++) {
- if (bottom > bottomEdge[j]) {
- bottomEdge[j] = bottom;
- }
- }
- break;
- }
- }
- }
-
- boolean isViewTouchingEdge(View v, int whichEdge) {
- CellAndSpan cs = config.map.get(v);
-
- if ((dirtyEdges & whichEdge) == whichEdge) {
- computeEdge(whichEdge);
- dirtyEdges &= ~whichEdge;
- }
-
- switch (whichEdge) {
- case LEFT:
- for (int i = cs.cellY; i < cs.cellY + cs.spanY; i++) {
- if (leftEdge[i] == cs.cellX + cs.spanX) {
- return true;
- }
- }
- break;
- case RIGHT:
- for (int i = cs.cellY; i < cs.cellY + cs.spanY; i++) {
- if (rightEdge[i] == cs.cellX) {
- return true;
- }
- }
- break;
- case TOP:
- for (int i = cs.cellX; i < cs.cellX + cs.spanX; i++) {
- if (topEdge[i] == cs.cellY + cs.spanY) {
- return true;
- }
- }
- break;
- case BOTTOM:
- for (int i = cs.cellX; i < cs.cellX + cs.spanX; i++) {
- if (bottomEdge[i] == cs.cellY) {
- return true;
- }
- }
- break;
- }
- return false;
- }
-
- void shift(int whichEdge, int delta) {
- for (View v: views) {
- CellAndSpan c = config.map.get(v);
- switch (whichEdge) {
- case LEFT:
- c.cellX -= delta;
- break;
- case RIGHT:
- c.cellX += delta;
- break;
- case TOP:
- c.cellY -= delta;
- break;
- case BOTTOM:
- default:
- c.cellY += delta;
- break;
- }
- }
- resetEdges();
- }
-
- public void addView(View v) {
- views.add(v);
- resetEdges();
- }
-
- public Rect getBoundingRect() {
- if (boundingRectDirty) {
- config.getBoundingRectForViews(views, boundingRect);
- }
- return boundingRect;
- }
-
- final PositionComparator comparator = new PositionComparator();
- class PositionComparator implements Comparator<View> {
- int whichEdge = 0;
- public int compare(View left, View right) {
- CellAndSpan l = config.map.get(left);
- CellAndSpan r = config.map.get(right);
- switch (whichEdge) {
- case LEFT:
- return (r.cellX + r.spanX) - (l.cellX + l.spanX);
- case RIGHT:
- return l.cellX - r.cellX;
- case TOP:
- return (r.cellY + r.spanY) - (l.cellY + l.spanY);
- case BOTTOM:
- default:
- return l.cellY - r.cellY;
- }
- }
- }
-
- public void sortConfigurationForEdgePush(int edge) {
- comparator.whichEdge = edge;
- Collections.sort(config.sortedViews, comparator);
- }
- }
-
// This method tries to find a reordering solution which satisfies the push mechanic by trying
// to push items in each of the cardinal directions, in an order based on the direction vector
// passed.
@@ -2532,54 +2348,6 @@
}
/**
- * Represents the solution to a reorder of items in the Workspace.
- */
- public static class ItemConfiguration extends CellAndSpan {
- public final ArrayMap<View, CellAndSpan> map = new ArrayMap<>();
- private final ArrayMap<View, CellAndSpan> savedMap = new ArrayMap<>();
- public final ArrayList<View> sortedViews = new ArrayList<>();
- public ArrayList<View> intersectingViews;
- public boolean isSolution = false;
-
- public void save() {
- // Copy current state into savedMap
- for (View v: map.keySet()) {
- savedMap.get(v).copyFrom(map.get(v));
- }
- }
-
- public void restore() {
- // Restore current state from savedMap
- for (View v: savedMap.keySet()) {
- map.get(v).copyFrom(savedMap.get(v));
- }
- }
-
- public void add(View v, CellAndSpan cs) {
- map.put(v, cs);
- savedMap.put(v, new CellAndSpan());
- sortedViews.add(v);
- }
-
- public int area() {
- return spanX * spanY;
- }
-
- public void getBoundingRectForViews(ArrayList<View> views, Rect outRect) {
- boolean first = true;
- for (View v: views) {
- CellAndSpan c = map.get(v);
- if (first) {
- outRect.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
- first = false;
- } else {
- outRect.union(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
- }
- }
- }
- }
-
- /**
* Find a starting cell position that will fit the given bounds nearest the requested
* cell location. Uses Euclidean distance to score multiple vacant areas.
*
@@ -2758,52 +2526,6 @@
return new CellLayoutLayoutParams(p);
}
- // This class stores info for two purposes:
- // 1. When dragging items (mDragInfo in Workspace), we store the View, its cellX & cellY,
- // its spanX, spanY, and the screen it is on
- // 2. When long clicking on an empty cell in a CellLayout, we save information about the
- // cellX and cellY coordinates and which page was clicked. We then set this as a tag on
- // the CellLayout that was long clicked
- public static final class CellInfo extends CellAndSpan {
- public final View cell;
- final int screenId;
- final int container;
-
- public CellInfo(View v, ItemInfo info, CellPos cellPos) {
- cellX = cellPos.cellX;
- cellY = cellPos.cellY;
- spanX = info.spanX;
- spanY = info.spanY;
- cell = v;
- screenId = cellPos.screenId;
- container = info.container;
- }
-
- @Override
- public String toString() {
- return "Cell[view=" + (cell == null ? "null" : cell.getClass())
- + ", x=" + cellX + ", y=" + cellY + "]";
- }
- }
-
- /**
- * A Delegated cell Drawing for drawing on CellLayout
- */
- public abstract static class DelegatedCellDrawing {
- public int mDelegateCellX;
- public int mDelegateCellY;
-
- /**
- * Draw under CellLayout
- */
- public abstract void drawUnderItem(Canvas canvas);
-
- /**
- * Draw over CellLayout
- */
- public abstract void drawOverItem(Canvas canvas);
- }
-
/**
* Returns whether an item can be placed in this CellLayout (after rearranging and/or resizing
* if necessary).
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 85d02eb..badd1c4 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -54,9 +54,11 @@
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.icons.IconNormalizer;
import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.responsive.CalculatedCellSpec;
import com.android.launcher3.responsive.CalculatedHotseatSpec;
import com.android.launcher3.responsive.CalculatedResponsiveSpec;
import com.android.launcher3.responsive.HotseatSpecsProvider;
+import com.android.launcher3.responsive.ResponsiveCellSpecsProvider;
import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType;
import com.android.launcher3.responsive.ResponsiveSpec.DimensionType;
import com.android.launcher3.responsive.ResponsiveSpecsProvider;
@@ -125,6 +127,8 @@
private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
private CalculatedHotseatSpec mResponsiveHotseatSpec;
+ private CalculatedCellSpec mResponsiveWorkspaceCellSpec;
+ private CalculatedCellSpec mResponsiveAllAppsCellSpec;
/**
* The maximum amount of left/right workspace padding as a percentage of the screen width.
@@ -165,7 +169,7 @@
public int iconSizePx;
public int iconTextSizePx;
public int iconDrawablePaddingPx;
- private final int mIconDrawablePaddingOriginalPx;
+ private int mIconDrawablePaddingOriginalPx;
public boolean iconCenterVertically;
public float cellScaleToFit;
@@ -176,7 +180,9 @@
public int cellYPaddingPx = -1;
// Folder
- public float folderLabelTextScale;
+ public final int numFolderRows;
+ public final int numFolderColumns;
+ public final float folderLabelTextScale;
public int folderLabelTextSizePx;
public int folderFooterHeightPx;
public int folderIconSizePx;
@@ -328,7 +334,9 @@
mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
&& inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
&& inv.folderSpecsId != INVALID_RESOURCE_HANDLE
- && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE;
+ && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE
+ && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE
+ && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE;
mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
// Determine device posture.
@@ -431,6 +439,8 @@
}
folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
+ numFolderRows = inv.numFolderRows[mTypeIndex];
+ numFolderColumns = inv.numFolderColumns[mTypeIndex];
if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
@@ -466,17 +476,19 @@
mWorkspacePageIndicatorOverlapWorkspace =
res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
- TypedArray cellStyle;
- if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
- cellStyle = context.obtainStyledAttributes(inv.cellStyle,
- R.styleable.CellStyle);
- } else {
- cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
- R.styleable.CellStyle);
+ if (!mIsResponsiveGrid) {
+ TypedArray cellStyle;
+ if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
+ cellStyle = context.obtainStyledAttributes(inv.cellStyle,
+ R.styleable.CellStyle);
+ } else {
+ cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
+ R.styleable.CellStyle);
+ }
+ mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
+ R.styleable.CellStyle_iconDrawablePadding, 0);
+ cellStyle.recycle();
}
- mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
- R.styleable.CellStyle_iconDrawablePadding, 0);
- cellStyle.recycle();
dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
@@ -533,6 +545,13 @@
mHotseatBarEdgePaddingPx =
isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
mHotseatBarWorkspaceSpacePx = 0;
+
+ ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
+ new ResourceHelper(context,
+ isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
+ : inv.workspaceCellSpecsId));
+ mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
+ responsiveAspectRatio, heightPx);
} else {
hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
@@ -566,7 +585,13 @@
springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
R.dimen.spring_loaded_hotseat_top_margin);
- updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
+
+ if (mIsResponsiveGrid) {
+ updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
+ } else {
+ updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
+ }
+
if (areNavButtonsInline && !isPhone) {
inlineNavButtonsEndSpacingPx =
res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
@@ -622,13 +647,22 @@
isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
ResponsiveSpecType.Folder);
mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
- DimensionType.WIDTH, inv.numFolderColumns,
+ DimensionType.WIDTH, numFolderColumns,
mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
mResponsiveWorkspaceWidthSpec);
mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
- DimensionType.HEIGHT, inv.numFolderRows,
+ DimensionType.HEIGHT, numFolderRows,
mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
mResponsiveWorkspaceHeightSpec);
+
+ ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
+ new ResourceHelper(context,
+ isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
+ : inv.allAppsCellSpecsId));
+ mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
+ responsiveAspectRatio,
+ mResponsiveAllAppsHeightSpec.getAvailableSpace(),
+ mResponsiveWorkspaceCellSpec);
}
desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
@@ -965,19 +999,22 @@
* Returns the amount of extra (or unused) vertical space.
*/
private int updateAvailableDimensions(Resources res) {
+ iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
+
+ if (mIsResponsiveGrid) {
+ updateIconSize(1f, res);
+ updateWorkspacePadding();
+ return 0;
+ }
+
float invIconSizeDp = inv.iconSize[mTypeIndex];
float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
- iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
updateIconSize(1f, res);
updateWorkspacePadding();
- if (mIsResponsiveGrid) {
- return 0;
- }
-
// Check to see if the icons fit within the available height.
float usedHeight = getCellLayoutHeightSpecification();
final int maxHeight = getCellLayoutHeight();
@@ -1021,7 +1058,7 @@
// TODO(b/235886078): workaround needed because of this bug
// Icons are 10% larger on XML than their visual size,
// so remove that extra space to get labels closer to the correct padding
- int iconVisibleSizePx = (int) Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
+ int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2));
}
@@ -1059,6 +1096,10 @@
cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
if (mIsResponsiveGrid) {
+ iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
+ iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
+ mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
+
cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
@@ -1164,7 +1205,7 @@
// All apps
if (mIsResponsiveGrid) {
- updateAllAppsWithResponsiveMeasures(res);
+ updateAllAppsWithResponsiveMeasures();
} else {
updateAllAppsIconSize(scale, res);
}
@@ -1263,13 +1304,16 @@
}
}
- private void updateAllAppsWithResponsiveMeasures(Resources res) {
+ private void updateAllAppsWithResponsiveMeasures() {
+ allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
+ allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
+ allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
+ mResponsiveAllAppsCellSpec.getIconDrawablePadding());
allAppsBorderSpacePx = new Point(
mResponsiveAllAppsWidthSpec.getGutterPx(),
mResponsiveAllAppsHeightSpec.getGutterPx()
);
- allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx()
- + mResponsiveAllAppsHeightSpec.getGutterPx();
+ allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
// This workaround is needed to align AllApps icons with Workspace icons
@@ -1278,22 +1322,6 @@
allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
- // TODO(b/287975993): Remove this after icon size is extracted to responsive grid
- // Copy icon size from the workspace when spec is matchWorkspace or
- // use the default all apps icon size
- if (mResponsiveAllAppsHeightSpec.isCellSizeMatchWorkspace()
- || mResponsiveAllAppsWidthSpec.isCellSizeMatchWorkspace()) {
- allAppsIconSizePx = iconSizePx;
- allAppsIconTextSizePx = iconTextSizePx;
- allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
- } else {
- allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
- allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
- allAppsIconDrawablePaddingPx = res.getDimensionPixelSize(
- R.dimen.all_apps_icon_drawable_padding);
- allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
- allAppsIconDrawablePaddingPx);
- }
// Reduce the size of the app icon if it doesn't fit
if (allAppsCellWidthPx < allAppsIconSizePx) {
@@ -1318,6 +1346,8 @@
allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
}
+
+ allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
}
/**
@@ -1365,16 +1395,16 @@
Point totalWorkspacePadding = getTotalWorkspacePadding();
// Check if the folder fit within the available height.
- float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
- + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
+ float contentUsedHeight = folderCellHeightPx * numFolderRows
+ + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
+ folderFooterHeightPx
+ folderContentPaddingTop;
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
float scaleY = contentMaxHeight / contentUsedHeight;
// Check if the folder fit within the available width.
- float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
- + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
+ float contentUsedWidth = folderCellWidthPx * numFolderColumns
+ + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
+ folderContentPaddingLeftRight * 2;
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
float scaleX = contentMaxWidth / contentUsedWidth;
@@ -1386,15 +1416,14 @@
}
private void updateFolderCellSize(float scale, Resources res) {
- float invIconSizeDp = inv.iconSize[mTypeIndex];
- folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
- folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
- folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
- (int) (folderChildTextSizePx * folderLabelTextScale));
-
- int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
-
+ int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
if (mIsResponsiveGrid) {
+ folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
+ folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
+ folderLabelTextSizePx = Math.max(minLabelTextSize,
+ (int) (folderChildTextSizePx * folderLabelTextScale));
+ int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
+
folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
@@ -1421,9 +1450,20 @@
folderChildIconSizePx = cellContentDimensions.getIconSizePx();
folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
- folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
+ folderLabelTextSizePx = Math.max(minLabelTextSize,
(int) (folderChildTextSizePx * folderLabelTextScale));
- } else if (mIsScalableGrid) {
+ return;
+ }
+
+ float invIconSizeDp = inv.iconSize[mTypeIndex];
+ float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
+ folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
+ folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
+ folderLabelTextSizePx = Math.max(minLabelTextSize,
+ (int) (folderChildTextSizePx * folderLabelTextScale));
+ int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
+
+ if (mIsScalableGrid) {
if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
@@ -1993,8 +2033,8 @@
writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
- writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
- writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
+ writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
+ writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
@@ -2132,6 +2172,9 @@
writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
+ writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
+ + mResponsiveWorkspaceCellSpec);
+ writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
}
}
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index e5a6b2b..dfbbcaa 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -122,8 +122,8 @@
/**
* Number of icons per row and column in the folder.
*/
- public int numFolderRows;
- public int numFolderColumns;
+ public int[] numFolderRows;
+ public int[] numFolderColumns;
public float[] iconSize;
public float[] iconTextSize;
public int iconBitmapSize;
@@ -191,8 +191,18 @@
public int folderSpecsId = INVALID_RESOURCE_HANDLE;
@XmlRes
public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
public String dbFile;
public int defaultLayoutId;
@@ -375,6 +385,10 @@
folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
hotseatSpecsId = closestProfile.mHotseatSpecsId;
hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
+ workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
+ workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
+ allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
+ allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
this.deviceType = deviceType;
inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
@@ -796,8 +810,8 @@
public final int numSearchContainerColumns;
public final int deviceCategory;
- private final int numFolderRows;
- private final int numFolderColumns;
+ private final int[] numFolderRows = new int[COUNT_SIZES];
+ private final int[] numFolderColumns = new int[COUNT_SIZES];
private final @StyleRes int folderStyle;
private final @StyleRes int cellStyle;
@@ -827,6 +841,10 @@
private final int mFolderSpecsTwoPanelId;
private final int mHotseatSpecsId;
private final int mHotseatSpecsTwoPanelId;
+ private final int mWorkspaceCellSpecsId;
+ private final int mWorkspaceCellSpecsTwoPanelId;
+ private final int mAllAppsCellSpecsId;
+ private final int mAllAppsCellSpecsTwoPanelId;
public GridOption(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(
@@ -870,11 +888,39 @@
a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
R.dimen.taskbar_button_margin_default);
- numFolderRows = a.getInt(
+ numFolderRows[INDEX_DEFAULT] = a.getInt(
R.styleable.GridDisplayOption_numFolderRows, numRows);
- numFolderColumns = a.getInt(
+ numFolderColumns[INDEX_DEFAULT] = a.getInt(
R.styleable.GridDisplayOption_numFolderColumns, numColumns);
+ if (FeatureFlags.enableResponsiveWorkspace()) {
+ numFolderRows[INDEX_LANDSCAPE] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderRowsLandscape,
+ numFolderRows[INDEX_DEFAULT]);
+ numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderColumnsLandscape,
+ numFolderColumns[INDEX_DEFAULT]);
+ numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
+ numFolderRows[INDEX_DEFAULT]);
+ numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
+ numFolderColumns[INDEX_DEFAULT]);
+ numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
+ numFolderRows[INDEX_DEFAULT]);
+ numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
+ R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
+ numFolderColumns[INDEX_DEFAULT]);
+ } else {
+ numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
+ numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
+ numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
+ numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
+ numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
+ numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
+ }
+
folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
INVALID_RESOURCE_HANDLE);
@@ -909,6 +955,18 @@
mHotseatSpecsTwoPanelId = a.getResourceId(
R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
INVALID_RESOURCE_HANDLE);
+ mWorkspaceCellSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_workspaceCellSpecsId,
+ INVALID_RESOURCE_HANDLE);
+ mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
+ R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
+ INVALID_RESOURCE_HANDLE);
+ mAllAppsCellSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_allAppsCellSpecsId,
+ INVALID_RESOURCE_HANDLE);
+ mAllAppsCellSpecsTwoPanelId = a.getResourceId(
+ R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
+ INVALID_RESOURCE_HANDLE);
} else {
mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
@@ -918,6 +976,10 @@
mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
+ mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
+ mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
}
int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 22870bc..9f7575d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -528,6 +528,7 @@
mAppWidgetManager = new WidgetManagerHelper(this);
mAppWidgetHolder = createAppWidgetHolder();
mAppWidgetHolder.startListening();
+ mAppWidgetHolder.addProviderChangeListener(() -> refreshAndBindWidgetsForPackageUser(null));
mPopupDataProvider = new PopupDataProvider(this::updateNotificationDots);
@@ -802,7 +803,7 @@
if (info.container >= 0) {
View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container);
if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) {
- if (new FolderGridOrganizer(getDeviceProfile().inv)
+ if (new FolderGridOrganizer(getDeviceProfile())
.setFolderInfo((FolderInfo) folderIcon.getTag())
.isItemInPreview(info.rank)) {
folderIcon.invalidate();
@@ -2657,7 +2658,7 @@
// Cache one page worth of icons
getViewCache().setCacheSize(R.layout.folder_application,
- mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
+ mDeviceProfile.numFolderColumns * mDeviceProfile.numFolderRows);
getViewCache().setCacheSize(R.layout.folder_page, 2);
TraceHelper.INSTANCE.endSection();
diff --git a/src/com/android/launcher3/MultipageCellLayout.java b/src/com/android/launcher3/MultipageCellLayout.java
index 4b5c9ef..123e8ca 100644
--- a/src/com/android/launcher3/MultipageCellLayout.java
+++ b/src/com/android/launcher3/MultipageCellLayout.java
@@ -23,6 +23,7 @@
import android.view.View;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
+import com.android.launcher3.celllayout.ItemConfiguration;
import com.android.launcher3.celllayout.MulticellReorderAlgorithm;
import com.android.launcher3.util.CellAndSpan;
import com.android.launcher3.util.GridOccupancy;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 30f3f5f..be4168d 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -74,6 +74,7 @@
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.apppairs.AppPairIcon;
+import com.android.launcher3.celllayout.CellInfo;
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
import com.android.launcher3.celllayout.CellPosMapper;
import com.android.launcher3.celllayout.CellPosMapper.CellPos;
@@ -189,7 +190,7 @@
/**
* CellInfo for the cell that is currently being dragged
*/
- protected CellLayout.CellInfo mDragInfo;
+ protected CellInfo mDragInfo;
/**
* Target drop area calculated during last acceptDrop call.
@@ -1620,7 +1621,7 @@
page.setAccessibilityDelegate(null);
}
- public void startDrag(CellLayout.CellInfo cellInfo, DragOptions options) {
+ public void startDrag(CellInfo cellInfo, DragOptions options) {
View child = cellInfo.cell;
mDragInfo = cellInfo;
@@ -1784,7 +1785,7 @@
int spanX;
int spanY;
if (mDragInfo != null) {
- final CellLayout.CellInfo dragCellInfo = mDragInfo;
+ final CellInfo dragCellInfo = mDragInfo;
spanX = dragCellInfo.spanX;
spanY = dragCellInfo.spanY;
} else {
@@ -3078,7 +3079,7 @@
* so that Launcher can sync this object with the correct info when the activity is created/
* destroyed
*/
- public CellLayout.CellInfo getDragInfo() {
+ public CellInfo getDragInfo() {
return mDragInfo;
}
diff --git a/src/com/android/launcher3/celllayout/CellInfo.kt b/src/com/android/launcher3/celllayout/CellInfo.kt
new file mode 100644
index 0000000..5a3b7f7
--- /dev/null
+++ b/src/com/android/launcher3/celllayout/CellInfo.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2023 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.celllayout
+
+import android.view.View
+import com.android.launcher3.celllayout.CellPosMapper.CellPos
+import com.android.launcher3.model.data.ItemInfo
+import com.android.launcher3.util.CellAndSpan
+
+// This class stores info for two purposes:
+// 1. When dragging items (mDragInfo in Workspace), we store the View, its cellX & cellY,
+// its spanX, spanY, and the screen it is on
+// 2. When long clicking on an empty cell in a CellLayout, we save information about the
+// cellX and cellY coordinates and which page was clicked. We then set this as a tag on
+// the CellLayout that was long clicked
+class CellInfo(v: View?, info: ItemInfo, cellPos: CellPos) :
+ CellAndSpan(cellPos.cellX, cellPos.cellY, info.spanX, info.spanY) {
+ @JvmField val cell: View?
+ @JvmField val screenId: Int
+ @JvmField val container: Int
+
+ init {
+ cell = v
+ screenId = cellPos.screenId
+ container = info.container
+ }
+
+ override fun toString(): String {
+ return "CellInfo(cell=$cell, screenId=$screenId, container=$container)"
+ }
+}
diff --git a/src/com/android/launcher3/celllayout/DelegatedCellDrawing.kt b/src/com/android/launcher3/celllayout/DelegatedCellDrawing.kt
new file mode 100644
index 0000000..1703f9b
--- /dev/null
+++ b/src/com/android/launcher3/celllayout/DelegatedCellDrawing.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2023 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.celllayout
+
+import android.graphics.Canvas
+
+/** A Delegated cell Drawing for drawing on CellLayout */
+abstract class DelegatedCellDrawing {
+ @JvmField var mDelegateCellX = 0
+ @JvmField var mDelegateCellY = 0
+
+ /** Draw under CellLayout */
+ abstract fun drawUnderItem(canvas: Canvas)
+
+ /** Draw over CellLayout */
+ abstract fun drawOverItem(canvas: Canvas)
+}
diff --git a/src/com/android/launcher3/celllayout/ItemConfiguration.kt b/src/com/android/launcher3/celllayout/ItemConfiguration.kt
new file mode 100644
index 0000000..e775145
--- /dev/null
+++ b/src/com/android/launcher3/celllayout/ItemConfiguration.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2023 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.celllayout
+
+import android.graphics.Rect
+import android.util.ArrayMap
+import android.view.View
+import com.android.launcher3.util.CellAndSpan
+
+/** Represents the solution to a reorder of items in the Workspace. */
+class ItemConfiguration : CellAndSpan() {
+ @JvmField val map = ArrayMap<View, CellAndSpan>()
+ private val savedMap = ArrayMap<View, CellAndSpan>()
+
+ @JvmField val sortedViews = ArrayList<View>()
+
+ @JvmField var intersectingViews: ArrayList<View> = ArrayList()
+
+ @JvmField var isSolution = false
+ fun save() {
+ // Copy current state into savedMap
+ map.forEach { (k, v) -> savedMap[k]?.copyFrom(v) }
+ }
+
+ fun restore() {
+ // Restore current state from savedMap
+ savedMap.forEach { (k, v) -> map[k]?.copyFrom(v) }
+ }
+
+ fun add(v: View, cs: CellAndSpan) {
+ map[v] = cs
+ savedMap[v] = CellAndSpan()
+ sortedViews.add(v)
+ }
+
+ fun area(): Int {
+ return spanX * spanY
+ }
+
+ fun getBoundingRectForViews(views: ArrayList<View>, outRect: Rect) {
+ views
+ .mapNotNull { v -> map[v] }
+ .forEachIndexed { i, c ->
+ if (i == 0) outRect.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY)
+ else outRect.union(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY)
+ }
+ }
+}
diff --git a/src/com/android/launcher3/celllayout/MulticellReorderAlgorithm.java b/src/com/android/launcher3/celllayout/MulticellReorderAlgorithm.java
index a2e26b3..7deb653 100644
--- a/src/com/android/launcher3/celllayout/MulticellReorderAlgorithm.java
+++ b/src/com/android/launcher3/celllayout/MulticellReorderAlgorithm.java
@@ -38,8 +38,8 @@
mSeam = new View(cellLayout.getContext());
}
- private CellLayout.ItemConfiguration removeSeamFromSolution(
- CellLayout.ItemConfiguration solution) {
+ public ItemConfiguration removeSeamFromSolution(ItemConfiguration solution) {
+ solution.map.remove(mSeam);
solution.map.forEach((view, cell) -> cell.cellX =
cell.cellX > mCellLayout.getCountX() / 2 ? cell.cellX - 1 : cell.cellX);
solution.cellX =
@@ -48,25 +48,24 @@
}
@Override
- public CellLayout.ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY,
- int minSpanX, int minSpanY,
- int spanX, int spanY) {
+ public ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY, int minSpanX,
+ int minSpanY, int spanX, int spanY) {
return removeSeamFromSolution(simulateSeam(
() -> super.closestEmptySpaceReorder(pixelX, pixelY, minSpanX, minSpanY, spanX,
spanY)));
}
@Override
- public CellLayout.ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX,
+ public ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX,
int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX,
- CellLayout.ItemConfiguration solution) {
+ ItemConfiguration solution) {
return removeSeamFromSolution(simulateSeam(
() -> super.findReorderSolution(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY,
direction, dragView, decX, solution)));
}
@Override
- public CellLayout.ItemConfiguration dropInPlaceSolution(int pixelX, int pixelY, int spanX,
+ public ItemConfiguration dropInPlaceSolution(int pixelX, int pixelY, int spanX,
int spanY,
View dragView) {
return removeSeamFromSolution(simulateSeam(
diff --git a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
index 17786f2..0f6464b 100644
--- a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
+++ b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
@@ -59,9 +59,17 @@
* @param solution variable to store the solution
* @return the same solution variable
*/
- public CellLayout.ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX,
+ public ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX,
int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX,
- CellLayout.ItemConfiguration solution) {
+ ItemConfiguration solution) {
+ return findReorderSolutionRecursive(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY,
+ direction, dragView, decX, solution);
+ }
+
+
+ private ItemConfiguration findReorderSolutionRecursive(int pixelX, int pixelY,
+ int minSpanX, int minSpanY, int spanX, int spanY, int[] direction, View dragView,
+ boolean decX, ItemConfiguration solution) {
// Copy the current state into the solution. This solution will be manipulated as necessary.
mCellLayout.copyCurrentStateToSolution(solution, false);
// Copy the current occupied array into the temporary occupied array. This array will be
@@ -83,11 +91,11 @@
// We try shrinking the widget down to size in an alternating pattern, shrink 1 in
// x, then 1 in y etc.
if (spanX > minSpanX && (minSpanY == spanY || decX)) {
- return findReorderSolution(pixelX, pixelY, minSpanX, minSpanY, spanX - 1, spanY,
- direction, dragView, false, solution);
+ return findReorderSolutionRecursive(pixelX, pixelY, minSpanX, minSpanY, spanX - 1,
+ spanY, direction, dragView, false, solution);
} else if (spanY > minSpanY) {
- return findReorderSolution(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY - 1,
- direction, dragView, true, solution);
+ return findReorderSolutionRecursive(pixelX, pixelY, minSpanX, minSpanY, spanX,
+ spanY - 1, direction, dragView, true, solution);
}
solution.isSolution = false;
} else {
@@ -110,11 +118,11 @@
* @param dragView view being dragged in reorder
* @return the configuration that represents the found reorder
*/
- public CellLayout.ItemConfiguration dropInPlaceSolution(int pixelX, int pixelY, int spanX,
+ public ItemConfiguration dropInPlaceSolution(int pixelX, int pixelY, int spanX,
int spanY, View dragView) {
int[] result = mCellLayout.findNearestAreaIgnoreOccupied(pixelX, pixelY, spanX, spanY,
new int[2]);
- CellLayout.ItemConfiguration solution = new CellLayout.ItemConfiguration();
+ ItemConfiguration solution = new ItemConfiguration();
mCellLayout.copyCurrentStateToSolution(solution, false);
solution.isSolution = !isConfigurationRegionOccupied(
@@ -133,7 +141,7 @@
}
private boolean isConfigurationRegionOccupied(Rect region,
- CellLayout.ItemConfiguration configuration, View ignoreView) {
+ ItemConfiguration configuration, View ignoreView) {
return configuration.map.entrySet()
.stream()
.filter(entry -> entry.getKey() != ignoreView)
@@ -153,9 +161,9 @@
* @param spanY vertical cell span
* @return the configuration that represents the found reorder
*/
- public CellLayout.ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY,
+ public ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY,
int minSpanX, int minSpanY, int spanX, int spanY) {
- CellLayout.ItemConfiguration solution = new CellLayout.ItemConfiguration();
+ ItemConfiguration solution = new ItemConfiguration();
int[] result = new int[2];
int[] resultSpan = new int[2];
mCellLayout.findNearestVacantArea(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, result,
@@ -188,23 +196,22 @@
* @return returns a solution for the given parameters, the solution contains all the icons and
* the locations they should be in the given solution.
*/
- public CellLayout.ItemConfiguration calculateReorder(int pixelX, int pixelY, int minSpanX,
+ public ItemConfiguration calculateReorder(int pixelX, int pixelY, int minSpanX,
int minSpanY, int spanX, int spanY, View dragView) {
mCellLayout.getDirectionVectorForDrop(pixelX, pixelY, spanX, spanY, dragView,
mCellLayout.mDirectionVector);
- CellLayout.ItemConfiguration dropInPlaceSolution = dropInPlaceSolution(pixelX, pixelY,
- spanX, spanY,
+ ItemConfiguration dropInPlaceSolution = dropInPlaceSolution(pixelX, pixelY, spanX, spanY,
dragView);
// Find a solution involving pushing / displacing any items in the way
- CellLayout.ItemConfiguration swapSolution = findReorderSolution(pixelX, pixelY, minSpanX,
+ ItemConfiguration swapSolution = findReorderSolution(pixelX, pixelY, minSpanX,
minSpanY, spanX, spanY, mCellLayout.mDirectionVector, dragView, true,
- new CellLayout.ItemConfiguration());
+ new ItemConfiguration());
// We attempt the approach which doesn't shuffle views at all
- CellLayout.ItemConfiguration closestSpaceSolution = closestEmptySpaceReorder(
- pixelX, pixelY, minSpanX, minSpanY, spanX, spanY);
+ ItemConfiguration closestSpaceSolution = closestEmptySpaceReorder(pixelX, pixelY, minSpanX,
+ minSpanY, spanX, spanY);
// If the reorder solution requires resizing (shrinking) the item being dropped, we instead
// favor a solution in which the item is not resized, but
diff --git a/src/com/android/launcher3/celllayout/ViewCluster.kt b/src/com/android/launcher3/celllayout/ViewCluster.kt
new file mode 100644
index 0000000..49693e3
--- /dev/null
+++ b/src/com/android/launcher3/celllayout/ViewCluster.kt
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2023 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.celllayout
+
+import android.graphics.Rect
+import android.view.View
+import com.android.launcher3.CellLayout
+import java.util.Collections
+
+/**
+ * This helper class defines a cluster of views. It helps with defining complex edges of the cluster
+ * and determining how those edges interact with other views. The edges essentially define a
+ * fine-grained boundary around the cluster of views -- like a more precise version of a bounding
+ * box.
+ */
+class ViewCluster(
+ private val mCellLayout: CellLayout,
+ views: ArrayList<View>,
+ val config: ItemConfiguration
+) {
+
+ @JvmField val views = ArrayList<View>(views)
+ private val boundingRect = Rect()
+
+ private val leftEdge = IntArray(mCellLayout.countY)
+ private val rightEdge = IntArray(mCellLayout.countY)
+ private val topEdge = IntArray(mCellLayout.countX)
+ private val bottomEdge = IntArray(mCellLayout.countX)
+
+ private var dirtyEdges = 0
+ private var boundingRectDirty = false
+
+ val comparator: PositionComparator = PositionComparator()
+
+ init {
+ resetEdges()
+ }
+ private fun resetEdges() {
+ for (i in 0 until mCellLayout.countX) {
+ topEdge[i] = -1
+ bottomEdge[i] = -1
+ }
+ for (i in 0 until mCellLayout.countY) {
+ leftEdge[i] = -1
+ rightEdge[i] = -1
+ }
+ dirtyEdges = LEFT or TOP or RIGHT or BOTTOM
+ boundingRectDirty = true
+ }
+
+ private fun computeEdge(which: Int) =
+ views
+ .mapNotNull { v -> config.map[v] }
+ .forEach { cs ->
+ val left = cs.cellX
+ val right = cs.cellX + cs.spanX
+ val top = cs.cellY
+ val bottom = cs.cellY + cs.spanY
+ when (which) {
+ LEFT ->
+ for (j in top until bottom) {
+ if (left < leftEdge[j] || leftEdge[j] < 0) {
+ leftEdge[j] = left
+ }
+ }
+ RIGHT ->
+ for (j in top until bottom) {
+ if (right > rightEdge[j]) {
+ rightEdge[j] = right
+ }
+ }
+ TOP ->
+ for (j in left until right) {
+ if (top < topEdge[j] || topEdge[j] < 0) {
+ topEdge[j] = top
+ }
+ }
+ BOTTOM ->
+ for (j in left until right) {
+ if (bottom > bottomEdge[j]) {
+ bottomEdge[j] = bottom
+ }
+ }
+ }
+ }
+
+ fun isViewTouchingEdge(v: View?, whichEdge: Int): Boolean {
+ val cs = config.map[v] ?: return false
+ val left = cs.cellX
+ val right = cs.cellX + cs.spanX
+ val top = cs.cellY
+ val bottom = cs.cellY + cs.spanY
+ if ((dirtyEdges and whichEdge) == whichEdge) {
+ computeEdge(whichEdge)
+ dirtyEdges = dirtyEdges and whichEdge.inv()
+ }
+ return when (whichEdge) {
+ // In this case if any of the values of leftEdge is equal to right, which is the
+ // rightmost x value of the view, it means that the cluster is touching the view from
+ // the left the same logic applies for the other sides.
+ LEFT -> edgeContainsValue(top, bottom, leftEdge, right)
+ RIGHT -> edgeContainsValue(top, bottom, rightEdge, left)
+ TOP -> edgeContainsValue(left, right, topEdge, bottom)
+ BOTTOM -> edgeContainsValue(left, right, bottomEdge, top)
+ else -> false
+ }
+ }
+
+ private fun edgeContainsValue(start: Int, end: Int, edge: IntArray, value: Int): Boolean {
+ for (i in start until end) {
+ if (edge[i] == value) {
+ return true
+ }
+ }
+ return false
+ }
+
+ fun shift(whichEdge: Int, delta: Int) {
+ views
+ .mapNotNull { v -> config.map[v] }
+ .forEach { c ->
+ when (whichEdge) {
+ LEFT -> c.cellX -= delta
+ RIGHT -> c.cellX += delta
+ TOP -> c.cellY -= delta
+ BOTTOM -> c.cellY += delta
+ else -> c.cellY += delta
+ }
+ }
+ resetEdges()
+ }
+
+ fun addView(v: View) {
+ views.add(v)
+ resetEdges()
+ }
+
+ fun getBoundingRect(): Rect {
+ if (boundingRectDirty) {
+ config.getBoundingRectForViews(views, boundingRect)
+ }
+ return boundingRect
+ }
+
+ inner class PositionComparator : Comparator<View?> {
+ var whichEdge = 0
+ override fun compare(left: View?, right: View?): Int {
+ val l = config.map[left]
+ val r = config.map[right]
+ if (l == null || r == null) throw NullPointerException()
+ return when (whichEdge) {
+ LEFT -> r.cellX + r.spanX - (l.cellX + l.spanX)
+ RIGHT -> l.cellX - r.cellX
+ TOP -> r.cellY + r.spanY - (l.cellY + l.spanY)
+ BOTTOM -> l.cellY - r.cellY
+ else -> l.cellY - r.cellY
+ }
+ }
+ }
+
+ fun sortConfigurationForEdgePush(edge: Int) {
+ comparator.whichEdge = edge
+ Collections.sort(config.sortedViews, comparator)
+ }
+
+ companion object {
+ const val LEFT = 1 shl 0
+ const val TOP = 1 shl 1
+ const val RIGHT = 1 shl 2
+ const val BOTTOM = 1 shl 3
+ }
+}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 8bf7ec2..e7a559e 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -1082,7 +1082,7 @@
private void updateItemLocationsInDatabaseBatch(boolean isBind) {
FolderGridOrganizer verifier = new FolderGridOrganizer(
- mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo);
+ mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
ArrayList<ItemInfo> items = new ArrayList<>();
int total = mInfo.contents.size();
@@ -1381,7 +1381,7 @@
@Override
public void onAdd(WorkspaceItemInfo item, int rank) {
FolderGridOrganizer verifier = new FolderGridOrganizer(
- mActivityContext.getDeviceProfile().inv).setFolderInfo(mInfo);
+ mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
verifier.updateRankAndPos(item, rank);
mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
item.cellY);
diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java
index 9e2e2bf..a91373b 100644
--- a/src/com/android/launcher3/folder/FolderAnimationManager.java
+++ b/src/com/android/launcher3/folder/FolderAnimationManager.java
@@ -96,7 +96,7 @@
mContext = folder.getContext();
mDeviceProfile = folder.mActivityContext.getDeviceProfile();
- mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile.inv);
+ mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile);
mIsOpening = isOpening;
diff --git a/src/com/android/launcher3/folder/FolderGridOrganizer.java b/src/com/android/launcher3/folder/FolderGridOrganizer.java
index 4be82ed..0436011 100644
--- a/src/com/android/launcher3/folder/FolderGridOrganizer.java
+++ b/src/com/android/launcher3/folder/FolderGridOrganizer.java
@@ -20,7 +20,7 @@
import android.graphics.Point;
-import com.android.launcher3.InvariantDeviceProfile;
+import com.android.launcher3.DeviceProfile;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
@@ -41,16 +41,33 @@
private int mCountX;
private int mCountY;
private boolean mDisplayingUpperLeftQuadrant = false;
+ private static final int PREVIEW_MAX_ROWS = 2;
+ private static final int PREVIEW_MAX_COLUMNS = 2;
/**
* Note: must call {@link #setFolderInfo(FolderInfo)} manually for verifier to work.
*/
- public FolderGridOrganizer(InvariantDeviceProfile profile) {
+ public FolderGridOrganizer(DeviceProfile profile) {
mMaxCountX = profile.numFolderColumns;
mMaxCountY = profile.numFolderRows;
mMaxItemsPerPage = mMaxCountX * mMaxCountY;
}
+ private FolderGridOrganizer(int maxCountX, int maxCountY) {
+ mMaxCountX = maxCountX;
+ mMaxCountY = maxCountY;
+ mMaxItemsPerPage = mMaxCountX * mMaxCountY;
+ }
+
+ /**
+ * Returns a FolderGridOrganizer that should only be used to verify if the folder icon is
+ * showing in the preview. Max number of rows is {@link #PREVIEW_MAX_ROWS} and columns is
+ * {@link #PREVIEW_MAX_COLUMNS}.
+ */
+ public static FolderGridOrganizer getPreviewIconVerifier() {
+ return new FolderGridOrganizer(PREVIEW_MAX_ROWS, PREVIEW_MAX_COLUMNS);
+ }
+
/**
* Updates the organizer with the provided folder info
*/
@@ -127,6 +144,7 @@
/**
* Updates the item's cellX, cellY and rank corresponding to the provided rank.
+ *
* @return true if there was any change
*/
public boolean updateRankAndPos(ItemInfo item, int rank) {
@@ -189,7 +207,7 @@
if (page > 0 || mDisplayingUpperLeftQuadrant) {
int col = rank % mCountX;
int row = rank / mCountX;
- return col < 2 && row < 2;
+ return col < PREVIEW_MAX_COLUMNS && row < PREVIEW_MAX_ROWS;
}
return rank < MAX_NUM_ITEMS_IN_PREVIEW;
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index cb1dc4f..c80fb8c 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -221,7 +221,7 @@
icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
- icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile().inv);
+ icon.mPreviewVerifier = new FolderGridOrganizer(activity.getDeviceProfile());
icon.mPreviewVerifier.setFolderInfo(folderInfo);
icon.updatePreviewItems(false);
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index 36e5e1b..f2bed92 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -37,8 +37,6 @@
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.InvariantDeviceProfile;
-import com.android.launcher3.LauncherAppState;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutAndWidgetContainer;
@@ -101,14 +99,15 @@
public FolderPagedView(Context context, AttributeSet attrs) {
super(context, attrs);
- InvariantDeviceProfile profile = LauncherAppState.getIDP(context);
+ ActivityContext activityContext = ActivityContext.lookupContext(context);
+ DeviceProfile profile = activityContext.getDeviceProfile();
mOrganizer = new FolderGridOrganizer(profile);
mIsRtl = Utilities.isRtl(getResources());
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
mFocusIndicatorHelper = new ViewGroupFocusHelper(this);
- mViewCache = ActivityContext.lookupContext(context).getViewCache();
+ mViewCache = activityContext.getViewCache();
}
public void setFolder(Folder folder) {
diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java
index b320ceb..ec03803 100644
--- a/src/com/android/launcher3/folder/PreviewBackground.java
+++ b/src/com/android/launcher3/folder/PreviewBackground.java
@@ -48,6 +48,7 @@
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
+import com.android.launcher3.celllayout.DelegatedCellDrawing;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -55,7 +56,7 @@
* This object represents a FolderIcon preview background. It stores drawing / measurement
* information, handles drawing, and animation (accept state <--> rest state).
*/
-public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
+public class PreviewBackground extends DelegatedCellDrawing {
private static final boolean DRAW_SHADOW = false;
private static final boolean DRAW_STROKE = false;
diff --git a/src/com/android/launcher3/graphics/SysUiScrim.java b/src/com/android/launcher3/graphics/SysUiScrim.java
index 260d490..66001d8 100644
--- a/src/com/android/launcher3/graphics/SysUiScrim.java
+++ b/src/com/android/launcher3/graphics/SysUiScrim.java
@@ -71,7 +71,7 @@
private static final int ALPHA_MASK_BITMAP_WIDTH_DP = 2;
private static final int BOTTOM_MASK_HEIGHT_DP = 200;
- private static final int TOP_MASK_HEIGHT_DP = 70;
+ private static final int TOP_MASK_HEIGHT_DP = 100;
private boolean mDrawTopScrim, mDrawBottomScrim;
@@ -104,7 +104,7 @@
mHideSysUiScrim = Themes.getAttrBoolean(view.getContext(), R.attr.isWorkspaceDarkText);
mTopMaskBitmap = mHideSysUiScrim ? null : createDitheredAlphaMask(mTopMaskHeight,
- new int[]{0x3DFFFFFF, 0x0AFFFFFF, 0x00FFFFFF},
+ new int[]{0x50FFFFFF, 0x0AFFFFFF, 0x00FFFFFF},
new float[]{0f, 0.7f, 1f});
mTopMaskPaint.setColor(0xFF222222);
mBottomMaskBitmap = mHideSysUiScrim ? null : createDitheredAlphaMask(mBottomMaskHeight,
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index bad9b79..9980218 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -341,6 +341,12 @@
@UiEvent(doc = "User tapped on image content in Overview Select mode.")
LAUNCHER_SELECT_MODE_IMAGE(627),
+ @UiEvent(doc = "User tapped on barcode content in Overview Select mode.")
+ LAUNCHER_SELECT_MODE_BARCODE(1531),
+
+ @UiEvent(doc = "Highlight gleams for barcode content in Overview Select mode.")
+ LAUNCHER_SELECT_MODE_SHOW_BARCODE_REGIONS(1532),
+
@UiEvent(doc = "Activity to add external item was started")
LAUNCHER_ADD_EXTERNAL_ITEM_START(641),
@@ -498,6 +504,21 @@
@UiEvent(doc = "User taps the More button to share an image")
LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_IMAGE(778),
+ @UiEvent(doc = "Show Barode indicator for overview sharing")
+ LAUNCHER_OVERVIEW_SHARING_SHOW_BARCODE_INDICATOR(1533),
+
+ @UiEvent(doc = "User taps barcode indicator in overview")
+ LAUNCHER_OVERVIEW_SHARING_BARCODE_INDICATOR_TAP(1534),
+
+ @UiEvent(doc = "Configure barcode region for long_press action for overview sharing")
+ LAUNCHER_OVERVIEW_SHARING_CONFIGURE_BARCODE_REGION_LONG_PRESS(1535),
+
+ @UiEvent(doc = "User long presses a barcode region in overview")
+ LAUNCHER_OVERVIEW_SHARING_BARCODE_REGION_LONG_PRESS(1536),
+
+ @UiEvent(doc = "User drags a barcode region in overview")
+ LAUNCHER_OVERVIEW_SHARING_BARCODE_REGION_DRAG(1537),
+
@UiEvent(doc = "User started resizing a widget on their home screen.")
LAUNCHER_WIDGET_RESIZE_STARTED(820),
@@ -839,6 +860,13 @@
}
/**
+ * Set the package name of the log message.
+ */
+ default StatsLogger withPackageName(@Nullable String packageName) {
+ return this;
+ }
+
+ /**
* Builds the final message and logs it as {@link EventEnum}.
*/
default void log(EventEnum event) {
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index f4ce360..d9f43ef 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -481,8 +481,7 @@
mItemsDeleted = c.commitDeleted();
// Sort the folder items, update ranks, and make sure all preview items are high res.
- FolderGridOrganizer verifier =
- new FolderGridOrganizer(mApp.getInvariantDeviceProfile());
+ FolderGridOrganizer verifier = FolderGridOrganizer.getPreviewIconVerifier();
for (FolderInfo folder : mBgDataModel.folders) {
Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR);
verifier.setFolderInfo(folder);
diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java
index 9a0a6eb..4f2d398 100644
--- a/src/com/android/launcher3/model/PackageUpdatedTask.java
+++ b/src/com/android/launcher3/model/PackageUpdatedTask.java
@@ -34,7 +34,6 @@
import androidx.annotation.NonNull;
import com.android.launcher3.Flags;
-import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
@@ -136,14 +135,6 @@
iconCache.updateIconsForPkg(packages[i], mUser);
activitiesLists.put(
packages[i], appsList.updatePackage(context, packages[i], mUser));
-
- // The update may have changed which shortcuts/widgets are available.
- // Refresh the widgets for the package if we have an activity running.
- Launcher launcher = Launcher.ACTIVITY_TRACKER.getCreatedActivity();
- if (launcher != null) {
- launcher.refreshAndBindWidgetsForPackageUser(
- new PackageUserKey(packages[i], mUser));
- }
}
}
// Since package was just updated, the target must be available now.
diff --git a/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
index 8710303..8e3a5b4 100644
--- a/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
+++ b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
@@ -23,7 +23,13 @@
import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
import com.android.launcher3.util.ResourceHelper
-class HotseatSpecsProvider(private val groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>) {
+class HotseatSpecsProvider(groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>) {
+
+ private val groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>
+ init {
+ this.groupOfSpecs = groupOfSpecs.sortedBy { it.aspectRatio }
+ }
+
fun getSpecsByAspectRatio(aspectRatio: Float): ResponsiveSpecGroup<HotseatSpec> {
check(aspectRatio > 0f) { "Invalid aspect ratio! The value should be bigger than 0." }
diff --git a/src/com/android/launcher3/responsive/ResponsiveCellSpecsProvider.kt b/src/com/android/launcher3/responsive/ResponsiveCellSpecsProvider.kt
new file mode 100644
index 0000000..affca60
--- /dev/null
+++ b/src/com/android/launcher3/responsive/ResponsiveCellSpecsProvider.kt
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2023 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.responsive
+
+import android.content.res.TypedArray
+import android.util.Log
+import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
+import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
+import com.android.launcher3.util.ResourceHelper
+
+class ResponsiveCellSpecsProvider(groupOfSpecs: List<ResponsiveSpecGroup<CellSpec>>) {
+ private val groupOfSpecs: List<ResponsiveSpecGroup<CellSpec>>
+
+ init {
+ this.groupOfSpecs =
+ groupOfSpecs
+ .onEach { group ->
+ check(group.widthSpecs.isEmpty() && group.heightSpecs.isNotEmpty()) {
+ "${this::class.simpleName} is invalid, only heightSpecs are allowed - " +
+ "width list size = ${group.widthSpecs.size}; " +
+ "height list size = ${group.heightSpecs.size}."
+ }
+ }
+ .sortedBy { it.aspectRatio }
+ }
+
+ fun getSpecsByAspectRatio(aspectRatio: Float): ResponsiveSpecGroup<CellSpec> {
+ check(aspectRatio > 0f) { "Invalid aspect ratio! The value should be bigger than 0." }
+
+ val specsGroup = groupOfSpecs.firstOrNull { aspectRatio <= it.aspectRatio }
+ check(specsGroup != null) { "No available spec with aspectRatio within $aspectRatio." }
+
+ return specsGroup
+ }
+
+ fun getCalculatedSpec(aspectRatio: Float, availableHeightSpace: Int): CalculatedCellSpec {
+ val specsGroup = getSpecsByAspectRatio(aspectRatio)
+ val spec = specsGroup.getSpec(DimensionType.HEIGHT, availableHeightSpace)
+ return CalculatedCellSpec(availableHeightSpace, spec)
+ }
+
+ fun getCalculatedSpec(
+ aspectRatio: Float,
+ availableHeightSpace: Int,
+ workspaceCellSpec: CalculatedCellSpec
+ ): CalculatedCellSpec {
+ val specsGroup = getSpecsByAspectRatio(aspectRatio)
+ val spec = specsGroup.getSpec(DimensionType.HEIGHT, availableHeightSpace)
+ return CalculatedCellSpec(availableHeightSpace, spec, workspaceCellSpec)
+ }
+
+ companion object {
+ @JvmStatic
+ fun create(resourceHelper: ResourceHelper): ResponsiveCellSpecsProvider {
+ val parser = ResponsiveSpecsParser(resourceHelper)
+ val specs = parser.parseXML(ResponsiveSpecType.Cell, ::CellSpec)
+ return ResponsiveCellSpecsProvider(specs)
+ }
+ }
+}
+
+data class CellSpec(
+ override val maxAvailableSize: Int,
+ override val dimensionType: DimensionType,
+ override val specType: ResponsiveSpecType,
+ val iconSize: SizeSpec,
+ val iconTextSize: SizeSpec,
+ val iconDrawablePadding: SizeSpec
+) : IResponsiveSpec {
+ init {
+ check(isValid()) { "Invalid CellSpec found." }
+ }
+
+ constructor(
+ responsiveSpecType: ResponsiveSpecType,
+ attrs: TypedArray,
+ specs: Map<String, SizeSpec>
+ ) : this(
+ maxAvailableSize =
+ attrs.getDimensionPixelSize(R.styleable.ResponsiveSpec_maxAvailableSize, 0),
+ dimensionType =
+ DimensionType.entries[
+ attrs.getInt(
+ R.styleable.ResponsiveSpec_dimensionType,
+ DimensionType.HEIGHT.ordinal
+ )],
+ specType = responsiveSpecType,
+ iconSize = specs.getOrError(SizeSpec.XmlTags.ICON_SIZE),
+ iconTextSize = specs.getOrError(SizeSpec.XmlTags.ICON_TEXT_SIZE),
+ iconDrawablePadding = specs.getOrError(SizeSpec.XmlTags.ICON_DRAWABLE_PADDING)
+ )
+
+ fun isValid(): Boolean {
+ if (maxAvailableSize <= 0) {
+ Log.e(LOG_TAG, "${this::class.simpleName}#isValid - maxAvailableSize <= 0")
+ return false
+ }
+
+ // All specs need to be individually valid
+ if (!allSpecsAreValid()) {
+ Log.e(LOG_TAG, "${this::class.simpleName}#isValid - !allSpecsAreValid()")
+ return false
+ }
+
+ return true
+ }
+
+ private fun allSpecsAreValid(): Boolean {
+ return (iconSize.fixedSize > 0f || iconSize.matchWorkspace) &&
+ (iconTextSize.fixedSize >= 0f || iconTextSize.matchWorkspace) &&
+ (iconDrawablePadding.fixedSize >= 0f || iconDrawablePadding.matchWorkspace)
+ }
+
+ companion object {
+ private const val LOG_TAG = "CellSpec"
+ }
+}
+
+data class CalculatedCellSpec(
+ val availableSpace: Int,
+ val spec: CellSpec,
+ val iconSize: Int,
+ val iconTextSize: Int,
+ val iconDrawablePadding: Int
+) {
+ constructor(
+ availableSpace: Int,
+ spec: CellSpec
+ ) : this(
+ availableSpace = availableSpace,
+ spec = spec,
+ iconSize = spec.iconSize.getCalculatedValue(availableSpace),
+ iconTextSize = spec.iconTextSize.getCalculatedValue(availableSpace),
+ iconDrawablePadding = spec.iconDrawablePadding.getCalculatedValue(availableSpace)
+ )
+
+ constructor(
+ availableSpace: Int,
+ spec: CellSpec,
+ workspaceCellSpec: CalculatedCellSpec
+ ) : this(
+ availableSpace = availableSpace,
+ spec = spec,
+ iconSize = getCalculatedValue(availableSpace, spec.iconSize, workspaceCellSpec.iconSize),
+ iconTextSize =
+ getCalculatedValue(availableSpace, spec.iconTextSize, workspaceCellSpec.iconTextSize),
+ iconDrawablePadding =
+ getCalculatedValue(
+ availableSpace,
+ spec.iconDrawablePadding,
+ workspaceCellSpec.iconDrawablePadding
+ )
+ )
+
+ companion object {
+ private fun getCalculatedValue(
+ availableSpace: Int,
+ spec: SizeSpec,
+ workspaceValue: Int
+ ): Int =
+ if (spec.matchWorkspace) workspaceValue else spec.getCalculatedValue(availableSpace)
+ }
+
+ override fun toString(): String {
+ return "${this::class.simpleName}(" +
+ "availableSpace=$availableSpace, iconSize=$iconSize, " +
+ "iconTextSize=$iconTextSize, iconDrawablePadding=$iconDrawablePadding, " +
+ "${spec::class.simpleName}.maxAvailableSize=${spec.maxAvailableSize}" +
+ ")"
+ }
+}
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpec.kt b/src/com/android/launcher3/responsive/ResponsiveSpec.kt
index 413e2dc..32dedfb 100644
--- a/src/com/android/launcher3/responsive/ResponsiveSpec.kt
+++ b/src/com/android/launcher3/responsive/ResponsiveSpec.kt
@@ -127,7 +127,8 @@
AllApps("allAppsSpec"),
Folder("folderSpec"),
Workspace("workspaceSpec"),
- Hotseat("hotseatSpec")
+ Hotseat("hotseatSpec"),
+ Cell("cellSpec")
}
}
}
@@ -205,9 +206,6 @@
fun isResponsiveSpecType(type: ResponsiveSpecType) = spec.specType == type
- // TODO(b/287975993): Remove this after icon size is extracted to responsive grid
- fun isCellSizeMatchWorkspace(): Boolean = spec.cellSize.matchWorkspace
-
private fun updateRemainderSpaces(availableSpace: Int, cells: Int, spec: ResponsiveSpec) {
val gutters = cells - 1
val usedSpace = startPaddingPx + endPaddingPx + (gutterPx * gutters) + (cellSizePx * cells)
diff --git a/src/com/android/launcher3/responsive/SizeSpec.kt b/src/com/android/launcher3/responsive/SizeSpec.kt
index 2db843b..d146898 100644
--- a/src/com/android/launcher3/responsive/SizeSpec.kt
+++ b/src/com/android/launcher3/responsive/SizeSpec.kt
@@ -122,6 +122,9 @@
const val CELL_SIZE = "cellSize"
const val HOTSEAT_QSB_SPACE = "hotseatQsbSpace"
const val EDGE_PADDING = "edgePadding"
+ const val ICON_SIZE = "iconSize"
+ const val ICON_TEXT_SIZE = "iconTextSize"
+ const val ICON_DRAWABLE_PADDING = "iconDrawablePadding"
}
companion object {
diff --git a/src/com/android/launcher3/statemanager/StateManager.java b/src/com/android/launcher3/statemanager/StateManager.java
index 9ac8f6b..360ff7e 100644
--- a/src/com/android/launcher3/statemanager/StateManager.java
+++ b/src/com/android/launcher3/statemanager/StateManager.java
@@ -27,6 +27,7 @@
import android.animation.AnimatorSet;
import android.os.Handler;
import android.os.Looper;
+import android.util.Log;
import androidx.annotation.FloatRange;
@@ -35,6 +36,7 @@
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.states.StateAnimationConfig.AnimationFlags;
+import com.android.launcher3.testing.shared.TestProtocol;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -225,6 +227,7 @@
private void goToState(
STATE_TYPE state, boolean animated, long delay, AnimatorListener listener) {
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "go to state " + state);
animated &= areAnimatorsEnabled();
if (mActivity.isInState(state)) {
@@ -380,6 +383,8 @@
mState = state;
mActivity.onStateSetStart(mState);
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "Notifying listeners for state transition start"
+ + " to state: " + state.toString());
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onStateTransitionStart(state);
}
@@ -397,6 +402,8 @@
setRestState(null);
}
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "Notifying " + mListeners.size() + " listeners "
+ + "for end transition for state: " + state.toString());
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onStateTransitionComplete(state);
}
@@ -434,6 +441,7 @@
* Cancels the current animation.
*/
public void cancelAnimation() {
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "current animation cancelled");
mConfig.reset();
// It could happen that a new animation is set as a result of an endListener on the
// existing animation.
@@ -457,6 +465,7 @@
* @param toState The state we are animating towards.
*/
public void setCurrentAnimation(AnimatorSet anim, STATE_TYPE toState) {
+ Log.d(TestProtocol.OVERVIEW_OVER_HOME, "setting animation to " + toState.toString());
cancelAnimation();
setCurrentAnimation(anim);
anim.addListener(createStateAnimationListener(toState));
diff --git a/src/com/android/launcher3/touch/ItemLongClickListener.java b/src/com/android/launcher3/touch/ItemLongClickListener.java
index 0c322cc..9e7d4dc 100644
--- a/src/com/android/launcher3/touch/ItemLongClickListener.java
+++ b/src/com/android/launcher3/touch/ItemLongClickListener.java
@@ -24,12 +24,15 @@
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_ITEM_LONG_PRESSED;
+import android.graphics.Point;
+import android.graphics.Rect;
import android.view.View;
import android.view.View.OnLongClickListener;
-import com.android.launcher3.CellLayout;
+import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
import com.android.launcher3.Launcher;
+import com.android.launcher3.celllayout.CellInfo;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
@@ -40,6 +43,10 @@
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.views.BubbleTextHolder;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
+import com.android.launcher3.widget.NavigableAppWidgetHostView;
+import com.android.launcher3.widget.PendingItemDragHelper;
+import com.android.launcher3.widget.WidgetCell;
+import com.android.launcher3.widget.WidgetImageView;
/**
* Class to handle long-clicks on workspace items and start drag as a result.
@@ -86,12 +93,51 @@
}
}
- CellLayout.CellInfo longClickCellInfo = new CellLayout.CellInfo(v, info,
+ CellInfo longClickCellInfo = new CellInfo(v, info,
launcher.getCellPosMapper().mapModelToPresenter(info));
launcher.getWorkspace().startDrag(longClickCellInfo, dragOptions);
}
+ private static boolean onWidgetItemLongClick(WidgetCell v) {
+ // Get the widget preview as the drag representation
+ WidgetImageView image = v.getWidgetView();
+ Launcher launcher = Launcher.getLauncher(v.getContext());
+ DragSource dragSource = (target, dragObject, success) -> { };
+
+ // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
+ // we abort the drag.
+ if (image.getDrawable() == null && v.getAppWidgetHostViewPreview() == null) {
+ return false;
+ }
+
+ PendingItemDragHelper dragHelper = new PendingItemDragHelper(v);
+ // RemoteViews are being rendered in AppWidgetHostView in WidgetCell. And thus, the scale of
+ // RemoteViews is equivalent to the AppWidgetHostView scale.
+ dragHelper.setRemoteViewsPreview(v.getRemoteViewsPreview(), v.getAppWidgetHostViewScale());
+ dragHelper.setAppWidgetHostViewPreview(v.getAppWidgetHostViewPreview());
+
+ if (image.getDrawable() != null) {
+ int[] loc = new int[2];
+ launcher.getDragLayer().getLocationInDragLayer(image, loc);
+
+ dragHelper.startDrag(image.getBitmapBounds(), image.getDrawable().getIntrinsicWidth(),
+ image.getWidth(), new Point(loc[0], loc[1]), dragSource, new DragOptions());
+ } else {
+ NavigableAppWidgetHostView preview = v.getAppWidgetHostViewPreview();
+ int[] loc = new int[2];
+ launcher.getDragLayer().getLocationInDragLayer(preview, loc);
+ Rect r = new Rect();
+ preview.getWorkspaceVisualDragBounds(r);
+ dragHelper.startDrag(r, preview.getMeasuredWidth(), preview.getMeasuredWidth(),
+ new Point(loc[0], loc[1]), dragSource, new DragOptions());
+ }
+ return true;
+ }
+
private static boolean onAllAppsItemLongClick(View view) {
+ if (view instanceof WidgetCell wc) {
+ return onWidgetItemLongClick(wc);
+ }
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onAllAppsItemLongClick");
view.cancelLongPress();
View v = (view instanceof BubbleTextHolder)
diff --git a/src/com/android/launcher3/util/KeyboardShortcutsDelegate.java b/src/com/android/launcher3/util/KeyboardShortcutsDelegate.java
index 3ec339d..c9db83d 100644
--- a/src/com/android/launcher3/util/KeyboardShortcutsDelegate.java
+++ b/src/com/android/launcher3/util/KeyboardShortcutsDelegate.java
@@ -25,6 +25,7 @@
import android.view.KeyboardShortcutInfo;
import android.view.Menu;
+import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -108,14 +109,26 @@
* @see android.view.KeyEvent
*/
public Boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
- // Close any open floating views.
- mLauncher.closeOpenViews();
- return true;
+ // Ignore escape if pressed in conjunction with any modifier keys.
+ if (keyCode == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) {
+ AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(mLauncher);
+ if (topView != null) {
+ // Close each floating view one at a time for each key press.
+ topView.close(/* animate= */ true);
+ return true;
+ } else if (mLauncher.getAppsView().isInAllApps()) {
+ // Close all apps if there are no open floating views.
+ closeAllApps();
+ return true;
+ }
}
return null;
}
+ private void closeAllApps() {
+ mLauncher.getStateManager().goToState(NORMAL, true);
+ }
+
/**
* Handle key up event.
* @param keyCode code of the key being pressed.
diff --git a/src/com/android/launcher3/util/Preconditions.java b/src/com/android/launcher3/util/Preconditions.java
index 63d56e4..0e5ab9a 100644
--- a/src/com/android/launcher3/util/Preconditions.java
+++ b/src/com/android/launcher3/util/Preconditions.java
@@ -51,6 +51,12 @@
}
}
+ public static void assertTrue(boolean condition) {
+ if (FeatureFlags.IS_STUDIO_BUILD && !condition) {
+ throw new IllegalStateException();
+ }
+ }
+
private static boolean isSameLooper(Looper looper) {
return Looper.myLooper() == looper;
}
diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java
index 20bcc3c..bef84f7 100644
--- a/src/com/android/launcher3/views/ActivityContext.java
+++ b/src/com/android/launcher3/views/ActivityContext.java
@@ -53,6 +53,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.core.view.WindowInsetsCompat;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
@@ -315,6 +316,25 @@
}
/**
+ * Returns if the software keyboard is hidden. Hardware keyboards do not display on screen by
+ * default.
+ */
+ default boolean isSoftwareKeyboardHidden() {
+ if (isHardwareKeyboard()) {
+ return true;
+ } else {
+ View dragLayer = getDragLayer();
+ WindowInsets insets = dragLayer.getRootWindowInsets();
+ if (insets == null) {
+ return false;
+ }
+ WindowInsetsCompat insetsCompat =
+ WindowInsetsCompat.toWindowInsetsCompat(insets, dragLayer);
+ return !insetsCompat.isVisible(WindowInsetsCompat.Type.ime());
+ }
+ }
+
+ /**
* Sends a pending intent animating from a view.
*
* @param v View to animate.
diff --git a/src/com/android/launcher3/views/WidgetsEduView.java b/src/com/android/launcher3/views/WidgetsEduView.java
index e70b1cb..40c6115 100644
--- a/src/com/android/launcher3/views/WidgetsEduView.java
+++ b/src/com/android/launcher3/views/WidgetsEduView.java
@@ -20,15 +20,15 @@
import android.util.AttributeSet;
import android.view.LayoutInflater;
+import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
-import com.android.launcher3.Launcher;
import com.android.launcher3.R;
/**
* Education view about widgets.
*/
-public class WidgetsEduView extends AbstractSlideInView<Launcher> implements Insettable {
+public class WidgetsEduView extends AbstractSlideInView<BaseActivity> implements Insettable {
private static final int DEFAULT_CLOSE_DURATION = 200;
@@ -124,10 +124,10 @@
}
/** Shows widget education dialog. */
- public static WidgetsEduView showEducationDialog(Launcher launcher) {
- LayoutInflater layoutInflater = LayoutInflater.from(launcher);
+ public static WidgetsEduView showEducationDialog(BaseActivity activity) {
+ LayoutInflater layoutInflater = LayoutInflater.from(activity);
WidgetsEduView v = (WidgetsEduView) layoutInflater.inflate(
- R.layout.widgets_edu, launcher.getDragLayer(), false);
+ R.layout.widgets_edu, activity.getDragLayer(), false);
v.show();
return v;
}
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index fc9c774..26e191d 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
-import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
@@ -35,32 +34,28 @@
import androidx.annotation.Px;
import androidx.core.view.ViewCompat;
+import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
-import com.android.launcher3.DragSource;
-import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
-import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
-import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.window.WindowManagerProxy;
import com.android.launcher3.views.AbstractSlideInView;
-import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ArrowTipView;
/**
* Base class for various widgets popup
*/
-public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
- implements OnClickListener, OnLongClickListener, DragSource,
+public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
+ implements OnClickListener, OnLongClickListener,
PopupDataProvider.PopupDataChangeListener, Insettable, OnDeviceProfileChangeListener {
/** The default number of cells that can fit horizontally in a widget sheet. */
public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
@@ -129,21 +124,25 @@
} else {
mWidgetInstructionToast = showWidgetToast(getContext(), mWidgetInstructionToast);
}
-
}
@Override
public boolean onLongClick(View v) {
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick");
v.cancelLongPress();
- if (!ItemLongClickListener.canStartDrag(mActivityContext)) return false;
+ boolean result = false;
if (v instanceof WidgetCell) {
- return beginDraggingWidget((WidgetCell) v);
- } else if (v.getParent() instanceof WidgetCell) {
- return beginDraggingWidget((WidgetCell) v.getParent());
+ result = mActivityContext.getAllAppsItemLongClickListener().onLongClick(v);
+ } else if (v.getParent() instanceof WidgetCell wc) {
+ result = mActivityContext.getAllAppsItemLongClickListener().onLongClick(wc);
+ } else {
+ return true;
}
- return true;
+ if (result) {
+ close(true);
+ }
+ return result;
}
@Override
@@ -212,55 +211,12 @@
MeasureSpec.getSize(heightMeasureSpec));
}
- private boolean beginDraggingWidget(WidgetCell v) {
- // Get the widget preview as the drag representation
- WidgetImageView image = v.getWidgetView();
-
- // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
- // we abort the drag.
- if (image.getDrawable() == null && v.getAppWidgetHostViewPreview() == null) {
- return false;
- }
-
- PendingItemDragHelper dragHelper = new PendingItemDragHelper(v);
- // RemoteViews are being rendered in AppWidgetHostView in WidgetCell. And thus, the scale of
- // RemoteViews is equivalent to the AppWidgetHostView scale.
- dragHelper.setRemoteViewsPreview(v.getRemoteViewsPreview(), v.getAppWidgetHostViewScale());
- dragHelper.setAppWidgetHostViewPreview(v.getAppWidgetHostViewPreview());
-
- if (image.getDrawable() != null) {
- int[] loc = new int[2];
- getPopupContainer().getLocationInDragLayer(image, loc);
-
- dragHelper.startDrag(image.getBitmapBounds(), image.getDrawable().getIntrinsicWidth(),
- image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions());
- } else {
- NavigableAppWidgetHostView preview = v.getAppWidgetHostViewPreview();
- int[] loc = new int[2];
- getPopupContainer().getLocationInDragLayer(preview, loc);
- Rect r = new Rect();
- preview.getWorkspaceVisualDragBounds(r);
- dragHelper.startDrag(r, preview.getMeasuredWidth(), preview.getMeasuredWidth(),
- new Point(loc[0], loc[1]), this, new DragOptions());
- }
- close(true);
- return true;
- }
-
@Override
protected Interpolator getIdleInterpolator() {
return mActivityContext.getDeviceProfile().isTablet
? EMPHASIZED : super.getIdleInterpolator();
}
- //
- // Drag related handling methods that implement {@link DragSource} interface.
- //
-
- @Override
- public void onDropCompleted(View target, DragObject d, boolean success) { }
-
-
protected void onCloseComplete() {
super.onCloseComplete();
clearNavBarColor();
@@ -344,7 +300,8 @@
@Override
protected void setTranslationShift(float translationShift) {
super.setTranslationShift(translationShift);
- Launcher launcher = ActivityContext.lookupContext(getContext());
- launcher.onWidgetsTransition(1 - translationShift);
+ if (mActivityContext instanceof Launcher ls) {
+ ls.onWidgetsTransition(1 - translationShift);
+ }
}
}
diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
index af77d03..953ecda 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
@@ -55,8 +55,9 @@
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;
+import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
@@ -72,7 +73,6 @@
import com.android.launcher3.views.StickyHeaderLayout;
import com.android.launcher3.views.WidgetsEduView;
import com.android.launcher3.widget.BaseWidgetSheet;
-import com.android.launcher3.widget.LauncherWidgetHolder.ProviderChangedListener;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.picker.search.SearchModeListener;
import com.android.launcher3.widget.picker.search.WidgetsSearchBar;
@@ -89,7 +89,7 @@
* Popup for showing the full list of available widgets
*/
public class WidgetsFullSheet extends BaseWidgetSheet
- implements ProviderChangedListener, OnActivePageChangedListener,
+ implements OnActivePageChangedListener,
WidgetsRecyclerView.HeaderViewDimensionsProvider, SearchModeListener {
private static final long FADE_IN_DURATION = 150;
@@ -166,7 +166,7 @@
private boolean mIsInSearchMode;
private boolean mIsNoWidgetsViewNeeded;
@Px private int mMaxSpanPerRow;
- private DeviceProfile mDeviceProfile;
+ private final DeviceProfile mDeviceProfile;
private int mOrientation;
@@ -181,7 +181,7 @@
public WidgetsFullSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- mDeviceProfile = Launcher.getLauncher(context).getDeviceProfile();
+ mDeviceProfile = mActivityContext.getDeviceProfile();
mHasWorkProfile = context.getSystemService(LauncherApps.class).getProfiles().size() > 1;
mOrientation = context.getResources().getConfiguration().orientation;
mAdapters.put(AdapterHolder.PRIMARY, new AdapterHolder(AdapterHolder.PRIMARY));
@@ -353,15 +353,14 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- mActivityContext.getAppWidgetHolder().addProviderChangeListener(this);
- notifyWidgetProvidersChanged();
+ LauncherAppState.getInstance(mActivityContext).getModel()
+ .refreshAndBindWidgetsAndShortcuts(null);
onRecommendedWidgetsBound();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- mActivityContext.getAppWidgetHolder().removeProviderChangeListener(this);
mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView
.removeOnAttachStateChangeListener(mBindScrollbarInSearchMode);
if (mHasWorkProfile) {
@@ -482,11 +481,6 @@
}
@Override
- public void notifyWidgetProvidersChanged() {
- mActivityContext.refreshAndBindWidgetsForPackageUser(null);
- }
-
- @Override
public void onWidgetsBound() {
if (mIsInSearchMode) {
return;
@@ -682,22 +676,22 @@
}
/** Shows the {@link WidgetsFullSheet} on the launcher. */
- public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
- boolean isTwoPane = launcher.getDeviceProfile().isTablet
- && launcher.getDeviceProfile().isLandscape
- && (!launcher.getDeviceProfile().isTwoPanels
+ public static WidgetsFullSheet show(BaseActivity activity, boolean animate) {
+ boolean isTwoPane = activity.getDeviceProfile().isTablet
+ && activity.getDeviceProfile().isLandscape
+ && (!activity.getDeviceProfile().isTwoPanels
|| FeatureFlags.UNFOLDED_WIDGET_PICKER.get());
WidgetsFullSheet sheet;
if (isTwoPane) {
- sheet = (WidgetsTwoPaneSheet) launcher.getLayoutInflater().inflate(
+ sheet = (WidgetsTwoPaneSheet) activity.getLayoutInflater().inflate(
R.layout.widgets_two_pane_sheet,
- launcher.getDragLayer(),
+ activity.getDragLayer(),
false);
} else {
- sheet = (WidgetsFullSheet) launcher.getLayoutInflater().inflate(
+ sheet = (WidgetsFullSheet) activity.getLayoutInflater().inflate(
R.layout.widgets_full_sheet,
- launcher.getDragLayer(),
+ activity.getDragLayer(),
false);
}
@@ -754,7 +748,7 @@
/** Gets the {@link WidgetsRecyclerView} which shows all widgets in {@link WidgetsFullSheet}. */
@VisibleForTesting
- public static WidgetsRecyclerView getWidgetsView(Launcher launcher) {
+ public static WidgetsRecyclerView getWidgetsView(BaseActivity launcher) {
return launcher.findViewById(R.id.primary_widgets_list_view);
}
@@ -803,7 +797,7 @@
mOrientation = newConfig.orientation;
if (mDeviceProfile.isTablet && !mDeviceProfile.isTwoPanels) {
handleClose(false);
- show(Launcher.getLauncher(getContext()), false);
+ show(BaseActivity.fromContext(getContext()), false);
} else {
reset();
}
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt
index 6c3fa5e..8473b68 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait.txt
@@ -37,8 +37,8 @@
iconSizePx: 147.0px (56.0dp)
iconTextSizePx: 38.0px (14.476191dp)
iconDrawablePaddingPx: 12.0px (4.571429dp)
- inv.numFolderRows: 4
- inv.numFolderColumns: 4
+ numFolderRows: 4
+ numFolderColumns: 4
folderCellWidthPx: 195.0px (74.28571dp)
folderCellHeightPx: 230.0px (87.61905dp)
folderChildIconSizePx: 147.0px (56.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt
index cd06ed9..c23fcc0 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phonePortrait3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 147.0px (56.0dp)
iconTextSizePx: 38.0px (14.476191dp)
iconDrawablePaddingPx: 12.0px (4.571429dp)
- inv.numFolderRows: 4
- inv.numFolderColumns: 4
+ numFolderRows: 4
+ numFolderColumns: 4
folderCellWidthPx: 195.0px (74.28571dp)
folderCellHeightPx: 230.0px (87.61905dp)
folderChildIconSizePx: 147.0px (56.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
index cd19907..5cd7dc8 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar.txt
@@ -37,8 +37,8 @@
iconSizePx: 147.0px (56.0dp)
iconTextSizePx: 0.0px (0.0dp)
iconDrawablePaddingPx: 0.0px (0.0dp)
- inv.numFolderRows: 4
- inv.numFolderColumns: 4
+ numFolderRows: 4
+ numFolderColumns: 4
folderCellWidthPx: 163.0px (62.095238dp)
folderCellHeightPx: 192.0px (73.14286dp)
folderChildIconSizePx: 123.0px (46.857143dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
index 8850583..f8afa37 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/phoneVerticalBar3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 147.0px (56.0dp)
iconTextSizePx: 0.0px (0.0dp)
iconDrawablePaddingPx: 0.0px (0.0dp)
- inv.numFolderRows: 4
- inv.numFolderColumns: 4
+ numFolderRows: 4
+ numFolderColumns: 4
folderCellWidthPx: 173.0px (65.90476dp)
folderCellHeightPx: 205.0px (78.09524dp)
folderChildIconSizePx: 131.0px (49.904762dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt
index 26b86dc..32e1f1b 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt
@@ -37,8 +37,8 @@
iconSizePx: 120.0px (60.0dp)
iconTextSizePx: 28.0px (14.0dp)
iconDrawablePaddingPx: 9.0px (4.5dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 3
+ numFolderRows: 3
+ numFolderColumns: 3
folderCellWidthPx: 240.0px (120.0dp)
folderCellHeightPx: 208.0px (104.0dp)
folderChildIconSizePx: 120.0px (60.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt
index 5778306..7c52c90 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 120.0px (60.0dp)
iconTextSizePx: 28.0px (14.0dp)
iconDrawablePaddingPx: 9.0px (4.5dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 3
+ numFolderRows: 3
+ numFolderColumns: 3
folderCellWidthPx: 240.0px (120.0dp)
folderCellHeightPx: 208.0px (104.0dp)
folderChildIconSizePx: 120.0px (60.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt
index 9e943ae..b284ce0 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt
@@ -37,8 +37,8 @@
iconSizePx: 120.0px (60.0dp)
iconTextSizePx: 28.0px (14.0dp)
iconDrawablePaddingPx: 9.0px (4.5dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 3
+ numFolderRows: 3
+ numFolderColumns: 3
folderCellWidthPx: 204.0px (102.0dp)
folderCellHeightPx: 240.0px (120.0dp)
folderChildIconSizePx: 120.0px (60.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt
index f159b85..7001967 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 120.0px (60.0dp)
iconTextSizePx: 28.0px (14.0dp)
iconDrawablePaddingPx: 9.0px (4.5dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 3
+ numFolderRows: 3
+ numFolderColumns: 3
folderCellWidthPx: 204.0px (102.0dp)
folderCellHeightPx: 240.0px (120.0dp)
folderChildIconSizePx: 120.0px (60.0dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt
index 55e9880..ba83533 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape.txt
@@ -37,8 +37,8 @@
iconSizePx: 141.0px (53.714287dp)
iconTextSizePx: 34.0px (12.952381dp)
iconDrawablePaddingPx: 13.0px (4.952381dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 4
+ numFolderRows: 3
+ numFolderColumns: 4
folderCellWidthPx: 189.0px (72.0dp)
folderCellHeightPx: 219.0px (83.42857dp)
folderChildIconSizePx: 141.0px (53.714287dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt
index a2f0aa2..1b1240b 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelLandscape3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 141.0px (53.714287dp)
iconTextSizePx: 34.0px (12.952381dp)
iconDrawablePaddingPx: 13.0px (4.952381dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 4
+ numFolderRows: 3
+ numFolderColumns: 4
folderCellWidthPx: 189.0px (72.0dp)
folderCellHeightPx: 219.0px (83.42857dp)
folderChildIconSizePx: 141.0px (53.714287dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt
index ca42cda..11e7077 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait.txt
@@ -37,8 +37,8 @@
iconSizePx: 141.0px (53.714287dp)
iconTextSizePx: 34.0px (12.952381dp)
iconDrawablePaddingPx: 13.0px (4.952381dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 4
+ numFolderRows: 3
+ numFolderColumns: 4
folderCellWidthPx: 189.0px (72.0dp)
folderCellHeightPx: 219.0px (83.42857dp)
folderChildIconSizePx: 141.0px (53.714287dp)
diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt
index d53badc..1a8b3ac 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/twoPanelPortrait3Button.txt
@@ -37,8 +37,8 @@
iconSizePx: 141.0px (53.714287dp)
iconTextSizePx: 34.0px (12.952381dp)
iconDrawablePaddingPx: 13.0px (4.952381dp)
- inv.numFolderRows: 3
- inv.numFolderColumns: 4
+ numFolderRows: 3
+ numFolderColumns: 4
folderCellWidthPx: 189.0px (72.0dp)
folderCellHeightPx: 219.0px (83.42857dp)
folderChildIconSizePx: 141.0px (53.714287dp)
diff --git a/tests/res/xml/invalid_cell_specs_1.xml b/tests/res/xml/invalid_cell_specs_1.xml
new file mode 100644
index 0000000..1e54771
--- /dev/null
+++ b/tests/res/xml/invalid_cell_specs_1.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright (C) 2023 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.
+ -->
+<!-- invalid: only fixedSize attribute is allowed -->
+<cellSpecs xmlns:launcher="http://schemas.android.com/apk/res-auto">
+ <!-- portrait -->
+ <specs launcher:maxAspectRatio="1.0">
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:ofAvailableSpace="0.0125" />
+ <iconSize launcher:fixedSize="48dp" />
+ <iconTextSize launcher:fixedSize="12sp" />
+ </cellSpec>
+ </specs>
+ <!-- landscape -->
+ <specs launcher:maxAspectRatio="10">
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="0dp" />
+ <iconSize launcher:ofAvailableSpace="0.0125" />
+ <iconTextSize launcher:fixedSize="0sp" />
+ </cellSpec>
+ </specs>
+</cellSpecs>
\ No newline at end of file
diff --git a/tests/res/xml/invalid_cell_specs_2.xml b/tests/res/xml/invalid_cell_specs_2.xml
new file mode 100644
index 0000000..6edfda0
--- /dev/null
+++ b/tests/res/xml/invalid_cell_specs_2.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright (C) 2023 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.
+ -->
+<!-- invalid: dimension type should be height -->
+<cellSpecs xmlns:launcher="http://schemas.android.com/apk/res-auto">
+ <!-- portrait -->
+ <specs launcher:maxAspectRatio="1.0">
+ <cellSpec
+ launcher:dimensionType="width"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="8dp" />
+ <iconSize launcher:fixedSize="48dp" />
+ <iconTextSize launcher:fixedSize="12sp" />
+ </cellSpec>
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="8dp" />
+ <iconSize launcher:fixedSize="48dp" />
+ <iconTextSize launcher:fixedSize="12sp" />
+ </cellSpec>
+ </specs>
+ <!-- landscape -->
+ <specs launcher:maxAspectRatio="10">
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="0dp" />
+ <iconSize launcher:fixedSize="52dp" />
+ <iconTextSize launcher:fixedSize="0sp" />
+ </cellSpec>
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="0dp" />
+ <iconSize launcher:fixedSize="52dp" />
+ <iconTextSize launcher:fixedSize="0sp" />
+ </cellSpec>
+ <cellSpec
+ launcher:dimensionType="width"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="0dp" />
+ <iconSize launcher:fixedSize="52dp" />
+ <iconTextSize launcher:fixedSize="0sp" />
+ </cellSpec>
+ </specs>
+</cellSpecs>
\ No newline at end of file
diff --git a/tests/res/xml/valid_cell_specs_file.xml b/tests/res/xml/valid_cell_specs_file.xml
new file mode 100644
index 0000000..7a5f03f
--- /dev/null
+++ b/tests/res/xml/valid_cell_specs_file.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright (C) 2023 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.
+ -->
+<cellSpecs xmlns:launcher="http://schemas.android.com/apk/res-auto">
+ <!-- portrait -->
+ <specs launcher:maxAspectRatio="1.0">
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="606dp">
+ <iconDrawablePadding launcher:fixedSize="8dp" />
+ <iconSize launcher:fixedSize="48dp" />
+ <iconTextSize launcher:fixedSize="12sp" />
+ </cellSpec>
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="11dp" />
+ <iconSize launcher:fixedSize="52dp" />
+ <iconTextSize launcher:fixedSize="12sp" />
+ </cellSpec>
+ </specs>
+ <!-- landscape -->
+ <specs launcher:maxAspectRatio="10">
+ <cellSpec
+ launcher:dimensionType="height"
+ launcher:maxAvailableSize="9999dp">
+ <iconDrawablePadding launcher:fixedSize="0dp" />
+ <iconSize launcher:fixedSize="52dp" />
+ <iconTextSize launcher:fixedSize="0sp" />
+ </cellSpec>
+ </specs>
+</cellSpecs>
\ No newline at end of file
diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
index 11f453a..4f79adc 100644
--- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
+++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
@@ -160,6 +160,7 @@
public static final String TWO_TASKBAR_LONG_CLICKS = "b/262282528";
public static final String ICON_MISSING = "b/282963545";
public static final String WORKSPACE_LONG_PRESS = "b/311099513";
+ public static final String OVERVIEW_OVER_HOME = "b/279059025";
public static final String REQUEST_EMULATE_DISPLAY = "emulate-display";
public static final String REQUEST_STOP_EMULATE_DISPLAY = "stop-emulate-display";
diff --git a/tests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt b/tests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt
index a421006..30b5663 100644
--- a/tests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt
+++ b/tests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt
@@ -121,8 +121,8 @@
listOf(PointF(16f, 16f), PointF(16f, 16f), PointF(16f, 16f), PointF(16f, 16f))
.toTypedArray()
- numFolderRows = 3
- numFolderColumns = 3
+ numFolderRows = intArrayOf(3, 3, 3, 3)
+ numFolderColumns = intArrayOf(3, 3, 3, 3)
folderStyle = R.style.FolderStyleDefault
inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_split
@@ -204,8 +204,8 @@
listOf(PointF(16f, 64f), PointF(64f, 16f), PointF(16f, 64f), PointF(16f, 64f))
.toTypedArray()
- numFolderRows = 3
- numFolderColumns = 3
+ numFolderRows = intArrayOf(3, 3, 3, 3)
+ numFolderColumns = intArrayOf(3, 3, 3, 3)
folderStyle = R.style.FolderStyleDefault
inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_6_5
@@ -288,8 +288,8 @@
listOf(PointF(16f, 16f), PointF(16f, 16f), PointF(16f, 20f), PointF(20f, 20f))
.toTypedArray()
- numFolderRows = 3
- numFolderColumns = 3
+ numFolderRows = intArrayOf(3, 3, 3, 3)
+ numFolderColumns = intArrayOf(3, 3, 3, 3)
folderStyle = R.style.FolderStyleDefault
inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_split
diff --git a/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java b/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java
index d71bf84..ee32e97 100644
--- a/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java
+++ b/tests/src/com/android/launcher3/allapps/TaplKeyboardFocusTest.java
@@ -15,7 +15,7 @@
*/
package com.android.launcher3.allapps;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT;
@@ -23,8 +23,6 @@
import static org.junit.Assert.assertTrue;
import android.view.KeyEvent;
-import android.view.View;
-import android.view.WindowInsets;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -33,6 +31,7 @@
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.rule.TestStabilityRule;
+import com.android.launcher3.views.ActivityContext;
import org.junit.Before;
import org.junit.Test;
@@ -102,11 +101,8 @@
executeOnLauncher(launcher -> launcher.getAppsView().getSearchUiManager().getEditText()
.hideKeyboard(/* clearFocus= */ false));
- waitForLauncherCondition("Keyboard still visible.", launcher -> {
- View root = launcher.getDragLayer();
- WindowInsets insets = root.getRootWindowInsets();
- return insets != null && !insets.isVisible(WindowInsets.Type.ime());
- });
+ waitForLauncherCondition("Keyboard still visible.",
+ ActivityContext::isSoftwareKeyboardHidden);
mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
mLauncher.unpressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
diff --git a/tests/src/com/android/launcher3/allapps/TaplOpenCloseAllApps.java b/tests/src/com/android/launcher3/allapps/TaplOpenCloseAllApps.java
index 39dbcb2..c7942c7 100644
--- a/tests/src/com/android/launcher3/allapps/TaplOpenCloseAllApps.java
+++ b/tests/src/com/android/launcher3/allapps/TaplOpenCloseAllApps.java
@@ -16,7 +16,7 @@
package com.android.launcher3.allapps;
import static com.android.launcher3.ui.TaplTestsLauncher3.expectFail;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -217,4 +217,10 @@
mLauncher.getWorkspace();
waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
}
+
+ @Test
+ public void testDismissAllAppsWithEscKey() {
+ mLauncher.goHome().switchToAllApps().dismissByEscKey();
+ waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
+ }
}
diff --git a/tests/src/com/android/launcher3/allapps/TaplTestsAllAppsIconsWorking.java b/tests/src/com/android/launcher3/allapps/TaplTestsAllAppsIconsWorking.java
index fd4619e..9f6bbdf 100644
--- a/tests/src/com/android/launcher3/allapps/TaplTestsAllAppsIconsWorking.java
+++ b/tests/src/com/android/launcher3/allapps/TaplTestsAllAppsIconsWorking.java
@@ -15,7 +15,7 @@
*/
package com.android.launcher3.allapps;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
diff --git a/tests/src/com/android/launcher3/appiconmenu/TaplAppIconMenuTest.java b/tests/src/com/android/launcher3/appiconmenu/TaplAppIconMenuTest.java
index 0f5d85b..a1f2cef 100644
--- a/tests/src/com/android/launcher3/appiconmenu/TaplAppIconMenuTest.java
+++ b/tests/src/com/android/launcher3/appiconmenu/TaplAppIconMenuTest.java
@@ -16,7 +16,7 @@
package com.android.launcher3.appiconmenu;
import static com.android.launcher3.util.TestConstants.AppNames.TEST_APP_NAME;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java b/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java
index 1fe02b2..d8ae74b 100644
--- a/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java
+++ b/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java
@@ -61,9 +61,7 @@
}
public static CellLayoutBoard viewsToBoard(List<View> views, int width, int height) {
- CellLayoutBoard board = new CellLayoutBoard();
- board.mWidth = width;
- board.mHeight = height;
+ CellLayoutBoard board = new CellLayoutBoard(width, height);
for (View callView : views) {
CellLayoutLayoutParams params = (CellLayoutLayoutParams) callView.getLayoutParams();
diff --git a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java
index 2108eee..bd52bda 100644
--- a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java
+++ b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java
@@ -22,7 +22,7 @@
import android.content.Context;
import android.graphics.Point;
-import android.graphics.Rect;
+import android.util.Log;
import android.view.View;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -31,9 +31,13 @@
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
+import com.android.launcher3.MultipageCellLayout;
import com.android.launcher3.celllayout.board.CellLayoutBoard;
import com.android.launcher3.celllayout.board.IconPoint;
+import com.android.launcher3.celllayout.board.PermutedBoardComparator;
import com.android.launcher3.celllayout.board.WidgetRect;
+import com.android.launcher3.celllayout.testgenerator.RandomBoardGenerator;
+import com.android.launcher3.celllayout.testgenerator.RandomMultiBoardGenerator;
import com.android.launcher3.util.ActivityContextWrapper;
import com.android.launcher3.views.DoubleShadowBubbleTextView;
@@ -53,10 +57,25 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ReorderAlgorithmUnitTest {
+
+ private static final String TAG = "ReorderAlgorithmUnitTest";
+ private static final char MAIN_WIDGET_TYPE = 'z';
+
+ // There is nothing special about this numbers, the random seed is just to be able to reproduce
+ // the test cases and the height and width is a random number similar to what users expect on
+ // their devices
+ private static final int SEED = 897;
+ private static final int MAX_BOARD_SIZE = 13;
+
+ private static final int TOTAL_OF_CASES_GENERATED = 300;
private Context mApplicationContext;
private int mPrevNumColumns, mPrevNumRows;
+ /**
+ * This test reads existing test cases and makes sure the CellLayout produces the same
+ * output for each of them for a given input.
+ */
@Test
public void testAllCases() throws IOException {
List<ReorderAlgorithmUnitTestCase> testCases = getTestCases(
@@ -65,7 +84,7 @@
List<Integer> failingCases = new ArrayList<>();
for (int i = 0; i < testCases.size(); i++) {
try {
- evaluateTestCase(testCases.get(i));
+ evaluateTestCase(testCases.get(i), false);
} catch (AssertionError e) {
e.printStackTrace();
failingCases.add(i);
@@ -75,6 +94,47 @@
failingCases.size());
}
+ /**
+ * This test generates random CellLayout configurations and then try to reorder it and makes
+ * sure the result is a valid board meaning it didn't remove any widget or icon.
+ */
+ @Test
+ public void generateValidTests() {
+ Random generator = new Random(SEED);
+ mApplicationContext = new ActivityContextWrapper(getApplicationContext());
+ for (int i = 0; i < TOTAL_OF_CASES_GENERATED; i++) {
+ // Using a new seed so that we can replicate the same test cases.
+ int seed = generator.nextInt();
+ Log.d(TAG, "Seed = " + seed);
+ ReorderAlgorithmUnitTestCase testCase = generateRandomTestCase(
+ new RandomBoardGenerator(new Random(seed))
+ );
+ Log.d(TAG, "testCase = " + testCase);
+ assertTrue("invalid case " + i,
+ validateIntegrity(testCase.startBoard, testCase.endBoard, testCase));
+ }
+ }
+
+ /**
+ * Same as above but testing the Multipage CellLayout.
+ */
+ @Test
+ public void generateValidTests_Multi() {
+ Random generator = new Random(SEED);
+ mApplicationContext = new ActivityContextWrapper(getApplicationContext());
+ for (int i = 0; i < TOTAL_OF_CASES_GENERATED; i++) {
+ // Using a new seed so that we can replicate the same test cases.
+ int seed = generator.nextInt();
+ Log.d(TAG, "Seed = " + seed);
+ ReorderAlgorithmUnitTestCase testCase = generateRandomTestCase(
+ new RandomMultiBoardGenerator(new Random(seed))
+ );
+ Log.d(TAG, "testCase = " + testCase);
+ assertTrue("invalid case " + i,
+ validateIntegrity(testCase.startBoard, testCase.endBoard, testCase));
+ }
+ }
+
private void addViewInCellLayout(CellLayout cellLayout, int cellX, int cellY, int spanX,
int spanY, boolean isWidget) {
View cell = isWidget ? new View(mApplicationContext) : new DoubleShadowBubbleTextView(
@@ -84,15 +144,16 @@
(CellLayoutLayoutParams) cell.getLayoutParams(), true);
}
- public CellLayout createCellLayout(int width, int height) {
+ public CellLayout createCellLayout(int width, int height, boolean isMulti) {
Context c = mApplicationContext;
DeviceProfile dp = InvariantDeviceProfile.INSTANCE.get(c).getDeviceProfile(c).copy(c);
// modify the device profile.
- dp.inv.numColumns = width;
+ dp.inv.numColumns = isMulti ? width / 2 : width;
dp.inv.numRows = height;
dp.cellLayoutBorderSpacePx = new Point(0, 0);
- CellLayout cl = new CellLayout(getWrappedContext(c, dp));
+ CellLayout cl = isMulti ? new MultipageCellLayout(getWrappedContext(c, dp))
+ : new CellLayout(getWrappedContext(c, dp));
// I put a very large number for width and height so that all the items can fit, it doesn't
// need to be exact, just bigger than the sum of cell border
cl.measure(View.MeasureSpec.makeMeasureSpec(10000, View.MeasureSpec.EXACTLY),
@@ -108,9 +169,9 @@
};
}
- public CellLayout.ItemConfiguration solve(CellLayoutBoard board, int x, int y, int spanX,
- int spanY, int minSpanX, int minSpanY) {
- CellLayout cl = createCellLayout(board.getWidth(), board.getHeight());
+ public ItemConfiguration solve(CellLayoutBoard board, int x, int y, int spanX,
+ int spanY, int minSpanX, int minSpanY, boolean isMulti) {
+ CellLayout cl = createCellLayout(board.getWidth(), board.getHeight(), isMulti);
// The views have to be sorted or the result can vary
board.getIcons()
@@ -118,42 +179,56 @@
.map(IconPoint::getCoord)
.sorted(Comparator.comparing(p -> ((Point) p).x).thenComparing(p -> ((Point) p).y))
.forEach(p -> addViewInCellLayout(cl, p.x, p.y, 1, 1, false));
- board.getWidgets().stream()
- .sorted(Comparator.comparing(WidgetRect::getCellX)
- .thenComparing(WidgetRect::getCellY))
- .forEach(widget -> addViewInCellLayout(cl, widget.getCellX(), widget.getCellY(),
- widget.getSpanX(), widget.getSpanY(), true));
+ board.getWidgets()
+ .stream()
+ .sorted(Comparator
+ .comparing(WidgetRect::getCellX)
+ .thenComparing(WidgetRect::getCellY)
+ ).forEach(
+ widget -> addViewInCellLayout(cl, widget.getCellX(), widget.getCellY(),
+ widget.getSpanX(), widget.getSpanY(), true)
+ );
int[] testCaseXYinPixels = new int[2];
cl.regionToCenterPoint(x, y, spanX, spanY, testCaseXYinPixels);
- CellLayout.ItemConfiguration solution = cl.createReorderAlgorithm().calculateReorder(
+ ItemConfiguration solution = cl.createReorderAlgorithm().calculateReorder(
testCaseXYinPixels[0], testCaseXYinPixels[1], minSpanX, minSpanY, spanX, spanY,
null);
if (solution == null) {
- solution = new CellLayout.ItemConfiguration();
+ solution = new ItemConfiguration();
+ solution.isSolution = false;
+ }
+ if (!solution.isSolution) {
+ cl.copyCurrentStateToSolution(solution, false);
+ if (cl instanceof MultipageCellLayout) {
+ solution =
+ ((MultipageCellLayout) cl).createReorderAlgorithm().removeSeamFromSolution(
+ solution);
+ }
solution.isSolution = false;
}
return solution;
}
- public CellLayoutBoard boardFromSolution(CellLayout.ItemConfiguration solution, int width,
+ public CellLayoutBoard boardFromSolution(ItemConfiguration solution, int width,
int height) {
// Update the views with solution value
solution.map.forEach((key, val) -> key.setLayoutParams(
new CellLayoutLayoutParams(val.cellX, val.cellY, val.spanX, val.spanY)));
CellLayoutBoard board = CellLayoutTestUtils.viewsToBoard(
new ArrayList<>(solution.map.keySet()), width, height);
- board.addWidget(solution.cellX, solution.cellY, solution.spanX, solution.spanY,
- 'z');
+ if (solution.isSolution) {
+ board.addWidget(solution.cellX, solution.cellY, solution.spanX, solution.spanY,
+ MAIN_WIDGET_TYPE);
+ }
return board;
}
- public void evaluateTestCase(ReorderAlgorithmUnitTestCase testCase) {
- CellLayout.ItemConfiguration solution = solve(testCase.startBoard, testCase.x,
- testCase.y, testCase.spanX, testCase.spanY, testCase.minSpanX,
- testCase.minSpanY);
- assertEquals("should be a valid solution", solution.isSolution,
- testCase.isValidSolution);
+ public void evaluateTestCase(ReorderAlgorithmUnitTestCase testCase, boolean isMultiCellLayout) {
+ ItemConfiguration solution = solve(testCase.startBoard, testCase.x, testCase.y,
+ testCase.spanX, testCase.spanY, testCase.minSpanX, testCase.minSpanY,
+ isMultiCellLayout);
+ assertEquals("should be a valid solution", solution.isSolution, testCase.isValidSolution);
if (testCase.isValidSolution) {
CellLayoutBoard finishBoard = boardFromSolution(solution,
testCase.startBoard.getWidth(), testCase.startBoard.getHeight());
@@ -178,36 +253,35 @@
dp.inv.numRows = mPrevNumRows;
}
- @SuppressWarnings("UnusedMethod")
- /**
- * Utility function used to generate all the test cases
- */
- private ReorderAlgorithmUnitTestCase generateRandomTestCase() {
+ private ReorderAlgorithmUnitTestCase generateRandomTestCase(
+ RandomBoardGenerator boardGenerator) {
ReorderAlgorithmUnitTestCase testCase = new ReorderAlgorithmUnitTestCase();
- int width = getRandom(3, 8);
- int height = getRandom(3, 8);
+ boolean isMultiCellLayout = boardGenerator instanceof RandomMultiBoardGenerator;
- int targetWidth = getRandom(1, width - 2);
- int targetHeight = getRandom(1, height - 2);
+ int width = isMultiCellLayout
+ ? boardGenerator.getRandom(3, MAX_BOARD_SIZE / 2) * 2
+ : boardGenerator.getRandom(3, MAX_BOARD_SIZE);
+ int height = boardGenerator.getRandom(3, MAX_BOARD_SIZE);
- int minTargetWidth = getRandom(1, targetWidth);
- int minTargetHeight = getRandom(1, targetHeight);
+ int targetWidth = boardGenerator.getRandom(1, width - 2);
+ int targetHeight = boardGenerator.getRandom(1, height - 2);
- int x = getRandom(0, width - targetWidth);
- int y = getRandom(0, height - targetHeight);
+ int minTargetWidth = boardGenerator.getRandom(1, targetWidth);
+ int minTargetHeight = boardGenerator.getRandom(1, targetHeight);
- CellLayoutBoard board = generateBoard(new CellLayoutBoard(width, height),
- new Rect(0, 0, width, height), targetWidth * targetHeight);
+ int x = boardGenerator.getRandom(0, width - targetWidth);
+ int y = boardGenerator.getRandom(0, height - targetHeight);
- CellLayout.ItemConfiguration solution = solve(board, x, y, targetWidth, targetHeight,
- minTargetWidth, minTargetHeight);
+ CellLayoutBoard board = boardGenerator.generateBoard(width, height,
+ targetWidth * targetHeight);
- CellLayoutBoard finishBoard = solution.isSolution ? boardFromSolution(solution,
- board.getWidth(), board.getHeight()) : new CellLayoutBoard(board.getWidth(),
+ ItemConfiguration solution = solve(board, x, y, targetWidth, targetHeight,
+ minTargetWidth, minTargetHeight, isMultiCellLayout);
+
+ CellLayoutBoard finishBoard = boardFromSolution(solution, board.getWidth(),
board.getHeight());
-
testCase.startBoard = board;
testCase.endBoard = finishBoard;
testCase.isValidSolution = solution.isSolution;
@@ -222,39 +296,24 @@
return testCase;
}
- private int getRandom(int start, int end) {
- int random = end == 0 ? 0 : new Random().nextInt(end);
- return start + random;
- }
-
- private CellLayoutBoard generateBoard(CellLayoutBoard board, Rect area,
- int emptySpaces) {
- if (area.height() * area.width() <= 0) return board;
-
- int width = getRandom(1, area.width() - 1);
- int height = getRandom(1, area.height() - 1);
-
- int x = area.left + getRandom(0, area.width() - width);
- int y = area.top + getRandom(0, area.height() - height);
-
- if (emptySpaces > 0) {
- emptySpaces -= width * height;
- } else if (width * height > 1) {
- board.addWidget(x, y, width, height);
- } else {
- board.addIcon(x, y);
+ /**
+ * Makes sure the final solution has valid integrity meaning that the number and sizes of
+ * widgets is the expect and there are no missing widgets.
+ */
+ public boolean validateIntegrity(CellLayoutBoard startBoard, CellLayoutBoard finishBoard,
+ ReorderAlgorithmUnitTestCase testCase) {
+ if (!testCase.isValidSolution) {
+ // if we couldn't place the widget then the solution should be identical to the board
+ return startBoard.compareTo(finishBoard) == 0;
}
-
- generateBoard(board,
- new Rect(area.left, area.top, area.right, y), emptySpaces);
- generateBoard(board,
- new Rect(area.left, y, x, area.bottom), emptySpaces);
- generateBoard(board,
- new Rect(x, y + height, area.right, area.bottom), emptySpaces);
- generateBoard(board,
- new Rect(x + width, y, area.right, y + height), emptySpaces);
-
- return board;
+ WidgetRect addedWidget = finishBoard.getWidgetOfType(MAIN_WIDGET_TYPE);
+ finishBoard.removeItem(MAIN_WIDGET_TYPE);
+ Comparator<CellLayoutBoard> comparator = new PermutedBoardComparator();
+ if (comparator.compare(startBoard, finishBoard) != 0) {
+ return false;
+ }
+ return addedWidget.getSpanX() >= testCase.minSpanX
+ && addedWidget.getSpanY() >= testCase.minSpanY;
}
private static List<ReorderAlgorithmUnitTestCase> getTestCases(String testPath)
diff --git a/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java b/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java
index 72de885..30bde0a 100644
--- a/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java
+++ b/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java
@@ -38,7 +38,6 @@
import com.android.launcher3.tapl.Widget;
import com.android.launcher3.tapl.WidgetResizeFrame;
import com.android.launcher3.ui.AbstractLauncherUiTest;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.ModelTestExtensions;
import com.android.launcher3.util.rule.ShellCommandRule;
@@ -73,7 +72,7 @@
@Before
public void setup() throws Throwable {
mWorkspaceBuilder = new TestWorkspaceBuilder(mTargetContext);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
}
@After
diff --git a/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java b/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
index e90e145..dbbdcf5 100644
--- a/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
+++ b/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2023 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -18,8 +18,11 @@
import android.graphics.Point;
import android.graphics.Rect;
+import androidx.annotation.NonNull;
+
import java.util.ArrayDeque;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -31,73 +34,13 @@
public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
- private boolean intersects(Rect r1, Rect r2) {
- // If one rectangle is on left side of other
- if (r1.left > r2.right || r2.left > r1.right) {
- return false;
- }
-
- // If one rectangle is above other
- if (r1.bottom > r2.top || r2.bottom > r1.top) {
- return false;
- }
-
- return true;
- }
-
- private boolean overlapsWithIgnored(Set<Rect> ignoredRectangles, Rect rect) {
- for (Rect ignoredRect : ignoredRectangles) {
- // Using the built in intersects doesn't work because it doesn't account for area 0
- if (intersects(ignoredRect, rect)) {
- return true;
- }
- }
- return false;
- }
+ public static final Comparator<CellLayoutBoard> COMPARATOR = new IdenticalBoardComparator();
@Override
- public int compareTo(CellLayoutBoard cellLayoutBoard) {
- // to be equal they need to have the same number of widgets and the same dimensions
- // their order can be different
- Set<Rect> widgetsSet = new HashSet<>();
- Set<Rect> ignoredRectangles = new HashSet<>();
- for (WidgetRect rect : mWidgetsRects) {
- if (rect.shouldIgnore()) {
- ignoredRectangles.add(rect.mBounds);
- } else {
- widgetsSet.add(rect.mBounds);
- }
- }
- for (WidgetRect rect : cellLayoutBoard.mWidgetsRects) {
- // ignore rectangles overlapping with the area marked by x
- if (overlapsWithIgnored(ignoredRectangles, rect.mBounds)) {
- continue;
- }
- if (!widgetsSet.contains(rect.mBounds)) {
- return -1;
- }
- widgetsSet.remove(rect.mBounds);
- }
- if (!widgetsSet.isEmpty()) {
- return 1;
- }
-
- // to be equal they need to have the same number of icons their order can be different
- Set<Point> iconsSet = new HashSet<>();
- mIconPoints.forEach(icon -> iconsSet.add(icon.getCoord()));
- for (IconPoint icon : cellLayoutBoard.mIconPoints) {
- if (!iconsSet.contains(icon.getCoord())) {
- return -1;
- }
- iconsSet.remove(icon.getCoord());
- }
- if (!iconsSet.isEmpty()) {
- return 1;
- }
- return 0;
+ public int compareTo(@NonNull CellLayoutBoard cellLayoutBoard) {
+ return COMPARATOR.compare(this, cellLayoutBoard);
}
-
private HashSet<Character> mUsedWidgetTypes = new HashSet<>();
static final int INFINITE = 99999;
@@ -112,7 +55,7 @@
WidgetRect mMain = null;
- public int mWidth, mHeight;
+ int mWidth, mHeight;
public CellLayoutBoard() {
for (int x = 0; x < mWidget.length; x++) {
@@ -123,7 +66,7 @@
}
public CellLayoutBoard(int width, int height) {
- mWidget = new char[width][height];
+ mWidget = new char[width + 1][height + 1];
this.mWidth = width;
this.mHeight = height;
for (int x = 0; x < mWidget.length; x++) {
@@ -139,6 +82,15 @@
return isXInRect && isYInRect;
}
+ public WidgetRect getWidgetAt(Point p) {
+ return getWidgetAt(p.x, p.y);
+ }
+
+ public WidgetRect getWidgetOfType(char type) {
+ return mWidgetsRects.stream()
+ .filter(widgetRect -> widgetRect.mType == type).findFirst().orElse(null);
+ }
+
public WidgetRect getWidgetAt(int x, int y) {
return mWidgetsRects.stream()
.filter(widgetRect -> pointInsideRect(x, y, widgetRect)).findFirst().orElse(null);
@@ -165,8 +117,8 @@
}
private void removeWidgetFromBoard(WidgetRect widget) {
- for (int xi = widget.mBounds.left; xi < widget.mBounds.right; xi++) {
- for (int yi = widget.mBounds.top; yi < widget.mBounds.bottom; yi++) {
+ for (int xi = widget.mBounds.left; xi <= widget.mBounds.right; xi++) {
+ for (int yi = widget.mBounds.bottom; yi <= widget.mBounds.top; yi++) {
mWidget[xi][yi] = '-';
}
}
@@ -207,7 +159,7 @@
private void removeOverlappingItems(Point p) {
// Remove overlapping widgets and remove them from the board
mWidgetsRects = mWidgetsRects.stream().filter(widget -> {
- if (widget.mBounds.contains(p.x, p.y)) {
+ if (IdenticalBoardComparator.Companion.touchesPoint(widget.mBounds, p)) {
removeWidgetFromBoard(widget);
return false;
}
@@ -237,8 +189,9 @@
}
private char getNextWidgetType() {
- for (char type = 'a'; type <= 'z'; type++) {
- if (type == 'i') continue;
+ for (char type = 'a'; type < 'z'; type++) {
+ if (type == CellType.ICON) continue;
+ if (type == CellType.IGNORE) continue;
if (mUsedWidgetTypes.contains(type)) continue;
mUsedWidgetTypes.add(type);
return type;
@@ -258,6 +211,17 @@
}
}
+ public void removeItem(char type) {
+ mWidgetsRects.stream()
+ .filter(widgetRect -> widgetRect.mType == type)
+ .forEach(widgetRect -> removeOverlappingItems(
+ new Point(widgetRect.getCellX(), widgetRect.getCellY())));
+ }
+
+ public void removeItem(Point p) {
+ removeOverlappingItems(p);
+ }
+
public void addWidget(int x, int y, int spanX, int spanY) {
addWidget(x, y, spanX, spanY, getNextWidgetType());
}
@@ -407,8 +371,8 @@
s.append("\n");
maxX = Math.min(maxX, mWidget.length);
maxY = Math.min(maxY, mWidget[0].length);
- for (int y = 0; y < maxY; y++) {
- for (int x = 0; x < maxX; x++) {
+ for (int y = 0; y <= maxY; y++) {
+ for (int x = 0; x <= maxX; x++) {
s.append(mWidget[x][y]);
}
s.append('\n');
diff --git a/tests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt b/tests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt
new file mode 100644
index 0000000..a4a420c
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2023 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.celllayout.board
+
+import android.graphics.Point
+import android.graphics.Rect
+
+/**
+ * Compares two [CellLayoutBoard] and returns 0 if they are identical, meaning they have the same
+ * widget and icons in the same place, they can be different letters tough.
+ */
+class IdenticalBoardComparator : Comparator<CellLayoutBoard> {
+
+ /** Converts a list of WidgetRect into a map of the count of different widget.bounds */
+ private fun widgetsToBoundsMap(widgets: List<WidgetRect>) =
+ widgets.groupingBy { it.mBounds }.eachCount()
+
+ /** Converts a list of IconPoint into a map of the count of different icon.coord */
+ private fun iconsToPosCountMap(widgets: List<IconPoint>) =
+ widgets.groupingBy { it.getCoord() }.eachCount()
+
+ override fun compare(
+ cellLayoutBoard: CellLayoutBoard,
+ otherCellLayoutBoard: CellLayoutBoard
+ ): Int {
+ // to be equal they need to have the same number of widgets and the same dimensions
+ // their order can be different
+ val widgetsMap: Map<Rect, Int> =
+ widgetsToBoundsMap(cellLayoutBoard.widgets.filter { !it.shouldIgnore() })
+ val ignoredRectangles: Map<Rect, Int> =
+ widgetsToBoundsMap(cellLayoutBoard.widgets.filter { it.shouldIgnore() })
+
+ val otherWidgetMap: Map<Rect, Int> =
+ widgetsToBoundsMap(
+ otherCellLayoutBoard.widgets
+ .filter { !it.shouldIgnore() }
+ .filter { !overlapsWithIgnored(ignoredRectangles, it.mBounds) }
+ )
+
+ if (widgetsMap != otherWidgetMap) {
+ return -1
+ }
+
+ // to be equal they need to have the same number of icons their order can be different
+ return if (
+ iconsToPosCountMap(cellLayoutBoard.icons) ==
+ iconsToPosCountMap(otherCellLayoutBoard.icons)
+ ) {
+ 0
+ } else {
+ 1
+ }
+ }
+
+ private fun overlapsWithIgnored(ignoredRectangles: Map<Rect, Int>, rect: Rect): Boolean {
+ for (ignoredRect in ignoredRectangles.keys) {
+ // Using the built in intersects doesn't work because it doesn't account for area 0
+ if (touches(ignoredRect, rect)) {
+ return true
+ }
+ }
+ return false
+ }
+
+ companion object {
+ /**
+ * Similar function to {@link Rect#intersects} but this one returns true if the rectangles
+ * are intersecting or touching whereas {@link Rect#intersects} doesn't return true when
+ * they are touching.
+ */
+ fun touches(r1: Rect, r2: Rect): Boolean {
+ // If one rectangle is on left side of other
+ return if (r1.left > r2.right || r2.left > r1.right) {
+ false
+ } else r1.bottom <= r2.top && r2.bottom <= r1.top
+
+ // If one rectangle is above other
+ }
+
+ /**
+ * Similar function to {@link Rect#contains} but this one returns true if {link @Point} is
+ * intersecting or touching the {@link Rect}. Similar to {@link touches}.
+ */
+ fun touchesPoint(r1: Rect, p: Point): Boolean {
+ return r1.left <= p.x && p.x <= r1.right && r1.bottom <= p.y && p.y <= r1.top
+ }
+ }
+}
diff --git a/tests/src/com/android/launcher3/celllayout/board/PermutedBoardComparator.kt b/tests/src/com/android/launcher3/celllayout/board/PermutedBoardComparator.kt
new file mode 100644
index 0000000..c3d13a5
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/board/PermutedBoardComparator.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2023 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.celllayout.board
+
+import android.graphics.Point
+
+/**
+ * Compares two [CellLayoutBoard] and returns 0 if they contain the same widgets and icons even if
+ * they are in different positions i.e. in a different permutation.
+ */
+class PermutedBoardComparator : Comparator<CellLayoutBoard> {
+
+ /**
+ * The key for the set is the span since the widgets could change location but shouldn't change
+ * size
+ */
+ private fun boardToSpanCountMap(widgets: List<WidgetRect>) =
+ widgets.groupingBy { Point(it.spanX, it.spanY) }.eachCount()
+ override fun compare(
+ cellLayoutBoard: CellLayoutBoard,
+ otherCellLayoutBoard: CellLayoutBoard
+ ): Int {
+ return if (
+ boardToSpanCountMap(cellLayoutBoard.widgets) !=
+ boardToSpanCountMap(otherCellLayoutBoard.widgets)
+ ) {
+ 1
+ } else cellLayoutBoard.icons.size.compareTo(otherCellLayoutBoard.icons.size)
+ }
+}
diff --git a/tests/src/com/android/launcher3/celllayout/testgenerator/DeterministicRandomGenerator.kt b/tests/src/com/android/launcher3/celllayout/testgenerator/DeterministicRandomGenerator.kt
new file mode 100644
index 0000000..e582973
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/testgenerator/DeterministicRandomGenerator.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 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.celllayout.testgenerator
+
+import java.util.Random
+
+abstract class DeterministicRandomGenerator(private val generator: Random) {
+ fun getRandom(start: Int, end: Int): Int = start + (if (end == 0) 0 else generator.nextInt(end))
+}
diff --git a/tests/src/com/android/launcher3/celllayout/testgenerator/RandomBoardGenerator.kt b/tests/src/com/android/launcher3/celllayout/testgenerator/RandomBoardGenerator.kt
new file mode 100644
index 0000000..770024f
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/testgenerator/RandomBoardGenerator.kt
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2023 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.celllayout.testgenerator
+
+import android.graphics.Rect
+import com.android.launcher3.celllayout.board.CellLayoutBoard
+import java.util.Random
+
+/** Generates a random CellLayoutBoard. */
+open class RandomBoardGenerator(generator: Random) : DeterministicRandomGenerator(generator) {
+ /**
+ * @param remainingEmptySpaces the maximum number of spaces we will fill with icons and widgets
+ * meaning that if the number is 100 we will try to fill the board with at most 100 spaces
+ * usually less than 100.
+ * @return a randomly generated board filled with icons and widgets.
+ */
+ open fun generateBoard(width: Int, height: Int, remainingEmptySpaces: Int): CellLayoutBoard? {
+ val cellLayoutBoard = CellLayoutBoard(width, height)
+ return fillBoard(cellLayoutBoard, Rect(0, 0, width, height), remainingEmptySpaces)
+ }
+
+ protected fun fillBoard(
+ board: CellLayoutBoard,
+ area: Rect,
+ remainingEmptySpacesArg: Int
+ ): CellLayoutBoard {
+ var remainingEmptySpaces = remainingEmptySpacesArg
+ if (area.height() * area.width() <= 0) return board
+ val width = getRandom(1, area.width() - 1)
+ val height = getRandom(1, area.height() - 1)
+ val x = area.left + getRandom(0, area.width() - width)
+ val y = area.top + getRandom(0, area.height() - height)
+ if (remainingEmptySpaces > 0) {
+ remainingEmptySpaces -= width * height
+ } else if (board.widgets.size <= 22 && width * height > 1) {
+ board.addWidget(x, y, width, height)
+ } else {
+ board.addIcon(x, y)
+ }
+ fillBoard(board, Rect(area.left, area.top, area.right, y), remainingEmptySpaces)
+ fillBoard(board, Rect(area.left, y, x, area.bottom), remainingEmptySpaces)
+ fillBoard(board, Rect(x, y + height, area.right, area.bottom), remainingEmptySpaces)
+ fillBoard(board, Rect(x + width, y, area.right, y + height), remainingEmptySpaces)
+ return board
+ }
+}
diff --git a/tests/src/com/android/launcher3/celllayout/testgenerator/RandomMultiBoardGenerator.kt b/tests/src/com/android/launcher3/celllayout/testgenerator/RandomMultiBoardGenerator.kt
new file mode 100644
index 0000000..da4de7d
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/testgenerator/RandomMultiBoardGenerator.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2023 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.celllayout.testgenerator
+
+import android.graphics.Rect
+import com.android.launcher3.celllayout.board.CellLayoutBoard
+import java.util.Random
+
+class RandomMultiBoardGenerator(generator: Random) : RandomBoardGenerator(generator) {
+ override fun generateBoard(
+ width: Int,
+ height: Int,
+ remainingEmptySpaces: Int
+ ): CellLayoutBoard {
+ val cellLayoutBoard = CellLayoutBoard(width, height)
+ fillBoard(cellLayoutBoard, Rect(0, 0, width / 2, height), remainingEmptySpaces / 2)
+ return fillBoard(
+ cellLayoutBoard,
+ Rect(width / 2, 0, width, height),
+ remainingEmptySpaces / 2
+ )
+ }
+}
diff --git a/tests/src/com/android/launcher3/dragging/TaplDragTest.java b/tests/src/com/android/launcher3/dragging/TaplDragTest.java
index 7ec7826..e040367 100644
--- a/tests/src/com/android/launcher3/dragging/TaplDragTest.java
+++ b/tests/src/com/android/launcher3/dragging/TaplDragTest.java
@@ -19,7 +19,7 @@
import static com.android.launcher3.util.TestConstants.AppNames.GMAIL_APP_NAME;
import static com.android.launcher3.util.TestConstants.AppNames.MAPS_APP_NAME;
import static com.android.launcher3.util.TestConstants.AppNames.STORE_APP_NAME;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
diff --git a/tests/src/com/android/launcher3/dragging/TaplUninstallRemove.java b/tests/src/com/android/launcher3/dragging/TaplUninstallRemove.java
index d69287b..ed34307 100644
--- a/tests/src/com/android/launcher3/dragging/TaplUninstallRemove.java
+++ b/tests/src/com/android/launcher3/dragging/TaplUninstallRemove.java
@@ -16,7 +16,7 @@
package com.android.launcher3.dragging;
import static com.android.launcher3.testing.shared.TestProtocol.ICON_MISSING;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static com.android.launcher3.util.TestConstants.AppNames.DUMMY_APP_NAME;
import static com.android.launcher3.util.TestConstants.AppNames.GMAIL_APP_NAME;
import static com.android.launcher3.util.TestConstants.AppNames.MAPS_APP_NAME;
diff --git a/tests/src/com/android/launcher3/responsive/ResponsiveCellSpecsProviderTest.kt b/tests/src/com/android/launcher3/responsive/ResponsiveCellSpecsProviderTest.kt
new file mode 100644
index 0000000..295f2e4
--- /dev/null
+++ b/tests/src/com/android/launcher3/responsive/ResponsiveCellSpecsProviderTest.kt
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2023 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.responsive
+
+import android.content.Context
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.launcher3.AbstractDeviceProfileTest
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
+import com.android.launcher3.tests.R as TestR
+import com.android.launcher3.util.TestResourceHelper
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class ResponsiveCellSpecsProviderTest : AbstractDeviceProfileTest() {
+ override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context
+ val deviceSpec = deviceSpecs["phone"]!!
+ val aspectRatio = deviceSpec.naturalSize.first.toFloat() / deviceSpec.naturalSize.second
+
+ @Before
+ fun setup() {
+ initializeVarsForPhone(deviceSpec)
+ }
+
+ @Test
+ fun parseValidFile() {
+ val testResourceHelper = TestResourceHelper(context, TestR.xml.valid_cell_specs_file)
+ val provider = ResponsiveCellSpecsProvider.create(testResourceHelper)
+
+ // Validate Portrait
+ val aspectRatioPortrait = 1.0f
+ val expectedPortraitSpecs =
+ listOf(
+ CellSpec(
+ maxAvailableSize = 606.dpToPx(),
+ dimensionType = ResponsiveSpec.DimensionType.HEIGHT,
+ specType = ResponsiveSpecType.Cell,
+ iconSize = SizeSpec(48f.dpToPx()),
+ iconTextSize = SizeSpec(12f.dpToPx()),
+ iconDrawablePadding = SizeSpec(8f.dpToPx())
+ ),
+ CellSpec(
+ maxAvailableSize = 9999.dpToPx(),
+ dimensionType = ResponsiveSpec.DimensionType.HEIGHT,
+ specType = ResponsiveSpecType.Cell,
+ iconSize = SizeSpec(52f.dpToPx()),
+ iconTextSize = SizeSpec(12f.dpToPx()),
+ iconDrawablePadding = SizeSpec(11f.dpToPx())
+ )
+ )
+
+ val portraitSpecs = provider.getSpecsByAspectRatio(aspectRatioPortrait)
+
+ assertThat(portraitSpecs.aspectRatio).isAtLeast(aspectRatioPortrait)
+ assertThat(portraitSpecs.widthSpecs.size).isEqualTo(0)
+ assertThat(portraitSpecs.heightSpecs.size).isEqualTo(2)
+ assertThat(portraitSpecs.heightSpecs[0]).isEqualTo(expectedPortraitSpecs[0])
+ assertThat(portraitSpecs.heightSpecs[1]).isEqualTo(expectedPortraitSpecs[1])
+
+ // Validate Landscape
+ val aspectRatioLandscape = 1.051f
+ val expectedLandscapeSpec =
+ CellSpec(
+ maxAvailableSize = 9999.dpToPx(),
+ dimensionType = ResponsiveSpec.DimensionType.HEIGHT,
+ specType = ResponsiveSpecType.Cell,
+ iconSize = SizeSpec(52f.dpToPx()),
+ iconTextSize = SizeSpec(0f),
+ iconDrawablePadding = SizeSpec(0f)
+ )
+ val landscapeSpecs = provider.getSpecsByAspectRatio(aspectRatioLandscape)
+
+ assertThat(landscapeSpecs.aspectRatio).isAtLeast(aspectRatioLandscape)
+ assertThat(landscapeSpecs.widthSpecs.size).isEqualTo(0)
+ assertThat(landscapeSpecs.heightSpecs.size).isEqualTo(1)
+ assertThat(landscapeSpecs.heightSpecs[0]).isEqualTo(expectedLandscapeSpec)
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun parseInvalidFile_IsNotFixedSizeOrMatchWorkspace_throwsError() {
+ ResponsiveCellSpecsProvider.create(
+ TestResourceHelper(context, TestR.xml.invalid_cell_specs_1)
+ )
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun parseInvalidFile_dimensionTypeIsNotHeight_throwsError() {
+ ResponsiveCellSpecsProvider.create(
+ TestResourceHelper(context, TestR.xml.invalid_cell_specs_2)
+ )
+ }
+}
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index cb1102e..5f536c7 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -220,6 +220,23 @@
@Rule
public SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT);
+ public static void initialize(AbstractLauncherUiTest test) throws Exception {
+ initialize(test, false);
+ }
+
+ public static void initialize(
+ AbstractLauncherUiTest test, boolean clearWorkspace) throws Exception {
+ test.reinitializeLauncherData(clearWorkspace);
+ test.mDevice.pressHome();
+ test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
+ test.waitForState("Launcher internal state didn't switch to Home",
+ () -> LauncherState.NORMAL);
+ test.waitForResumed("Launcher internal state is still Background");
+ // Check that we switched to home.
+ test.mLauncher.getWorkspace();
+ AbstractLauncherUiTest.checkDetectedLeaks(test.mLauncher, true);
+ }
+
protected void clearPackageData(String pkg) throws IOException, InterruptedException {
final CountDownLatch count = new CountDownLatch(2);
final SimpleBroadcastReceiver broadcastReceiver =
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index f2cbd92..65d1f46 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -22,8 +22,6 @@
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.launcher3.LauncherState;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,23 +36,6 @@
initialize(this);
}
- public static void initialize(AbstractLauncherUiTest test) throws Exception {
- initialize(test, false);
- }
-
- public static void initialize(
- AbstractLauncherUiTest test, boolean clearWorkspace) throws Exception {
- test.reinitializeLauncherData(clearWorkspace);
- test.mDevice.pressHome();
- test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
- test.waitForState("Launcher internal state didn't switch to Home",
- () -> LauncherState.NORMAL);
- test.waitForResumed("Launcher internal state is still Background");
- // Check that we switched to home.
- test.mLauncher.getWorkspace();
- AbstractLauncherUiTest.checkDetectedLeaks(test.mLauncher, true);
- }
-
// Please don't add negative test cases for methods that fail only after a long wait.
public static void expectFail(String message, Runnable action) {
boolean failed = false;
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index 5c753f9..3c88f1d 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -18,8 +18,6 @@
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.app.PendingIntent.FLAG_ONE_SHOT;
-import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;
-
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
@@ -44,7 +42,6 @@
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
import com.android.launcher3.testcomponent.RequestPinItemActivity;
import com.android.launcher3.ui.AbstractLauncherUiTest;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.Wait.Condition;
@@ -77,7 +74,7 @@
super.setUp();
mCallbackAction = UUID.randomUUID().toString();
mShortcutId = UUID.randomUUID().toString();
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
}
@Test
diff --git a/tests/src/com/android/launcher3/ui/widget/TaplWidgetPickerTest.java b/tests/src/com/android/launcher3/ui/widget/TaplWidgetPickerTest.java
index a5e9868..4ae2baa 100644
--- a/tests/src/com/android/launcher3/ui/widget/TaplWidgetPickerTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/TaplWidgetPickerTest.java
@@ -15,7 +15,7 @@
*/
package com.android.launcher3.ui.widget;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT;
diff --git a/tests/src/com/android/launcher3/ui/workspace/TaplWorkspaceTest.java b/tests/src/com/android/launcher3/ui/workspace/TaplWorkspaceTest.java
index d776f21..59c82a7 100644
--- a/tests/src/com/android/launcher3/ui/workspace/TaplWorkspaceTest.java
+++ b/tests/src/com/android/launcher3/ui/workspace/TaplWorkspaceTest.java
@@ -15,7 +15,7 @@
*/
package com.android.launcher3.ui.workspace;
-import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;
+import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static com.android.launcher3.util.TestConstants.AppNames.CHROME_APP_NAME;
import static org.junit.Assert.assertEquals;
diff --git a/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java b/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
index 34c7707..e21918f 100644
--- a/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
+++ b/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
@@ -36,7 +36,6 @@
import com.android.launcher3.tapl.HomeAppIcon;
import com.android.launcher3.tapl.HomeAppIconMenuItem;
import com.android.launcher3.ui.AbstractLauncherUiTest;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.Executors;
import org.junit.Test;
@@ -58,7 +57,7 @@
@Test
public void testIconWithoutTheme() throws Exception {
setThemeEnabled(false);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
@@ -76,7 +75,7 @@
@Test
public void testShortcutIconWithoutTheme() throws Exception {
setThemeEnabled(false);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
@@ -95,7 +94,7 @@
@Test
public void testIconWithTheme() throws Exception {
setThemeEnabled(true);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
@@ -113,7 +112,7 @@
@Test
public void testShortcutIconWithTheme() throws Exception {
setThemeEnabled(true);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
diff --git a/tests/src/com/android/launcher3/ui/workspace/TwoPanelWorkspaceTest.java b/tests/src/com/android/launcher3/ui/workspace/TwoPanelWorkspaceTest.java
index 35b4883..e7112d1 100644
--- a/tests/src/com/android/launcher3/ui/workspace/TwoPanelWorkspaceTest.java
+++ b/tests/src/com/android/launcher3/ui/workspace/TwoPanelWorkspaceTest.java
@@ -35,7 +35,6 @@
import com.android.launcher3.tapl.Workspace;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
-import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.LauncherLayoutBuilder;
import com.android.launcher3.util.TestUtil;
@@ -74,7 +73,7 @@
.atWorkspace(3, -1, 0).putApp(
"com.android.vending", "com.android.vending.AssetBrowserActivity");
mLauncherLayout = TestUtil.setLauncherDefaultLayout(mTargetContext, builder);
- TaplTestsLauncher3.initialize(this);
+ AbstractLauncherUiTest.initialize(this);
assumeTrue(mLauncher.isTwoPanels());
// Pre verifying the screens
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index dbb3cc3..7d25121 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -16,6 +16,7 @@
package com.android.launcher3.tapl;
+import static android.view.KeyEvent.KEYCODE_ESCAPE;
import static android.view.KeyEvent.KEYCODE_META_RIGHT;
import static com.android.launcher3.tapl.LauncherInstrumentation.DEFAULT_POLL_INTERVAL;
@@ -39,6 +40,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -53,6 +55,11 @@
private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background";
+ private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile(
+ "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_ESCAPE.*?metaState=0");
+ private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile(
+ "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_ESCAPE.*?metaState=0");
+
private final int mHeight;
private final int mIconHeight;
@@ -383,6 +390,19 @@
}
}
+ /** Presses the esc key to dismiss AllApps. */
+ public void dismissByEscKey() {
+ try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
+ mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN);
+ mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP);
+ mLauncher.getDevice().pressKeyCode(KEYCODE_ESCAPE);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "pressed esc key")) {
+ verifyVisibleContainerOnDismiss();
+ }
+ }
+ }
+
protected abstract void verifyVisibleContainerOnDismiss();
/**