am d424e8a0: am 736432ed: Merge "Disallow going back to initial empty page in captive portal app" into mnc-dev
* commit 'd424e8a01694651a4c10f1d3b11ff55ff6e9fd35': Disallow going back to initial empty page in captive portal app
This commit is contained in:
@@ -66,6 +66,7 @@ public class CaptivePortalLoginActivity extends Activity {
|
|||||||
private NetworkCallback mNetworkCallback;
|
private NetworkCallback mNetworkCallback;
|
||||||
private ConnectivityManager mCm;
|
private ConnectivityManager mCm;
|
||||||
private boolean mLaunchBrowser = false;
|
private boolean mLaunchBrowser = false;
|
||||||
|
private MyWebViewClient mWebViewClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -115,7 +116,8 @@ public class CaptivePortalLoginActivity extends Activity {
|
|||||||
myWebView.clearCache(true);
|
myWebView.clearCache(true);
|
||||||
WebSettings webSettings = myWebView.getSettings();
|
WebSettings webSettings = myWebView.getSettings();
|
||||||
webSettings.setJavaScriptEnabled(true);
|
webSettings.setJavaScriptEnabled(true);
|
||||||
myWebView.setWebViewClient(new MyWebViewClient());
|
mWebViewClient = new MyWebViewClient();
|
||||||
|
myWebView.setWebViewClient(mWebViewClient);
|
||||||
myWebView.setWebChromeClient(new MyWebChromeClient());
|
myWebView.setWebChromeClient(new MyWebChromeClient());
|
||||||
// Start initial page load so WebView finishes loading proxy settings.
|
// Start initial page load so WebView finishes loading proxy settings.
|
||||||
// Actual load of mUrl is initiated by MyWebViewClient.
|
// Actual load of mUrl is initiated by MyWebViewClient.
|
||||||
@@ -174,7 +176,7 @@ public class CaptivePortalLoginActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
WebView myWebView = (WebView) findViewById(R.id.webview);
|
WebView myWebView = (WebView) findViewById(R.id.webview);
|
||||||
if (myWebView.canGoBack()) {
|
if (myWebView.canGoBack() && mWebViewClient.allowBack()) {
|
||||||
myWebView.goBack();
|
myWebView.goBack();
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
@@ -255,7 +257,12 @@ public class CaptivePortalLoginActivity extends Activity {
|
|||||||
getResources().getDisplayMetrics()) /
|
getResources().getDisplayMetrics()) /
|
||||||
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
|
||||||
getResources().getDisplayMetrics());
|
getResources().getDisplayMetrics());
|
||||||
private boolean mFirstPageLoad = true;
|
private int mPagesLoaded;
|
||||||
|
|
||||||
|
// If we haven't finished cleaning up the history, don't allow going back.
|
||||||
|
public boolean allowBack() {
|
||||||
|
return mPagesLoaded > 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||||
@@ -264,26 +271,32 @@ public class CaptivePortalLoginActivity extends Activity {
|
|||||||
done(Result.WANTED_AS_IS);
|
done(Result.WANTED_AS_IS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mFirstPageLoad) return;
|
// The first page load is used only to cause the WebView to
|
||||||
|
// fetch the proxy settings. Don't update the URL bar, and
|
||||||
|
// don't check if the captive portal is still there.
|
||||||
|
if (mPagesLoaded == 0) return;
|
||||||
|
// For internally generated pages, leave URL bar listing prior URL as this is the URL
|
||||||
|
// the page refers to.
|
||||||
|
if (!url.startsWith(INTERNAL_ASSETS)) {
|
||||||
|
final TextView myUrlBar = (TextView) findViewById(R.id.url_bar);
|
||||||
|
myUrlBar.setText(url);
|
||||||
|
}
|
||||||
testForCaptivePortal();
|
testForCaptivePortal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
if (mFirstPageLoad) {
|
mPagesLoaded++;
|
||||||
mFirstPageLoad = false;
|
if (mPagesLoaded == 1) {
|
||||||
// Now that WebView has loaded at least one page we know it has read in the proxy
|
// Now that WebView has loaded at least one page we know it has read in the proxy
|
||||||
// settings. Now prompt the WebView read the Network-specific proxy settings.
|
// settings. Now prompt the WebView read the Network-specific proxy settings.
|
||||||
setWebViewProxy();
|
setWebViewProxy();
|
||||||
// Load the real page.
|
// Load the real page.
|
||||||
view.loadUrl(mURL.toString());
|
view.loadUrl(mURL.toString());
|
||||||
return;
|
return;
|
||||||
}
|
} else if (mPagesLoaded == 2) {
|
||||||
// For internally generated pages, leave URL bar listing prior URL as this is the URL
|
// Prevent going back to empty first page.
|
||||||
// the page refers to.
|
view.clearHistory();
|
||||||
if (!url.startsWith(INTERNAL_ASSETS)) {
|
|
||||||
final TextView myUrlBar = (TextView) findViewById(R.id.url_bar);
|
|
||||||
myUrlBar.setText(url);
|
|
||||||
}
|
}
|
||||||
testForCaptivePortal();
|
testForCaptivePortal();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user