Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java

Issue 1128573002: [Android WebView] Add "about" menu with information about WebView settings to WebViewShell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no-find-copies Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/tools/WebViewShell/res/values/strings.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java
diff --git a/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java b/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java
index 047a87d9354287a10fd7244eadc3ad07828fda5c..b56d667980c2e31c8b2d0582c80f1501a32fed4a 100644
--- a/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java
+++ b/android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java
@@ -5,29 +5,47 @@
package org.chromium.webview_shell;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+
import android.view.KeyEvent;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
+
import android.webkit.GeolocationPermissions;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
+
import android.widget.EditText;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.PopupMenu;
import android.widget.TextView;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* This activity is designed for starting a "mini-browser" for manual testing of WebView.
* It takes an optional URL as an argument, and displays the page. There is a URL bar
* on top of the webview for manually specifying URLs to load.
*/
-public class WebViewBrowserActivity extends Activity {
+public class WebViewBrowserActivity extends Activity implements PopupMenu.OnMenuItemClickListener {
private EditText mUrlBar;
private WebView mWebView;
+ private String mWebViewVersion;
+
+ private static final Pattern WEBVIEW_VERSION_PATTERN =
+ Pattern.compile("(Chrome/)([\\d\\.]+)\\s");
private static final String[] AUTOMATICALLY_GRANT =
{ PermissionRequest.RESOURCE_VIDEO_CAPTURE, PermissionRequest.RESOURCE_AUDIO_CAPTURE };
@@ -35,12 +53,18 @@ public class WebViewBrowserActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getWindow().setTitle(
- getResources().getString(R.string.title_activity_browser));
setContentView(R.layout.activity_webview_browser);
mWebView = (WebView) findViewById(R.id.webview);
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView.getSettings().setGeolocationEnabled(true);
+ WebSettings settings = mWebView.getSettings();
+ initializeSettings(settings);
+
+ Matcher matcher = WEBVIEW_VERSION_PATTERN.matcher(settings.getUserAgentString());
+ if (matcher.find()) {
+ mWebViewVersion = matcher.group(2);
+ } else {
+ mWebViewVersion = "-";
+ }
+ setTitle(getResources().getString(R.string.title_activity_browser) + " " + mWebViewVersion);
mWebView.setWebViewClient(new WebViewClient() {
@Override
@@ -85,6 +109,59 @@ public class WebViewBrowserActivity extends Activity {
hideKeyboard(mUrlBar);
}
+ public void showPopup(View v) {
+ PopupMenu popup = new PopupMenu(this, v);
+ popup.setOnMenuItemClickListener(this);
+ popup.inflate(R.menu.main_menu);
+ popup.show();
+ }
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch(item.getItemId()) {
+ case R.id.menu_about:
+ about();
+ hideKeyboard(mUrlBar);
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private void initializeSettings(WebSettings settings) {
+ settings.setJavaScriptEnabled(true);
+ settings.setGeolocationEnabled(true);
+ }
+
+ private void about() {
+ WebSettings settings = mWebView.getSettings();
+ StringBuilder summary = new StringBuilder();
+ summary.append("WebView version : " + mWebViewVersion + "\n");
+
+ for (Method method : settings.getClass().getMethods()) {
+ if (!methodIsSimpleInspector(method)) continue;
+ try {
+ summary.append(method.getName() + " : " + method.invoke(settings) + "\n");
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) { }
+ }
+
+ AlertDialog dialog = new AlertDialog.Builder(this)
+ .setTitle(getResources().getString(R.string.menu_about))
+ .setMessage(summary)
+ .setPositiveButton("OK", null)
+ .create();
+ dialog.show();
+ dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+ }
+
+ // Returns true is a method has no arguments and returns either a boolean or a String.
+ private boolean methodIsSimpleInspector(Method method) {
+ Class<?> returnType = method.getReturnType();
+ return ((returnType.equals(boolean.class) || returnType.equals(String.class))
+ && method.getParameterTypes().length == 0);
+ }
+
private void loadUrl(String url) {
mWebView.loadUrl(url);
mWebView.requestFocus();
« no previous file with comments | « android_webview/tools/WebViewShell/res/values/strings.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698