Commit bc98a1ac authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Add progress bar animations.

Bug: 806868
Change-Id: Ia30d9ff86560bfb39217877f40c7b0e36cf475b6
Reviewed-on: https://chromium-review.googlesource.com/c/1307508
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604315}
parent 32b0f78a
......@@ -80,19 +80,18 @@
<org.chromium.chrome.browser.widget.MaterialProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="4dp"
app:colorBackground="@color/modern_grey_300"
app:colorProgress="@color/modern_blue_600"
android:visibility="invisible" />
android:layout_height="6dp"
app:colorBackground="@color/modern_grey_100"
app:colorProgress="@color/modern_blue_600" />
<LinearLayout
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="24dp"
android:layout_height="64dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:layout_marginBottom="20dp"
android:background="@drawable/autofill_assistant_details_bg"
android:padding="8dp"
android:visibility="gone"
......@@ -139,7 +138,7 @@
android:id="@+id/carousel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingBottom="16dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:gravity="center_vertical"
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.autofill_assistant;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
import org.chromium.chrome.browser.widget.MaterialProgressBar;
import java.util.ArrayDeque;
import java.util.Queue;
/**
* Wrapper around {@link MaterialProgressBar} to animate progress changes and enable/disable
* pulsing.
*/
public class AnimatedProgressBar {
private static final String PROGRESS_PROPERTY_NAME = "progress";
private static final String PROGRESS_COLOR_PROPERTY_NAME = "progressColor";
// The number of ms the progress bar would take to go from 0 to 100%.
private static final int PROGRESS_BAR_SPEED_MS = 3_000;
private static final int PROGRESS_BAR_PULSING_DURATION_MS = 1_000;
private final MaterialProgressBar mProgressBar;
private final int mNormalColor;
private final int mPulsedColor;
private boolean mIsRunningProgressAnimation = false;
private int mLastProgress = 0;
private Queue<ObjectAnimator> mPendingIncreaseAnimations = new ArrayDeque<>();
private ObjectAnimator mPulseAnimation = null;
public AnimatedProgressBar(MaterialProgressBar progressBar, int normalColor, int pulsedColor) {
mProgressBar = progressBar;
mNormalColor = normalColor;
mPulsedColor = pulsedColor;
}
public void show() {
mProgressBar.setVisibility(View.VISIBLE);
}
public void hide() {
mProgressBar.setVisibility(View.INVISIBLE);
}
public void setProgress(int progress) {
if (progress > mLastProgress) {
ObjectAnimator progressAnimation = ObjectAnimator.ofInt(
mProgressBar, PROGRESS_PROPERTY_NAME, mLastProgress, progress);
progressAnimation.setDuration(PROGRESS_BAR_SPEED_MS * (progress - mLastProgress) / 100);
progressAnimation.setInterpolator(ChromeAnimation.getAccelerateInterpolator());
progressAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mPendingIncreaseAnimations.isEmpty()) {
mIsRunningProgressAnimation = false;
} else {
mIsRunningProgressAnimation = true;
mPendingIncreaseAnimations.poll().start();
}
}
});
mLastProgress = progress;
if (mIsRunningProgressAnimation) {
mPendingIncreaseAnimations.offer(progressAnimation);
} else {
mIsRunningProgressAnimation = true;
progressAnimation.start();
}
}
}
public void enablePulsing() {
if (mPulseAnimation == null) {
mPulseAnimation = ObjectAnimator.ofInt(
mProgressBar, PROGRESS_COLOR_PROPERTY_NAME, mNormalColor, mPulsedColor);
mPulseAnimation.setDuration(PROGRESS_BAR_PULSING_DURATION_MS);
mPulseAnimation.setEvaluator(new ArgbEvaluator());
mPulseAnimation.setRepeatCount(ValueAnimator.INFINITE);
mPulseAnimation.setRepeatMode(ValueAnimator.REVERSE);
mPulseAnimation.setInterpolator(ChromeAnimation.getAccelerateInterpolator());
mPulseAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
mProgressBar.setProgressColor(mNormalColor);
}
});
mPulseAnimation.start();
}
}
public void disablePulsing() {
if (mPulseAnimation != null) {
mPulseAnimation.cancel();
mPulseAnimation = null;
}
}
}
......@@ -206,12 +206,18 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
@CalledByNative
private void onShowOverlay() {
mUiDelegateHolder.performUiOperation(AutofillAssistantUiDelegate::showOverlay);
mUiDelegateHolder.performUiOperation(uiDelegate -> {
uiDelegate.showOverlay();
uiDelegate.disableProgressBarPulsing();
});
}
@CalledByNative
private void onHideOverlay() {
mUiDelegateHolder.performUiOperation(AutofillAssistantUiDelegate::hideOverlay);
mUiDelegateHolder.performUiOperation(uiDelegate -> {
uiDelegate.hideOverlay();
uiDelegate.enableProgressBarPulsing();
});
}
@CalledByNative
......
......@@ -32,7 +32,6 @@ import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.snackbar.Snackbar;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.widget.MaterialProgressBar;
import java.io.InputStream;
import java.net.URL;
......@@ -61,7 +60,7 @@ class AutofillAssistantUiDelegate {
private final HorizontalScrollView mCarouselScroll;
private final ViewGroup mChipsViewContainer;
private final TextView mStatusMessageView;
private final MaterialProgressBar mProgressBar;
private final AnimatedProgressBar mProgressBar;
private final ViewGroup mDetails;
private final AppCompatImageView mDetailsImage;
......@@ -210,7 +209,9 @@ class AutofillAssistantUiDelegate {
mCarouselScroll = mBottomBar.findViewById(R.id.carousel_scroll);
mChipsViewContainer = mCarouselScroll.findViewById(R.id.carousel);
mStatusMessageView = mBottomBar.findViewById(R.id.status_message);
mProgressBar = mBottomBar.findViewById(R.id.progress_bar);
mProgressBar = new AnimatedProgressBar(mBottomBar.findViewById(R.id.progress_bar),
mActivity.getColor(R.color.modern_blue_600),
mActivity.getColor(R.color.modern_blue_600_alpha_38_opaque));
mDetails = (ViewGroup) mBottomBar.findViewById(R.id.details);
mDetailsImage = (AppCompatImageView) mDetails.findViewById(R.id.details_image);
......@@ -221,6 +222,8 @@ class AutofillAssistantUiDelegate {
mDetailsImageHeight = mActivity.getResources().getDimensionPixelSize(
R.dimen.autofill_assistant_details_image_size);
setCarouselTopPadding();
// TODO(crbug.com/806868): Listen for contextual search shown so as to hide this UI.
}
......@@ -299,7 +302,7 @@ class AutofillAssistantUiDelegate {
if (mChipsViewContainer.getChildCount() > 0) {
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(newChild.getLayoutParams());
int leftMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
int leftMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16,
newChild.getContext().getResources().getDisplayMetrics());
layoutParams.setMargins(leftMargin, 0, 0, 0);
newChild.setLayoutParams(layoutParams);
......@@ -390,7 +393,7 @@ class AutofillAssistantUiDelegate {
int topPadding = 0;
if (mDetails.getVisibility() != View.VISIBLE) {
topPadding = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 8, mActivity.getResources().getDisplayMetrics());
TypedValue.COMPLEX_UNIT_DIP, 16, mActivity.getResources().getDisplayMetrics());
}
mChipsViewContainer.setPadding(mChipsViewContainer.getPaddingLeft(), topPadding,
mChipsViewContainer.getPaddingRight(), mChipsViewContainer.getPaddingBottom());
......@@ -424,9 +427,8 @@ class AutofillAssistantUiDelegate {
public void showProgressBar(int progress, String message) {
ensureFullContainerIsShown();
// TODO(crbug.com/806868): Animate the progress change.
mProgressBar.show();
mProgressBar.setProgress(progress);
mProgressBar.setVisibility(View.VISIBLE);
if (!message.isEmpty()) {
mStatusMessageView.setText(message);
......@@ -434,7 +436,15 @@ class AutofillAssistantUiDelegate {
}
public void hideProgressBar() {
mProgressBar.setVisibility(View.INVISIBLE);
mProgressBar.hide();
}
public void enableProgressBarPulsing() {
mProgressBar.enablePulsing();
}
public void disableProgressBarPulsing() {
mProgressBar.disablePulsing();
}
/**
......
......@@ -117,6 +117,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/autofill/keyboard_accessory/PasswordAccessoryBridge.java",
"java/src/org/chromium/chrome/browser/autofill/keyboard_accessory/PasswordAccessorySheetCoordinator.java",
"java/src/org/chromium/chrome/browser/autofill/keyboard_accessory/PasswordAccessorySheetViewBinder.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AnimatedProgressBar.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantUiController.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantUiDelegate.java",
"java/src/org/chromium/chrome/browser/background_task_scheduler/NativeBackgroundTask.java",
......
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