OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.support.annotation.ColorRes; | 8 import android.support.annotation.ColorRes; |
9 import android.util.AttributeSet; | 9 import android.util.AttributeSet; |
10 import android.view.View; | 10 import android.view.View; |
11 import android.widget.ImageView; | 11 import android.widget.ImageView; |
12 | 12 |
13 import org.chromium.base.ApiCompatibilityUtils; | 13 import org.chromium.base.ApiCompatibilityUtils; |
14 import org.chromium.chrome.R; | 14 import org.chromium.chrome.R; |
15 import org.chromium.third_party.android.swiperefresh.MaterialProgressDrawable; | 15 import org.chromium.third_party.android.swiperefresh.MaterialProgressDrawable; |
16 | 16 |
17 /** | 17 /** |
18 * Displays an indeterminate circular spinner, similar to {@link android.widget.
ProgressBar} in | 18 * Displays an indeterminate circular spinner, similar to {@link android.widget.
ProgressBar} in |
19 * Lollipop+. This class allows to backport the Material style to pre-L OS versi
ons. | 19 * Lollipop+. This class allows to backport the Material style to pre-L OS versi
ons. |
20 * | 20 * |
21 * It stays invisible for the first 500ms when shown, to avoid showing a spinner
when content | 21 * It stays invisible for the first 500ms when shown, to avoid showing a spinner
when content |
22 * can load very quickly. | 22 * can load very quickly. |
23 */ | 23 */ |
24 public class ProgressIndicatorView extends ImageView { | 24 public class ProgressIndicatorView extends ImageView { |
25 private static final int SHOW_DELAY_MS = 500; | 25 private static final int SHOW_DELAY_MS = 500; |
26 private final Runnable mShowSpinnerRunnable; | 26 private final Runnable mShowSpinnerRunnable; |
27 | 27 |
28 private final MaterialProgressDrawable mProgressDrawable; | 28 private final MaterialProgressDrawable mProgressDrawable; |
29 private boolean mPostedCallback = false; | 29 private boolean mPostedCallback; |
30 | 30 |
31 /** | 31 /** |
32 * Constructor for use in layout files. | 32 * Constructor for use in layout files. |
33 */ | 33 */ |
34 public ProgressIndicatorView(Context context, AttributeSet attrs) { | 34 public ProgressIndicatorView(Context context, AttributeSet attrs) { |
35 super(context, attrs); | 35 super(context, attrs); |
36 | 36 |
37 mShowSpinnerRunnable = new Runnable() { | 37 mShowSpinnerRunnable = new Runnable() { |
38 @Override | 38 @Override |
39 public void run() { | 39 public void run() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 mPostedCallback = true; | 86 mPostedCallback = true; |
87 // We don't want to show the spinner every time we load content if it lo
ads quickly; instead | 87 // We don't want to show the spinner every time we load content if it lo
ads quickly; instead |
88 // only start showing the spinner if loading the content has taken longe
r than 500ms | 88 // only start showing the spinner if loading the content has taken longe
r than 500ms |
89 postDelayed(mShowSpinnerRunnable, SHOW_DELAY_MS); | 89 postDelayed(mShowSpinnerRunnable, SHOW_DELAY_MS); |
90 } | 90 } |
91 | 91 |
92 private int getColorAsInt(@ColorRes int colorId) { | 92 private int getColorAsInt(@ColorRes int colorId) { |
93 return ApiCompatibilityUtils.getColor(getResources(), colorId); | 93 return ApiCompatibilityUtils.getColor(getResources(), colorId); |
94 } | 94 } |
95 } | 95 } |
OLD | NEW |