mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Bottom user education view shown in work tab
Introduced a BottomUserEducationView for similar use case. Screenshot: https://hsv.googleplex.com/4856820942241792 BUG=69963630 Change-Id: Ia818ee44fa5ce97ad1778f33e6a9a3a36cea5017
This commit is contained in:
@@ -15,94 +15,43 @@
|
||||
*/
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Property;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.DragSource;
|
||||
import com.android.launcher3.DropTarget.DragObject;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAnimUtils;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.graphics.GradientView;
|
||||
import com.android.launcher3.touch.SwipeDetector;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
||||
import com.android.launcher3.util.SystemUiController;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.views.AbstractSlideInView;
|
||||
|
||||
/**
|
||||
* Base class for various widgets popup
|
||||
*/
|
||||
abstract class BaseWidgetSheet extends AbstractFloatingView
|
||||
implements OnClickListener, OnLongClickListener, DragSource, SwipeDetector.Listener {
|
||||
abstract class BaseWidgetSheet extends AbstractSlideInView
|
||||
implements OnClickListener, OnLongClickListener, DragSource {
|
||||
|
||||
|
||||
protected static Property<BaseWidgetSheet, Float> TRANSLATION_SHIFT =
|
||||
new Property<BaseWidgetSheet, Float>(Float.class, "translationShift") {
|
||||
|
||||
@Override
|
||||
public Float get(BaseWidgetSheet view) {
|
||||
return view.mTranslationShift;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(BaseWidgetSheet view, Float value) {
|
||||
view.setTranslationShift(value);
|
||||
}
|
||||
};
|
||||
protected static final float TRANSLATION_SHIFT_CLOSED = 1f;
|
||||
protected static final float TRANSLATION_SHIFT_OPENED = 0f;
|
||||
|
||||
/* Touch handling related member variables. */
|
||||
private Toast mWidgetInstructionToast;
|
||||
|
||||
protected final Launcher mLauncher;
|
||||
protected final SwipeDetector mSwipeDetector;
|
||||
protected final ObjectAnimator mOpenCloseAnimator;
|
||||
|
||||
protected View mContent;
|
||||
protected GradientView mGradientView;
|
||||
protected Interpolator mScrollInterpolator;
|
||||
|
||||
// range [0, 1], 0=> completely open, 1=> completely closed
|
||||
protected float mTranslationShift = TRANSLATION_SHIFT_CLOSED;
|
||||
|
||||
protected boolean mNoIntercept;
|
||||
|
||||
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
|
||||
mScrollInterpolator = Interpolators.SCROLL_CUBIC;
|
||||
mSwipeDetector = new SwipeDetector(context, this, SwipeDetector.VERTICAL);
|
||||
|
||||
mOpenCloseAnimator = LauncherAnimUtils.ofPropertyValuesHolder(this);
|
||||
mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mSwipeDetector.finishedScrolling();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,9 +79,8 @@ abstract class BaseWidgetSheet extends AbstractFloatingView
|
||||
}
|
||||
|
||||
protected void setTranslationShift(float translationShift) {
|
||||
mTranslationShift = translationShift;
|
||||
super.setTranslationShift(translationShift);
|
||||
mGradientView.setAlpha(1 - mTranslationShift);
|
||||
mContent.setTranslationY(mTranslationShift * mContent.getHeight());
|
||||
}
|
||||
|
||||
private boolean beginDraggingWidget(WidgetCell v) {
|
||||
@@ -163,94 +111,8 @@ abstract class BaseWidgetSheet extends AbstractFloatingView
|
||||
public void onDropCompleted(View target, DragObject d, boolean success) { }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_UP && !mNoIntercept) {
|
||||
// If we got ACTION_UP without ever returning true on intercept,
|
||||
// the user never started dragging the bottom sheet.
|
||||
if (!mLauncher.getDragLayer().isEventOverView(mContent, ev)) {
|
||||
close(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mNoIntercept) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int directionsToDetectScroll = mSwipeDetector.isIdleState() ?
|
||||
SwipeDetector.DIRECTION_NEGATIVE : 0;
|
||||
mSwipeDetector.setDetectableScrollConditions(
|
||||
directionsToDetectScroll, false);
|
||||
mSwipeDetector.onTouchEvent(ev);
|
||||
return mSwipeDetector.isDraggingOrSettling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onControllerTouchEvent(MotionEvent ev) {
|
||||
return mSwipeDetector.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
/* SwipeDetector.Listener */
|
||||
|
||||
@Override
|
||||
public void onDragStart(boolean start) { }
|
||||
|
||||
@Override
|
||||
public boolean onDrag(float displacement, float velocity) {
|
||||
float range = mContent.getHeight();
|
||||
displacement = Utilities.boundToRange(displacement, 0, range);
|
||||
setTranslationShift(displacement / range);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragEnd(float velocity, boolean fling) {
|
||||
if ((fling && velocity > 0) || mTranslationShift > 0.5f) {
|
||||
mScrollInterpolator = scrollInterpolatorForVelocity(velocity);
|
||||
mOpenCloseAnimator.setDuration(SwipeDetector.calculateDuration(
|
||||
velocity, TRANSLATION_SHIFT_CLOSED - mTranslationShift));
|
||||
close(true);
|
||||
} else {
|
||||
mOpenCloseAnimator.setValues(PropertyValuesHolder.ofFloat(
|
||||
TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
|
||||
mOpenCloseAnimator.setDuration(
|
||||
SwipeDetector.calculateDuration(velocity, mTranslationShift))
|
||||
.setInterpolator(Interpolators.DEACCEL);
|
||||
mOpenCloseAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleClose(boolean animate, long defaultDuration) {
|
||||
if (!mIsOpen || mOpenCloseAnimator.isRunning()) {
|
||||
return;
|
||||
}
|
||||
if (animate) {
|
||||
mOpenCloseAnimator.setValues(
|
||||
PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_CLOSED));
|
||||
mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
onCloseComplete();
|
||||
}
|
||||
});
|
||||
if (mSwipeDetector.isIdleState()) {
|
||||
mOpenCloseAnimator
|
||||
.setDuration(defaultDuration)
|
||||
.setInterpolator(Interpolators.ACCEL);
|
||||
} else {
|
||||
mOpenCloseAnimator.setInterpolator(mScrollInterpolator);
|
||||
}
|
||||
mOpenCloseAnimator.start();
|
||||
} else {
|
||||
setTranslationShift(TRANSLATION_SHIFT_CLOSED);
|
||||
onCloseComplete();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onCloseComplete() {
|
||||
mIsOpen = false;
|
||||
mLauncher.getDragLayer().removeView(this);
|
||||
super.onCloseComplete();
|
||||
mLauncher.getSystemUiController().updateUiState(
|
||||
SystemUiController.UI_STATE_WIDGET_BOTTOM_SHEET, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user