Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2941)

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkLoadingView.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkLoadingView.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkLoadingView.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkLoadingView.java
new file mode 100644
index 0000000000000000000000000000000000000000..44440b55953cffa23a07137455c546eedc1c6ca6
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkLoadingView.java
@@ -0,0 +1,97 @@
+// Copyright 2015 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.enhancedbookmarks;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.ProgressBar;
+
+import com.google.android.apps.chrome.R;
+
+import org.chromium.ui.interpolators.BakedBezierInterpolator;
+
+/**
+ * View for showing loading content animation. The animation logic follows the Android loading
+ * content UI guideline.
+ */
+public class EnhancedBookmarkLoadingView extends FrameLayout {
+ private static final int LOADING_ANIMATION_DELAY_MS = 500;
+ private static final int MINIMUM_ANIMATION_SHOW_TIME_MS = 500;
+
+ private long mStartTime = -1;
+
+ private ProgressBar mLoadingProgressBar;
+
+ private final Runnable mDelayedShow = new Runnable() {
+ @Override
+ public void run() {
+ mStartTime = System.currentTimeMillis();
+ mLoadingProgressBar.setAlpha(1.0f);
+ mLoadingProgressBar.setVisibility(View.VISIBLE);
+ }
+ };
+
+ // Material loading design spec requires us to show progress spinner at least 500ms, so we need
+ // this delayed runnable to implement that.
+ private final Runnable mDelayedHide = new Runnable() {
+ @Override
+ public void run() {
+ animate().alpha(0.0f).setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ setVisibility(GONE);
+ }
+ });
+ }
+ };
+
+ /**
+ * Constructor for inflating from XML.
+ */
+ public EnhancedBookmarkLoadingView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mLoadingProgressBar = (ProgressBar) findViewById(R.id.eb_loading_circle);
+ }
+
+ /**
+ * Show loading UI. It shows the loading animation 500ms after.
+ */
+ public void showLoadingUI() {
+ removeCallbacks(mDelayedShow);
+ removeCallbacks(mDelayedHide);
+
+ setVisibility(VISIBLE);
+ setAlpha(1.0f);
+ mLoadingProgressBar.setVisibility(GONE);
+
+ postDelayed(mDelayedShow, LOADING_ANIMATION_DELAY_MS);
+ }
+
+ /**
+ * Hide loading UI. If progress bar is not shown, it disappears immediately. If so, it smoothly
+ * fades out.
+ */
+ public void hideLoadingUI() {
+ removeCallbacks(mDelayedShow);
+ removeCallbacks(mDelayedHide);
+
+ if (mLoadingProgressBar.getVisibility() == VISIBLE) {
+ postDelayed(mDelayedHide, Math.max(0,
+ mStartTime + MINIMUM_ANIMATION_SHOW_TIME_MS - System.currentTimeMillis()));
+ } else {
+ setVisibility(GONE);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698