Commit 9564f471 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Polish drag-and-drop IPH behavior

* No longer dismiss the IPH entrance when user enters the IPH dialog
  and sees the animation. Instead, only dismiss it when user explicitly
  closes the IPH entrance, or has performed drag-and-drop behavior (this
  is not reflected in this CL).
* Make the IPH animation repeat and restart from beginning every time
  the dialog is reopen.

Bug: 997707
Change-Id: If419316c9dc406927649260575b128c650ef2120
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1777108Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692080}
parent 442bc972
...@@ -30,21 +30,19 @@ class TabGridIphItemMediator implements TabSwitcherMediator.IphProvider { ...@@ -30,21 +30,19 @@ class TabGridIphItemMediator implements TabSwitcherMediator.IphProvider {
private void setupOnClickListeners() { private void setupOnClickListeners() {
View.OnClickListener showIPHOnClickListener = view -> { View.OnClickListener showIPHOnClickListener = view -> {
mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, true); mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, true);
// When the dialog is showing, the entrance should be closed.
mModel.set(TabGridIphItemProperties.IS_IPH_ENTRANCE_VISIBLE, false);
}; };
mModel.set( mModel.set(
TabGridIphItemProperties.IPH_ENTRANCE_SHOW_BUTTON_LISTENER, showIPHOnClickListener); TabGridIphItemProperties.IPH_ENTRANCE_SHOW_BUTTON_LISTENER, showIPHOnClickListener);
View.OnClickListener closeIPHDialogOnClickListener = view -> { View.OnClickListener closeIPHDialogOnClickListener = view -> {
mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false); mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false);
dismissIPHFeature();
}; };
mModel.set(TabGridIphItemProperties.IPH_DIALOG_CLOSE_BUTTON_LISTENER, mModel.set(TabGridIphItemProperties.IPH_DIALOG_CLOSE_BUTTON_LISTENER,
closeIPHDialogOnClickListener); closeIPHDialogOnClickListener);
View.OnClickListener closeIPHEntranceOnClickListener = view -> { View.OnClickListener closeIPHEntranceOnClickListener = view -> {
mModel.set(TabGridIphItemProperties.IS_IPH_ENTRANCE_VISIBLE, false); mModel.set(TabGridIphItemProperties.IS_IPH_ENTRANCE_VISIBLE, false);
// Dismiss the drag-and-drop IPH feature when user explicitly closes the entrance.
dismissIPHFeature(); dismissIPHFeature();
}; };
mModel.set(TabGridIphItemProperties.IPH_ENTRANCE_CLOSE_BUTTON_LISTENER, mModel.set(TabGridIphItemProperties.IPH_ENTRANCE_CLOSE_BUTTON_LISTENER,
...@@ -56,7 +54,6 @@ class TabGridIphItemMediator implements TabSwitcherMediator.IphProvider { ...@@ -56,7 +54,6 @@ class TabGridIphItemMediator implements TabSwitcherMediator.IphProvider {
@Override @Override
public void onScrimClick() { public void onScrimClick() {
mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false); mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false);
dismissIPHFeature();
} }
@Override @Override
......
...@@ -9,6 +9,9 @@ import android.graphics.Bitmap; ...@@ -9,6 +9,9 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Animatable; import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.graphics.drawable.Animatable2Compat;
import android.support.graphics.drawable.AnimatedVectorDrawableCompat;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
...@@ -36,6 +39,8 @@ public class TabGridIphItemView extends FrameLayout { ...@@ -36,6 +39,8 @@ public class TabGridIphItemView extends FrameLayout {
private ScrimView.ScrimParams mScrimParams; private ScrimView.ScrimParams mScrimParams;
private Drawable mIphDrawable; private Drawable mIphDrawable;
private PopupWindow mIphWindow; private PopupWindow mIphWindow;
private Animatable mIphAnimation;
private Animatable2Compat.AnimationCallback mAnimationCallback;
public TabGridIphItemView(Context context, AttributeSet attrs) { public TabGridIphItemView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
...@@ -57,6 +62,14 @@ public class TabGridIphItemView extends FrameLayout { ...@@ -57,6 +62,14 @@ public class TabGridIphItemView extends FrameLayout {
mIphDialogView.findViewById(R.id.iph_drag_and_drop_dialog_close_button); mIphDialogView.findViewById(R.id.iph_drag_and_drop_dialog_close_button);
mIphDrawable = mIphDrawable =
((ImageView) mIphDialogView.findViewById(R.id.animation_drawable)).getDrawable(); ((ImageView) mIphDialogView.findViewById(R.id.animation_drawable)).getDrawable();
mIphAnimation = (Animatable) mIphDrawable;
mAnimationCallback = new Animatable2Compat.AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
Handler handler = new Handler();
handler.postDelayed(mIphAnimation::start, 1500);
}
};
backgroundView.addView(mIphDialogView); backgroundView.addView(mIphDialogView);
mIphWindow = new PopupWindow(backgroundView, ViewGroup.LayoutParams.MATCH_PARENT, mIphWindow = new PopupWindow(backgroundView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT);
...@@ -105,6 +118,8 @@ public class TabGridIphItemView extends FrameLayout { ...@@ -105,6 +118,8 @@ public class TabGridIphItemView extends FrameLayout {
void closeIphDialog() { void closeIphDialog() {
mIphWindow.dismiss(); mIphWindow.dismiss();
mScrimView.hideScrim(true); mScrimView.hideScrim(true);
AnimatedVectorDrawableCompat.unregisterAnimationCallback(mIphDrawable, mAnimationCallback);
mIphAnimation.stop();
} }
/** /**
...@@ -115,7 +130,8 @@ public class TabGridIphItemView extends FrameLayout { ...@@ -115,7 +130,8 @@ public class TabGridIphItemView extends FrameLayout {
mScrimView.showScrim(mScrimParams); mScrimView.showScrim(mScrimParams);
} }
mIphWindow.showAtLocation((View) getParent(), Gravity.CENTER, 0, 0); mIphWindow.showAtLocation((View) getParent(), Gravity.CENTER, 0, 0);
((Animatable) mIphDrawable).start(); AnimatedVectorDrawableCompat.registerAnimationCallback(mIphDrawable, mAnimationCallback);
mIphAnimation.start();
} }
private Drawable getScaledCloseImageDrawable() { private Drawable getScaledCloseImageDrawable() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment