Fields Summary |
---|
public static final String | LOGTAG |
public static final String | PARAM_URL |
public static final String | PARAM_TIMEOUT |
public static final int | RESULT_TIMEOUT |
public static final int | MSG_TIMEOUT |
public static final int | MSG_NAVIGATE |
public static final String | MSG_NAV_URL |
public static final String | MSG_NAV_LOGTIME |
private android.webkit.WebView | webView |
private SimpleWebViewClient | webViewClient |
private SimpleChromeClient | chromeClient |
private android.os.Handler | handler |
private boolean | timeoutFlag |
private boolean | logTime |
private boolean | pageDone |
private Object | pageDoneLock |
private int | pageStartCount |
private int | manualDelay |
private long | startTime |
private long | pageLoadTime |
private PageDoneRunner | pageDoneRunner |
Methods Summary |
---|
public android.os.Handler | getHandler()
return handler;
|
public boolean | getPageError()
return webViewClient.getPageErrorFlag();
|
public long | getPageLoadTime()
return pageLoadTime;
|
private void | handleTimeout()
int progress = webView.getProgress();
webView.stopLoading();
Log.v(LOGTAG, "Page timeout triggered, progress = " + progress);
timeoutFlag = true;
handler.postDelayed(pageDoneRunner, manualDelay);
|
private boolean | isPageDone()
synchronized (pageDoneLock) {
return pageDone;
}
|
private void | navigate(java.lang.String url, int timeout)
if(url == null) {
Log.v(LOGTAG, "URL is null, cancelling...");
finish();
}
webView.stopLoading();
if(logTime) {
webView.clearCache(true);
}
startTime = System.currentTimeMillis();
Log.v(LOGTAG, "Navigating to URL: " + url);
webView.loadUrl(url);
if(timeout != 0) {
//set a timer with specified timeout (in ms)
handler.sendMessageDelayed(handler.obtainMessage(MSG_TIMEOUT),
timeout);
}
|
protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
Log.v(LOGTAG, "onCreate, inst=" + Integer.toHexString(hashCode()));
LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView);
setTitle("Idle");
webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
webViewClient = new SimpleWebViewClient();
chromeClient = new SimpleChromeClient();
webView.setWebViewClient(webViewClient);
webView.setWebChromeClient(chromeClient);
contentView.addView(webView, new LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_TIMEOUT:
handleTimeout();
return;
case MSG_NAVIGATE:
manualDelay = msg.arg2;
navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
return;
}
}
};
pageDoneLock = new Object();
|
protected void | onDestroy()
super.onDestroy();
Log.v(LOGTAG, "onDestroy, inst=" + Integer.toHexString(hashCode()));
webView.clearCache(true);
webView.destroy();
|
public void | reset()
synchronized (pageDoneLock) {
pageDone = false;
}
timeoutFlag = false;
pageStartCount = 0;
chromeClient.resetJsTimeout();
|
private void | setPageDone(boolean pageDone)
synchronized (pageDoneLock) {
this.pageDone = pageDone;
pageDoneLock.notifyAll();
}
|
private final void | validateNotAppThread()
if (Looper.myLooper() == Looper.getMainLooper()) {
throw new RuntimeException(
"This method can not be called from the main application thread");
}
|
public boolean | waitUntilDone()
validateNotAppThread();
synchronized (pageDoneLock) {
while(!isPageDone()) {
try {
pageDoneLock.wait();
} catch (InterruptedException ie) {
//no-op
}
}
}
return timeoutFlag;
|