зеркало из https://github.com/mozilla/gecko-dev.git
Bug 917896 - Replace throbber with progress bar. r=lucasr
This commit is contained in:
Родитель
54aac6f336
Коммит
589fbd51c4
2
CLOBBER
2
CLOBBER
|
@ -22,4 +22,4 @@
|
|||
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
|
||||
# don't change CLOBBER for WebIDL changes any more.
|
||||
|
||||
Updates to NSS seem to require a clobber due bug 959928.
|
||||
Bug 917896 requires a clobber due to bug 961339.
|
||||
|
|
|
@ -1421,14 +1421,6 @@ abstract public class BrowserApp extends GeckoApp
|
|||
int id = Favicons.getSizedFavicon(tab.getURL(), tab.getFaviconURL(), tabFaviconSize, flags, sFaviconLoadedListener);
|
||||
|
||||
tab.setFaviconLoadId(id);
|
||||
|
||||
final Tabs tabs = Tabs.getInstance();
|
||||
if (id != Favicons.LOADED && tabs.isSelectedTab(tab)) {
|
||||
// We're loading the current tab's favicon from somewhere
|
||||
// other than the cache. Display the globe favicon until then.
|
||||
tab.updateFavicon(Favicons.sDefaultFavicon);
|
||||
tabs.notifyListeners(tab, Tabs.TabEvents.FAVICON);
|
||||
}
|
||||
}
|
||||
|
||||
private void maybeCancelFaviconLoad(Tab tab) {
|
||||
|
|
|
@ -69,6 +69,7 @@ public class Tab {
|
|||
private Context mAppContext;
|
||||
private ErrorType mErrorType = ErrorType.NONE;
|
||||
private static final int MAX_HISTORY_LIST_SIZE = 50;
|
||||
private int mLoadProgress;
|
||||
|
||||
public static final int STATE_DELAYED = 0;
|
||||
public static final int STATE_LOADING = 1;
|
||||
|
@ -764,4 +765,22 @@ public class Tab {
|
|||
public boolean isPrivate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tab load progress to the given percentage.
|
||||
*
|
||||
* @param progressPercentage Percentage to set progress to (0-100)
|
||||
*/
|
||||
void setLoadProgress(int progressPercentage) {
|
||||
mLoadProgress = progressPercentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tab load progress percentage.
|
||||
*
|
||||
* @return Current progress percentage
|
||||
*/
|
||||
public int getLoadProgress() {
|
||||
return mLoadProgress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ public class Tabs implements GeckoEventListener {
|
|||
private AccountManager mAccountManager;
|
||||
private OnAccountsUpdateListener mAccountListener = null;
|
||||
|
||||
private static final int LOAD_PROGRESS_START = 20;
|
||||
private static final int LOAD_PROGRESS_LOCATION_CHANGE = 60;
|
||||
private static final int LOAD_PROGRESS_LOADED = 80;
|
||||
|
||||
public static final int LOADURL_NONE = 0;
|
||||
public static final int LOADURL_NEW_TAB = 1 << 0;
|
||||
public static final int LOADURL_USER_ENTERED = 1 << 1;
|
||||
|
@ -435,6 +439,7 @@ public class Tabs implements GeckoEventListener {
|
|||
} else if (event.equals("Tab:Select")) {
|
||||
selectTab(tab.getId());
|
||||
} else if (event.equals("Content:LocationChange")) {
|
||||
tab.setLoadProgress(LOAD_PROGRESS_LOCATION_CHANGE);
|
||||
tab.handleLocationChange(message);
|
||||
} else if (event.equals("Content:SecurityChange")) {
|
||||
tab.updateIdentityData(message.getJSONObject("identity"));
|
||||
|
@ -448,6 +453,7 @@ public class Tabs implements GeckoEventListener {
|
|||
if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
|
||||
boolean showProgress = message.getBoolean("showProgress");
|
||||
tab.handleDocumentStart(showProgress, message.getString("uri"));
|
||||
tab.setLoadProgress(LOAD_PROGRESS_START);
|
||||
notifyListeners(tab, Tabs.TabEvents.START);
|
||||
} else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
|
||||
tab.handleDocumentStop(message.getBoolean("success"));
|
||||
|
@ -455,6 +461,7 @@ public class Tabs implements GeckoEventListener {
|
|||
}
|
||||
}
|
||||
} else if (event.equals("Content:LoadError")) {
|
||||
tab.setLoadProgress(LOAD_PROGRESS_LOADED);
|
||||
notifyListeners(tab, Tabs.TabEvents.LOAD_ERROR);
|
||||
} else if (event.equals("Content:PageShow")) {
|
||||
notifyListeners(tab, TabEvents.PAGE_SHOW);
|
||||
|
@ -467,6 +474,7 @@ public class Tabs implements GeckoEventListener {
|
|||
tab.setBackgroundColor(Color.WHITE);
|
||||
}
|
||||
tab.setErrorType(message.optString("errorType"));
|
||||
tab.setLoadProgress(LOAD_PROGRESS_LOADED);
|
||||
notifyListeners(tab, Tabs.TabEvents.LOADED);
|
||||
} else if (event.equals("DOMTitleChanged")) {
|
||||
tab.updateTitle(message.getString("title"));
|
||||
|
|
|
@ -320,6 +320,7 @@ gbjar.sources += [
|
|||
'toolbar/ToolbarDisplayLayout.java',
|
||||
'toolbar/ToolbarEditLayout.java',
|
||||
'toolbar/ToolbarEditText.java',
|
||||
'toolbar/ToolbarProgressView.java',
|
||||
'toolbar/ToolbarTitlePrefs.java',
|
||||
'TouchEventInterceptor.java',
|
||||
'updater/UpdateService.java',
|
||||
|
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 300 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 248 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 384 B |
|
@ -105,4 +105,12 @@
|
|||
android:background="@color/url_bar_shadow"
|
||||
android:contentDescription="@null"/>
|
||||
|
||||
<org.mozilla.gecko.toolbar.ToolbarProgressView android:id="@+id/progress"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_alignBottom="@id/shadow"
|
||||
android:src="@drawable/progress"
|
||||
android:background="@null"
|
||||
android:visibility="gone" />
|
||||
|
||||
</merge>
|
||||
|
|
|
@ -105,4 +105,12 @@
|
|||
android:background="@color/url_bar_shadow"
|
||||
android:contentDescription="@null"/>
|
||||
|
||||
<org.mozilla.gecko.toolbar.ToolbarProgressView android:id="@+id/progress"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_alignBottom="@id/shadow"
|
||||
android:src="@drawable/progress"
|
||||
android:background="@null"
|
||||
android:visibility="gone" />
|
||||
|
||||
</merge>
|
||||
|
|
|
@ -123,6 +123,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
private ImageButton mBack;
|
||||
private ImageButton mForward;
|
||||
|
||||
private ToolbarProgressView mProgressBar;
|
||||
private TabCounter mTabsCounter;
|
||||
private GeckoImageButton mMenu;
|
||||
private GeckoImageView mMenuIcon;
|
||||
|
@ -204,6 +205,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
mActionItemBar = (LinearLayout) findViewById(R.id.menu_items);
|
||||
mHasSoftMenuButton = !HardwareUtils.hasMenuButton();
|
||||
|
||||
mProgressBar = (ToolbarProgressView) findViewById(R.id.progress);
|
||||
|
||||
// We use different layouts on phones and tablets, so adjust the focus
|
||||
// order appropriately.
|
||||
mFocusOrder = new ArrayList<View>();
|
||||
|
@ -444,12 +447,33 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
mUrlDisplayLayout.dismissSiteIdentityPopup();
|
||||
updateTabCount(tabs.getDisplayCount());
|
||||
mSwitchingTabs = true;
|
||||
// Fall through.
|
||||
break;
|
||||
}
|
||||
|
||||
if (tabs.isSelectedTab(tab)) {
|
||||
final EnumSet<UpdateFlags> flags = EnumSet.noneOf(UpdateFlags.class);
|
||||
|
||||
// Progress-related handling
|
||||
switch (msg) {
|
||||
case START:
|
||||
updateProgressVisibility(tab, 0);
|
||||
// Fall through.
|
||||
case LOCATION_CHANGE:
|
||||
case LOAD_ERROR:
|
||||
case LOADED:
|
||||
flags.add(UpdateFlags.PROGRESS);
|
||||
if (mProgressBar.getVisibility() == View.VISIBLE) {
|
||||
mProgressBar.animateProgress(tab.getLoadProgress());
|
||||
}
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
case SELECTED:
|
||||
flags.add(UpdateFlags.PROGRESS);
|
||||
updateProgressVisibility();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (msg) {
|
||||
case TITLE:
|
||||
flags.add(UpdateFlags.TITLE);
|
||||
|
@ -458,16 +482,12 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
case START:
|
||||
updateBackButton(tab);
|
||||
updateForwardButton(tab);
|
||||
|
||||
flags.add(UpdateFlags.PROGRESS);
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
updateBackButton(tab);
|
||||
updateForwardButton(tab);
|
||||
|
||||
flags.add(UpdateFlags.PROGRESS);
|
||||
|
||||
// Reset the title in case we haven't navigated
|
||||
// to a new page yet.
|
||||
flags.add(UpdateFlags.TITLE);
|
||||
|
@ -511,6 +531,20 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
}
|
||||
}
|
||||
|
||||
private void updateProgressVisibility() {
|
||||
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
||||
updateProgressVisibility(selectedTab, selectedTab.getLoadProgress());
|
||||
}
|
||||
|
||||
private void updateProgressVisibility(Tab selectedTab, int progress) {
|
||||
if (!mIsEditing && selectedTab.getState() == Tab.STATE_LOADING) {
|
||||
mProgressBar.setProgress(progress);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return ViewHelper.getTranslationY(this) == 0;
|
||||
}
|
||||
|
@ -870,6 +904,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
setIsEditing(true);
|
||||
updateChildrenForEditing();
|
||||
|
||||
updateProgressVisibility();
|
||||
|
||||
if (mStartEditingListener != null) {
|
||||
mStartEditingListener.onStartEditing();
|
||||
}
|
||||
|
@ -990,6 +1026,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
mStopEditingListener.onStopEditing();
|
||||
}
|
||||
|
||||
updateProgressVisibility();
|
||||
|
||||
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
|
||||
hideUrlEditLayout();
|
||||
|
||||
|
@ -1214,7 +1252,6 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||
if (tab != null) {
|
||||
updateDisplayLayout(tab, EnumSet.of(UpdateFlags.FAVICON,
|
||||
UpdateFlags.SITE_IDENTITY,
|
||||
UpdateFlags.PROGRESS,
|
||||
UpdateFlags.PRIVATE_MODE));
|
||||
updateBackButton(tab);
|
||||
updateForwardButton(tab);
|
||||
|
|
|
@ -117,8 +117,6 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
|
||||
private PageActionLayout mPageActionLayout;
|
||||
|
||||
private Animation mProgressSpinner;
|
||||
|
||||
private AlphaAnimation mLockFadeIn;
|
||||
private TranslateAnimation mTitleSlideLeft;
|
||||
private TranslateAnimation mTitleSlideRight;
|
||||
|
@ -166,8 +164,6 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
|
||||
mSiteIdentityPopup.setAnchor(mSiteSecurity);
|
||||
|
||||
mProgressSpinner = AnimationUtils.loadAnimation(mActivity, R.anim.progress_spinner);
|
||||
|
||||
mStop = (ImageButton) findViewById(R.id.stop);
|
||||
mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
|
||||
}
|
||||
|
@ -357,12 +353,9 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
return;
|
||||
}
|
||||
|
||||
if (tab.getState() == Tab.STATE_LOADING) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap image = tab.getFavicon();
|
||||
if (image == mLastFavicon) {
|
||||
|
||||
if (image != null && image == mLastFavicon) {
|
||||
Log.d(LOGTAG, "Ignoring favicon: new image is identical to previous one.");
|
||||
return;
|
||||
}
|
||||
|
@ -376,7 +369,7 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false);
|
||||
mFavicon.setImageBitmap(image);
|
||||
} else {
|
||||
mFavicon.setImageDrawable(null);
|
||||
mFavicon.setImageResource(R.drawable.favicon);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,17 +415,8 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
// are needed by S1/S2 tests (http://mrcote.info/phonedash/#).
|
||||
// See discussion in Bug 804457. Bug 805124 tracks paring these down.
|
||||
if (mUiMode == UIMode.PROGRESS) {
|
||||
mLastFavicon = null;
|
||||
mFavicon.setImageResource(R.drawable.progress_spinner);
|
||||
mFavicon.setAnimation(mProgressSpinner);
|
||||
mProgressSpinner.start();
|
||||
|
||||
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
|
||||
} else {
|
||||
updateFavicon(tab);
|
||||
mFavicon.setAnimation(null);
|
||||
mProgressSpinner.cancel();
|
||||
|
||||
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber stop");
|
||||
}
|
||||
|
||||
|
@ -572,4 +556,4 @@ public class ToolbarDisplayLayout extends GeckoLinearLayout
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.mozilla.gecko.toolbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Progress view used for page loads.
|
||||
*
|
||||
* Because we're given limited information about the page load progress, the
|
||||
* bar also includes incremental animation between each step to improve
|
||||
* perceived performance.
|
||||
*/
|
||||
public class ToolbarProgressView extends ImageView {
|
||||
public static final int MAX_PROGRESS = 10000;
|
||||
private static final int MSG_UPDATE = 42;
|
||||
private static final int STEPS = 10;
|
||||
private static final int DELAY = 40;
|
||||
|
||||
private int mTargetProgress;
|
||||
private int mIncrement;
|
||||
private Rect mBounds;
|
||||
private Handler mHandler;
|
||||
private int mCurrentProgress;
|
||||
|
||||
public ToolbarProgressView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ToolbarProgressView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ToolbarProgressView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context ctx) {
|
||||
mBounds = new Rect(0,0,0,0);
|
||||
mTargetProgress = 0;
|
||||
|
||||
mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == MSG_UPDATE) {
|
||||
final int progress = Math.min(mTargetProgress, mCurrentProgress + mIncrement);
|
||||
mCurrentProgress = progress;
|
||||
|
||||
updateBounds();
|
||||
|
||||
if (progress < mTargetProgress) {
|
||||
sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE), DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(boolean f, int l, int t, int r, int b) {
|
||||
mBounds.left = 0;
|
||||
mBounds.right = (r - l) * mCurrentProgress / MAX_PROGRESS;
|
||||
mBounds.top = 0;
|
||||
mBounds.bottom = b - t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
final Drawable d = getDrawable();
|
||||
d.setBounds(mBounds);
|
||||
d.draw(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Immediately sets the progress bar to the given progress percentage.
|
||||
*
|
||||
* @param progress Percentage (0-100) to which progress bar should be set
|
||||
*/
|
||||
void setProgress(int progressPercentage) {
|
||||
mCurrentProgress = mTargetProgress = getAbsoluteProgress(progressPercentage);
|
||||
updateBounds();
|
||||
|
||||
mHandler.removeMessages(MSG_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates the progress bar from the current progress value to the given
|
||||
* progress percentage.
|
||||
*
|
||||
* @param progress Percentage (0-100) to which progress bar should be animated
|
||||
*/
|
||||
void animateProgress(int progressPercentage) {
|
||||
final int absoluteProgress = getAbsoluteProgress(progressPercentage);
|
||||
if (absoluteProgress == mTargetProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCurrentProgress = mTargetProgress;
|
||||
mTargetProgress = absoluteProgress;
|
||||
mIncrement = (mTargetProgress - mCurrentProgress) / STEPS;
|
||||
|
||||
mHandler.removeMessages(MSG_UPDATE);
|
||||
mHandler.sendEmptyMessage(MSG_UPDATE);
|
||||
}
|
||||
|
||||
private int getAbsoluteProgress(int progressPercentage) {
|
||||
if (progressPercentage < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (progressPercentage > 100) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return progressPercentage * MAX_PROGRESS / 100;
|
||||
}
|
||||
|
||||
private void updateBounds() {
|
||||
mBounds.right = getWidth() * mCurrentProgress / MAX_PROGRESS;
|
||||
invalidate();
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче