Loading packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml +23 −19 Original line number Diff line number Diff line Loading @@ -5,23 +5,27 @@ android:layout_height="match_parent" tools:context="com.android.captiveportallogin.CaptivePortalLoginActivity" tools:ignore="MergeRootFrame" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/url_bar" <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:singleLine="true" /> android:layout_height="4dp" > <!-- Eliminates ProgressBar padding by boxing it into a 4dp high container --> <ProgressBar android:id="@+id/progress_bar" style="@android:style/Widget.Material.Light.ProgressBar.Horizontal" android:indeterminate="false" android:max="100" android:progress="0" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" /> android:layout_height="wrap_content" /> </FrameLayout> <WebView android:id="@+id/webview" Loading packages/CaptivePortalLogin/res/values/styles.xml +1 −4 Original line number Diff line number Diff line Loading @@ -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. --> <style name="AppBaseTheme" parent="@android:style/Theme.Material.Settings"> <style name="AppBaseTheme" parent="@android:style/Theme.DeviceDefault.Settings"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to Loading @@ -15,8 +15,5 @@ <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <!-- Setting's theme's accent color makes ProgressBar useless, reset back. --> <item name="android:colorAccent">@*android:color/material_deep_teal_500</item> </style> </resources> packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +45 −13 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -117,9 +116,14 @@ public class CaptivePortalLoginActivity extends Activity { } mCm.registerNetworkCallback(builder.build(), mNetworkCallback); final WebView myWebView = (WebView) 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); Loading @@ -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. Loading Loading @@ -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; } Loading Loading @@ -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 = (TextView) 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. Loading Loading @@ -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 = (ProgressBar) findViewById(R.id.progress_bar); myProgressBar.setProgress(newProgress); getProgressBar().setProgress(newProgress); } } private ProgressBar getProgressBar() { return (ProgressBar) findViewById(R.id.progress_bar); } private WebView getWebview() { return (WebView) 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(); } } Loading
packages/CaptivePortalLogin/res/layout/activity_captive_portal_login.xml +23 −19 Original line number Diff line number Diff line Loading @@ -5,23 +5,27 @@ android:layout_height="match_parent" tools:context="com.android.captiveportallogin.CaptivePortalLoginActivity" tools:ignore="MergeRootFrame" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/url_bar" <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:singleLine="true" /> android:layout_height="4dp" > <!-- Eliminates ProgressBar padding by boxing it into a 4dp high container --> <ProgressBar android:id="@+id/progress_bar" style="@android:style/Widget.Material.Light.ProgressBar.Horizontal" android:indeterminate="false" android:max="100" android:progress="0" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" /> android:layout_height="wrap_content" /> </FrameLayout> <WebView android:id="@+id/webview" Loading
packages/CaptivePortalLogin/res/values/styles.xml +1 −4 Original line number Diff line number Diff line Loading @@ -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. --> <style name="AppBaseTheme" parent="@android:style/Theme.Material.Settings"> <style name="AppBaseTheme" parent="@android:style/Theme.DeviceDefault.Settings"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to Loading @@ -15,8 +15,5 @@ <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <!-- Setting's theme's accent color makes ProgressBar useless, reset back. --> <item name="android:colorAccent">@*android:color/material_deep_teal_500</item> </style> </resources>
packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +45 −13 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -117,9 +116,14 @@ public class CaptivePortalLoginActivity extends Activity { } mCm.registerNetworkCallback(builder.build(), mNetworkCallback); final WebView myWebView = (WebView) 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); Loading @@ -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. Loading Loading @@ -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; } Loading Loading @@ -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 = (TextView) 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. Loading Loading @@ -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 = (ProgressBar) findViewById(R.id.progress_bar); myProgressBar.setProgress(newProgress); getProgressBar().setProgress(newProgress); } } private ProgressBar getProgressBar() { return (ProgressBar) findViewById(R.id.progress_bar); } private WebView getWebview() { return (WebView) 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(); } }