Modify pin widget dialog open-close animation.

Pin widget sheet should open from bottom up and close on drag down.
Behaviour with navigation bar is similar to that of widgets bottom sheet.

Add a drag layer and reuse AbstractSlideInView for open-close
animation.

Test: Tested manually- opening, closing through dragging/ cancel button/
back button. Adding widget to screen by dragging/ add to home screen
button.
Bug: 186124244

Change-Id: I4b77d5bdd4ed1689b651847dfed69d19cafa7456
This commit is contained in:
Alina Zaidi
2021-05-13 14:13:18 +01:00
parent 85584c9eba
commit d80cec62b4
14 changed files with 336 additions and 137 deletions

View File

@@ -31,17 +31,21 @@ import android.view.View;
import android.view.animation.Interpolator;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.touch.BaseSwipeDetector;
import com.android.launcher3.touch.SingleAxisSwipeDetector;
import java.util.ArrayList;
import java.util.List;
/**
* Extension of AbstractFloatingView with common methods for sliding in from bottom
* Extension of {@link AbstractFloatingView} with common methods for sliding in from bottom.
*
* @param <T> Type of ActivityContext inflating this view.
*/
public abstract class AbstractSlideInView extends AbstractFloatingView
implements SingleAxisSwipeDetector.Listener {
public abstract class AbstractSlideInView<T extends Context & ActivityContext>
extends AbstractFloatingView implements SingleAxisSwipeDetector.Listener {
protected static final Property<AbstractSlideInView, Float> TRANSLATION_SHIFT =
new Property<AbstractSlideInView, Float>(Float.class, "translationShift") {
@@ -59,7 +63,8 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
protected static final float TRANSLATION_SHIFT_CLOSED = 1f;
protected static final float TRANSLATION_SHIFT_OPENED = 0f;
protected final Launcher mLauncher;
protected final T mActivityContext;
protected final SingleAxisSwipeDetector mSwipeDetector;
protected final ObjectAnimator mOpenCloseAnimator;
@@ -71,10 +76,11 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
protected float mTranslationShift = TRANSLATION_SHIFT_CLOSED;
protected boolean mNoIntercept;
protected List<OnCloseListener> mOnCloseListeners = new ArrayList<>();
public AbstractSlideInView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mLauncher = Launcher.getLauncher(context);
mActivityContext = ActivityContext.lookupContext(context);
mScrollInterpolator = Interpolators.SCROLL_CUBIC;
mSwipeDetector = new SingleAxisSwipeDetector(context, this,
@@ -88,8 +94,8 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
announceAccessibilityChanges();
}
});
int scrimColor = getScrimColor(mLauncher);
mColorScrim = scrimColor != -1 ? createColorScrim(mLauncher, scrimColor) : null;
int scrimColor = getScrimColor(context);
mColorScrim = scrimColor != -1 ? createColorScrim(context, scrimColor) : null;
}
protected void attachToContainer() {
@@ -120,8 +126,8 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
return false;
}
int directionsToDetectScroll = mSwipeDetector.isIdleState() ?
SingleAxisSwipeDetector.DIRECTION_NEGATIVE : 0;
int directionsToDetectScroll = mSwipeDetector.isIdleState()
? SingleAxisSwipeDetector.DIRECTION_NEGATIVE : 0;
mSwipeDetector.setDetectableScrollConditions(
directionsToDetectScroll, false);
mSwipeDetector.onTouchEvent(ev);
@@ -176,6 +182,11 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
}
}
/** Registers an {@link OnCloseListener}. */
public void addOnCloseListener(OnCloseListener listener) {
mOnCloseListeners.add(listener);
}
protected void handleClose(boolean animate, long defaultDuration) {
if (!mIsOpen) {
return;
@@ -210,10 +221,11 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
if (mColorScrim != null) {
getPopupContainer().removeView(mColorScrim);
}
mOnCloseListeners.forEach(OnCloseListener::onSlideInViewClosed);
}
protected BaseDragLayer getPopupContainer() {
return mLauncher.getDragLayer();
return mActivityContext.getDragLayer();
}
protected View createColorScrim(Context context, int bgColor) {
@@ -227,4 +239,15 @@ public abstract class AbstractSlideInView extends AbstractFloatingView
return view;
}
/**
* Interface to report that the {@link AbstractSlideInView} has closed.
*/
public interface OnCloseListener {
/**
* Called when {@link AbstractSlideInView} closes.
*/
void onSlideInViewClosed();
}
}