Merge "[Predictive Back] Add extra bottom space in taskbar all apps to home" into udc-dev

This commit is contained in:
Fengjiang Li
2023-03-16 00:46:42 +00:00
committed by Android (Google) Code Review
7 changed files with 58 additions and 38 deletions
@@ -20,7 +20,6 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.WindowInsets;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
@@ -61,13 +60,6 @@ public class TaskbarAllAppsContainerView extends
return false;
}
@Override
protected void updateBackground(DeviceProfile deviceProfile) {
super.updateBackground(deviceProfile);
// TODO(b/240670050): Remove this and add header protection for the taskbar entrypoint.
mBottomSheetBackground.setBackgroundResource(R.drawable.bg_rounded_corner_bottom_sheet);
}
@Override
public boolean isInAllApps() {
// All apps is always open
@@ -97,6 +97,8 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
}
if (FeatureFlags.ENABLE_BACK_SWIPE_LAUNCHER_ANIMATION.get()) {
mAppsView.getAppsRecyclerViewContainer().setOutlineProvider(mViewOutlineProvider);
mAppsView.getAppsRecyclerViewContainer().setClipToOutline(true);
findOnBackInvokedDispatcher().registerOnBackInvokedCallback(
OnBackInvokedDispatcher.PRIORITY_DEFAULT, mOnBackAnimationCallback);
}
@@ -135,6 +137,16 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
setShiftRange(dp.allAppsShiftRange);
mActivityContext.addOnDeviceProfileChangeListener(this);
setContentBackgroundWithParent(
getContext().getDrawable(R.drawable.bg_rounded_corner_bottom_sheet),
mAppsView.getBottomSheetBackground());
}
@Override
protected void onScaleProgressChanged() {
super.onScaleProgressChanged();
mAppsView.setClipChildren(!mIsBackProgressing);
mAppsView.getAppsRecyclerViewContainer().setClipChildren(!mIsBackProgressing);
}
@Override
@@ -47,6 +47,7 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowInsets;
import android.widget.Button;
@@ -266,6 +267,10 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
return mSearchUiManager;
}
public View getBottomSheetBackground() {
return mBottomSheetBackground;
}
public View getSearchView() {
return mSearchContainer;
}
@@ -905,7 +910,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
* The container for A-Z apps (the ViewPager for main+work tabs, or main RV). This is currently
* hidden while searching.
**/
protected View getAppsRecyclerViewContainer() {
public ViewGroup getAppsRecyclerViewContainer() {
return mViewPager != null ? mViewPager : findViewById(R.id.apps_list_view);
}
@@ -33,7 +33,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
public class ScrollableLayoutManager extends GridLayoutManager {
public static final float PREDICTIVE_BACK_MIN_SCALE = 0.9f;
private static final float EXTRA_BOTTOM_SPACE_BY_HEIGHT_PERCENT =
public static final float EXTRA_BOTTOM_SPACE_BY_HEIGHT_PERCENT =
(1 - PREDICTIVE_BACK_MIN_SCALE) / 2;
// keyed on item type
@@ -30,15 +30,18 @@ import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Property;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.animation.Interpolator;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
@@ -96,8 +99,21 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
private final AnimatedFloat mSlideInViewScale =
new AnimatedFloat(this::onScaleProgressChanged, VIEW_NO_SCALE);
private boolean mIsBackProgressing;
protected boolean mIsBackProgressing;
@Nullable private Drawable mContentBackground;
@Nullable private View mContentBackgroundParentView;
protected final ViewOutlineProvider mViewOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRect(
0,
0,
view.getMeasuredWidth(),
view.getMeasuredHeight() + getBottomOffsetPx()
);
}
};
public AbstractSlideInView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@@ -119,10 +135,6 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
mColorScrim = scrimColor != -1 ? createColorScrim(context, scrimColor) : null;
}
protected void setContentBackground(Drawable drawable) {
mContentBackground = drawable;
}
protected void attachToContainer() {
if (mColorScrim != null) {
getPopupContainer().addView(mColorScrim);
@@ -190,7 +202,7 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
+ (1 - PREDICTIVE_BACK_MIN_SCALE) * (1 - deceleratedProgress));
}
private void onScaleProgressChanged() {
protected void onScaleProgressChanged() {
float scaleProgress = mSlideInViewScale.value;
SCALE_PROPERTY.set(this, scaleProgress);
setClipChildren(!mIsBackProgressing);
@@ -222,16 +234,27 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
super.dispatchDraw(canvas);
}
/**
* Set slide in view's background {@link Drawable} which will be draw onto a parent view in
* {@link #dispatchDraw(Canvas)}
*/
protected void setContentBackgroundWithParent(
@NonNull Drawable drawable, @NonNull View parentView) {
mContentBackground = drawable;
mContentBackgroundParentView = parentView;
}
/** Draw scaled background during predictive back animation. */
protected void drawScaledBackground(Canvas canvas) {
if (mContentBackground == null) {
private void drawScaledBackground(Canvas canvas) {
if (mContentBackground == null || mContentBackgroundParentView == null) {
return;
}
mContentBackground.setBounds(
mContent.getLeft(),
mContent.getTop() + (int) mContent.getTranslationY(),
mContent.getRight(),
mContent.getBottom() + (mIsBackProgressing ? getBottomOffsetPx() : 0));
mContentBackgroundParentView.getLeft(),
mContentBackgroundParentView.getTop() + (int) mContent.getTranslationY(),
mContentBackgroundParentView.getRight(),
mContentBackgroundParentView.getBottom()
+ (mIsBackProgressing ? getBottomOffsetPx() : 0));
mContentBackground.draw(canvas);
}
@@ -112,13 +112,14 @@ public class WidgetsBottomSheet extends BaseWidgetSheet {
if (!hasSeenEducationTip()) {
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
}
setContentBackground(getContext().getDrawable(R.drawable.bg_rounded_corner_bottom_sheet));
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mContent = findViewById(R.id.widgets_bottom_sheet);
setContentBackgroundWithParent(
getContext().getDrawable(R.drawable.bg_rounded_corner_bottom_sheet), mContent);
}
@Override
@@ -29,7 +29,6 @@ import android.content.Context;
import android.content.pm.LauncherApps;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Process;
import android.os.UserHandle;
@@ -41,7 +40,6 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowInsets;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
@@ -170,18 +168,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
}
};
private final ViewOutlineProvider mViewOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRect(
0,
0,
view.getMeasuredWidth(),
view.getMeasuredHeight() + getBottomOffsetPx()
);
}
};
@Px private final int mTabsHeight;
@Nullable private WidgetsRecyclerView mCurrentWidgetsRecyclerView;
@@ -227,7 +213,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mUserManagerState.init(UserCache.INSTANCE.get(context),
context.getSystemService(UserManager.class));
setContentBackground(getContext().getDrawable(R.drawable.bg_widgets_full_sheet));
}
public WidgetsFullSheet(Context context, AttributeSet attrs) {
@@ -238,6 +223,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
protected void onFinishInflate() {
super.onFinishInflate();
mContent = findViewById(R.id.container);
setContentBackgroundWithParent(getContext().getDrawable(R.drawable.bg_widgets_full_sheet),
mContent);
mContent.setOutlineProvider(mViewOutlineProvider);
mContent.setClipToOutline(true);