List of usage examples for android.webkit WebView WebView
public WebView(Context context)
From source file:com.codename1.impl.android.AndroidImplementation.java
public PeerComponent createBrowserComponent(final Object parent) { if (getActivity() == null) { return null; }/* w w w .j a v a2 s . co m*/ final AndroidImplementation.AndroidBrowserComponent[] bc = new AndroidImplementation.AndroidBrowserComponent[1]; final Throwable[] error = new Throwable[1]; final Object lock = new Object(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { synchronized (lock) { try { WebView wv = new WebView(getActivity()) { public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_BACK); return true; case KeyEvent.KEYCODE_MENU: //if the native commands are used don't handle the keycode if (Display.getInstance() .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) { Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU); return true; } } return super.onKeyDown(keyCode, event); } public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Display.getInstance().keyReleased(AndroidImplementation.DROID_IMPL_KEY_BACK); return true; case KeyEvent.KEYCODE_MENU: //if the native commands are used don't handle the keycode if (Display.getInstance() .getCommandBehavior() != Display.COMMAND_BEHAVIOR_NATIVE) { Display.getInstance().keyPressed(AndroidImplementation.DROID_IMPL_KEY_MENU); return true; } } return super.onKeyUp(keyCode, event); } }; wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); wv.getSettings().setDomStorageEnabled(true); wv.requestFocus(View.FOCUS_DOWN); wv.setFocusableInTouchMode(true); bc[0] = new AndroidImplementation.AndroidBrowserComponent(wv, getActivity(), parent); lock.notify(); } catch (Throwable t) { error[0] = t; lock.notify(); } } } }); while (bc[0] == null && error[0] == null) { Display.getInstance().invokeAndBlock(new Runnable() { public void run() { synchronized (lock) { if (bc[0] == null && error[0] == null) { try { lock.wait(20); } catch (InterruptedException ex) { ex.printStackTrace(); } } } } }); } if (error[0] != null) { throw new RuntimeException(error[0]); } return bc[0]; }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
private void onAbout() { String appName = getString(R.string.app_name); int year = Calendar.getInstance().get(Calendar.YEAR); WebView wv = new WebView(this); StringBuilder html = new StringBuilder() .append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />") .append("<img src=\"file:///android_asset/icon.png\" alt=\"").append(appName).append("\"/>") .append("<h1>") .append(String.format(getString(R.string.about_title_fmt), "<a href=\"" + getString(R.string.app_webpage_url)) + "\">") .append(appName).append("</a>").append("</h1><p>").append(appName).append(" ") .append(String.format(getString(R.string.debug_version_fmt), getVersionNumber())).append("</p><p>") .append(String.format(getString(R.string.app_authors_fmt), getString(R.string.app_authors))) .append("</p><p>") .append(String.format(getString(R.string.app_revision_fmt), "<a href=\"" + getString(R.string.app_revision_url) + "\">" + getString(R.string.app_revision_url) + "</a>")) .append("</p><hr/><p>").append(String.format(getString(R.string.app_copyright_fmt), year, year)) .append("</p><hr/><p>").append(getString(R.string.app_license)).append("</p><hr/><p>"); StringBuilder libs = new StringBuilder().append("<ul>"); for (String[] library : USED_LIBRARIES) { libs.append("<li><a href=\"").append(library[1]).append("\">").append(library[0]).append("</a></li>"); }/*from w w w . ja v a2 s . com*/ libs.append("</ul>"); html.append(String.format(getString(R.string.app_libraries), libs.toString())).append("</p><hr/><p>") .append(String.format(getString(R.string.app_emoji_icons), "<div>TypePad \u7d75\u6587\u5b57\u30a2\u30a4\u30b3\u30f3\u753b\u50cf " + "(<a href=\"http://typepad.jp/\">Six Apart Ltd</a>) / " + "<a href=\"http://creativecommons.org/licenses/by/2.1/jp/\">CC BY 2.1</a></div>")) .append("</p><hr/><p>").append(getString(R.string.app_htmlcleaner_license)); wv.loadDataWithBaseURL("file:///android_res/drawable/", html.toString(), "text/html", "utf-8", null); new AlertDialog.Builder(this).setView(wv).setCancelable(true) .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int c) { d.dismiss(); } }).setNeutralButton(R.string.changelog_full_title, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int c) { new ChangeLog(MessageList.this).getFullLogDialog().show(); } }).show(); }