Bug 1337238 - Involve ProgressBar to CustomTabsActivity for page loading
To add a progressbar to CustomTabsActivity then user knows page loading
progress.
MozReview-Commit-ID: L1Qc7Oj81bZ
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -25,16 +25,17 @@ import android.support.v7.widget.Toolbar
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
+import android.widget.ProgressBar;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.menu.GeckoMenuInflater;
import org.mozilla.gecko.util.ColorUtil;
@@ -49,16 +50,17 @@ public class CustomTabsActivity extends
private static final String SAVED_TOOLBAR_COLOR = "SavedToolbarColor";
@ColorInt
private static final int DEFAULT_ACTION_BAR_COLOR = 0xFF363b40; // default color to match design
private final SparseArrayCompat<PendingIntent> menuItemsIntent = new SparseArrayCompat<>();
private GeckoPopupMenu popupMenu;
private ActionBarPresenter actionBarPresenter;
+ private ProgressBar mProgressView;
// A state to indicate whether this activity is finishing with customize animation
private boolean usingCustomAnimation = false;
@ColorInt
private int toolbarColor = DEFAULT_ACTION_BAR_COLOR;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -70,16 +72,17 @@ public class CustomTabsActivity extends
toolbarColor = getIntent().getIntExtra(EXTRA_TOOLBAR_COLOR, DEFAULT_ACTION_BAR_COLOR);
}
// Translucent color does not make sense for toolbar color. Ensure it is 0xFF.
toolbarColor = 0xFF000000 | toolbarColor;
setThemeFromToolbarColor();
+ mProgressView = (ProgressBar) findViewById(R.id.page_progress);
final Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
bindNavigationCallback(toolbar);
actionBarPresenter = new ActionBarPresenter(actionBar);
actionBarPresenter.displayUrlOnly(getIntent().getDataString());
actionBarPresenter.setBackgroundColor(toolbarColor, getWindow());
@@ -145,16 +148,27 @@ public class CustomTabsActivity extends
}
@Override
public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
if (!Tabs.getInstance().isSelectedTab(tab)) {
return;
}
+ if (msg == Tabs.TabEvents.START
+ || msg == Tabs.TabEvents.STOP
+ || msg == Tabs.TabEvents.ADDED
+ || msg == Tabs.TabEvents.LOAD_ERROR
+ || msg == Tabs.TabEvents.LOADED
+ || msg == Tabs.TabEvents.LOCATION_CHANGE) {
+
+ updateProgress((tab.getState() == Tab.STATE_LOADING),
+ tab.getLoadProgress());
+ }
+
if (msg == Tabs.TabEvents.LOCATION_CHANGE
|| msg == Tabs.TabEvents.SECURITY_CHANGE
|| msg == Tabs.TabEvents.TITLE) {
actionBarPresenter.update(tab);
}
updateMenuItemForward();
}
@@ -358,16 +372,31 @@ public class CustomTabsActivity extends
}
final MenuItem forwardMenuItem = popupMenu.getMenu().findItem(R.id.custom_tabs_menu_forward);
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean enabled = (tab != null && tab.canDoForward());
forwardMenuItem.setEnabled(enabled);
}
+ /**
+ * Update loading progress of current page
+ *
+ * @param isLoading to indicate whether ProgressBar should be visible or not
+ * @param progress value of loading progress in percent, should be 0 - 100.
+ */
+ private void updateProgress(final boolean isLoading, final int progress) {
+ if (isLoading) {
+ mProgressView.setVisibility(View.VISIBLE);
+ mProgressView.setProgress(progress);
+ } else {
+ mProgressView.setVisibility(View.GONE);
+ }
+ }
+
private void onReloadClicked() {
final Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
tab.doReload(true);
}
}
private void onForwardClicked() {
--- a/mobile/android/base/resources/layout/customtabs_activity.xml
+++ b/mobile/android/base/resources/layout/customtabs_activity.xml
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--
This layout is quite complex because GeckoApp accesses all view groups
in this tree. In a perfect world this should just include a GeckoView.
@@ -42,9 +43,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"/>
</RelativeLayout>
</view>
+ <ProgressBar
+ android:id="@id/page_progress"
+ style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="4dp"
+ android:layout_alignTop="@id/main_layout"
+ android:background="@drawable/url_bar_bg"
+ android:progressDrawable="@drawable/progressbar"
+ tools:progress="70"/>
+
</RelativeLayout>
\ No newline at end of file