Snap for 7761443 from 9ac78866d3 to sc-v2-release

Change-Id: If76c9968abef782bdef849523a0d4f36d5b7eaf3
This commit is contained in:
Android Build Coastguard Worker
2021-09-23 23:12:21 +00:00
28 changed files with 438 additions and 264 deletions
@@ -104,6 +104,23 @@
</LinearLayout>
<!-- Unused. Included only for compatibility with parent class. -->
<Button
android:id="@+id/action_split"
style="@style/GoOverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_split_screen"
android:text="@string/action_split"
android:theme="@style/ThemeControlHighlightWorkspaceColor"
android:visibility="gone" />
<Space
android:id="@+id/action_split_space"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:visibility="gone" />
<Button
android:id="@+id/action_share"
style="@style/GoOverviewActionButton"
+1
View File
@@ -27,6 +27,7 @@
<dimen name="task_menu_corner_radius">22dp</dimen>
<dimen name="task_menu_item_corner_radius">4dp</dimen>
<dimen name="task_menu_spacing">2dp</dimen>
<dimen name="task_menu_width_grid">200dp</dimen>
<dimen name="overview_proactive_row_height">48dp</dimen>
<dimen name="overview_proactive_row_bottom_margin">16dp</dimen>
@@ -107,7 +107,7 @@ public class TaskbarStashController {
// Evaluate whether the handle should be stashed
private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder(
flags -> {
if (!supportsStashing()) {
if (!supportsVisualStashing()) {
return false;
}
boolean inApp = (flags & FLAG_IN_APP) != 0;
@@ -141,7 +141,7 @@ public class TaskbarStashController {
mTaskbarStashedHandleAlpha = stashedHandleController.getStashedHandleAlpha();
mTaskbarStashedHandleHintScale = stashedHandleController.getStashedHandleHintScale();
mIsStashedInApp = supportsStashing()
mIsStashedInApp = supportsManualStashing()
&& mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
@@ -149,11 +149,19 @@ public class TaskbarStashController {
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
}
/**
* Returns whether the taskbar can visually stash into a handle based on the current device
* state.
*/
private boolean supportsVisualStashing() {
return !mActivity.isThreeButtonNav();
}
/**
* Returns whether the user can manually stash the taskbar based on the current device state.
*/
private boolean supportsStashing() {
return !mActivity.isThreeButtonNav()
private boolean supportsManualStashing() {
return supportsVisualStashing()
&& (!Utilities.IS_RUNNING_IN_TEST_HARNESS || supportsStashingForTests());
}
@@ -206,7 +214,7 @@ public class TaskbarStashController {
* @return Whether we started an animation to either be newly stashed or unstashed.
*/
public boolean updateAndAnimateIsStashedInApp(boolean isStashedInApp) {
if (!supportsStashing()) {
if (!supportsManualStashing()) {
return false;
}
if (mIsStashedInApp != isStashedInApp) {
@@ -307,7 +315,7 @@ public class TaskbarStashController {
* unstashed state.
*/
public void startStashHint(boolean animateForward) {
if (isStashed() || !supportsStashing()) {
if (isStashed() || !supportsManualStashing()) {
// Already stashed, no need to hint in that direction.
return;
}
@@ -151,7 +151,7 @@ public class TaskMenuView extends AbstractFloatingView implements OnScrollChange
}
setRotation(pagedOrientationHandler.getDegreesRotated());
setX(pagedOrientationHandler.getTaskMenuX(adjustedX,
mTaskContainer.getThumbnailView(), overscrollShift));
mTaskContainer.getThumbnailView(), overscrollShift, deviceProfile));
setY(pagedOrientationHandler.getTaskMenuY(
adjustedY, mTaskContainer.getThumbnailView(), overscrollShift));
@@ -229,7 +229,6 @@ public class TaskMenuView extends AbstractFloatingView implements OnScrollChange
private void addMenuOptions(TaskIdAttributeContainer taskContainer) {
mTaskName.setText(TaskUtils.getTitle(getContext(), taskContainer.getTask()));
mTaskName.setOnClickListener(v -> close(true));
TaskOverlayFactory.getEnabledShortcuts(mTaskView, mActivity.getDeviceProfile(),
taskContainer)
.forEach(this::addMenuOption);
@@ -256,13 +255,21 @@ public class TaskMenuView extends AbstractFloatingView implements OnScrollChange
orientationHandler.setTaskMenuAroundTaskView(this, mTaskInsetMargin);
// Get Position
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
mActivity.getDragLayer().getDescendantRectRelativeToSelf(mTaskView, sTempRect);
Rect insets = mActivity.getDragLayer().getInsets();
BaseDragLayer.LayoutParams params = (BaseDragLayer.LayoutParams) getLayoutParams();
int padding = getResources()
.getDimensionPixelSize(R.dimen.task_menu_vertical_padding);
params.width = orientationHandler
.getTaskMenuWidth(taskContainer.getThumbnailView()) - (2 * padding);
if (deviceProfile.overviewShowAsGrid) {
// TODO(b/193432925) temporary so it doesn't look terrible on large screen
params.width =
getContext().getResources().getDimensionPixelSize(R.dimen.task_menu_width_grid);
} else {
params.width = orientationHandler
.getTaskMenuWidth(taskContainer.getThumbnailView(),
deviceProfile) - (2 * padding);
}
// Gravity set to Left instead of Start as sTempRect.left measures Left distance not Start
params.gravity = Gravity.LEFT;
setLayoutParams(params);
@@ -276,7 +283,7 @@ public class TaskMenuView extends AbstractFloatingView implements OnScrollChange
mOptionLayout.setShowDividers(SHOW_DIVIDER_MIDDLE);
orientationHandler.setTaskOptionsMenuLayoutOrientation(
mActivity.getDeviceProfile(), mOptionLayout, dividerSpacing, divider);
deviceProfile, mOptionLayout, dividerSpacing, divider);
setPosition(sTempRect.left - insets.left, sTempRect.top - insets.top, 0);
}
+1 -1
View File
@@ -14,5 +14,5 @@
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/system_neutral2_500" android:lStar="35" />
<item android:color="@android:color/system_neutral1_500" android:lStar="35" />
</selector>
+1 -1
View File
@@ -67,7 +67,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/collapse_handle"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
android:visibility="gone"
android:clipToPadding="false" />
+2 -1
View File
@@ -20,7 +20,6 @@
android:id="@+id/widgets_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:clipToPadding="false"
android:layout_below="@id/collapse_handle"
android:descendantFocusability="afterDescendants"
@@ -30,12 +29,14 @@
android:id="@+id/primary_widgets_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
android:clipToPadding="false" />
<com.android.launcher3.widget.picker.WidgetsRecyclerView
android:id="@+id/work_widgets_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
android:clipToPadding="false" />
</com.android.launcher3.workprofile.PersonalWorkPagedView>
@@ -19,7 +19,7 @@
android:layout_below="@id/collapse_handle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
android:clipToPadding="false" />
<!-- SearchAndRecommendationsView without the tab layout as well -->
+3 -2
View File
@@ -128,7 +128,6 @@
<dimen name="work_card_button_height">52dp</dimen>
<dimen name="work_fab_margin">16dp</dimen>
<dimen name="work_profile_footer_padding">20dp</dimen>
<dimen name="work_profile_footer_text_size">16sp</dimen>
<dimen name="work_edu_card_margin">16dp</dimen>
<dimen name="work_edu_card_radius">28dp</dimen>
@@ -324,7 +323,7 @@
<!-- Size of the maximum radius for the enforced rounded rectangles. -->
<dimen name="enforced_rounded_corner_max_radius">16dp</dimen>
<!-- Overview placeholder to compile in Launcer3 without Quickstep -->
<!-- Overview placeholder to compile in Launcher3 without Quickstep -->
<dimen name="task_thumbnail_icon_size">0dp</dimen>
<dimen name="task_thumbnail_icon_drawable_size">0dp</dimen>
<dimen name="task_thumbnail_icon_drawable_size_grid">0dp</dimen>
@@ -342,6 +341,8 @@
<dimen name="recents_page_spacing">0dp</dimen>
<dimen name="recents_page_spacing_grid">0dp</dimen>
<dimen name="split_placeholder_size">110dp</dimen>
<dimen name="task_menu_width_grid">200dp</dimen>
<!-- Workspace grid visualization parameters -->
<dimen name="grid_visualization_rounding_radius">22dp</dimen>
+7 -20
View File
@@ -33,7 +33,6 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.Surface;
import com.android.launcher3.CellLayout.ContainerType;
@@ -215,8 +214,6 @@ public class DeviceProfile {
// Whether Taskbar will inset the bottom of apps by taskbarSize.
public boolean isTaskbarPresentInApps;
public int taskbarSize;
// How much of the bottom inset is due to Taskbar rather than other system elements.
public int nonOverlappingTaskbarInset;
// DragController
public int flingToDeleteThresholdVelocity;
@@ -239,7 +236,7 @@ public class DeviceProfile {
widthPx = windowBounds.bounds.width();
heightPx = windowBounds.bounds.height();
availableWidthPx = windowBounds.availableSize.x;
int nonFinalAvailableHeightPx = windowBounds.availableSize.y;
availableHeightPx = windowBounds.availableSize.y;
mInfo = info;
// If the device's pixel density was scaled (usually via settings for A11y), use the
@@ -266,15 +263,8 @@ public class DeviceProfile {
isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS
&& FeatureFlags.ENABLE_TASKBAR.get();
if (isTaskbarPresent) {
// Taskbar will be added later, but provides bottom insets that we should subtract
// from availableHeightPx.
taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
nonOverlappingTaskbarInset = taskbarSize - windowBounds.insets.bottom;
if (nonOverlappingTaskbarInset > 0) {
nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset;
}
}
availableHeightPx = nonFinalAvailableHeightPx;
edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
@@ -842,7 +832,7 @@ public class DeviceProfile {
padding.right = hotseatBarSizePx;
}
} else {
int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
int hotseatTop = hotseatBarSizePx;
int paddingBottom = hotseatTop + workspacePageIndicatorHeight
+ workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
if (isTablet) {
@@ -853,8 +843,7 @@ public class DeviceProfile {
((inv.numColumns - 1) * cellWidthPx)));
availablePaddingX = (int) Math.min(availablePaddingX,
widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
int hotseatVerticalPadding = isTaskbarPresent ? 0
: hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
int hotseatVerticalPadding = hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
- (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding);
padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
@@ -886,9 +875,9 @@ public class DeviceProfile {
mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
}
} else if (isTaskbarPresent) {
int hotseatHeight = workspacePadding.bottom + taskbarSize;
int hotseatHeight = workspacePadding.bottom;
int taskbarOffset = getTaskbarOffsetY();
int hotseatTopDiff = hotseatHeight - taskbarSize - taskbarOffset;
int hotseatTopDiff = hotseatHeight - taskbarOffset;
int endOffset = ApiWrapper.getHotseatEndOffset(context);
int requiredWidth = iconSizePx * numShownHotseatIcons;
@@ -938,7 +927,8 @@ public class DeviceProfile {
: hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight;
if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) {
return Math.min(qsbBottomMarginPx, freeSpace);
// Note that taskbarSize = 0 unless isTaskbarPresent.
return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace);
} else {
return (int) (freeSpace * QSB_CENTER_FACTOR)
+ (isTaskbarPresent ? taskbarSize : mInsets.bottom);
@@ -1116,10 +1106,7 @@ public class DeviceProfile {
writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
writer.println(prefix + pxToDpStr("nonOverlappingTaskbarInset",
nonOverlappingTaskbarInset));
writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
@@ -47,15 +47,8 @@ public class LauncherRootView extends InsettableFrameLayout {
}
private void handleSystemWindowInsets(Rect insets) {
DeviceProfile dp = mActivity.getDeviceProfile();
// Taskbar provides insets, but we don't want that for most Launcher elements so remove it.
mTempRect.set(insets);
insets = mTempRect;
insets.bottom = Math.max(0, insets.bottom - dp.nonOverlappingTaskbarInset);
// Update device profile before notifying the children.
dp.updateInsets(insets);
mActivity.getDeviceProfile().updateInsets(insets);
boolean resetState = !insets.equals(mInsets);
setInsets(insets);
@@ -86,10 +79,6 @@ public class LauncherRootView extends InsettableFrameLayout {
* get its insets, we calculate them ourselves so they are stable regardless of whether taskbar
* is currently attached.
*
* TODO(b/198798034): Currently we always calculate nav insets as taskbarSize, but then we
* subtract nonOverlappingTaskbarInset in handleSystemWindowInsets(). Instead, we should just
* calculate the normal nav bar height here, and remove nonOverlappingTaskbarInset altogether.
*
* @param oldInsets The system-provided insets, which we are modifying.
* @return The updated insets.
*/
@@ -108,10 +97,8 @@ public class LauncherRootView extends InsettableFrameLayout {
Insets oldNavInsets = oldInsets.getInsets(WindowInsets.Type.navigationBars());
Rect newNavInsets = new Rect(oldNavInsets.left, oldNavInsets.top, oldNavInsets.right,
oldNavInsets.bottom);
if (dp.isTaskbarPresent) {
// TODO (see javadoc): Remove this block and fall into the next one instead.
newNavInsets.bottom = dp.taskbarSize;
} else if (dp.isLandscape) {
if (dp.isLandscape) {
if (dp.isTablet) {
newNavInsets.bottom = ResourceUtils.getNavbarSize(
"navigation_bar_height_landscape", resources);
-2
View File
@@ -314,8 +314,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
Rect padding = grid.workspacePadding;
setPadding(padding.left, padding.top, padding.right, padding.bottom);
mInsets.set(insets);
// Increase our bottom insets so we don't overlap with the taskbar.
mInsets.bottom += grid.nonOverlappingTaskbarInset;
if (mWorkspaceFadeInAdjacentScreens) {
// In landscape mode the page spacing is set to the default.
@@ -17,15 +17,11 @@ package com.android.launcher3.allapps;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -34,7 +30,7 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.Process;
import android.text.Selection;
import android.os.UserManager;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;
import android.util.Log;
@@ -88,11 +84,12 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
public static final float FLING_VELOCITY_MULTIPLIER = 1200f;
private final Paint mHeaderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Rect mInsets = new Rect();
protected final BaseDraggingActivity mLauncher;
protected final AdapterHolder[] mAH;
private final ItemInfoMatcher mPersonalMatcher = ItemInfoMatcher.ofUser(Process.myUserHandle());
private final ItemInfoMatcher mWorkMatcher = mPersonalMatcher.negate();
protected final ItemInfoMatcher mPersonalMatcher = ItemInfoMatcher.ofUser(
Process.myUserHandle());
private final AllAppsStore mAllAppsStore = new AllAppsStore();
private final RecyclerView.OnScrollListener mScrollListener =
@@ -102,6 +99,8 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
updateHeaderScroll(((AllAppsRecyclerView) recyclerView).getCurrentScrollY());
}
};
private final WorkProfileManager mWorkManager;
private final Paint mNavBarScrimPaint;
private int mNavBarScrimHeight = 0;
@@ -111,8 +110,6 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
private AllAppsPagedView mViewPager;
protected FloatingHeaderView mHeader;
private float mHeaderTop;
private WorkModeSwitch mWorkModeSwitch;
private SpannableStringBuilder mSearchQueryBuilder = null;
@@ -124,10 +121,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
protected RecyclerViewFastScroller mTouchHandler;
protected final Point mFastScrollerOffset = new Point();
private Rect mInsets = new Rect();
private SearchAdapterProvider mSearchAdapterProvider;
private WorkAdapterProvider mWorkAdapterProvider;
private final int mScrimColor;
private final int mHeaderProtectionColor;
private final float mHeaderThreshold;
@@ -156,15 +150,11 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mLauncher.addOnDeviceProfileChangeListener(this);
mSearchAdapterProvider = mLauncher.createSearchAdapterProvider(this);
mSearchQueryBuilder = new SpannableStringBuilder();
Selection.setSelection(mSearchQueryBuilder, 0);
mAH = new AdapterHolder[2];
mWorkAdapterProvider = new WorkAdapterProvider(mLauncher, () -> {
if (mAH[AdapterHolder.WORK] != null) {
mAH[AdapterHolder.WORK].appsList.updateAdapterItems();
}
});
mWorkManager = new WorkProfileManager(mLauncher.getSystemService(UserManager.class), this,
Utilities.getPrefs(mLauncher));
mAH[AdapterHolder.MAIN] = new AdapterHolder(false /* isWork */);
mAH[AdapterHolder.WORK] = new AdapterHolder(true /* isWork */);
@@ -220,8 +210,8 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
return mAllAppsStore;
}
public WorkModeSwitch getWorkModeSwitch() {
return mWorkModeSwitch;
public WorkProfileManager getWorkManager() {
return mWorkManager;
}
@Override
@@ -240,7 +230,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
private void onAppsUpdated() {
boolean hasWorkApps = false;
for (AppInfo app : mAllAppsStore.getApps()) {
if (mWorkMatcher.matches(app, null)) {
if (mWorkManager.getMatcher().matches(app, null)) {
hasWorkApps = true;
break;
}
@@ -248,20 +238,12 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mHasWorkApps = hasWorkApps;
if (!mAH[AdapterHolder.MAIN].appsList.hasFilter()) {
rebindAdapters();
if (mHasWorkApps) {
resetWorkProfile();
if (hasWorkApps) {
mWorkManager.reset();
}
}
}
private void resetWorkProfile() {
boolean isEnabled = !mAllAppsStore.hasModelFlag(FLAG_QUIET_MODE_ENABLED);
if (mWorkModeSwitch != null) {
mWorkModeSwitch.updateCurrentState(isEnabled);
}
mWorkAdapterProvider.updateCurrentState(isEnabled);
}
/**
* Returns whether the view itself will handle the touch event or not.
*/
@@ -460,7 +442,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
if (mUsingTabs) {
mAH[AdapterHolder.MAIN].setup(mViewPager.getChildAt(0), mPersonalMatcher);
mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkMatcher);
mAH[AdapterHolder.WORK].setup(mViewPager.getChildAt(1), mWorkManager.getMatcher());
mAH[AdapterHolder.WORK].recyclerView.setId(R.id.apps_list_view_work);
mViewPager.getPageIndicator().setActiveMarker(AdapterHolder.MAIN);
findViewById(R.id.tab_personal)
@@ -488,34 +470,12 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAllAppsStore.registerIconContainer(mAH[AdapterHolder.WORK].recyclerView);
}
private void setupWorkToggle() {
removeWorkToggle();
if (Utilities.ATLEAST_P) {
mWorkModeSwitch = (WorkModeSwitch) mLauncher.getLayoutInflater().inflate(
R.layout.work_mode_fab, this, false);
this.addView(mWorkModeSwitch);
mWorkModeSwitch.setInsets(mInsets);
mWorkModeSwitch.post(() -> {
mAH[AdapterHolder.WORK].applyPadding();
resetWorkProfile();
});
}
}
private void removeWorkToggle() {
if (mWorkModeSwitch == null) return;
if (mWorkModeSwitch.getParent() == this) {
this.removeView(mWorkModeSwitch);
}
mWorkModeSwitch = null;
}
private void replaceRVContainer(boolean showTabs) {
for (int i = 0; i < mAH.length; i++) {
AllAppsRecyclerView rv = mAH[i].recyclerView;
if (rv != null) {
rv.setLayoutManager(null);
rv.setAdapter(null);
for (AdapterHolder adapterHolder : mAH) {
if (adapterHolder.recyclerView != null) {
adapterHolder.recyclerView.setLayoutManager(null);
adapterHolder.recyclerView.setAdapter(null);
}
}
View oldView = getRecyclerViewContainer();
@@ -532,10 +492,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mViewPager = (AllAppsPagedView) newView;
mViewPager.initParentViews(this);
mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
setupWorkToggle();
mWorkManager.attachWorkModeSwitch();
} else {
mWorkManager.detachWorkModeSwitch();
mViewPager = null;
removeWorkToggle();
}
}
@@ -550,11 +510,8 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAH[currentActivePage].recyclerView.bindFastScrollbar();
}
reset(true /* animate */);
if (mWorkModeSwitch != null) {
mWorkModeSwitch.setWorkTabVisible(currentActivePage == AdapterHolder.WORK
&& mAllAppsStore.hasModelFlag(
FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION));
}
mWorkManager.onActivePageChanged(currentActivePage);
}
// Used by tests only
@@ -626,7 +583,6 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
mAH[i].recyclerView.scrollToTop();
}
}
mHeaderTop = mHeader.getTop();
}
public void setLastSearchQuery(String query) {
@@ -731,7 +687,6 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
public static final int MAIN = 0;
public static final int WORK = 1;
private ItemInfoMatcher mInfoMatcher;
private final boolean mIsWork;
public final AllAppsGridAdapter adapter;
final LinearLayoutManager layoutManager;
@@ -739,17 +694,16 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
final Rect padding = new Rect();
AllAppsRecyclerView recyclerView;
boolean verticalFadingEdge;
private View mOverlay;
boolean mWorkDisabled;
AdapterHolder(boolean isWork) {
mIsWork = isWork;
appsList = new AlphabeticalAppsList(mLauncher, mAllAppsStore,
isWork ? mWorkAdapterProvider : null);
isWork ? mWorkManager.getAdapterProvider() : null);
BaseAdapterProvider[] adapterProviders =
isWork ? new BaseAdapterProvider[]{mSearchAdapterProvider, mWorkAdapterProvider}
isWork ? new BaseAdapterProvider[]{mSearchAdapterProvider,
mWorkManager.getAdapterProvider()}
: new BaseAdapterProvider[]{mSearchAdapterProvider};
adapter = new AllAppsGridAdapter(mLauncher, getLayoutInflater(), appsList,
@@ -759,7 +713,6 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
}
void setup(@NonNull View rv, @Nullable ItemInfoMatcher matcher) {
mInfoMatcher = matcher;
appsList.updateItemFilter(matcher);
recyclerView = (AllAppsRecyclerView) rv;
recyclerView.setEdgeEffectFactory(createEdgeEffectFactory());
@@ -782,12 +735,10 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
void applyPadding() {
if (recyclerView != null) {
Resources res = getResources();
int switchH = res.getDimensionPixelSize(R.dimen.work_profile_footer_padding) * 2
+ mInsets.bottom + Utilities.calculateTextHeight(
res.getDimension(R.dimen.work_profile_footer_text_size));
int bottomOffset = mWorkModeSwitch != null && mIsWork ? switchH : 0;
int bottomOffset = 0;
if (mIsWork && mWorkManager.getWorkModeSwitch() != null) {
bottomOffset = mInsets.bottom + mWorkManager.getWorkModeSwitch().getHeight();
}
recyclerView.setPadding(padding.left, padding.top, padding.right,
padding.bottom + bottomOffset);
}
@@ -15,12 +15,11 @@
*/
package com.android.launcher3.allapps;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import java.util.ArrayList;
@@ -33,13 +32,13 @@ public class WorkAdapterProvider extends BaseAdapterProvider {
private static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 20;
private static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 21;
private final Runnable mRefreshCB;
private final BaseDraggingActivity mLauncher;
private boolean mEnabled;
WorkAdapterProvider(BaseDraggingActivity launcher, Runnable refreshCallback) {
mLauncher = launcher;
mRefreshCB = refreshCallback;
@WorkProfileManager.WorkProfileState
private int mState;
private SharedPreferences mPreferences;
WorkAdapterProvider(SharedPreferences prefs) {
mPreferences = prefs;
}
@Override
@@ -61,19 +60,19 @@ public class WorkAdapterProvider extends BaseAdapterProvider {
* returns whether or not work apps should be visible in work tab.
*/
public boolean shouldShowWorkApps() {
return mEnabled;
return mState != WorkProfileManager.STATE_DISABLED;
}
/**
* Adds work profile specific adapter items to adapterItems and returns number of items added
*/
public int addWorkItems(ArrayList<AllAppsGridAdapter.AdapterItem> adapterItems) {
if (!mEnabled) {
if (mState == WorkProfileManager.STATE_DISABLED) {
//add disabled card here.
AllAppsGridAdapter.AdapterItem disabledCard = new AllAppsGridAdapter.AdapterItem();
disabledCard.viewType = VIEW_TYPE_WORK_DISABLED_CARD;
adapterItems.add(disabledCard);
} else if (!isEduSeen()) {
} else if (mState == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
AllAppsGridAdapter.AdapterItem eduCard = new AllAppsGridAdapter.AdapterItem();
eduCard.viewType = VIEW_TYPE_WORK_EDU_CARD;
adapterItems.add(eduCard);
@@ -85,9 +84,8 @@ public class WorkAdapterProvider extends BaseAdapterProvider {
/**
* Sets the current state of work profile
*/
public void updateCurrentState(boolean isEnabled) {
mEnabled = isEnabled;
mRefreshCB.run();
public void updateCurrentState(@WorkProfileManager.WorkProfileState int state) {
mState = state;
}
@Override
@@ -101,6 +99,6 @@ public class WorkAdapterProvider extends BaseAdapterProvider {
}
private boolean isEduSeen() {
return Utilities.getPrefs(mLauncher).getInt(KEY_WORK_EDU_STEP, 0) != 0;
return mPreferences.getInt(KEY_WORK_EDU_STEP, 0) != 0;
}
}
@@ -16,43 +16,41 @@
package com.android.launcher3.allapps;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
/**
* Work profile toggle switch shown at the bottom of AllApps work tab
*/
public class WorkModeSwitch extends Button implements Insettable, View.OnClickListener {
public class WorkModeSwitch extends Button implements Insettable, View.OnClickListener,
KeyboardInsetAnimationCallback.KeyboardInsetListener,
PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
private Rect mInsets = new Rect();
private static final int FLAG_FADE_ONGOING = 1 << 1;
private static final int FLAG_TRANSLATION_ONGOING = 1 << 2;
private static final int FLAG_PROFILE_TOGGLE_ONGOING = 1 << 3;
private final Rect mInsets = new Rect();
private int mFlags;
private boolean mWorkEnabled;
private boolean mOnWorkTab;
@Nullable
private KeyboardInsetAnimationCallback mKeyboardInsetAnimationCallback;
private boolean mWorkTabVisible;
public WorkModeSwitch(Context context) {
this(context, null, 0);
}
@@ -71,9 +69,12 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
setSelected(true);
setOnClickListener(this);
if (Utilities.ATLEAST_R) {
mKeyboardInsetAnimationCallback = new KeyboardInsetAnimationCallback(this);
setWindowInsetsAnimationCallback(mKeyboardInsetAnimationCallback);
KeyboardInsetAnimationCallback keyboardInsetAnimationCallback =
new KeyboardInsetAnimationCallback(this);
setWindowInsetsAnimationCallback(keyboardInsetAnimationCallback);
}
DeviceProfile grid = BaseDraggingActivity.fromContext(getContext()).getDeviceProfile();
setInsets(grid.getInsets());
}
@Override
@@ -87,57 +88,57 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
}
}
/**
* Animates in/out work profile toggle panel based on the tab user is on
*/
public void setWorkTabVisible(boolean workTabVisible) {
clearAnimation();
mWorkTabVisible = workTabVisible;
if (workTabVisible && mWorkEnabled) {
setEnabled(true);
setVisibility(VISIBLE);
setAlpha(0);
animate().alpha(1).start();
} else {
animate().alpha(0).withEndAction(() -> this.setVisibility(GONE)).start();
}
@Override
public void onActivePageChanged(int page) {
mOnWorkTab = page == AllAppsContainerView.AdapterHolder.WORK;
updateVisibility();
}
@Override
public void onClick(View view) {
if (Utilities.ATLEAST_P && mWorkTabVisible) {
setEnabled(false);
Launcher.fromContext(getContext()).getStatsLogManager().logger().log(
LAUNCHER_TURN_OFF_WORK_APPS_TAP);
UI_HELPER_EXECUTOR.post(() -> setWorkProfileEnabled(getContext(), false));
if (Utilities.ATLEAST_P && isEnabled()) {
setFlag(FLAG_PROFILE_TOGGLE_ONGOING);
Launcher launcher = Launcher.getLauncher(getContext());
launcher.getStatsLogManager().logger().log(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
launcher.getAppsView().getWorkManager().setWorkProfileEnabled(false);
}
}
@Override
public boolean isEnabled() {
return super.isEnabled() && getVisibility() == VISIBLE && mFlags == 0;
}
/**
* Sets the enabled or disabled state of the button
*/
public void updateCurrentState(boolean active) {
removeFlag(FLAG_PROFILE_TOGGLE_ONGOING);
mWorkEnabled = active;
setEnabled(true);
setVisibility(active ? VISIBLE : GONE);
updateVisibility();
}
@RequiresApi(Build.VERSION_CODES.P)
public static Boolean setWorkProfileEnabled(Context context, boolean enabled) {
UserManager userManager = context.getSystemService(UserManager.class);
boolean showConfirm = false;
for (UserHandle userProfile : UserCache.INSTANCE.get(context).getUserProfiles()) {
if (Process.myUserHandle().equals(userProfile)) {
continue;
}
showConfirm |= !userManager.requestQuietModeEnabled(!enabled, userProfile);
private void updateVisibility() {
clearAnimation();
if (mWorkEnabled && mOnWorkTab) {
setFlag(FLAG_FADE_ONGOING);
setVisibility(VISIBLE);
setAlpha(0);
animate().alpha(1).withEndAction(() -> removeFlag(FLAG_FADE_ONGOING)).start();
} else if (getVisibility() != GONE) {
setFlag(FLAG_FADE_ONGOING);
animate().alpha(0).withEndAction(() -> {
removeFlag(FLAG_FADE_ONGOING);
this.setVisibility(GONE);
}).start();
}
return showConfirm;
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (Utilities.ATLEAST_R && mWorkTabVisible) {
if (Utilities.ATLEAST_R && isEnabled()) {
setTranslationY(0);
if (insets.isVisible(WindowInsets.Type.ime())) {
Insets keyboardInsets = insets.getInsets(WindowInsets.Type.ime());
@@ -146,4 +147,22 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
}
return insets;
}
@Override
public void onTranslationStart() {
setFlag(FLAG_TRANSLATION_ONGOING);
}
@Override
public void onTranslationEnd() {
removeFlag(FLAG_TRANSLATION_ONGOING);
}
private void setFlag(int flag) {
mFlags |= flag;
}
private void removeFlag(int flag) {
mFlags &= ~flag;
}
}
@@ -16,7 +16,6 @@
package com.android.launcher3.allapps;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_ON_WORK_APPS_TAP;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.Context;
import android.content.res.Configuration;
@@ -62,8 +61,8 @@ public class WorkPausedCard extends LinearLayout implements View.OnClickListener
public void onClick(View view) {
if (Utilities.ATLEAST_P) {
setEnabled(false);
mLauncher.getAppsView().getWorkManager().setWorkProfileEnabled(true);
mLauncher.getStatsLogManager().logger().log(LAUNCHER_TURN_ON_WORK_APPS_TAP);
UI_HELPER_EXECUTOR.post(() -> WorkModeSwitch.setWorkProfileEnabled(getContext(), true));
}
}
@@ -0,0 +1,175 @@
/*
* Copyright (C) 2021 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.allapps;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import androidx.annotation.IntDef;
import androidx.annotation.RequiresApi;
import com.android.launcher3.R;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Companion class for {@link AllAppsContainerView} to manage work tab and personal tab related
* logic based on {@link WorkProfileState}?
*/
public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActivePageChangedListener {
private static final String TAG = "WorkProfileManager";
public static final int STATE_ENABLED = 1;
public static final int STATE_DISABLED = 2;
public static final int STATE_TRANSITION = 3;
private final UserManager mUserManager;
/**
* Work profile manager states
*/
@IntDef(value = {
STATE_ENABLED,
STATE_DISABLED,
STATE_TRANSITION
})
@Retention(RetentionPolicy.SOURCE)
public @interface WorkProfileState {
}
private final AllAppsContainerView mAllApps;
private final WorkAdapterProvider mAdapterProvider;
private final ItemInfoMatcher mMatcher;
private WorkModeSwitch mWorkModeSwitch;
@WorkProfileState
private int mCurrentState;
public WorkProfileManager(UserManager userManager, AllAppsContainerView allApps,
SharedPreferences preferences) {
mUserManager = userManager;
mAllApps = allApps;
mAdapterProvider = new WorkAdapterProvider(preferences);
mMatcher = mAllApps.mPersonalMatcher.negate();
}
/**
* Posts quite mode enable/disable call for work profile user
*/
@RequiresApi(Build.VERSION_CODES.P)
public void setWorkProfileEnabled(boolean enabled) {
updateCurrentState(STATE_TRANSITION);
UI_HELPER_EXECUTOR.post(() -> {
for (UserHandle userProfile : mUserManager.getUserProfiles()) {
if (Process.myUserHandle().equals(userProfile)) {
continue;
}
mUserManager.requestQuietModeEnabled(!enabled, userProfile);
}
});
}
@Override
public void onActivePageChanged(int page) {
if (mWorkModeSwitch != null) {
mWorkModeSwitch.onActivePageChanged(page);
}
}
/**
* Requests work profile state from {@link AllAppsStore} and updates work profile related views
*/
public void reset() {
boolean isEnabled = !mAllApps.getAppsStore().hasModelFlag(FLAG_QUIET_MODE_ENABLED);
updateCurrentState(isEnabled ? STATE_ENABLED : STATE_DISABLED);
}
private void updateCurrentState(@WorkProfileState int currentState) {
mCurrentState = currentState;
mAdapterProvider.updateCurrentState(currentState);
if (getAH() != null) {
getAH().appsList.updateAdapterItems();
}
if (mWorkModeSwitch != null) {
mWorkModeSwitch.updateCurrentState(currentState == STATE_ENABLED);
}
}
/**
* Creates and attaches for profile toggle button to {@link AllAppsContainerView}
*/
public void attachWorkModeSwitch() {
if (!mAllApps.getAppsStore().hasModelFlag(
FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION)) {
Log.e(TAG, "Unable to attach widget; Missing required permissions");
return;
}
if (mWorkModeSwitch == null) {
mWorkModeSwitch = (WorkModeSwitch) mAllApps.getLayoutInflater().inflate(
R.layout.work_mode_fab, mAllApps, false);
}
if (mWorkModeSwitch.getParent() != mAllApps) {
mAllApps.addView(mWorkModeSwitch);
}
if (getAH() != null) {
getAH().applyPadding();
}
mWorkModeSwitch.updateCurrentState(mCurrentState == STATE_ENABLED);
}
/**
* Removes work profile toggle button from {@link AllAppsContainerView}
*/
public void detachWorkModeSwitch() {
if (mWorkModeSwitch != null && mWorkModeSwitch.getParent() == mAllApps) {
mAllApps.removeView(mWorkModeSwitch);
}
mWorkModeSwitch = null;
}
public WorkAdapterProvider getAdapterProvider() {
return mAdapterProvider;
}
public ItemInfoMatcher getMatcher() {
return mMatcher;
}
public WorkModeSwitch getWorkModeSwitch() {
return mWorkModeSwitch;
}
private AllAppsContainerView.AdapterHolder getAH() {
return mAllApps.mAH[AllAppsContainerView.AdapterHolder.WORK];
}
}
@@ -65,7 +65,32 @@ public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callba
public WindowInsetsAnimation.Bounds onStart(WindowInsetsAnimation animation,
WindowInsetsAnimation.Bounds bounds) {
mTerminalTranslation = mView.getTranslationY();
mView.setTranslationY(mInitialTranslation);
if (mView instanceof KeyboardInsetListener) {
((KeyboardInsetListener) mView).onTranslationStart();
}
return super.onStart(animation, bounds);
}
@Override
public void onEnd(WindowInsetsAnimation animation) {
if (mView instanceof KeyboardInsetListener) {
((KeyboardInsetListener) mView).onTranslationEnd();
}
super.onEnd(animation);
}
/**
* Interface Allowing views to listen for keyboard translation events
*/
public interface KeyboardInsetListener {
/**
* Called from {@link KeyboardInsetAnimationCallback#onStart}
*/
void onTranslationStart();
/**
* Called from {@link KeyboardInsetAnimationCallback#onEnd}
*/
void onTranslationEnd();
}
}
@@ -268,9 +268,7 @@ public class WorkspacePageIndicator extends View implements Insettable, PageIndi
} else {
lp.leftMargin = lp.rightMargin = 0;
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
lp.bottomMargin = grid.isTaskbarPresent
? grid.workspacePadding.bottom + grid.taskbarSize
: grid.hotseatBarSizePx + insets.bottom;
lp.bottomMargin = grid.hotseatBarSizePx + insets.bottom;
}
setLayoutParams(lp);
}
@@ -59,11 +59,10 @@ public class SpringLoadedState extends LauncherState {
float scale = grid.workspaceSpringLoadShrinkFactor;
Rect insets = launcher.getDragLayer().getInsets();
int insetsBottom = grid.isTaskbarPresent ? grid.taskbarSize : insets.bottom;
float scaledHeight = scale * ws.getNormalChildHeight();
float shrunkTop = insets.top + grid.dropTargetBarSizePx;
float shrunkBottom = ws.getMeasuredHeight() - insetsBottom
float shrunkBottom = ws.getMeasuredHeight() - insets.bottom
- grid.workspacePadding.bottom
- grid.workspaceSpringLoadedBottomSpace;
float totalShrunkSpace = shrunkBottom - shrunkTop;
@@ -116,9 +116,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
return getUIProperty(Bundle::putParcelable, activity -> {
WindowInsets insets = activity.getWindow()
.getDecorView().getRootWindowInsets();
return Insets.subtract(
insets.getSystemWindowInsets(),
Insets.of(0, 0, 0, mDeviceProfile.nonOverlappingTaskbarInset));
return insets.getSystemWindowInsets();
}, this::getCurrentActivity);
}
@@ -20,7 +20,8 @@ import static android.view.Gravity.CENTER_VERTICAL;
import static android.view.Gravity.END;
import static android.view.Gravity.START;
import static android.view.Gravity.TOP;
import static android.widget.ListPopupWindow.WRAP_CONTENT;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
@@ -257,26 +258,28 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler {
}
@Override
public float getTaskMenuX(float x, View thumbnailView, int overScroll) {
public float getTaskMenuX(float x, View thumbnailView, int overScroll,
DeviceProfile deviceProfile) {
return thumbnailView.getMeasuredWidth() + x;
}
@Override
public float getTaskMenuY(float y, View thumbnailView, int overScroll) {
return y + overScroll;
return y + overScroll +
(thumbnailView.getMeasuredHeight() - thumbnailView.getMeasuredWidth()) / 2f;
}
@Override
public int getTaskMenuWidth(View view) {
return view.getMeasuredHeight();
public int getTaskMenuWidth(View view, DeviceProfile deviceProfile) {
return view.getMeasuredWidth();
}
@Override
public void setTaskOptionsMenuLayoutOrientation(DeviceProfile deviceProfile,
LinearLayout taskMenuLayout, int dividerSpacing,
ShapeDrawable dividerDrawable) {
taskMenuLayout.setOrientation(LinearLayout.HORIZONTAL);
dividerDrawable.setIntrinsicWidth(dividerSpacing);
taskMenuLayout.setOrientation(LinearLayout.VERTICAL);
dividerDrawable.setIntrinsicHeight(dividerSpacing);
taskMenuLayout.setDividerDrawable(dividerDrawable);
}
@@ -284,12 +287,9 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler {
public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp,
LinearLayout viewGroup, DeviceProfile deviceProfile) {
// Phone fake landscape
viewGroup.setOrientation(LinearLayout.VERTICAL);
lp.width = 0;
viewGroup.setOrientation(LinearLayout.HORIZONTAL);
lp.width = MATCH_PARENT;
lp.height = WRAP_CONTENT;
lp.weight = 1;
Utilities.setStartMarginForView(viewGroup.findViewById(R.id.text), 0);
Utilities.setStartMarginForView(viewGroup.findViewById(R.id.icon), 0);
}
@Override
@@ -171,9 +171,16 @@ public interface PagedOrientationHandler {
void setSplitIconParams(View primaryIconView, View secondaryIconView,
int taskIconHeight, Rect primarySnapshotBounds, Rect secondarySnapshotBounds,
boolean isRtl, DeviceProfile deviceProfile, StagedSplitBounds splitConfig);
float getTaskMenuX(float x, View thumbnailView, int overScroll);
/*
* The following two methods try to center the TaskMenuView in landscape by finding the center
* of the thumbnail view and then subtracting half of the taskMenu width. In this case, the
* taskMenu width is the same size as the thumbnail width (what got set below in
* getTaskMenuWidth()), so we directly use that in the calculations.
*/
float getTaskMenuX(float x, View thumbnailView, int overScroll, DeviceProfile deviceProfile);
float getTaskMenuY(float y, View thumbnailView, int overScroll);
int getTaskMenuWidth(View view);
int getTaskMenuWidth(View view, DeviceProfile deviceProfile);
/**
* Sets linear layout orientation for {@link com.android.launcher3.popup.SystemShortcut} items
* inside task menu view.
@@ -20,6 +20,7 @@ import static android.view.Gravity.BOTTOM;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Gravity.START;
import static android.view.Gravity.TOP;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
@@ -264,8 +265,14 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler {
}
@Override
public float getTaskMenuX(float x, View thumbnailView, int overScroll) {
return x + overScroll;
public float getTaskMenuX(float x, View thumbnailView, int overScroll,
DeviceProfile deviceProfile) {
if (deviceProfile.isLandscape) {
return x + overScroll
+ (thumbnailView.getMeasuredWidth() - thumbnailView.getMeasuredHeight()) / 2f;
} else {
return x + overScroll;
}
}
@Override
@@ -274,43 +281,27 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler {
}
@Override
public int getTaskMenuWidth(View view) {
return view.getMeasuredWidth();
public int getTaskMenuWidth(View view, DeviceProfile deviceProfile) {
return deviceProfile.isLandscape && !deviceProfile.overviewShowAsGrid ?
view.getMeasuredHeight() :
view.getMeasuredWidth();
}
@Override
public void setTaskOptionsMenuLayoutOrientation(DeviceProfile deviceProfile,
LinearLayout taskMenuLayout, int dividerSpacing,
ShapeDrawable dividerDrawable) {
if (deviceProfile.isLandscape && !deviceProfile.isTablet) {
// Phone landscape
taskMenuLayout.setOrientation(LinearLayout.HORIZONTAL);
dividerDrawable.setIntrinsicWidth(dividerSpacing);
} else {
// Phone Portrait, LargeScreen Landscape/Portrait
taskMenuLayout.setOrientation(LinearLayout.VERTICAL);
dividerDrawable.setIntrinsicHeight(dividerSpacing);
}
taskMenuLayout.setOrientation(LinearLayout.VERTICAL);
dividerDrawable.setIntrinsicHeight(dividerSpacing);
taskMenuLayout.setDividerDrawable(dividerDrawable);
}
@Override
public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp,
LinearLayout viewGroup, DeviceProfile deviceProfile) {
if (deviceProfile.isLandscape && !deviceProfile.isTablet) {
// Phone landscape
viewGroup.setOrientation(LinearLayout.VERTICAL);
lp.width = 0;
lp.weight = 1;
Utilities.setStartMarginForView(viewGroup.findViewById(R.id.text), 0);
Utilities.setStartMarginForView(viewGroup.findViewById(R.id.icon), 0);
} else {
// Phone Portrait, LargeScreen Landscape/Portrait
viewGroup.setOrientation(LinearLayout.HORIZONTAL);
lp.width = LinearLayout.LayoutParams.MATCH_PARENT;
}
lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
viewGroup.setOrientation(LinearLayout.HORIZONTAL);
lp.width = LinearLayout.LayoutParams.MATCH_PARENT;
lp.height = WRAP_CONTENT;
}
@Override
@@ -81,13 +81,15 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler {
}
@Override
public float getTaskMenuX(float x, View thumbnailView, int overScroll) {
public float getTaskMenuX(float x, View thumbnailView, int overScroll,
DeviceProfile deviceProfile) {
return x;
}
@Override
public float getTaskMenuY(float y, View thumbnailView, int overScroll) {
return y + thumbnailView.getMeasuredHeight() + overScroll;
return y + overScroll +
(thumbnailView.getMeasuredHeight() + thumbnailView.getMeasuredWidth()) / 2f;
}
@Override
@@ -113,7 +113,6 @@ public class RecyclerViewFastScroller extends View {
private boolean mIsThumbDetached;
private final boolean mCanThumbDetach;
private boolean mIgnoreDragGesture;
private boolean mIsRecyclerViewFirstChildInParent = true;
private long mDownTimeStampMillis;
// This is the offset from the top of the scrollbar when the user first starts touching. To
@@ -438,9 +437,7 @@ public class RecyclerViewFastScroller extends View {
return false;
}
getHitRect(sTempRect);
if (mIsRecyclerViewFirstChildInParent) {
sTempRect.top += mRv.getScrollBarTop();
}
sTempRect.top += mRv.getScrollBarTop();
if (outOffset != null) {
outOffset.set(sTempRect.left, sTempRect.top);
}
@@ -453,8 +450,4 @@ public class RecyclerViewFastScroller extends View {
// alpha is so low, it does not matter.
return false;
}
public void setIsRecyclerViewFirstChildInParent(boolean isRecyclerViewFirstChildInParent) {
mIsRecyclerViewFirstChildInParent = isRecyclerViewFirstChildInParent;
}
}
@@ -198,7 +198,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
.setOnClickListener((View view) -> mViewPager.snapToPage(0));
findViewById(R.id.tab_work)
.setOnClickListener((View view) -> mViewPager.snapToPage(1));
fastScroller.setIsRecyclerViewFirstChildInParent(false);
mAdapters.get(AdapterHolder.WORK).setup(findViewById(R.id.work_widgets_list_view));
} else {
mViewPager = null;
@@ -334,13 +333,18 @@ public class WidgetsFullSheet extends BaseWidgetSheet
setContentViewChildHorizontalMargin(mSearchScrollController.mContainer,
contentHorizontalMarginInPx);
if (mViewPager == null) {
setContentViewChildHorizontalMargin(
setContentViewChildHorizontalPadding(
mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView,
contentHorizontalMarginInPx);
} else {
setContentViewChildHorizontalMargin(mViewPager, contentHorizontalMarginInPx);
setContentViewChildHorizontalPadding(
mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView,
contentHorizontalMarginInPx);
setContentViewChildHorizontalPadding(
mAdapters.get(AdapterHolder.WORK).mWidgetsRecyclerView,
contentHorizontalMarginInPx);
}
setContentViewChildHorizontalMargin(
setContentViewChildHorizontalPadding(
mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView,
contentHorizontalMarginInPx);
}
@@ -352,6 +356,11 @@ public class WidgetsFullSheet extends BaseWidgetSheet
layoutParams.setMarginEnd(horizontalMarginInPx);
}
private static void setContentViewChildHorizontalPadding(View view, int horizontalPaddingInPx) {
view.setPadding(horizontalPaddingInPx, view.getPaddingTop(), horizontalPaddingInPx,
view.getPaddingBottom());
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
doMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -153,6 +153,8 @@ public abstract class AbstractLauncherUiTest {
public static String dumpHprofData() {
String result;
if (sDumpWasGenerated) {
Log.d("b/195319692", "dump has already been generated by another test",
new Exception());
result = "dump has already been generated by another test";
} else {
try {
@@ -167,6 +169,7 @@ public abstract class AbstractLauncherUiTest {
"am dumpheap " + device.getLauncherPackageName() + " " + fileName);
}
sDumpWasGenerated = true;
Log.d("b/195319692", "sDumpWasGenerated := true", new Exception());
result = "memory dump filename: " + fileName;
} catch (Throwable e) {
Log.e(TAG, "dumpHprofData failed", e);