Chromium Code Reviews| Index: components/autofill/android/java/src/org/chromium/components/autofill/AutofillKeyboardAccessory.java |
| diff --git a/components/autofill/android/java/src/org/chromium/components/autofill/AutofillKeyboardAccessory.java b/components/autofill/android/java/src/org/chromium/components/autofill/AutofillKeyboardAccessory.java |
| index 56475a385245b4eda771492457202070f1e3d3b9..0c3f19d10ff8000b0aff1b61835070fc33ce3e16 100644 |
| --- a/components/autofill/android/java/src/org/chromium/components/autofill/AutofillKeyboardAccessory.java |
| +++ b/components/autofill/android/java/src/org/chromium/components/autofill/AutofillKeyboardAccessory.java |
| @@ -4,6 +4,8 @@ |
| package org.chromium.components.autofill; |
| +import android.animation.Animator; |
| +import android.animation.ObjectAnimator; |
| import android.annotation.SuppressLint; |
| import android.graphics.Typeface; |
| import android.os.Build; |
| @@ -29,19 +31,37 @@ import org.chromium.ui.base.WindowAndroid; |
| public class AutofillKeyboardAccessory extends LinearLayout |
| implements WindowAndroid.KeyboardVisibilityListener, View.OnClickListener, |
| View.OnLongClickListener { |
| + // We start animating by scrolling the suggestions from beyond the viewport. |
| + private static final int NUM_DIP_TO_ANIMATE_SCROLL_FROM = 100; |
| + |
| + // Time to pause before reversing animation when the first suggestion is a hint. |
| + private static final long PAUSE_ANIMATION_BEFORE_REVERSE_MILLIS = 1000; |
| + |
| private final WindowAndroid mWindowAndroid; |
| private final AutofillDelegate mAutofillDelegate; |
| + // If |mMaximumLabelWidthPx| is 0, we do not call |setMaxWidth| on the |TextView| for a fillable |
| + // suggestion label. |
| private final int mMaximumLabelWidthPx; |
| private final int mMaximumSublabelWidthPx; |
| + private final int mAnimationDurationMillis; |
| + private final boolean mIsFirstSuggestionAHint; |
| + private ObjectAnimator mAnimator; |
| /** |
| * Creates an AutofillKeyboardAccessory with specified parameters. |
| * @param windowAndroid The owning WindowAndroid. |
| * @param autofillDelegate A object that handles the calls to the native |
| * AutofillKeyboardAccessoryView. |
| + * @param animationDurationMillis If 0, do not animate. |
| + * @param shouldLimitLabelWidth If true, limit suggestion label width to 1/2 device's |
| + * pixel width. |
|
please use gerrit instead
2017/05/15 14:37:29
Remove the word "pixel" from this comment, please.
csashi
2017/05/15 20:07:26
Done.
|
| + * @param isFirstSuggestionAHint If {@code true} and {@param animationDurationMillis} > 0, |
| + * we reverse the animation and scroll the first suggestion (which is a non-fillable hint) out |
| + * of the viewport at the end of the reversed animation. |
| */ |
| - public AutofillKeyboardAccessory( |
| - WindowAndroid windowAndroid, AutofillDelegate autofillDelegate) { |
| + public AutofillKeyboardAccessory(WindowAndroid windowAndroid, AutofillDelegate autofillDelegate, |
| + int animationDurationMillis, boolean shouldLimitLabelWidth, |
| + boolean isFirstSuggestionAHint) { |
| super(windowAndroid.getActivity().get()); |
| assert autofillDelegate != null; |
| assert windowAndroid.getActivity().get() != null; |
| @@ -49,13 +69,16 @@ public class AutofillKeyboardAccessory extends LinearLayout |
| mAutofillDelegate = autofillDelegate; |
| int deviceWidthPx = windowAndroid.getDisplay().getDisplayWidth(); |
| - mMaximumLabelWidthPx = deviceWidthPx / 2; |
| + mMaximumLabelWidthPx = shouldLimitLabelWidth ? deviceWidthPx / 2 : 0; |
| mMaximumSublabelWidthPx = deviceWidthPx / 4; |
| mWindowAndroid.addKeyboardVisibilityListener(this); |
| int horizontalPaddingPx = getResources().getDimensionPixelSize( |
| R.dimen.keyboard_accessory_half_padding); |
| setPadding(horizontalPaddingPx, 0, horizontalPaddingPx, 0); |
| + |
| + mAnimationDurationMillis = animationDurationMillis; |
| + mIsFirstSuggestionAHint = isFirstSuggestionAHint; |
| } |
| /** |
| @@ -65,12 +88,18 @@ public class AutofillKeyboardAccessory extends LinearLayout |
| */ |
| @SuppressLint("InlinedApi") |
| public void showWithSuggestions(AutofillSuggestion[] suggestions, final boolean isRtl) { |
| + if (mIsFirstSuggestionAHint) assert suggestions.length > 1; |
| + |
| removeAllViews(); |
| int separatorPosition = -1; |
| for (int i = 0; i < suggestions.length; i++) { |
| AutofillSuggestion suggestion = suggestions[i]; |
| assert !TextUtils.isEmpty(suggestion.getLabel()); |
| + if (i == 0 && mIsFirstSuggestionAHint) { |
| + assert !suggestion.isFillable() && suggestion.getIconId() != 0; |
| + } |
| + |
| View touchTarget; |
| if (!suggestion.isFillable() && suggestion.getIconId() != 0) { |
| touchTarget = LayoutInflater.from(getContext()).inflate( |
| @@ -89,7 +118,7 @@ public class AutofillKeyboardAccessory extends LinearLayout |
| TextView label = (TextView) touchTarget.findViewById( |
| R.id.autofill_keyboard_accessory_item_label); |
| - if (suggestion.isFillable()) { |
| + if (mMaximumLabelWidthPx > 0 && suggestion.isFillable()) { |
| label.setMaxWidth(mMaximumLabelWidthPx); |
| } |
| @@ -137,14 +166,56 @@ public class AutofillKeyboardAccessory extends LinearLayout |
| (HorizontalScrollView) mWindowAndroid.getKeyboardAccessoryView(); |
| if (getParent() == null) { |
| container.addView(this); |
| - container.setVisibility(View.VISIBLE); |
| + // If we are animating the view, we |setVisibility| in |onAnimationStart|. |
| + if (mAnimationDurationMillis == 0) { |
| + container.setVisibility(View.VISIBLE); |
| + } |
| container.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| } |
| + if (mAnimationDurationMillis > 0) { |
| + mAnimator = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, |
| + isRtl ? getRight() + NUM_DIP_TO_ANIMATE_SCROLL_FROM |
| + : -NUM_DIP_TO_ANIMATE_SCROLL_FROM, |
| + isRtl ? getRight() : 0); |
| + mAnimator.setDuration(mAnimationDurationMillis); |
| + mAnimator.addListener(new Animator.AnimatorListener() { |
| + @Override |
| + public void onAnimationStart(Animator animator) { |
| + container.setVisibility(View.VISIBLE); |
| + } |
| + @Override |
| + public void onAnimationEnd(Animator animator) { |
| + mAnimator.removeListener(this); |
| + if (mIsFirstSuggestionAHint) { |
| + assert getChildCount() > 1; |
| + int hint_width = getChildAt(0).getWidth(); |
|
please use gerrit instead
2017/05/15 14:37:29
hintWidth
csashi
2017/05/15 20:07:26
Done.
|
| + mAnimator.setFloatValues(isRtl ? getRight() : 0, |
| + isRtl ? getRight() + hint_width : -hint_width); |
| + container.postDelayed(new Runnable() { |
| + @Override |
| + public void run() { |
| + mWindowAndroid.startAnimationOverContent(mAnimator); |
| + } |
| + }, PAUSE_ANIMATION_BEFORE_REVERSE_MILLIS); |
| + } |
| + } |
| + |
| + @Override |
| + public void onAnimationCancel(Animator animation) {} |
| + |
| + @Override |
| + public void onAnimationRepeat(Animator animation) {} |
| + }); |
| + } |
| container.post(new Runnable() { |
| @Override |
| public void run() { |
| - container.scrollTo(isRtl ? getRight() : 0, 0); |
| + if (mAnimationDurationMillis > 0) { |
| + mWindowAndroid.startAnimationOverContent(mAnimator); |
| + } else { |
| + container.scrollTo(isRtl ? getRight() : 0, 0); |
| + } |
| } |
| }); |
| } |