Commit b5bc3370 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: display progress loading indicator in Android shell.

Bug: none
Change-Id: If5638142eff88e547ba37fe9288faf9be7cdc286
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814869
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698671}
parent d2ff8c99
......@@ -35,9 +35,16 @@ void BrowserObserverProxy::DisplayedURLChanged(const GURL& url) {
}
void BrowserObserverProxy::LoadingStateChanged(bool is_loading,
bool to_different_document) {}
bool to_different_document) {
JNIEnv* env = AttachCurrentThread();
Java_BrowserObserverProxy_loadingStateChanged(env, java_observer_, is_loading,
to_different_document);
}
void BrowserObserverProxy::LoadProgressChanged(double progress) {}
void BrowserObserverProxy::LoadProgressChanged(double progress) {
JNIEnv* env = AttachCurrentThread();
Java_BrowserObserverProxy_loadProgressChanged(env, java_observer_, progress);
}
void BrowserObserverProxy::FirstContentfulPaint() {}
......
......@@ -42,6 +42,24 @@ public final class BrowserObserverProxy {
}
}
@CalledByNative
private void loadingStateChanged(boolean isLoading, boolean toDifferentDocument) {
try {
mClient.loadingStateChanged(isLoading, toDifferentDocument);
} catch (RemoteException e) {
throw new APICallException(e);
}
}
@CalledByNative
private void loadProgressChanged(double progress) {
try {
mClient.loadProgressChanged(progress);
} catch (RemoteException e) {
throw new APICallException(e);
}
}
@NativeMethods
interface Natives {
long createBrowserObserverProxy(BrowserObserverProxy proxy, long browserController);
......
......@@ -9,6 +9,7 @@ package org.chromium.weblayer_private.aidl;
* BrowserObserver interface, but is a singleton to avoid unnecessary IPC.
*/
interface IBrowserControllerClient {
/** The Uri that should be displayed in the url-bar has updated. */
void displayURLChanged(in String url) = 0;
void loadingStateChanged(boolean is_loading, boolean to_different_document) = 1;
void loadProgressChanged(double progress) = 2;
}
......@@ -76,5 +76,19 @@ public final class BrowserController {
observer.displayURLChanged(uri);
}
}
@Override
public void loadingStateChanged(boolean isLoading, boolean toDifferentDocument) {
for (BrowserObserver observer : mObservers) {
observer.loadingStateChanged(isLoading, toDifferentDocument);
}
}
@Override
public void loadProgressChanged(double progress) {
for (BrowserObserver observer : mObservers) {
observer.loadProgressChanged(progress);
}
}
}
}
......@@ -12,6 +12,24 @@ import android.net.Uri;
public abstract class BrowserObserver {
/**
* The Uri that should be displayed in the url-bar has updated.
*
* @param url The new user-visible url.
*/
public void displayURLChanged(Uri url) {}
/**
* The load state of the document has changed.
*
* @param isLoading Whether any resource is loading.
* @param toDifferentDocument True if the main frame is loading a different document. Only valid
* when |isLoading| is true.
*/
public void loadingStateChanged(boolean isLoading, boolean toDifferentDocument) {}
/**
* The progress of loading the main frame in the document has changed.
*
* @param progress A value in the range of 0.0-1.0.
*/
public void loadProgressChanged(double progress) {}
}
......@@ -16,9 +16,12 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
......@@ -38,6 +41,7 @@ public class WebLayerShellActivity extends FragmentActivity {
private BrowserFragmentImpl mBrowserFragment;
private BrowserController mBrowserController;
private EditText mUrlView;
private ProgressBar mLoadProgressBar;
private View mMainView;
public static class ShellFragment extends Fragment {
......@@ -76,6 +80,7 @@ public class WebLayerShellActivity extends FragmentActivity {
setContentView(mainView);
mUrlView = new EditText(this);
mUrlView.setId(View.generateViewId());
mUrlView.setSelectAllOnFocus(true);
mUrlView.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
mUrlView.setImeOptions(EditorInfo.IME_ACTION_GO);
......@@ -95,6 +100,23 @@ public class WebLayerShellActivity extends FragmentActivity {
}
});
mLoadProgressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
mLoadProgressBar.setIndeterminate(false);
mLoadProgressBar.setMax(100);
mLoadProgressBar.setVisibility(View.INVISIBLE);
// The progress bar sits above the URL bar in Z order and at its bottom in Y.
RelativeLayout topContentsContainer = new RelativeLayout(this);
topContentsContainer.addView(mUrlView,
new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
RelativeLayout.LayoutParams progressLayoutParams = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
progressLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, mUrlView.getId());
progressLayoutParams.setMargins(0, 0, 0, -10);
topContentsContainer.addView(mLoadProgressBar, progressLayoutParams);
mProfile = WebLayer.getInstance().createProfile(null);
mBrowserFragment = mProfile.createBrowserFragment(this);
mBrowserController = mBrowserFragment.getBrowserController();
......@@ -103,7 +125,7 @@ public class WebLayerShellActivity extends FragmentActivity {
transaction.add(viewId, new ShellFragment(mBrowserFragment));
transaction.commit();
mBrowserFragment.setTopView(mUrlView);
mBrowserFragment.setTopView(topContentsContainer);
String startupUrl = getUrlFromIntent(getIntent());
if (TextUtils.isEmpty(startupUrl)) {
......@@ -115,6 +137,17 @@ public class WebLayerShellActivity extends FragmentActivity {
public void displayURLChanged(Uri uri) {
mUrlView.setText(uri.toString());
}
@Override
public void loadingStateChanged(boolean isLoading, boolean toDifferentDocument) {
mLoadProgressBar.setVisibility(
isLoading && toDifferentDocument ? View.VISIBLE : View.INVISIBLE);
}
@Override
public void loadProgressChanged(double progress) {
mLoadProgressBar.setProgress((int) Math.round(100 * progress));
}
});
}
......
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