Commit 57fbc869 authored by jdduke's avatar jdduke Committed by Commit bot

[Android] Invalidate ChromeShell progress bar during animation

View invalidations outside of animation can stall the Chrome message
loop. Avoid such stalls during page load by synchronizing all
ChromeShell progress drawable updates with View animation.

BUG=414674

Review URL: https://codereview.chromium.org/583673002

Cr-Commit-Position: refs/heads/master@{#295604}
parent 0db1f016
......@@ -4,6 +4,7 @@
package org.chromium.base;
import android.animation.ValueAnimator;
import android.app.PendingIntent;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
......@@ -233,6 +234,37 @@ public class ApiCompatibilityUtils {
}
}
/**
* @see android.view.View#postOnAnimation()
*/
public static void postOnAnimation(View view, Runnable action) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postOnAnimation(action);
} else {
view.postDelayed(action, getFrameTime());
}
}
/**
* @see android.view.View#postOnAnimationDelayed()
*/
public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postOnAnimationDelayed(action, delayMillis);
} else {
view.postDelayed(action, getFrameTime() + delayMillis);
}
}
private static long getFrameTime() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return ValueAnimator.getFrameDelay();
} else {
// Any reasonable fake frame delay will have to do.
return 10;
}
}
/**
* @see android.widget.RemoteViews#setContentDescription(int, CharSequence)
*/
......
......@@ -19,6 +19,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine;
import org.chromium.chrome.browser.EmptyTabObserver;
import org.chromium.chrome.browser.Tab;
......@@ -41,6 +42,20 @@ public class ChromeShellToolbar extends LinearLayout {
}
};
private final Runnable mUpdateProgressRunnable = new Runnable() {
@Override
public void run() {
mProgressDrawable.setLevel(100 * mProgress);
if (mLoading) {
mStopReloadButton.setImageResource(R.drawable.btn_stop_normal);
} else {
mStopReloadButton.setImageResource(R.drawable.btn_reload_normal);
ApiCompatibilityUtils.postOnAnimationDelayed(ChromeShellToolbar.this,
mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
}
}
};
private EditText mUrlTextView;
private ClipDrawable mProgressDrawable;
......@@ -53,6 +68,7 @@ public class ChromeShellToolbar extends LinearLayout {
private SuggestionPopup mSuggestionPopup;
private ImageButton mStopReloadButton;
private int mProgress = 0;
private boolean mLoading = true;
/**
......@@ -89,14 +105,10 @@ public class ChromeShellToolbar extends LinearLayout {
private void onLoadProgressChanged(int progress) {
removeCallbacks(mClearProgressRunnable);
mProgressDrawable.setLevel(100 * progress);
removeCallbacks(mUpdateProgressRunnable);
mProgress = progress;
mLoading = progress != 100;
if (mLoading) {
mStopReloadButton.setImageResource(R.drawable.btn_stop_normal);
} else {
mStopReloadButton.setImageResource(R.drawable.btn_reload_normal);
postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
}
ApiCompatibilityUtils.postOnAnimation(this, mUpdateProgressRunnable);
}
/**
......
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