diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
index d1fa2fd3ef..5b301433c3 100644
--- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
@@ -222,7 +222,7 @@ public abstract class BaseQuickstepLauncher extends Launcher
mTaskbarController.cleanup();
mTaskbarController = null;
}
- if (FeatureFlags.ENABLE_TASKBAR.get() && mDeviceProfile.isTablet) {
+ if (mDeviceProfile.isTaskbarPresent) {
TaskbarActivityContext taskbarActivityContext = new TaskbarActivityContext(this);
mTaskbarController = new TaskbarController(this,
taskbarActivityContext.getTaskbarContainerView());
diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
index f53a5efe95..7d494c28bf 100644
--- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
+++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
@@ -130,7 +130,7 @@ public class PredictionRowView extends LinearLayout implements
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
mDecorationHandler = new AllAppsSectionDecorator.SectionDecorationHandler(getContext(),
- false);
+ false, 0, true, true);
}
updateVisibility();
@@ -164,7 +164,7 @@ public class PredictionRowView extends LinearLayout implements
for (int i = 0; i < childrenCount; i++) {
mDecorationHandler.extendBounds(getChildAt(i));
}
- mDecorationHandler.onDraw(canvas);
+ mDecorationHandler.onGroupDraw(canvas);
mDecorationHandler.onFocusDraw(canvas, getFocusedChild());
mLauncher.getAppsView().getActiveRecyclerView().invalidateItemDecorations();
}
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarController.java
index ab05fbf036..5dddaf3ed0 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarController.java
@@ -89,8 +89,7 @@ public class TaskbarController {
mTaskbarView = mTaskbarContainerView.findViewById(R.id.taskbar_view);
mTaskbarView.construct(createTaskbarViewCallbacks());
mWindowManager = mLauncher.getWindowManager();
- mTaskbarSize = new Point(MATCH_PARENT,
- mLauncher.getResources().getDimensionPixelSize(R.dimen.taskbar_size));
+ mTaskbarSize = new Point(MATCH_PARENT, mLauncher.getDeviceProfile().taskbarSize);
mTaskbarStateHandler = mLauncher.getTaskbarStateHandler();
mTaskbarVisibilityController = new TaskbarVisibilityController(mLauncher,
createTaskbarVisibilityControllerCallbacks());
@@ -233,14 +232,10 @@ public class TaskbarController {
}
private void removeFromWindowManager() {
- if (mTaskbarContainerView.isAttachedToWindow()) {
- mWindowManager.removeViewImmediate(mTaskbarContainerView);
- }
+ mWindowManager.removeViewImmediate(mTaskbarContainerView);
}
private void addToWindowManager() {
- removeFromWindowManager();
-
final int gravity = Gravity.BOTTOM;
mWindowLayoutParams = new WindowManager.LayoutParams(
@@ -378,7 +373,8 @@ public class TaskbarController {
* @return Whether the given View is in the same window as Taskbar.
*/
public boolean isViewInTaskbar(View v) {
- return mTaskbarContainerView.getWindowId().equals(v.getWindowId());
+ return mTaskbarContainerView.isAttachedToWindow()
+ && mTaskbarContainerView.getWindowId().equals(v.getWindowId());
}
/**
diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml
index 0041c9a7c8..8ed16c7493 100644
--- a/res/layout/all_apps.xml
+++ b/res/layout/all_apps.xml
@@ -40,35 +40,7 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/personal_work_tabs.xml b/res/layout/personal_work_tabs.xml
new file mode 100644
index 0000000000..8f29997802
--- /dev/null
+++ b/res/layout/personal_work_tabs.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/secondary_launcher.xml b/res/layout/secondary_launcher.xml
index fdf4446c96..e3c60ecb5f 100644
--- a/res/layout/secondary_launcher.xml
+++ b/res/layout/secondary_launcher.xml
@@ -67,7 +67,7 @@
android:paddingTop="@dimen/all_apps_header_top_padding"
android:orientation="vertical" >
-
-
+
9dp
- 260dp
+
+ 234dp
56dp
48dp
6dp
@@ -193,7 +194,7 @@
56dp
- 164dp
+ 178dp
24dp
16dp
@@ -253,10 +254,15 @@
16sp
- 15sp
+ 14sp
12sp
36dp
16dp
4dp
+ 28dp
+ 1dp
+
+
+ 0dp
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index e5a4335dcd..ee4d7ecb55 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -53,7 +53,6 @@ import androidx.annotation.UiThread;
import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
-import com.android.launcher3.allapps.AllAppsSectionDecorator;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dot.DotInfo;
import com.android.launcher3.dragndrop.DraggableView;
@@ -84,7 +83,7 @@ import java.text.NumberFormat;
* too aggressive.
*/
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, OnResumeCallback,
- IconLabelDotView, DraggableView, Reorderable, AllAppsSectionDecorator.SelfDecoratingView {
+ IconLabelDotView, DraggableView, Reorderable {
private static final int DISPLAY_WORKSPACE = 0;
private static final int DISPLAY_ALL_APPS = 1;
@@ -954,16 +953,4 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
setCompoundDrawables(null, newIcon, null, null);
}
}
-
- @Override
- public void decorate(int color) {
- mHighlightColor = color;
- invalidate();
- }
-
- @Override
- public void removeDecoration() {
- mHighlightColor = Color.TRANSPARENT;
- invalidate();
- }
}
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 9992fdeb90..634093c141 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -25,9 +25,12 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.view.Surface;
+import android.view.WindowInsets;
+import android.view.WindowManager;
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.DevicePaddings.DevicePadding;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.icons.IconNormalizer;
@@ -149,6 +152,10 @@ public class DeviceProfile {
public DotRenderer mDotRendererWorkSpace;
public DotRenderer mDotRendererAllApps;
+ // Taskbar
+ public boolean isTaskbarPresent;
+ public int taskbarSize;
+
DeviceProfile(Context context, InvariantDeviceProfile inv, Info info,
Point minSize, Point maxSize, int width, int height, boolean isLandscape,
boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
@@ -163,12 +170,13 @@ public class DeviceProfile {
// Determine sizes.
widthPx = width;
heightPx = height;
+ int nonFinalAvailableHeightPx;
if (isLandscape) {
availableWidthPx = maxSize.x;
- availableHeightPx = minSize.y;
+ nonFinalAvailableHeightPx = minSize.y;
} else {
availableWidthPx = minSize.x;
- availableHeightPx = maxSize.y;
+ nonFinalAvailableHeightPx = maxSize.y;
}
mInfo = info;
@@ -192,6 +200,22 @@ public class DeviceProfile {
: Configuration.ORIENTATION_PORTRAIT);
final Resources res = context.getResources();
+ isTaskbarPresent = isTablet && 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);
+ WindowInsets windowInsets = DisplayController.INSTANCE.get(context).getHolder(mInfo.id)
+ .getDisplayContext().getSystemService(WindowManager.class)
+ .getCurrentWindowMetrics().getWindowInsets();
+ int nonOverlappingTaskbarInset =
+ taskbarSize - windowInsets.getSystemWindowInsetBottom();
+ if (nonOverlappingTaskbarInset > 0) {
+ nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset;
+ }
+ }
+ availableHeightPx = nonFinalAvailableHeightPx;
+
edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 505e6d82e9..746bfba756 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -67,12 +67,13 @@ import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.RecyclerViewFastScroller;
import com.android.launcher3.views.SpringRelativeLayout;
+import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.OnActivePageChangedListener;
/**
* The all apps view container.
*/
public class AllAppsContainerView extends SpringRelativeLayout implements DragSource,
- Insettable, OnDeviceProfileChangeListener {
+ Insettable, OnDeviceProfileChangeListener, OnActivePageChangedListener {
private static final float FLING_VELOCITY_MULTIPLIER = 135f;
// Starts the springs after at least 55% of the animation has passed.
@@ -434,7 +435,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
.setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.MAIN));
findViewById(R.id.tab_work)
.setOnClickListener((View view) -> mViewPager.snapToPage(AdapterHolder.WORK));
- onTabChanged(mViewPager.getNextPage());
+ onActivePageChanged(mViewPager.getNextPage());
} else {
mAH[AdapterHolder.MAIN].setup(findViewById(R.id.apps_list_view), null);
mAH[AdapterHolder.WORK].recyclerView = null;
@@ -483,7 +484,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
if (showTabs) {
mViewPager = (AllAppsPagedView) newView;
mViewPager.initParentViews(this);
- mViewPager.getPageIndicator().setContainerView(this);
+ mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
} else {
mViewPager = null;
}
@@ -493,14 +494,15 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
return mViewPager != null ? mViewPager : findViewById(R.id.apps_list_view);
}
- public void onTabChanged(int pos) {
- mHeader.setMainActive(pos == 0);
- if (mAH[pos].recyclerView != null) {
- mAH[pos].recyclerView.bindFastScrollbar();
+ @Override
+ public void onActivePageChanged(int currentActivePage) {
+ mHeader.setMainActive(currentActivePage == 0);
+ if (mAH[currentActivePage].recyclerView != null) {
+ mAH[currentActivePage].recyclerView.bindFastScrollbar();
}
reset(true /* animate */);
if (mWorkModeSwitch != null) {
- mWorkModeSwitch.setWorkTabVisible(pos == AdapterHolder.WORK
+ mWorkModeSwitch.setWorkTabVisible(currentActivePage == AdapterHolder.WORK
&& mAllAppsStore.hasModelFlag(
FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION));
}
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 715c142ac9..5030c5e1a3 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -42,8 +42,7 @@ import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
-import com.android.launcher3.allapps.search.SearchSectionInfo;
-import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.allapps.search.SectionDecorationInfo;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.util.PackageManagerHelper;
@@ -109,7 +108,7 @@ public class AllAppsGridAdapter extends
// The index of this app not including sections
public int appIndex = -1;
// Search section associated to result
- public SearchSectionInfo searchSectionInfo = null;
+ public SectionDecorationInfo sectionDecorationInfo = null;
/**
* Factory method for AppIcon AdapterItem
@@ -372,10 +371,6 @@ public class AllAppsGridAdapter extends
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
- if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()
- && holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
- ((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
- }
switch (holder.getItemViewType()) {
case VIEW_TYPE_ICON:
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
@@ -409,10 +404,6 @@ public class AllAppsGridAdapter extends
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
super.onViewRecycled(holder);
- if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) return;
- if (holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
- ((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
- }
}
@Override
diff --git a/src/com/android/launcher3/allapps/AllAppsPagedView.java b/src/com/android/launcher3/allapps/AllAppsPagedView.java
index e2550f597a..647402b9e1 100644
--- a/src/com/android/launcher3/allapps/AllAppsPagedView.java
+++ b/src/com/android/launcher3/allapps/AllAppsPagedView.java
@@ -17,17 +17,17 @@ package com.android.launcher3.allapps;
import android.content.Context;
import android.util.AttributeSet;
-import android.view.MotionEvent;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.workprofile.PersonalWorkPagedView;
-public class AllAppsPagedView extends PagedView {
-
- static final float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
- static final float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
- static final float TOUCH_SLOP_DAMPING_FACTOR = 4;
+/**
+ * A {@link PagedView} for showing different views for the personal and work profile respectively
+ * in the {@link AllAppsContainerView}.
+ */
+public class AllAppsPagedView extends PersonalWorkPagedView {
public AllAppsPagedView(Context context) {
this(context, null);
@@ -44,52 +44,4 @@ public class AllAppsPagedView extends PagedView {
R.dimen.all_apps_header_top_padding);
setPadding(0, topPadding, 0, 0);
}
-
- @Override
- protected String getCurrentPageDescription() {
- // Not necessary, tab-bar already has two tabs with their own descriptions.
- return "";
- }
-
- @Override
- protected void onScrollChanged(int l, int t, int oldl, int oldt) {
- super.onScrollChanged(l, t, oldl, oldt);
- mPageIndicator.setScroll(l, mMaxScroll);
- }
-
- @Override
- protected void determineScrollingStart(MotionEvent ev) {
- float absDeltaX = Math.abs(ev.getX() - getDownMotionX());
- float absDeltaY = Math.abs(ev.getY() - getDownMotionY());
-
- if (Float.compare(absDeltaX, 0f) == 0) return;
-
- float slope = absDeltaY / absDeltaX;
- float theta = (float) Math.atan(slope);
-
- if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
- cancelCurrentPageLongPress();
- }
-
- if (theta > MAX_SWIPE_ANGLE) {
- return;
- } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
- theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
- float extraRatio = (float)
- Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
- super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
- } else {
- super.determineScrollingStart(ev);
- }
- }
-
- @Override
- public boolean hasOverlappingRendering() {
- return false;
- }
-
- @Override
- protected boolean canScroll(float absVScroll, float absHScroll) {
- return (absHScroll > absVScroll) && super.canScroll(absVScroll, absHScroll);
- }
}
diff --git a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java
index 6c95992397..176dce6c84 100644
--- a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java
+++ b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java
@@ -18,16 +18,18 @@ package com.android.launcher3.allapps;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsGridAdapter.AppsGridLayoutManager;
-import com.android.launcher3.allapps.search.SearchSectionInfo;
+import com.android.launcher3.allapps.search.SectionDecorationInfo;
import com.android.launcher3.util.Themes;
import java.util.List;
@@ -45,52 +47,51 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
- // Iterate through views in recylerview and draw bounds around views in the same section.
- // Since views in the same section will follow each other, we can skip to a last view in
- // a section to get the bounds of the section without having to iterate on every item.
- int itemCount = parent.getChildCount();
List adapterItems = mAppsView.getApps().getAdapterItems();
- SectionDecorationHandler lastDecorationHandler = null;
- int i = 0;
- while (i < itemCount) {
+ boolean drawFallbackFocusedView = true;
+ for (int i = 0; i < parent.getChildCount(); i++) {
View view = parent.getChildAt(i);
- if (view instanceof SelfDecoratingView) {
- ((SelfDecoratingView) view).removeDecoration();
- }
int position = parent.getChildAdapterPosition(view);
AllAppsGridAdapter.AdapterItem adapterItem = adapterItems.get(position);
- if (adapterItem.searchSectionInfo != null) {
- SearchSectionInfo sectionInfo = adapterItem.searchSectionInfo;
- int endIndex = Math.min(i + sectionInfo.getPosEnd() - position, itemCount - 1);
+ if (adapterItem.sectionDecorationInfo != null) {
+ SectionDecorationInfo sectionInfo = adapterItem.sectionDecorationInfo;
SectionDecorationHandler decorationHandler = sectionInfo.getDecorationHandler();
- if (decorationHandler != lastDecorationHandler && lastDecorationHandler != null) {
- drawDecoration(c, lastDecorationHandler, parent);
- }
- lastDecorationHandler = decorationHandler;
if (decorationHandler != null) {
decorationHandler.extendBounds(view);
- }
-
- if (endIndex > i) {
- i = endIndex;
- continue;
+ if (sectionInfo.isFocusedView()) {
+ decorationHandler.onFocusDraw(c, view);
+ drawFallbackFocusedView = false;
+ } else {
+ decorationHandler.onGroupDraw(c);
+ }
}
}
- i++;
}
- if (lastDecorationHandler != null) {
- drawDecoration(c, lastDecorationHandler, parent);
+ // fallback logic in case none of the SearchTarget is labeled as focused item
+ if (drawFallbackFocusedView) {
+ for (int i = 0; i < parent.getChildCount(); i++) {
+ View view = parent.getChildAt(i);
+ int position = parent.getChildAdapterPosition(view);
+ AllAppsGridAdapter.AdapterItem adapterItem = adapterItems.get(position);
+ if (adapterItem.sectionDecorationInfo != null) {
+ SectionDecorationInfo sectionInfo = adapterItem.sectionDecorationInfo;
+ SectionDecorationHandler decorationHandler = sectionInfo.getDecorationHandler();
+ if (decorationHandler != null) {
+ drawDecoration(c, decorationHandler, parent);
+ }
+ }
+ }
}
}
- private void drawDecoration(Canvas c, SectionDecorationHandler decorationHandler,
- RecyclerView parent) {
- if (decorationHandler == null) return;
+ // Fallback logic in case non of the SearchTarget is labeled as focused item.
+ private void drawDecoration(@NonNull Canvas c,
+ @NonNull SectionDecorationHandler decorationHandler,
+ @NonNull RecyclerView parent) {
if (decorationHandler.mIsFullWidth) {
decorationHandler.mBounds.left = parent.getPaddingLeft();
decorationHandler.mBounds.right = parent.getWidth() - parent.getPaddingRight();
}
- decorationHandler.onDraw(c);
if (mAppsView.getFloatingHeaderView().getFocusedChild() == null
&& mAppsView.getApps().getFocusedChild() != null) {
int index = mAppsView.getApps().getFocusedChildIndex();
@@ -109,23 +110,41 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
* Handles grouping and drawing of items in the same all apps sections.
*/
public static class SectionDecorationHandler {
- private static final int FILL_ALPHA = 0;
-
protected RectF mBounds = new RectF();
private final boolean mIsFullWidth;
private final float mRadius;
- protected int mFocusColor;
- protected int mFillcolor;
+ protected final int mFocusColor; // main focused item color
+ protected final int mFillcolor; // grouping color
+
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final boolean mIsTopRound;
+ private final boolean mIsBottomRound;
+ private float [] mCorners;
+ private float mFillSpacing;
+ public SectionDecorationHandler(Context context, boolean isFullWidth, int fillAlpha,
+ boolean isTopRound, boolean isBottomRound) {
- public SectionDecorationHandler(Context context, boolean isFullWidth) {
mIsFullWidth = isFullWidth;
int endScrim = Themes.getColorBackground(context);
- mFillcolor = ColorUtils.setAlphaComponent(endScrim, FILL_ALPHA);
- mFocusColor = endScrim;
- mRadius = Themes.getDialogCornerRadius(context);
+ mFillcolor = ColorUtils.setAlphaComponent(endScrim, fillAlpha);
+ mFocusColor = ColorUtils.setAlphaComponent(endScrim, fillAlpha);
+
+ mIsTopRound = isTopRound;
+ mIsBottomRound = isBottomRound;
+
+ mRadius = context.getResources().getDimensionPixelSize(
+ R.dimen.search_decoration_corner_radius);
+ mFillSpacing = context.getResources().getDimensionPixelSize(
+ R.dimen.search_decoration_padding);
+ mCorners = new float[]{
+ mIsTopRound ? mRadius : 0, mIsTopRound ? mRadius : 0, // Top left radius in px
+ mIsTopRound ? mRadius : 0, mIsTopRound ? mRadius : 0, // Top right radius in px
+ mIsBottomRound ? mRadius : 0, mIsBottomRound ? mRadius : 0, // Bottom right
+ mIsBottomRound ? mRadius : 0, mIsBottomRound ? mRadius : 0 // Bottom left
+ };
+
}
/**
@@ -147,9 +166,9 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
/**
* Draw bounds onto canvas.
*/
- public void onDraw(Canvas canvas) {
+ public void onGroupDraw(Canvas canvas) {
mPaint.setColor(mFillcolor);
- canvas.drawRoundRect(mBounds, mRadius, mRadius, mPaint);
+ onDraw(canvas);
}
/**
@@ -159,13 +178,20 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
if (view == null) {
return;
}
- if (view instanceof SelfDecoratingView) {
- ((SelfDecoratingView) view).decorate(mFocusColor);
- return;
- }
mPaint.setColor(mFocusColor);
- canvas.drawRoundRect(view.getLeft(), view.getTop(),
- view.getRight(), view.getBottom(), mRadius, mRadius, mPaint);
+ mBounds.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
+ onDraw(canvas);
+ }
+
+
+ private void onDraw(Canvas canvas) {
+ final Path path = new Path();
+ RectF finalBounds = new RectF(mBounds.left + mFillSpacing,
+ mBounds.top + mFillSpacing,
+ mBounds.right - mFillSpacing,
+ mBounds.bottom - mFillSpacing);
+ path.addRoundRect(finalBounds, mCorners, Path.Direction.CW);
+ canvas.drawPath(path, mPaint);
}
/**
@@ -175,19 +201,4 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration {
mBounds.setEmpty();
}
}
-
- /**
- * An interface for a view to draw highlight indicator
- */
- public interface SelfDecoratingView {
- /**
- * Removes decorations drawing if focus is acquired by another view
- */
- void removeDecoration();
-
- /**
- * Draws highlight indicator on view.
- */
- void decorate(int focusColor);
- }
}
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
index 1dc10fea1f..123ace7938 100644
--- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
+++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
@@ -20,7 +20,7 @@ import android.content.Context;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem;
-import com.android.launcher3.allapps.search.SearchSectionInfo;
+import com.android.launcher3.allapps.search.SectionDecorationInfo;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.util.ItemInfoMatcher;
@@ -201,20 +201,11 @@ public class AlphabeticalAppsList implements AllAppsStore.OnUpdateListener {
}
void updateSearchAdapterItems(ArrayList list, int offset) {
- SearchSectionInfo lastSection = null;
for (int i = 0; i < list.size(); i++) {
AdapterItem adapterItem = list.get(i);
adapterItem.position = offset + i;
mAdapterItems.add(adapterItem);
- if (adapterItem.searchSectionInfo != lastSection) {
- if (adapterItem.searchSectionInfo != null) {
- adapterItem.searchSectionInfo.setPosStart(adapterItem.position);
- }
- if (lastSection != null) {
- lastSection.setPosEnd(adapterItem.position - 1);
- }
- lastSection = adapterItem.searchSectionInfo;
- }
+
if (adapterItem.isCountedForAccessibility()) {
mAccessibilityResultsCount++;
}
@@ -295,16 +286,16 @@ public class AlphabeticalAppsList implements AllAppsStore.OnUpdateListener {
mFastScrollerSections.clear();
mAdapterItems.clear();
- SearchSectionInfo appSection = new SearchSectionInfo();
+ SectionDecorationInfo appSection = new SectionDecorationInfo();
appSection.setDecorationHandler(
- new AllAppsSectionDecorator.SectionDecorationHandler(mLauncher, true));
+ new AllAppsSectionDecorator.SectionDecorationHandler(mLauncher, true,
+ 0, false, false));
// Recreate the filtered and sectioned apps (for convenience for the grid layout) from the
// ordered set of sections
if (!hasFilter()) {
mAccessibilityResultsCount = mApps.size();
- appSection.setPosStart(position);
for (AppInfo info : mApps) {
String sectionName = info.sectionName;
@@ -321,11 +312,10 @@ public class AlphabeticalAppsList implements AllAppsStore.OnUpdateListener {
lastFastScrollerSectionInfo.fastScrollToItem = appItem;
}
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
- appItem.searchSectionInfo = appSection;
+ appItem.sectionDecorationInfo = appSection;
}
mAdapterItems.add(appItem);
}
- appSection.setPosEnd(mApps.isEmpty() ? appSection.getPosStart() : position - 1);
} else {
updateSearchAdapterItems(mSearchResults, 0);
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
diff --git a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
index 4876298761..bc2e66c36b 100644
--- a/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/LauncherAllAppsContainerView.java
@@ -87,17 +87,18 @@ public class LauncherAllAppsContainerView extends AllAppsContainerView {
}
@Override
- public void onTabChanged(int pos) {
- super.onTabChanged(pos);
+ public void onActivePageChanged(int currentActivePage) {
+ super.onActivePageChanged(currentActivePage);
if (mUsingTabs) {
// Log tab switches only when the launcher is in AllApps state
if (mLauncher.getStateManager().getCurrentStableState() == LauncherState.ALL_APPS) {
mLauncher.getStatsLogManager().logger()
- .log(pos == AdapterHolder.WORK ? LAUNCHER_ALLAPPS_SWITCHED_TO_WORK_TAB
+ .log(currentActivePage == AdapterHolder.WORK
+ ? LAUNCHER_ALLAPPS_SWITCHED_TO_WORK_TAB
: LAUNCHER_ALLAPPS_SWITCHED_TO_MAIN_TAB);
}
- if (pos == AdapterHolder.WORK) {
+ if (currentActivePage == AdapterHolder.WORK) {
WorkEduView.showWorkEduIfNeeded(mLauncher);
} else {
mWorkTabListener = WorkEduView.showEduFlowIfNeeded(mLauncher, mWorkTabListener);
diff --git a/src/com/android/launcher3/allapps/search/AppsSearchPipeline.java b/src/com/android/launcher3/allapps/search/AppsSearchPipeline.java
index 84688e1737..f9fb22ece7 100644
--- a/src/com/android/launcher3/allapps/search/AppsSearchPipeline.java
+++ b/src/com/android/launcher3/allapps/search/AppsSearchPipeline.java
@@ -37,14 +37,14 @@ public class AppsSearchPipeline implements SearchPipeline {
private static final int MAX_RESULTS_COUNT = 5;
- private final SearchSectionInfo mSearchSectionInfo;
+ private final SectionDecorationInfo mSearchSectionInfo;
private final LauncherAppState mLauncherAppState;
public AppsSearchPipeline(Context context, LauncherAppState launcherAppState) {
mLauncherAppState = launcherAppState;
- mSearchSectionInfo = new SearchSectionInfo();
+ mSearchSectionInfo = new SectionDecorationInfo();
mSearchSectionInfo.setDecorationHandler(
- new SectionDecorationHandler(context, true));
+ new SectionDecorationHandler(context, true, 0, true, true));
}
@Override
@@ -81,7 +81,7 @@ public class AppsSearchPipeline implements SearchPipeline {
ArrayList items = new ArrayList<>();
for (int i = 0; i < matchingApps.size() && i < MAX_RESULTS_COUNT; i++) {
AdapterItem appItem = AdapterItem.asApp(i, "", matchingApps.get(i), i);
- appItem.searchSectionInfo = mSearchSectionInfo;
+ appItem.sectionDecorationInfo = mSearchSectionInfo;
items.add(appItem);
}
diff --git a/src/com/android/launcher3/allapps/search/SearchSectionInfo.java b/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java
similarity index 73%
rename from src/com/android/launcher3/allapps/search/SearchSectionInfo.java
rename to src/com/android/launcher3/allapps/search/SectionDecorationInfo.java
index 464df68c96..0b64fcaece 100644
--- a/src/com/android/launcher3/allapps/search/SearchSectionInfo.java
+++ b/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java
@@ -18,37 +18,30 @@ package com.android.launcher3.allapps.search;
import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHandler;
/**
- * Info class for a search section
+ * Info class for a search section that is primarily used for decoration.
*/
-public class SearchSectionInfo {
+public class SectionDecorationInfo {
+
+ public static final int QUICK_LAUNCH = 1 << 0;
+ public static final int GROUPING = 1 << 1;
private String mSectionId;
+ private boolean mFocused;
private SectionDecorationHandler mDecorationHandler;
- public int getPosStart() {
- return mPosStart;
+ public boolean isFocusedView() {
+ return mFocused;
}
- public void setPosStart(int posStart) {
- mPosStart = posStart;
+ public void setFocusedView(boolean focused) {
+ mFocused = focused;
}
- public int getPosEnd() {
- return mPosEnd;
- }
-
- public void setPosEnd(int posEnd) {
- mPosEnd = posEnd;
- }
-
- private int mPosStart;
- private int mPosEnd;
-
- public SearchSectionInfo() {
+ public SectionDecorationInfo() {
this(null);
}
- public SearchSectionInfo(String sectionId) {
+ public SectionDecorationInfo(String sectionId) {
mSectionId = sectionId;
}
@@ -56,7 +49,6 @@ public class SearchSectionInfo {
mDecorationHandler = sectionDecorationHandler;
}
-
public SectionDecorationHandler getDecorationHandler() {
return mDecorationHandler;
}
diff --git a/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java b/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java
index a9389bc8b3..71e10a82b0 100644
--- a/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java
+++ b/src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java
@@ -10,7 +10,9 @@ import android.widget.RemoteViews;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
+import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.icons.BitmapRenderer;
+import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.widget.WidgetCell;
/**
@@ -36,6 +38,15 @@ public class LivePreviewWidgetCell extends WidgetCell {
mPreview = view;
}
+ public RemoteViews getPreview() {
+ return mPreview;
+ }
+
+ /** Resets any resource. This should be called before recycling this view. */
+ public void reset() {
+ mPreview = null;
+ }
+
@Override
public void ensurePreview() {
if (mPreview != null && mActiveRequest == null) {
@@ -49,6 +60,18 @@ public class LivePreviewWidgetCell extends WidgetCell {
super.ensurePreview();
}
+ @Override
+ public void applyFromCellItem(WidgetItem item, WidgetPreviewLoader loader) {
+ if (mPreview == null
+ && item.widgetInfo != null
+ && item.widgetInfo.previewLayout != View.NO_ID) {
+ mPreview = new RemoteViews(item.widgetInfo.provider.getPackageName(),
+ item.widgetInfo.previewLayout);
+ }
+
+ super.applyFromCellItem(item, loader);
+ }
+
/**
* Generates a bitmap by inflating {@param views}.
* @see com.android.launcher3.WidgetPreviewLoader#generateWidgetPreview
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 1266bb48aa..0802f8a574 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -31,8 +31,6 @@ import com.android.launcher3.logger.LauncherAtom.ToState;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.ResourceBasedOverride;
-import java.util.Optional;
-
/**
* Handles the user event logging in R+.
*
@@ -486,7 +484,9 @@ public class StatsLogManager implements ResourceBasedOverride {
*/
public StatsLogger logger() {
StatsLogger logger = createLogger();
- Optional.ofNullable(mInstanceId).ifPresent(logger::withInstanceId);
+ if (mInstanceId != null) {
+ return logger.withInstanceId(mInstanceId);
+ }
return logger;
}
diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java
index a519f9275c..92b5885e9e 100644
--- a/src/com/android/launcher3/model/AllAppsList.java
+++ b/src/com/android/launcher3/model/AllAppsList.java
@@ -136,7 +136,7 @@ public class AllAppsList {
if (findAppInfo(info.componentName, info.user) != null) {
return;
}
- mIconCache.getTitleAndIcon(info, activityInfo, true /* useLowResIcon */);
+ mIconCache.getTitleAndIcon(info, activityInfo, false /* useLowResIcon */);
info.sectionName = mIndex.computeSectionName(info.title);
data.add(info);
@@ -280,7 +280,7 @@ public class AllAppsList {
} else {
Intent launchIntent = AppInfo.makeLaunchIntent(info);
- mIconCache.getTitleAndIcon(applicationInfo, info, true /* useLowResIcon */);
+ mIconCache.getTitleAndIcon(applicationInfo, info, false /* useLowResIcon */);
applicationInfo.sectionName = mIndex.computeSectionName(applicationInfo.title);
applicationInfo.setProgressLevel(
PackageManagerHelper.getLoadingProgress(info),
diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java
index a8a7e944cf..d0e8bb1b39 100644
--- a/src/com/android/launcher3/util/DisplayController.java
+++ b/src/com/android/launcher3/util/DisplayController.java
@@ -197,6 +197,10 @@ public class DisplayController implements DisplayListener {
return new Info(displayContext, display);
}
+ public Context getDisplayContext() {
+ return mDisplayContext;
+ }
+
protected void handleOnChange() {
Info oldInfo = mInfo;
Info newInfo = createInfoForContext(mDisplayContext);
diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java
index 0cb8c1ec77..899dcf702b 100644
--- a/src/com/android/launcher3/views/OptionsPopupView.java
+++ b/src/com/android/launcher3/views/OptionsPopupView.java
@@ -158,6 +158,14 @@ public class OptionsPopupView extends ArrowPopup
*/
public static ArrayList getOptions(Launcher launcher) {
ArrayList options = new ArrayList<>();
+ options.add(new OptionItem(R.string.settings_button_text, R.drawable.ic_setting,
+ LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS,
+ OptionsPopupView::startSettings));
+ if (!WidgetsModel.GO_DISABLE_WIDGETS) {
+ options.add(new OptionItem(R.string.widget_button_text, R.drawable.ic_widget,
+ LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS,
+ OptionsPopupView::onWidgetsClicked));
+ }
int resString = Utilities.existsStyleWallpapers(launcher) ?
R.string.styles_wallpaper_button_text : R.string.wallpaper_button_text;
int resDrawable = Utilities.existsStyleWallpapers(launcher) ?
@@ -165,15 +173,6 @@ public class OptionsPopupView extends ArrowPopup
options.add(new OptionItem(resString, resDrawable,
IGNORE,
OptionsPopupView::startWallpaperPicker));
- if (!WidgetsModel.GO_DISABLE_WIDGETS) {
- options.add(new OptionItem(R.string.widget_button_text, R.drawable.ic_widget,
- LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS,
- OptionsPopupView::onWidgetsClicked));
- }
- options.add(new OptionItem(R.string.settings_button_text, R.drawable.ic_setting,
- LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS,
- OptionsPopupView::startSettings));
-
return options;
}
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index a38e90dfd8..15566a4e8e 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -30,6 +30,7 @@ import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.dragndrop.DragOptions;
+import com.android.launcher3.dragndrop.LivePreviewWidgetCell;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
@@ -99,12 +100,16 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView
return false;
}
+ PendingItemDragHelper dragHelper = new PendingItemDragHelper(v);
+ if (v instanceof LivePreviewWidgetCell) {
+ dragHelper.setPreview(((LivePreviewWidgetCell) v).getPreview());
+ }
+
int[] loc = new int[2];
getPopupContainer().getLocationInDragLayer(image, loc);
- new PendingItemDragHelper(v).startDrag(
- image.getBitmapBounds(), image.getBitmap().getWidth(), image.getWidth(),
- new Point(loc[0], loc[1]), this, new DragOptions());
+ dragHelper.startDrag(image.getBitmapBounds(), image.getBitmap().getWidth(),
+ image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions());
close(true);
return true;
}
diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java
index 3c112740cf..8fe42f4861 100644
--- a/src/com/android/launcher3/widget/PendingItemDragHelper.java
+++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java
@@ -25,6 +25,8 @@ import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.RemoteViews;
+import androidx.annotation.Nullable;
+
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.Launcher;
@@ -48,14 +50,14 @@ public class PendingItemDragHelper extends DragPreviewProvider {
private final PendingAddItemInfo mAddInfo;
private int[] mEstimatedCellSize;
- private RemoteViews mPreview;
+ @Nullable private RemoteViews mPreview;
public PendingItemDragHelper(View view) {
super(view);
mAddInfo = (PendingAddItemInfo) view.getTag();
}
- public void setPreview(RemoteViews preview) {
+ public void setPreview(@Nullable RemoteViews preview) {
mPreview = preview;
}
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index 3585a1814b..223cda272a 100644
--- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
@@ -36,6 +36,7 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.ResourceUtils;
import com.android.launcher3.anim.PendingAnimation;
+import com.android.launcher3.dragndrop.LivePreviewWidgetCell;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.PackageUserKey;
@@ -136,8 +137,8 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
}
protected WidgetCell addItemCell(ViewGroup parent) {
- WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate(
- R.layout.widget_cell, parent, false);
+ LivePreviewWidgetCell widget = (LivePreviewWidgetCell) LayoutInflater.from(
+ getContext()).inflate(R.layout.live_preview_widget_cell, parent, false);
widget.setOnClickListener(this);
widget.setOnLongClickListener(this);
diff --git a/src/com/android/launcher3/widget/picker/WidgetsListRowViewHolderBinder.java b/src/com/android/launcher3/widget/picker/WidgetsListRowViewHolderBinder.java
index cec6b807ec..bd787775d9 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsListRowViewHolderBinder.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsListRowViewHolderBinder.java
@@ -25,6 +25,7 @@ import android.view.ViewGroup;
import com.android.launcher3.R;
import com.android.launcher3.WidgetPreviewLoader;
+import com.android.launcher3.dragndrop.LivePreviewWidgetCell;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.recyclerview.ViewHolderBinder;
import com.android.launcher3.widget.WidgetCell;
@@ -107,8 +108,8 @@ public class WidgetsListRowViewHolderBinder
mLayoutInflater.inflate(R.layout.widget_list_divider, row);
} else {
// Add cell for even index
- WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
- R.layout.widget_cell, row, false);
+ LivePreviewWidgetCell widget = (LivePreviewWidgetCell) mLayoutInflater.inflate(
+ R.layout.live_preview_widget_cell, row, false);
// set up touch.
widget.setOnClickListener(mIconClickListener);
@@ -124,7 +125,8 @@ public class WidgetsListRowViewHolderBinder
// Bind the view in the widget horizontal tray region.
for (int i = 0; i < infoList.size(); i++) {
- WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
+ LivePreviewWidgetCell widget = (LivePreviewWidgetCell) row.getChildAt(2 * i);
+ widget.reset();
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
widget.ensurePreview();
diff --git a/src/com/android/launcher3/workprofile/PersonalWorkPagedView.java b/src/com/android/launcher3/workprofile/PersonalWorkPagedView.java
new file mode 100644
index 0000000000..8b05a0d55a
--- /dev/null
+++ b/src/com/android/launcher3/workprofile/PersonalWorkPagedView.java
@@ -0,0 +1,92 @@
+/*
+ * 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.workprofile;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+import com.android.launcher3.PagedView;
+
+/**
+ * A {@link PagedView} for showing different views for the personal and work profile respectively.
+ */
+public class PersonalWorkPagedView extends PagedView {
+
+ static final float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
+ static final float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
+ static final float TOUCH_SLOP_DAMPING_FACTOR = 4;
+
+ public PersonalWorkPagedView(Context context) {
+ this(context, null);
+ }
+
+ public PersonalWorkPagedView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public PersonalWorkPagedView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ protected String getCurrentPageDescription() {
+ // Not necessary, tab-bar already has two tabs with their own descriptions.
+ return "";
+ }
+
+ @Override
+ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
+ super.onScrollChanged(l, t, oldl, oldt);
+ mPageIndicator.setScroll(l, mMaxScroll);
+ }
+
+ @Override
+ protected void determineScrollingStart(MotionEvent ev) {
+ float absDeltaX = Math.abs(ev.getX() - getDownMotionX());
+ float absDeltaY = Math.abs(ev.getY() - getDownMotionY());
+
+ if (Float.compare(absDeltaX, 0f) == 0) return;
+
+ float slope = absDeltaY / absDeltaX;
+ float theta = (float) Math.atan(slope);
+
+ if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
+ cancelCurrentPageLongPress();
+ }
+
+ if (theta > MAX_SWIPE_ANGLE) {
+ return;
+ } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
+ theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
+ float extraRatio = (float)
+ Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
+ super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
+ } else {
+ super.determineScrollingStart(ev);
+ }
+ }
+
+ @Override
+ public boolean hasOverlappingRendering() {
+ return false;
+ }
+
+ @Override
+ protected boolean canScroll(float absVScroll, float absHScroll) {
+ return (absHScroll > absVScroll) && super.canScroll(absVScroll, absHScroll);
+ }
+}
diff --git a/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
similarity index 85%
rename from src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java
rename to src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
index 2de425ea4b..3a3028f8d9 100644
--- a/src/com/android/launcher3/allapps/PersonalWorkSlidingTabStrip.java
+++ b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.launcher3.allapps;
+package com.android.launcher3.workprofile;
import android.content.Context;
import android.graphics.Canvas;
@@ -35,9 +35,6 @@ import com.android.launcher3.util.Themes;
* Supports two indicator colors, dedicated for personal and work tabs.
*/
public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageIndicator {
- private static final int POSITION_PERSONAL = 0;
- private static final int POSITION_WORK = 1;
-
private final Paint mSelectedIndicatorPaint;
private final Paint mDividerPaint;
@@ -47,7 +44,7 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
private float mScrollOffset;
private int mSelectedPosition = 0;
- private AllAppsContainerView mContainerView;
+ private OnActivePageChangedListener mOnActivePageChangedListener;
private int mLastActivePage = 0;
private boolean mIsRtl;
@@ -123,7 +120,7 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
float y = getHeight() - mDividerPaint.getStrokeWidth();
canvas.drawLine(getPaddingLeft(), y, getWidth() - getPaddingRight(), y, mDividerPaint);
canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight,
- mIndicatorRight, getHeight(), mSelectedIndicatorPaint);
+ mIndicatorRight, getHeight(), mSelectedIndicatorPaint);
}
@Override
@@ -135,15 +132,15 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
@Override
public void setActiveMarker(int activePage) {
updateTabTextColor(activePage);
- if (mContainerView != null && mLastActivePage != activePage) {
+ if (mOnActivePageChangedListener != null && mLastActivePage != activePage) {
updateIndicatorPosition(activePage);
- mContainerView.onTabChanged(activePage);
+ mOnActivePageChangedListener.onActivePageChanged(activePage);
}
mLastActivePage = activePage;
}
- public void setContainerView(AllAppsContainerView containerView) {
- mContainerView = containerView;
+ public void setOnActivePageChangedListener(OnActivePageChangedListener listener) {
+ mOnActivePageChangedListener = listener;
}
@Override
@@ -153,4 +150,12 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
public boolean hasOverlappingRendering() {
return false;
}
+
+ /**
+ * Interface definition for a callback to be invoked when an active page has been changed.
+ */
+ public interface OnActivePageChangedListener {
+ /** Called when the active page has been changed. */
+ void onActivePageChanged(int currentActivePage);
+ }
}