List of usage examples for android.webkit WebView WebView
public WebView(Context context)
From source file:biz.bokhorst.xprivacy.ActivityMain.java
private void optionChangelog() { WebView webview = new WebView(this); webview.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { int userId = Util.getUserId(Process.myUid()); Version currentVersion = new Version(Util.getSelfVersionName(ActivityMain.this)); PrivacyManager.setSetting(userId, PrivacyManager.cSettingChangelog, currentVersion.toString()); }// w w w. j a v a 2 s . co m }); webview.loadUrl("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md"); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.menu_changelog); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(webview); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:com.fsck.k9.activity.Accounts.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, 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 . j a va 2s . co m 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() { public void onClick(DialogInterface d, int c) { d.dismiss(); } }).setNeutralButton(R.string.changelog_full_title, new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int c) { new ChangeLog(Accounts.this).getFullLogDialog().show(); } }).show(); }
From source file:com.openatk.field_work.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.main_menu_add) { // Check if have an operation if (operationsList.isEmpty()) { // Show dialog to create operation createOperation(new Callable<Void>() { public Void call() { //Do this after we create an operation return addFieldMapView(); }//from ww w.ja v a2 s.c om }); } else { addFieldMapView(); } } else if (item.getItemId() == R.id.main_menu_current_location) { Location myLoc = map.getMyLocation(); if (myLoc == null) { Toast.makeText(this, "Still searching for your location", Toast.LENGTH_SHORT).show(); } else { CameraPosition oldPos = map.getCameraPosition(); CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()), map.getMaxZoomLevel() - 5.0f, oldPos.tilt, oldPos.bearing); map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos)); } } else if (item.getItemId() == R.id.main_menu_layers) { MenuItem layers = menu.findItem(R.id.main_menu_layers); //TODO hazards /*if(showingHazards == false){ showingHazards = true; layers.setTitle("Hide Hazards"); } else { showingHazards = false; layers.setTitle("Show Hazards"); } SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("showingHazards",showingHazards); editor.commit(); drawHazards();*/ } else if (item.getItemId() == R.id.main_menu_sync) { this.syncHelper.sync(this); } else if (item.getItemId() == R.id.main_menu_list_view) { // Show list view Log.d("MainActivity", "Showing list view"); setState(STATE_LIST_VIEW); } else if (item.getItemId() == R.id.main_menu_map_view) { // Show map view Log.d("MainActivity", "Showing map view"); setState(STATE_DEFAULT); closeKeyboard(); } else if (item.getItemId() == R.id.main_menu_help) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Help"); WebView wv = new WebView(this); wv.loadUrl("file:///android_asset/Help.html"); wv.getSettings().setSupportZoom(true); wv.getSettings().setBuiltInZoomControls(true); /*wv.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } });*/ alert.setView(wv); alert.setNegativeButton("Close", null); alert.show(); } else if (item.getItemId() == R.id.main_menu_legal) { CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n" + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy " + "of this software and associated documentation files (the \"Software\"), to deal " + "in the Software without restriction, including without limitation the rights " + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell " + "copies of the Software, and to permit persons to whom the Software is " + "furnished to do so, subject to the following conditions:" + "\n" + "The above copyright notice and this permission notice shall be included in " + "all copies or substantial portions of the Software.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, " + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, " + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN " + "THE SOFTWARE.\n"; new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show(); } else if (item.getItemId() == R.id.main_menu_autosync) { TrelloSyncInfo syncInfo = syncHelper.getSyncInfo(getApplicationContext()); int selected = -1; if (syncInfo != null) { if (syncInfo.getAutoSync() != null && syncInfo.getAutoSync() == false) { selected = 0; } else if (syncInfo.getInterval() != null) { Log.d("MainActivity", "syncInfo interval:" + syncInfo.getInterval()); if (syncInfo.getInterval() == 60) selected = 1; if (syncInfo.getInterval() == 60 * 5) selected = 2; if (syncInfo.getInterval() == 60 * 10) selected = 3; if (syncInfo.getInterval() == 60 * 30) selected = 4; } } String[] options = { "Never", "1 min", "5 min", "10 min", "30 min" }; new AlertDialog.Builder(this).setTitle("Autosync Interval") .setSingleChoiceItems(options, selected, new DialogInterface.OnClickListener() { Integer devAutoSyncOnTrigger = 0; public void onClick(DialogInterface dialog, int which) { if (which == 0) { syncHelper.autoSyncOff(getApplicationContext()); } else if (which == 1) { syncHelper.autoSyncOn(getApplicationContext(), 60); } else if (which == 2) { syncHelper.autoSyncOn(getApplicationContext(), 60 * 5); } else if (which == 3) { syncHelper.autoSyncOn(getApplicationContext(), 60 * 10); } else if (which == 4) { syncHelper.autoSyncOn(getApplicationContext(), 60 * 30); devAutoSyncOnTrigger++; if (devAutoSyncOnTrigger > 9) { if (devAutoSyncOnTrigger % 2 == 0) { syncHelper.devAutoSyncOn(getApplicationContext(), 3); Toast.makeText(getApplicationContext(), "Presentation auto sync on, every 3 seconds.", Toast.LENGTH_SHORT) .show(); } else { syncHelper.devAutoSyncOff(getApplicationContext()); Toast.makeText(getApplicationContext(), "Presentation auto sync off.", Toast.LENGTH_SHORT).show(); } } } } }).setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }).show(); } return true; }
From source file:android.webkit.cts.WebViewTest.java
@UiThreadTest public void testDestroy() { if (!NullWebViewUtils.isWebViewAvailable()) { return;/*from w ww.j av a2s . c om*/ } // Create a new WebView, since we cannot call destroy() on a view in the hierarchy WebView localWebView = new WebView(getActivity()); localWebView.destroy(); }
From source file:org.mdc.chess.MDChess.java
private void aboutDialog() { //AlertDialog.Builder builder = new AlertDialog.Builder(this); String title = getString(R.string.app_name); WebView wv = new WebView(this); //builder.setView(wv); InputStream is = getResources().openRawResource(R.raw.about); String data = Util.readFromStream(is); if (data == null) { data = ""; }/*from w ww. ja v a 2 s . c o m*/ try { is.close(); } catch (IOException e1) { Log.d("Exception", e1.toString()); } wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null); try { PackageInfo pi = getPackageManager().getPackageInfo("org.mdc.chess", 0); title += " " + pi.versionName; } catch (NameNotFoundException e) { Log.d("Exception", e.toString()); } new MaterialDialog.Builder(this).title(title).customView(wv, true).show(); }
From source file:android.webkit.cts.WebViewTest.java
@UiThreadTest public void testSaveAndRestoreState() throws Throwable { if (!NullWebViewUtils.isWebViewAvailable()) { return;/*from w w w .j a v a2 s . c o m*/ } // nothing to save assertNull(mWebView.saveState(new Bundle())); startWebServer(false); String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1); String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2); String url3 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL3); // make a history list mOnUiThread.loadUrlAndWaitForCompletion(url1); pollingCheckWebBackForwardList(url1, 0, 1); mOnUiThread.loadUrlAndWaitForCompletion(url2); pollingCheckWebBackForwardList(url2, 1, 2); mOnUiThread.loadUrlAndWaitForCompletion(url3); pollingCheckWebBackForwardList(url3, 2, 3); // save the list Bundle bundle = new Bundle(); WebBackForwardList saveList = mWebView.saveState(bundle); assertNotNull(saveList); assertEquals(3, saveList.getSize()); assertEquals(2, saveList.getCurrentIndex()); assertEquals(url1, saveList.getItemAtIndex(0).getUrl()); assertEquals(url2, saveList.getItemAtIndex(1).getUrl()); assertEquals(url3, saveList.getItemAtIndex(2).getUrl()); // change the content to a new "blank" web view without history final WebView newWebView = new WebView(getActivity()); WebBackForwardList copyListBeforeRestore = newWebView.copyBackForwardList(); assertNotNull(copyListBeforeRestore); assertEquals(0, copyListBeforeRestore.getSize()); // restore the list final WebBackForwardList restoreList = newWebView.restoreState(bundle); assertNotNull(restoreList); assertEquals(3, restoreList.getSize()); assertEquals(2, saveList.getCurrentIndex()); // wait for the list items to get inflated new PollingCheck(TEST_TIMEOUT) { @Override protected boolean check() { return restoreList.getItemAtIndex(0).getUrl() != null && restoreList.getItemAtIndex(1).getUrl() != null && restoreList.getItemAtIndex(2).getUrl() != null; } }.run(); assertEquals(url1, restoreList.getItemAtIndex(0).getUrl()); assertEquals(url2, restoreList.getItemAtIndex(1).getUrl()); assertEquals(url3, restoreList.getItemAtIndex(2).getUrl()); WebBackForwardList copyListAfterRestore = newWebView.copyBackForwardList(); assertNotNull(copyListAfterRestore); assertEquals(3, copyListAfterRestore.getSize()); assertEquals(2, copyListAfterRestore.getCurrentIndex()); assertEquals(url1, copyListAfterRestore.getItemAtIndex(0).getUrl()); assertEquals(url2, copyListAfterRestore.getItemAtIndex(1).getUrl()); assertEquals(url3, copyListAfterRestore.getItemAtIndex(2).getUrl()); }
From source file:org.petero.droidfish.DroidFish.java
private final Dialog aboutDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String title = getString(R.string.app_name); WebView wv = new WebView(this); builder.setView(wv);//from ww w . java2s . c o m InputStream is = getResources().openRawResource(R.raw.about); String data = Util.readFromStream(is); if (data == null) data = ""; try { is.close(); } catch (IOException e1) { } wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null); try { PackageInfo pi = getPackageManager().getPackageInfo("org.petero.droidfish", 0); title += " " + pi.versionName; } catch (NameNotFoundException e) { } builder.setTitle(title); AlertDialog alert = builder.create(); return alert; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog aboutDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String title = getString(R.string.app_name); WebView wv = new WebView(this); builder.setView(wv);// ww w . j av a2s. c om InputStream is = getResources().openRawResource(R.raw.about); String data = Util.readFromStream(is); if (data == null) data = ""; try { is.close(); } catch (IOException e1) { } wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null); try { PackageInfo pi = getPackageManager().getPackageInfo("edu.mit.viral.shen", 0); title += " " + pi.versionName; } catch (NameNotFoundException e) { } builder.setTitle(title); AlertDialog alert = builder.create(); return alert; }
From source file:com.if3games.chessonline.DroidFish.java
private final Dialog aboutDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String title = getString(R.string.app_name); WebView wv = new WebView(this); builder.setView(wv);/*from w w w . j a v a 2s . com*/ InputStream is = getResources().openRawResource(R.raw.about); String data = Util.readFromStream(is); if (data == null) data = ""; try { is.close(); } catch (IOException e1) { } wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null); try { PackageInfo pi = getPackageManager().getPackageInfo("com.if3games.chessonline", 0); title += " " + pi.versionName; } catch (NameNotFoundException e) { } builder.setTitle(title); AlertDialog alert = builder.create(); return alert; }
From source file:com.codename1.impl.android.AndroidImplementation.java
private String getUserAgent() { try {/* w w w . j a v a 2 s . c om*/ String userAgent = System.getProperty("http.agent"); if (userAgent != null) { return userAgent; } } catch (Exception e) { } if (getActivity() == null) { return "Android-CN1"; } try { Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class); constructor.setAccessible(true); try { WebSettings settings = constructor.newInstance(getActivity(), null); return settings.getUserAgentString(); } finally { constructor.setAccessible(false); } } catch (Exception e) { final StringBuffer ua = new StringBuffer(); if (Thread.currentThread().getName().equalsIgnoreCase("main")) { WebView m_webview = new WebView(getActivity()); ua.append(m_webview.getSettings().getUserAgentString()); m_webview.destroy(); } else { final boolean[] flag = new boolean[1]; Thread thread = new Thread() { public void run() { Looper.prepare(); WebView m_webview = new WebView(getActivity()); ua.append(m_webview.getSettings().getUserAgentString()); m_webview.destroy(); Looper.loop(); flag[0] = true; synchronized (flag) { flag.notify(); } } }; thread.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler); thread.start(); while (!flag[0]) { synchronized (flag) { try { flag.wait(100); } catch (InterruptedException ex) { } } } } return ua.toString(); } }