Merge "Extra checks to find the source of flaky tests" into tm-dev
diff --git a/quickstep/AndroidManifest-launcher.xml b/quickstep/AndroidManifest-launcher.xml
index a24a588..7d7054f 100644
--- a/quickstep/AndroidManifest-launcher.xml
+++ b/quickstep/AndroidManifest-launcher.xml
@@ -57,6 +57,7 @@
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
+ <action android:name="android.intent.action.SHOW_WORK_APPS" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index dc2b61b..f60b225 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1065,11 +1065,10 @@
: LAST_TASK;
}
} else {
- // If swiping at a diagonal on the current task, base end target on the faster velocity.
+ // If swiping at a diagonal, base end target on the faster velocity.
boolean isSwipeUp = endVelocity < 0;
- boolean willGoToNewTask = canGoToNewTask && (
- mRecentsView.getDestinationPage() != mRecentsView.getCurrentPage()
- || Math.abs(velocity.x) > Math.abs(endVelocity));
+ boolean willGoToNewTask =
+ canGoToNewTask && Math.abs(velocity.x) > Math.abs(endVelocity);
if (mDeviceState.isFullyGesturalNavMode() && isSwipeUp) {
endTarget = willGoToNewTask ? NEW_TASK : HOME;
diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java
index db19c45..269b3c2 100644
--- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java
+++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java
@@ -54,6 +54,7 @@
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
+import com.android.launcher3.util.Executors;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.GestureState;
import com.android.quickstep.TouchInteractionService.TISBinder;
@@ -136,6 +137,10 @@
startBackgroundAnimation();
}
+ private void runOnUiHelperThread(Runnable runnable) {
+ Executors.UI_HELPER_EXECUTOR.execute(runnable);
+ }
+
private void startBackgroundAnimation() {
if (Utilities.ATLEAST_S && mVibrator != null && mVibrator.areAllPrimitivesSupported(
VibrationEffect.Composition.PRIMITIVE_THUD)) {
@@ -144,22 +149,22 @@
new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
- mVibrator.vibrate(getVibrationEffect());
+ runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect()));
}
@Override
public void onAnimationRepeat(Animator animation) {
- mVibrator.vibrate(getVibrationEffect());
+ runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect()));
}
@Override
public void onAnimationEnd(Animator animation) {
- mVibrator.cancel();
+ runOnUiHelperThread(mVibrator::cancel);
}
@Override
public void onAnimationCancel(Animator animation) {
- mVibrator.cancel();
+ runOnUiHelperThread(mVibrator::cancel);
}
};
}
diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml
index dce09e3..63970cd 100644
--- a/res/values-sw600dp-land/dimens.xml
+++ b/res/values-sw600dp-land/dimens.xml
@@ -16,6 +16,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">3600dp</dimen>
+
<!-- Hotseat -->
<dimen name="spring_loaded_hotseat_top_margin">44dp</dimen>
diff --git a/res/values-sw600dp/config.xml b/res/values-sw600dp/config.xml
new file mode 100644
index 0000000..072b92d
--- /dev/null
+++ b/res/values-sw600dp/config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+ 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.
+-->
+<resources>
+
+ <!-- The duration of the PagedView page snap animation -->
+ <integer name="config_pageSnapAnimationDuration">550</integer>
+
+</resources>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index eb347f2..d69e777 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView-->
+ <dimen name="min_page_snap_velocity">3000dp</dimen>
+
<!-- DragController -->
<dimen name="drag_flingToDeleteMinVelocity">-1000dp</dimen>
diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml
index 439ea93..235631d 100644
--- a/res/values-sw720dp-land/dimens.xml
+++ b/res/values-sw720dp-land/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">5300dp</dimen>
+
<!-- Dynamic grid -->
<dimen name="dynamic_grid_edge_margin">21.93dp</dimen>
<dimen name="cell_layout_padding">29.33dp</dimen>
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 8e985bd..7b2ed8b 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -15,6 +15,9 @@
-->
<resources>
+<!-- PagedView -->
+ <dimen name="min_page_snap_velocity">3400dp</dimen>
+
<!-- AllApps -->
<dimen name="all_apps_bottom_sheet_horizontal_padding">28dp</dimen>
diff --git a/res/values/config.xml b/res/values/config.xml
index 5ecd929..9aa1f03 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -1,3 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+ 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.
+-->
<resources>
<!-- Miscellaneous -->
<bool name="config_largeHeap">false</bool>
@@ -25,6 +40,9 @@
<!-- The duration of the animation from search hint to text entry -->
<integer name="config_searchHintAnimationDuration">50</integer>
+ <!-- The duration of the PagedView page snap animation -->
+ <integer name="config_pageSnapAnimationDuration">750</integer>
+
<!-- View tag key used to store SpringAnimation data. -->
<item type="id" name="spring_animation_tag" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index e02ee8a..dd99a7a 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -97,6 +97,13 @@
<dimen name="fastscroll_width">58dp</dimen>
<dimen name="fastscroll_end_margin">-26dp</dimen>
+ <!-- PagedView -->
+ <dimen name="fling_threshold_velocity">500dp</dimen>
+ <dimen name="easy_fling_threshold_velocity">400dp</dimen>
+ <dimen name="min_fling_velocity">250dp</dimen>
+ <!-- The minimum velocity of a page snap after a fling gesture -->
+ <dimen name="min_page_snap_velocity">1500dp</dimen>
+
<!-- All Apps -->
<dimen name="all_apps_starting_vertical_translate">300dp</dimen>
<dimen name="all_apps_search_bar_field_height">48dp</dimen>
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 95a8a2a..4d33eae 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -28,6 +28,8 @@
import android.animation.LayoutTransition;
import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
@@ -78,27 +80,19 @@
public static final int INVALID_PAGE = -1;
protected static final ComputePageScrollsLogic SIMPLE_SCROLL_LOGIC = (v) -> v.getVisibility() != GONE;
- public static final int PAGE_SNAP_ANIMATION_DURATION = 750;
-
private static final float RETURN_TO_ORIGINAL_PAGE_THRESHOLD = 0.33f;
// The page is moved more than halfway, automatically move to the next page on touch up.
private static final float SIGNIFICANT_MOVE_THRESHOLD = 0.4f;
private static final float MAX_SCROLL_PROGRESS = 1.0f;
- // The following constants need to be scaled based on density. The scaled versions will be
- // assigned to the corresponding member variables below.
- private static final int FLING_THRESHOLD_VELOCITY = 500;
- private static final int EASY_FLING_THRESHOLD_VELOCITY = 400;
- private static final int MIN_SNAP_VELOCITY = 1500;
- private static final int MIN_FLING_VELOCITY = 250;
-
private boolean mFreeScroll = false;
- protected final int mFlingThresholdVelocity;
- protected final int mEasyFlingThresholdVelocity;
- protected final int mMinFlingVelocity;
- protected final int mMinSnapVelocity;
+ private int mFlingThresholdVelocity;
+ private int mEasyFlingThresholdVelocity;
+ private int mMinFlingVelocity;
+ private int mMinSnapVelocity;
+ private int mPageSnapAnimationDuration;
protected boolean mFirstLayout = true;
@@ -192,11 +186,7 @@
mPageSlop = configuration.getScaledPagingTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
- float density = getResources().getDisplayMetrics().density;
- mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * density);
- mEasyFlingThresholdVelocity = (int) (EASY_FLING_THRESHOLD_VELOCITY * density);
- mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * density);
- mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * density);
+ updateVelocityValues();
initEdgeEffect();
setDefaultFocusHighlightEnabled(false);
@@ -628,6 +618,22 @@
- mInsets.left - mInsets.right;
}
+ private void updateVelocityValues() {
+ Resources res = getResources();
+ mFlingThresholdVelocity = res.getDimensionPixelSize(R.dimen.fling_threshold_velocity);
+ mEasyFlingThresholdVelocity =
+ res.getDimensionPixelSize(R.dimen.easy_fling_threshold_velocity);
+ mMinFlingVelocity = res.getDimensionPixelSize(R.dimen.min_fling_velocity);
+ mMinSnapVelocity = res.getDimensionPixelSize(R.dimen.min_page_snap_velocity);
+ mPageSnapAnimationDuration = res.getInteger(R.integer.config_pageSnapAnimationDuration);
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ updateVelocityValues();
+ }
+
@Override
public void requestLayout() {
mIsLayoutValid = false;
@@ -1616,7 +1622,7 @@
}
protected void snapToDestination() {
- snapToPage(getDestinationPage(), PAGE_SNAP_ANIMATION_DURATION);
+ snapToPage(getDestinationPage(), mPageSnapAnimationDuration);
}
// We want the duration of the page snap animation to be influenced by the distance that
@@ -1640,7 +1646,7 @@
if (Math.abs(velocity) < mMinFlingVelocity) {
// If the velocity is low enough, then treat this more as an automatic page advance
// as opposed to an apparent physical response to flinging
- return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION);
+ return snapToPage(whichPage, mPageSnapAnimationDuration);
}
// Here we compute a "distance" that will be used in the computation of the overall
@@ -1663,11 +1669,11 @@
}
public boolean snapToPage(int whichPage) {
- return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION);
+ return snapToPage(whichPage, mPageSnapAnimationDuration);
}
public boolean snapToPageImmediately(int whichPage) {
- return snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION, true);
+ return snapToPage(whichPage, mPageSnapAnimationDuration, true);
}
public boolean snapToPage(int whichPage, int duration) {
diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
index 95c67dd..fc52797 100644
--- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
@@ -326,7 +326,7 @@
}
protected boolean isPersonalTab() {
- return mViewPager.getNextPage() == 0;
+ return mViewPager == null || mViewPager.getNextPage() == 0;
}
/**
@@ -388,34 +388,34 @@
mInsets.set(insets);
DeviceProfile grid = mActivityContext.getDeviceProfile();
- for (int i = 0; i < mAH.size(); i++) {
- mAH.get(i).mPadding.bottom = insets.bottom;
- mAH.get(i).mPadding.left = mAH.get(i).mPadding.right = grid.allAppsLeftRightPadding;
- mAH.get(i).applyPadding();
- }
+ applyAdapterPaddings(grid);
MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
- int leftRightMargin = grid.allAppsLeftRightMargin;
- mlp.leftMargin = insets.left + leftRightMargin;
- mlp.rightMargin = insets.right + leftRightMargin;
+ mlp.leftMargin = insets.left;
+ mlp.rightMargin = insets.right;
setLayoutParams(mlp);
if (grid.isVerticalBarLayout()) {
setPadding(grid.workspacePadding.left, 0, grid.workspacePadding.right, 0);
} else {
- setPadding(0, grid.allAppsTopPadding, 0, 0);
+ setPadding(grid.allAppsLeftRightMargin, grid.allAppsTopPadding,
+ grid.allAppsLeftRightMargin, 0);
}
InsettableFrameLayout.dispatchInsets(this, insets);
}
+ /**
+ * Returns a padding in case a scrim is shown on the bottom of the view and a padding is needed.
+ */
+ protected int getNavBarScrimHeight(WindowInsets insets) {
+ return 0;
+ }
+
@Override
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
- if (Utilities.ATLEAST_Q) {
- mNavBarScrimHeight = insets.getTappableElementInsets().bottom;
- } else {
- mNavBarScrimHeight = insets.getStableInsetBottom();
- }
+ mNavBarScrimHeight = getNavBarScrimHeight(insets);
+ applyAdapterPaddings(mActivityContext.getDeviceProfile());
return super.dispatchApplyWindowInsets(insets);
}
@@ -483,6 +483,15 @@
mAllAppsStore.registerIconContainer(mAH.get(AdapterHolder.WORK).mRecyclerView);
}
+ private void applyAdapterPaddings(DeviceProfile grid) {
+ int bottomPadding = Math.max(mInsets.bottom, mNavBarScrimHeight);
+ for (int i = 0; i < mAH.size(); i++) {
+ mAH.get(i).mPadding.bottom = bottomPadding;
+ mAH.get(i).mPadding.left = mAH.get(i).mPadding.right = grid.allAppsLeftRightPadding;
+ mAH.get(i).applyPadding();
+ }
+ }
+
private void setDeviceManagementResources() {
if (mActivityContext.getStringCache() != null) {
Button personalTab = findViewById(R.id.tab_personal);
diff --git a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
index 8601819..20f5e74 100644
--- a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
@@ -18,9 +18,11 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
+import android.view.WindowInsets;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
+import com.android.launcher3.Utilities;
/**
* AllAppsContainerView with launcher specific callbacks
@@ -58,4 +60,13 @@
}
return super.onTouchEvent(ev);
}
+
+ @Override
+ protected int getNavBarScrimHeight(WindowInsets insets) {
+ if (Utilities.ATLEAST_Q) {
+ return insets.getTappableElementInsets().bottom;
+ } else {
+ return insets.getStableInsetBottom();
+ }
+ }
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 512fa1c..e68ebdb 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -72,7 +72,6 @@
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.OnAlarmListener;
-import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutAndWidgetContainer;
import com.android.launcher3.Utilities;
@@ -145,7 +144,7 @@
* Time for which the scroll hint is shown before automatically changing page.
*/
public static final int SCROLL_HINT_DURATION = 500;
- public static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150;
+ private static final int RESCROLL_EXTRA_DELAY = 150;
public static final int SCROLL_NONE = -1;
public static final int SCROLL_LEFT = 0;
@@ -1523,7 +1522,9 @@
// Pause drag event until the scrolling is finished
mScrollPauseAlarm.setOnAlarmListener(new OnScrollFinishedListener(mDragObject));
- mScrollPauseAlarm.setAlarm(RESCROLL_DELAY);
+ int rescrollDelay = getResources().getInteger(
+ R.integer.config_pageSnapAnimationDuration) + RESCROLL_EXTRA_DELAY;
+ mScrollPauseAlarm.setAlarm(rescrollDelay);
}
}
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
index e906c95..c79d70d 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
@@ -120,23 +120,20 @@
int maxWidth =
grid.allAppsCellWidthPx * grid.numShownAllAppsColumns + horizontalPadding;
- int appsWidth = Math.min(width, maxWidth);
+ int appsWidth = Math.min(width - getPaddingLeft() - getPaddingRight(), maxWidth);
int maxHeight =
grid.allAppsCellHeightPx * grid.numShownAllAppsColumns + verticalPadding;
- int appsHeight = Math.min(height, maxHeight);
+ int appsHeight = Math.min(height - getPaddingTop() - getPaddingBottom(), maxHeight);
mAppsView.measure(
makeMeasureSpec(appsWidth, EXACTLY), makeMeasureSpec(appsHeight, EXACTLY));
-
} else if (child == mAllAppsButton) {
int appsButtonSpec = makeMeasureSpec(grid.iconSizePx, EXACTLY);
mAllAppsButton.measure(appsButtonSpec, appsButtonSpec);
-
} else if (child == mWorkspace) {
measureChildWithMargins(mWorkspace, widthMeasureSpec, 0, heightMeasureSpec,
grid.iconSizePx + grid.edgeMarginPx);
-
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java
index 8b425da..38b62d4 100644
--- a/src/com/android/launcher3/states/RotationHelper.java
+++ b/src/com/android/launcher3/states/RotationHelper.java
@@ -109,7 +109,7 @@
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
- if (mDestroyed) return;
+ if (mDestroyed || mIgnoreAutoRotateSettings) return;
boolean wasRotationEnabled = mHomeRotationEnabled;
mHomeRotationEnabled = mSharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
getAllowRotationDefaultValue(mActivity.getDeviceProfile()));
diff --git a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
index d2d569f..9442734 100644
--- a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java
@@ -18,7 +18,6 @@
import static com.android.launcher3.Utilities.ATLEAST_R;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
-import static com.android.launcher3.widget.BaseWidgetSheet.MAX_WIDTH_SCALE_FOR_LARGER_SCREEN;
import android.animation.PropertyValuesHolder;
import android.annotation.SuppressLint;
@@ -106,7 +105,10 @@
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int widthUsed;
- if (mInsets.bottom > 0) {
+ if (deviceProfile.isTablet) {
+ int margin = deviceProfile.allAppsLeftRightMargin;
+ widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
+ } else if (mInsets.bottom > 0) {
widthUsed = mInsets.left + mInsets.right;
} else {
Rect padding = deviceProfile.workspacePadding;
@@ -114,18 +116,8 @@
2 * (mInsets.left + mInsets.right));
}
- if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
- // In large screen devices, we restrict the width of the widgets picker to show part of
- // the home screen. Let's ensure the minimum width used is at least the minimum width
- // that isn't taken by the widgets picker.
- int minUsedWidth = (int) (deviceProfile.availableWidthPx
- * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
- widthUsed = Math.max(widthUsed, minUsedWidth);
- }
-
- int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
measureChildWithMargins(mContent, widthMeasureSpec,
- widthUsed, heightMeasureSpec, heightUsed);
+ widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index c7bb612..1bcba14 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -16,6 +16,8 @@
package com.android.launcher3.widget;
import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
@@ -23,6 +25,7 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
+import android.view.WindowInsets;
import android.widget.Toast;
import androidx.annotation.GuardedBy;
@@ -43,6 +46,7 @@
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;
@@ -55,11 +59,6 @@
PopupDataProvider.PopupDataChangeListener, Insettable {
/** The default number of cells that can fit horizontally in a widget sheet. */
protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
- /**
- * The maximum scale, [0, 1], of the device screen width that the widgets picker can consume
- * on large screen devices.
- */
- protected static final float MAX_WIDTH_SCALE_FOR_LARGER_SCREEN = 0.89f;
protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN =
"launcher.widgets_education_tip_seen";
@@ -70,10 +69,15 @@
private int mContentHorizontalMarginInPx;
+ protected int mNavBarScrimHeight;
+ private final Paint mNavBarScrimPaint;
+
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContentHorizontalMarginInPx = getResources().getDimensionPixelSize(
R.dimen.widget_list_horizontal_margin);
+ mNavBarScrimPaint = new Paint();
+ mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor));
}
protected int getScrimColor(Context context) {
@@ -83,6 +87,9 @@
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
+ WindowInsets windowInsets = WindowManagerProxy.INSTANCE.get(getContext())
+ .normalizeWindowInsets(getContext(), getRootWindowInsets(), new Rect());
+ mNavBarScrimHeight = getNavBarScrimHeight(windowInsets);
mActivityContext.getPopupDataProvider().setChangeListener(this);
}
@@ -136,6 +143,30 @@
}
}
+ private int getNavBarScrimHeight(WindowInsets insets) {
+ if (Utilities.ATLEAST_Q) {
+ return insets.getTappableElementInsets().bottom;
+ } else {
+ return insets.getStableInsetBottom();
+ }
+ }
+
+ @Override
+ public WindowInsets onApplyWindowInsets(WindowInsets insets) {
+ mNavBarScrimHeight = getNavBarScrimHeight(insets);
+ return super.onApplyWindowInsets(insets);
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+
+ if (mNavBarScrimHeight > 0) {
+ canvas.drawRect(0, getHeight() - mNavBarScrimHeight, getWidth(), getHeight(),
+ mNavBarScrimPaint);
+ }
+ }
+
/** Called when the horizontal margin of the content view has changed. */
protected abstract void onContentHorizontalMarginChanged(int contentHorizontalMarginInPx);
@@ -147,7 +178,10 @@
protected void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int widthUsed;
- if (mInsets.bottom > 0) {
+ if (deviceProfile.isTablet) {
+ int margin = deviceProfile.allAppsLeftRightMargin;
+ widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
+ } else if (mInsets.bottom > 0) {
widthUsed = mInsets.left + mInsets.right;
} else {
Rect padding = deviceProfile.workspacePadding;
@@ -155,15 +189,6 @@
2 * (mInsets.left + mInsets.right));
}
- if (deviceProfile.isTablet || deviceProfile.isTwoPanels) {
- // In large screen devices, we restrict the width of the widgets picker to show part of
- // the home screen. Let's ensure the minimum width used is at least the minimum width
- // that isn't taken by the widgets picker.
- int minUsedWidth = (int) (deviceProfile.availableWidthPx
- * (1 - MAX_WIDTH_SCALE_FOR_LARGER_SCREEN));
- widthUsed = Math.max(widthUsed, minUsedWidth);
- }
-
measureChildWithMargins(mContent, widthMeasureSpec,
widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index b152ddc..bf521cc 100644
--- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
@@ -247,10 +247,12 @@
@Override
public void setInsets(Rect insets) {
super.setInsets(insets);
+ int bottomPadding = Math.max(insets.bottom, mNavBarScrimHeight);
mContent.setPadding(mContent.getPaddingStart(),
- mContent.getPaddingTop(), mContent.getPaddingEnd(), insets.bottom);
- if (insets.bottom > 0) {
+ mContent.getPaddingTop(), mContent.getPaddingEnd(),
+ bottomPadding);
+ if (bottomPadding > 0) {
setupNavBarColor();
} else {
clearNavBarColor();
diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
index 341cb5c..a49cdc0 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
@@ -328,15 +328,15 @@
@Override
public void setInsets(Rect insets) {
super.setInsets(insets);
-
- setBottomPadding(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, insets.bottom);
- setBottomPadding(mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView, insets.bottom);
+ int bottomPadding = Math.max(insets.bottom, mNavBarScrimHeight);
+ setBottomPadding(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, bottomPadding);
+ setBottomPadding(mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView, bottomPadding);
if (mHasWorkProfile) {
- setBottomPadding(mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView, insets.bottom);
+ setBottomPadding(mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView, bottomPadding);
}
- ((MarginLayoutParams) mNoWidgetsView.getLayoutParams()).bottomMargin = insets.bottom;
+ ((MarginLayoutParams) mNoWidgetsView.getLayoutParams()).bottomMargin = bottomPadding;
- if (insets.bottom > 0) {
+ if (bottomPadding > 0) {
setupNavBarColor();
} else {
clearNavBarColor();