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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.enhancedbookmarks;
6
7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter;
9 import android.content.Context;
10 import android.util.AttributeSet;
11 import android.view.View;
12 import android.widget.FrameLayout;
13 import android.widget.ProgressBar;
14
15 import com.google.android.apps.chrome.R;
16
17 import org.chromium.ui.interpolators.BakedBezierInterpolator;
18
19 /**
20 * View for showing loading content animation. The animation logic follows the A ndroid loading
21 * content UI guideline.
22 */
23 public class EnhancedBookmarkLoadingView extends FrameLayout {
24 private static final int LOADING_ANIMATION_DELAY_MS = 500;
25 private static final int MINIMUM_ANIMATION_SHOW_TIME_MS = 500;
26
27 private long mStartTime = -1;
28
29 private ProgressBar mLoadingProgressBar;
30
31 private final Runnable mDelayedShow = new Runnable() {
32 @Override
33 public void run() {
34 mStartTime = System.currentTimeMillis();
35 mLoadingProgressBar.setAlpha(1.0f);
36 mLoadingProgressBar.setVisibility(View.VISIBLE);
37 }
38 };
39
40 // Material loading design spec requires us to show progress spinner at leas t 500ms, so we need
41 // this delayed runnable to implement that.
42 private final Runnable mDelayedHide = new Runnable() {
43 @Override
44 public void run() {
45 animate().alpha(0.0f).setInterpolator(BakedBezierInterpolator.TRANSF ORM_CURVE)
46 .setListener(new AnimatorListenerAdapter() {
47 @Override
48 public void onAnimationEnd(Animator animation) {
49 setVisibility(GONE);
50 }
51 });
52 }
53 };
54
55 /**
56 * Constructor for inflating from XML.
57 */
58 public EnhancedBookmarkLoadingView(Context context, AttributeSet attrs) {
59 super(context, attrs);
60 }
61
62 @Override
63 protected void onFinishInflate() {
64 super.onFinishInflate();
65 mLoadingProgressBar = (ProgressBar) findViewById(R.id.eb_loading_circle) ;
66 }
67
68 /**
69 * Show loading UI. It shows the loading animation 500ms after.
70 */
71 public void showLoadingUI() {
72 removeCallbacks(mDelayedShow);
73 removeCallbacks(mDelayedHide);
74
75 setVisibility(VISIBLE);
76 setAlpha(1.0f);
77 mLoadingProgressBar.setVisibility(GONE);
78
79 postDelayed(mDelayedShow, LOADING_ANIMATION_DELAY_MS);
80 }
81
82 /**
83 * Hide loading UI. If progress bar is not shown, it disappears immediately. If so, it smoothly
84 * fades out.
85 */
86 public void hideLoadingUI() {
87 removeCallbacks(mDelayedShow);
88 removeCallbacks(mDelayedHide);
89
90 if (mLoadingProgressBar.getVisibility() == VISIBLE) {
91 postDelayed(mDelayedHide, Math.max(0,
92 mStartTime + MINIMUM_ANIMATION_SHOW_TIME_MS - System.current TimeMillis()));
93 } else {
94 setVisibility(GONE);
95 }
96 }
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698