List of usage examples for android.webkit WebView WebView
public WebView(Context context)
From source file:net.gsantner.opoc.util.ActivityUtils.java
public void showDialogWithRawFileInWebView(String fileInRaw, @StringRes int resTitleId) { WebView wv = new WebView(_context); wv.loadUrl("file:///android_res/raw/" + fileInRaw); AlertDialog.Builder dialog = new AlertDialog.Builder(_context).setPositiveButton(android.R.string.ok, null) .setTitle(resTitleId).setView(wv); dialog.show();//from w w w . j a v a 2 s . c om }
From source file:io.github.hidroh.materialistic.ComposeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_send) { if (mEditText.length() == 0) { Toast.makeText(this, R.string.comment_required, Toast.LENGTH_SHORT).show(); return false; } else {/*from w w w . j av a 2 s. c om*/ send(); return true; } } if (item.getItemId() == R.id.menu_quote) { mEditText.getEditableText().insert(0, createQuote()); } if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; } if (item.getItemId() == R.id.menu_save_draft) { Preferences.saveDraft(this, mParentId, mEditText.getText().toString()); return true; } if (item.getItemId() == R.id.menu_discard_draft) { Preferences.deleteDraft(this, mParentId); return true; } if (item.getItemId() == R.id.menu_guidelines) { WebView webView = new WebView(ComposeActivity.this); webView.loadUrl(HN_FORMAT_DOC_URL); mAlertDialogBuilder.init(ComposeActivity.this).setView(webView) .setPositiveButton(android.R.string.ok, null).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:in.animeshpathak.nextbus.NextBusMain.java
/** Called when the activity is first started. */ @Override//from ww w . j av a 2s . c o m public void onCreate(Bundle bundle) { Log.d(LOG_TAG, "entering onCreate()"); SettingsActivity.setTheme(this); super.onCreate(bundle); setContentView(R.layout.main); try { busNet = BusNetwork.getInstance(this); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage(), e); return; } // get the button // set handler to launch a processing dialog ImageButton updateButton = (ImageButton) findViewById(R.id.update_button); updateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { BusLine selectedLine = lineAdapter.getItem(lineSpinner.getSelectedItemPosition()); BusStop selectedStop = stopAdapter.getItem(stopSpinner.getSelectedItemPosition()); getBusTimings(selectedLine, selectedStop); } }); ImageButton feedbackButton = (ImageButton) findViewById(R.id.feedback_button); feedbackButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); // use from live device i.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FEEDBACK_EMAIL_ADDRESS }); i.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_EMAIL_SUBJECT); i.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_hello)); startActivity(Intent.createChooser(i, getString(R.string.select_email_app))); } }); ImageButton phebusinfoButton = (ImageButton) findViewById(R.id.phebusinfo_button); phebusinfoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog alertDialog = new AlertDialog.Builder(NextBusMain.this).create(); WebView wv = new WebView(NextBusMain.this); new PhebusNewsLoader(wv, NextBusMain.this).execute(); alertDialog.setView(wv); alertDialog.show(); } }); lineSpinner = (Spinner) findViewById(R.id.line_spinner); lineAdapter = new ArrayAdapter<BusLine>(this, android.R.layout.simple_spinner_item, busNet.getLines()); lineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); lineSpinner.setAdapter(lineAdapter); stopSpinner = (Spinner) findViewById(R.id.stop_spinner); stopAdapter = new ArrayAdapter<BusStop>(this, android.R.layout.simple_spinner_item); stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stopSpinner.setAdapter(stopAdapter); ImageButton favoriteButton = (ImageButton) findViewById(R.id.favorites_button); favoriteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { new FavoriteDialog(NextBusMain.this, new OnFavoriteSelectedListener() { @Override public void favoriteSelected(Favorite fav) { BusLine bl = busNet.getLineByName(fav.getLine()); BusStop bs = bl.getFirstStopWithSimilarName(fav.getStop()); if (bl == null || bs == null) { Log.e(LOG_TAG, "Favorite not found!"); return; } updateSpinners(bl, bs); getBusTimings(bl, bs); } }, lineSpinner.getSelectedItem().toString(), stopSpinner.getSelectedItem().toString()); } }); }
From source file:com.microsoft.windowsazure.messaging.e2etestapp.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: startActivity(new Intent(this, NotificationHubsPreferenceActivity.class)); return true; case R.id.menu_run_tests: if (ApplicationContext.getNotificationHubEndpoint().trim().equals("") || ApplicationContext.getNotificationHubKeyName().trim().equals("") || ApplicationContext.getNotificationHubKeyValue().trim().equals("") || ApplicationContext.getNotificationHubName().trim().equals("")) { startActivity(new Intent(this, NotificationHubsPreferenceActivity.class)); } else {//from w w w . j a va 2 s . co m runTests(); } return true; case R.id.menu_check_all: changeCheckAllTests(true); return true; case R.id.menu_uncheck_all: changeCheckAllTests(false); return true; case R.id.menu_reset: refreshTestGroupsAndLog(); return true; case R.id.menu_view_log: AlertDialog.Builder logDialogBuilder = new AlertDialog.Builder(this); logDialogBuilder.setTitle("Log"); final WebView webView = new WebView(this); String logContent = TextUtils.htmlEncode(mLog.toString()).replace("\n", "<br />"); String logHtml = "<html><body><pre>" + logContent + "</pre></body></html>"; webView.loadData(logHtml, "text/html", "utf-8"); logDialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboardManager.setText(mLog.toString()); } }); final String postContent = mLog.toString(); logDialogBuilder.setNeutralButton("Post data", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { String url = ApplicationContext.getLogPostURL(); if (url != null && url.trim() != "") { url = url + "?platform=android"; HttpPost post = new HttpPost(); post.setEntity(new StringEntity(postContent, "utf-8")); post.setURI(new URI(url)); new DefaultHttpClient().execute(post); } } catch (Exception e) { // Wasn't able to post the data. Do nothing } return null; } }.execute(); } }); logDialogBuilder.setView(webView); logDialogBuilder.create().show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:edu.cscie71.imm.slacker.plugin.Slacker.java
private void openAuthScreen() { Runnable runnable = new Runnable() { @SuppressLint("NewApi") public void run() { dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true);//from w ww.j a v a2 s. c om LinearLayout mainLayout = new LinearLayout(cordova.getActivity()); mainLayout.setOrientation(LinearLayout.VERTICAL); inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new WebChromeClient()); WebViewClient client = new AuthBrowser(); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); inAppWebView.loadUrl(authURL + "?client_id=" + slackClientID + "&scope=" + scope); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); mainLayout.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(mainLayout); dialog.show(); dialog.getWindow().setAttributes(lp); } }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:org.runbuddy.libtomahawk.resolver.ScriptAccount.java
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" }) public ScriptAccount(String path, boolean manuallyInstalled) { String prefix = manuallyInstalled ? "file://" : "file:///android_asset"; mPath = prefix + path;// w ww .j a v a2 s.co m mManuallyInstalled = manuallyInstalled; String[] parts = mPath.split("/"); mName = parts[parts.length - 1]; InputStream inputStream = null; try { if (mManuallyInstalled) { File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json"); inputStream = new FileInputStream(metadataFile); } else { inputStream = TomahawkApp.getContext().getAssets() .open(path.substring(1) + "/content/metadata.json"); } String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8); mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class); if (mMetaData == null) { Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); } } } CookieManager.setAcceptFileSchemeCookies(true); mWebView = new WebView(TomahawkApp.getContext()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true); } WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { //noinspection deprecation settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath()); } settings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new TomahawkWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { //initalize WebView String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>" + "<script src=\"file:///android_asset/js/rsvp-latest.min.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/cryptojs-core.js" + "\" type=\"text/javascript\"></script>"; if (mMetaData.manifest.scripts != null) { for (String scriptPath : mMetaData.manifest.scripts) { data += "<script src=\"" + mPath + "/content/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } try { String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs"); for (String scriptPath : cryptoJsScripts) { data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } catch (IOException e) { Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage()); } data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk_android_post.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/" + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>"; mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this)); mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME); mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null); } }); }
From source file:nya.miku.wishmaster.http.cloudflare.InterceptingAntiDDOS.java
/** anti-DDOS , ? ? ?? webview httpclient (? ?? ? ?-? API >= 11) */ Cookie check(final CloudflareException exception, final ExtendedHttpClient httpClient, final CancellableTask task, final Activity activity) { synchronized (lock) { if (processing) return null; processing = true;//from w w w. j av a2s. c o m } processing2 = true; currentCookie = null; final HttpRequestModel rqModel = HttpRequestModel.builder().setGET().build(); final CookieStore cookieStore = httpClient.getCookieStore(); CloudflareChecker.removeCookie(cookieStore, exception.getRequiredCookieName()); final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView(); final WebViewClient client = new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { HttpResponseModel responseModel = null; try { responseModel = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, null, task); for (int i = 0; i < 3 && responseModel.statusCode == 400; ++i) { Logger.d(TAG, "HTTP 400"); responseModel.release(); responseModel = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, null, task); } for (Cookie cookie : cookieStore.getCookies()) { if (CloudflareChecker.isClearanceCookie(cookie, url, exception.getRequiredCookieName())) { Logger.d(TAG, "Cookie found: " + cookie.getValue()); currentCookie = cookie; processing2 = false; return new WebResourceResponse("text/html", "UTF-8", new ByteArrayInputStream("cookie received".getBytes())); } } BufOutputStream output = new BufOutputStream(); IOUtils.copyStream(responseModel.stream, output); return new WebResourceResponse(null, null, output.toInputStream()); } catch (Exception e) { Logger.e(TAG, e); } finally { if (responseModel != null) responseModel.release(); } return new WebResourceResponse("text/html", "UTF-8", new ByteArrayInputStream("something wrong".getBytes())); } }; activity.runOnUiThread(new Runnable() { @SuppressLint("SetJavaScriptEnabled") @Override public void run() { webView = new WebView(activity); webView.setVisibility(View.GONE); layout.addView(webView); webView.setWebViewClient(client); webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(exception.getCheckUrl()); } }); long startTime = System.currentTimeMillis(); while (processing2) { long time = System.currentTimeMillis() - startTime; if ((task != null && task.isCancelled()) || time > CloudflareChecker.TIMEOUT) { processing2 = false; } } activity.runOnUiThread(new Runnable() { @Override public void run() { try { layout.removeView(webView); webView.stopLoading(); webView.clearCache(true); webView.destroy(); webView = null; } finally { processing = false; } } }); return currentCookie; }
From source file:com.fastbootmobile.encore.app.fragments.SettingsFragment.java
private void openLicenses() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); String text = getString(R.string.licenses); text = "<pre>" + text + "</pre>"; text = text.replaceAll("\n", "<br />"); WebView view = new WebView(getActivity()); view.loadData(text, "text/html", "UTF-8"); builder.setView(view);//from w w w.ja v a 2 s.co m builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); }
From source file:com.jwork.dhammapada.MainActivity.java
public void displayChangeLog() { AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle("Changelog"); WebView wv = new WebView(this); wv.loadData(getString(R.string.changelog_dialog_text), "text/html", "utf-8"); wv.setScrollContainer(true);//from w w w. j av a 2s . c o m dialog.setView(wv); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName()); Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri); try { MainActivity.this.startActivity(myAppLinkToMarket); } catch (ActivityNotFoundException e) { Toast.makeText(MainActivity.this, "Failed to find Market application", Toast.LENGTH_LONG) .show(); } } }); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Donate", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Configuration.getInstance(MainActivity.this) .setCurrentVersion(CrashHandler.getVersionCode(MainActivity.this)); dialog.dismiss(); openDonate(); } }); dialog.show(); }
From source file:de.dreier.mytargets.features.scoreboard.ScoreboardActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void print() { // Get a print adapter instance final WebView webViewPrint = new WebView(this); webViewPrint.setVisibility(View.INVISIBLE); ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); webViewPrint.setLayoutParams(p);/*from www . j a va 2 s . c o m*/ ((ViewGroup) binding.getRoot()).addView(webViewPrint); new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { return HtmlUtils.getScoreboard(mTraining, mRound, ScoreboardConfiguration.fromPrintSettings()); } @SuppressWarnings("deprecation") @Override protected void onPostExecute(String s) { webViewPrint.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "UTF-8", ""); PrintDocumentAdapter printAdapter = webViewPrint.createPrintDocumentAdapter(); // Create a print job with name and adapter instance PrintManager printManager = (PrintManager) getSystemService(PRINT_SERVICE); String jobName = getString(R.string.scoreboard) + " Document"; printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); } }.execute(); }