From a206649a6f66f16cc56db2f4e32b846d9b03501c Mon Sep 17 00:00:00 2001 From: Hugo Benichi Date: Wed, 17 May 2017 09:26:30 +0900 Subject: Prettify the captive portal sign-in activity - fuses url bar with activity header: url is now the subtitle - url appears as text and not as editable content - url only shows host name - header style is the device default for Settings - Material progress bar - progress bar disappears at page load finished - webview does not jump at page load finished Bug: 62107381 Bug: 38197949 Test: tested by manually triggering the sign-in activity Change-Id: Id75023acad04f444dbfc41de56814a09e70cc6f9 --- .../res/layout/activity_captive_portal_login.xml | 42 +++++++++------- packages/CaptivePortalLogin/res/values/styles.xml | 5 +- .../CaptivePortalLoginActivity.java | 58 +++++++++++++++++----- 3 files changed, 69 insertions(+), 36 deletions(-) diff --git a/packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml b/packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml index 2f0a411448a5..232459338f48 100644 --- a/packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml +++ b/packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml @@ -4,31 +4,35 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.android.captiveportallogin.CaptivePortalLoginActivity" - tools:ignore="MergeRootFrame"> + tools:ignore="MergeRootFrame" > + - + - + + + - + - + diff --git a/packages/CaptivePortalLogin/res/values/styles.xml b/packages/CaptivePortalLogin/res/values/styles.xml index 4a99638aec95..f6c233954b52 100644 --- a/packages/CaptivePortalLogin/res/values/styles.xml +++ b/packages/CaptivePortalLogin/res/values/styles.xml @@ -4,7 +4,7 @@ Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> - - diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java index c9fba95bc828..401a7bca525c 100644 --- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java @@ -37,6 +37,7 @@ import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.webkit.SslErrorHandler; import android.webkit.WebChromeClient; import android.webkit.WebSettings; @@ -97,8 +98,6 @@ public class CaptivePortalLoginActivity extends Activity { // setContentView initializes the WebView logic which in turn reads the system properties. setContentView(R.layout.activity_captive_portal_login); - getActionBar().setDisplayShowHomeEnabled(false); - // Exit app if Network disappears. final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork); if (networkCapabilities == null) { @@ -117,9 +116,14 @@ public class CaptivePortalLoginActivity extends Activity { } mCm.registerNetworkCallback(builder.build(), mNetworkCallback); - final WebView myWebView = findViewById(R.id.webview); - myWebView.clearCache(true); - WebSettings webSettings = myWebView.getSettings(); + getActionBar().setDisplayShowHomeEnabled(false); + getActionBar().setElevation(0); // remove shadow + getActionBar().setTitle(getHeaderTitle()); + getActionBar().setSubtitle(""); + + final WebView webview = getWebview(); + webview.clearCache(true); + WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); webSettings.setUseWideViewPort(true); @@ -128,11 +132,11 @@ public class CaptivePortalLoginActivity extends Activity { webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); mWebViewClient = new MyWebViewClient(); - myWebView.setWebViewClient(mWebViewClient); - myWebView.setWebChromeClient(new MyWebChromeClient()); + webview.setWebViewClient(mWebViewClient); + webview.setWebChromeClient(new MyWebChromeClient()); // Start initial page load so WebView finishes loading proxy settings. // Actual load of mUrl is initiated by MyWebViewClient. - myWebView.loadData("", "text/html", null); + webview.loadData("", "text/html", null); } // Find WebView's proxy BroadcastReceiver and prompt it to read proxy system properties. @@ -251,10 +255,14 @@ public class CaptivePortalLoginActivity extends Activity { if (url == null) { url = mCm.getCaptivePortalServerUrl(); } + return makeURL(url); + } + + private static URL makeURL(String url) { try { return new URL(url); } catch (MalformedURLException e) { - Log.e(TAG, "Invalid captive portal URL " + url); + Log.e(TAG, "Invalid URL " + url); } return null; } @@ -331,15 +339,16 @@ public class CaptivePortalLoginActivity extends Activity { // 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 = findViewById(R.id.url_bar); - myUrlBar.setText(url); + getActionBar().setSubtitle(getHeaderSubtitle(url)); } + getProgressBar().setVisibility(View.VISIBLE); testForCaptivePortal(); } @Override public void onPageFinished(WebView view, String url) { mPagesLoaded++; + getProgressBar().setVisibility(View.INVISIBLE); if (mPagesLoaded == 1) { // 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. @@ -412,8 +421,31 @@ public class CaptivePortalLoginActivity extends Activity { private class MyWebChromeClient extends WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { - final ProgressBar myProgressBar = findViewById(R.id.progress_bar); - myProgressBar.setProgress(newProgress); + getProgressBar().setProgress(newProgress); + } + } + + private ProgressBar getProgressBar() { + return findViewById(R.id.progress_bar); + } + + private WebView getWebview() { + return findViewById(R.id.webview); + } + + private String getHeaderTitle() { + return getString(R.string.action_bar_label); + } + + private String getHeaderSubtitle(String urlString) { + URL url = makeURL(urlString); + if (url == null) { + return urlString; + } + final String https = "https"; + if (https.equals(url.getProtocol())) { + return https + "://" + url.getHost(); } + return url.getHost(); } } -- cgit v1.2.3-59-g8ed1b