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 56d4fe776231143a8ac61caa7e76b28e8dc91c2f..9daa0f65a43d3b369ff3c0b00c3c7ae9e165e1a0 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 |
@@ -7,32 +7,49 @@ package org.chromium.webview_shell; |
import android.app.Activity; |
import android.content.Context; |
import android.content.Intent; |
+import android.content.pm.PackageInfo; |
+import android.content.pm.PackageManager; |
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.WebChromeClient; |
+import android.webkit.WebSettings; |
import android.webkit.WebView; |
import android.webkit.WebViewClient; |
+ |
import android.widget.EditText; |
+import android.widget.PopupMenu; |
import android.widget.TextView; |
+import org.chromium.base.Log; |
+ |
+import java.lang.reflect.InvocationTargetException; |
+import java.lang.reflect.Method; |
+import java.text.DateFormat; |
+ |
/** |
* 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 static final String WEBVIEW_PACKAGE_NAME = "com.google.android.webview"; |
Torne
2015/05/06 11:01:39
This isn't the WebView package name on all configu
timvolodine
2015/05/07 10:43:47
as we discussed I've removed the packageInfo relat
|
+ private static final String ABOUT_HEADER = "<html><body>"; |
+ private static final String ABOUT_FOOTER = "</body></html>"; |
+ |
@Override |
public void onCreate(Bundle savedInstanceState) { |
super.onCreate(savedInstanceState); |
- getWindow().setTitle( |
- getResources().getString(R.string.title_activity_browser)); |
+ 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); |
@@ -76,6 +93,62 @@ 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 about() { |
Torne
2015/05/06 11:01:39
I'd probably prefer this be a regular text popup d
timvolodine
2015/05/07 10:43:47
good point ;). I've added an AlertDialog instead
|
+ WebSettings settings = mWebView.getSettings(); |
+ PackageManager pm = getPackageManager(); |
+ |
+ StringBuilder summary = new StringBuilder(); |
+ summary.append(ABOUT_HEADER); |
+ try { |
+ PackageInfo pi = pm.getPackageInfo(WEBVIEW_PACKAGE_NAME, 0); |
+ summary.append("webview version : " + pi.versionName + ", " + pi.versionCode + "<br/>"); |
+ summary.append("first install time : " |
+ + DateFormat.getDateTimeInstance().format(pi.firstInstallTime) + "<br/>"); |
+ summary.append("last update time : " |
+ + DateFormat.getDateTimeInstance().format(pi.lastUpdateTime) + "<br/><hr/>"); |
+ } catch (PackageManager.NameNotFoundException e) { |
+ Log.i("WebView", "Android System WebView not found"); |
+ } |
+ |
+ // extract all no-argument methods returning a boolean or a String. |
+ for (Method method : settings.getClass().getMethods()) { |
+ if (!methodIsSimpleInspector(method)) continue; |
+ try { |
+ summary.append(method.getName() + " : " + method.invoke(settings) + "<br/>"); |
+ } catch (IllegalAccessException e) { |
+ } catch (InvocationTargetException e) { } |
+ } |
+ |
+ summary.append(ABOUT_FOOTER); |
+ mWebView.loadData(summary.toString(), "text/html", null); |
+ } |
+ |
+ // 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(); |