List of usage examples for android.webkit WebView loadData
public void loadData(String data, @Nullable String mimeType, @Nullable String encoding)
From source file:com.brayanarias.alarmproject.activity.MainActivity.java
private void setupNavigationView() { navigationView = (NavigationView) findViewById(R.id.navigation); MenuItem item = navigationView.getMenu().findItem(actualItem); View nav_header = LayoutInflater.from(this).inflate(R.layout.nav_header, null); final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation); navigationView.addHeaderView(nav_header); //salute//w w w. ja v a 2 s . c om String salute = AlarmUtilities.getSalute(getApplicationContext()); TextView tvWellcome = (TextView) nav_header.findViewById(R.id.tvWellcome); tvWellcome.setText(salute); if (item != null) { item.setChecked(true); } navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { CharSequence title = menuItem.getTitle(); closeDrawer(); switch (menuItem.getItemId()) { case R.id.itMyAlarms: showFragment(R.id.itMyAlarms); actualItem = menuItem.getItemId(); menuItem.setChecked(true); getSupportActionBar().setTitle(title); return true; case R.id.itAddAlarm: Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); TimePickerDialog timePickerDialog = TimePickerDialog .newInstance(new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { Alarm alarm = AlarmUtilities.createDefaultAlarm(); String min = minute < 10 ? "0" + minute : "" + minute; if (hourOfDay == 12) { alarm.setAmPm("PM"); alarm.setHour(hourOfDay); alarm.setHourFormatted((hourOfDay) + ":" + min); } else if (hourOfDay > 12) { alarm.setAmPm("PM"); alarm.setHour(hourOfDay - 12); alarm.setHourFormatted((hourOfDay - 12) + ":" + min); } else { if (hourOfDay == 0) { hourOfDay = 12; } alarm.setAmPm("AM"); alarm.setHour(hourOfDay); alarm.setHourFormatted(hourOfDay + ":" + min); } alarm.setMinute(minute); Intent intent = new Intent(getApplicationContext(), AddAlarmActivity.class); intent.putExtra(Constant.actionAlarmKey, Constant.addAlarm); intent.putExtra(Constant.alarmSerializableKey, alarm); startActivity(intent); } }, hour, minute, false); timePickerDialog.show(getSupportFragmentManager(), "tag"); return true; case R.id.itCurrentMonth: actualItem = menuItem.getItemId(); menuItem.setChecked(true); showFragment(R.id.itCurrentMonth); getSupportActionBar().setTitle(title); return true; /* case R.id.itConfig: actualItem = menuItem.getItemId(); menuItem.setChecked(true); showFragment(R.id.itConfig); getSupportActionBar().setTitle(title); closeDrawer(); return true; */ case R.id.itAbout: AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this); WebView wvLegal = (WebView) LayoutInflater.from(getApplication()) .inflate(R.layout.web_view_legal, null); wvLegal.loadData(getString(R.string.html_legal), "text/html", "UTF-8"); wvLegal.setWebChromeClient(new WebChromeClient()); alertBuilder.setView(wvLegal); alertBuilder.setTitle(R.string.txt_about_app); alertBuilder.setCancelable(true).setPositiveButton(getString(R.string.txt_button_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alertBuilder.show(); return true; default: return false; } } }); }
From source file:com.typingsolutions.passwordmanager.fragments.LicenseFragment.java
@Nullable @Override// w w w. j a v a 2 s . com public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.license_layout, container, false); WebView webView = (WebView) root.findViewById(R.id.licenselayout_webview_about); InputStream rawStream = getResources().openRawResource(R.raw.about); try { if (rawStream == null || rawStream.available() == 0) throw new IllegalStateException("Couldn't read source"); final byte[] data = new byte[rawStream.available()]; rawStream.read(data); String html = new String(data); webView.loadData(html, "text/html", "UTF-8"); } catch (Exception e) { } return root; }
From source file:com.gsma.mobileconnect.helpers.AuthorizationService.java
private void closeWebViewAndNotify(final AuthorizationListener listener, final WebView webView) { webView.stopLoading();/*from w w w .j av a2 s.c om*/ webView.loadData("", "text/html", null); listener.onAuthorizationDialogClose(); }
From source file:com.njlabs.amrita.aid.landing.Landing.java
public void checkForUpdates() { OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build(); Request.Builder request = new Request.Builder().url("https://api.codezero.xyz/aid/latest"); client.newCall(request.build()).enqueue(new Callback() { @Override//from www .j a v a 2s .co m public void onFailure(Call call, IOException e) { Ln.e(e); } @Override public void onResponse(Call call, final Response rawResponse) throws IOException { final String responseString = rawResponse.body().string(); ((Activity) baseContext).runOnUiThread(new Runnable() { @Override public void run() { JSONObject response; try { response = new JSONObject(responseString); String status = ""; status = response.getString("status"); if (status.equals("ok")) { Double Latest = 0.0; String Description = null; try { Latest = response.getDouble("version"); Description = response.getString("description"); } catch (JSONException e) { FirebaseCrash.report(e); } if (Latest > BuildConfig.VERSION_CODE) { AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(Landing.this); LayoutInflater factory = LayoutInflater.from(Landing.this); final View changelogView = factory.inflate(R.layout.webview_dialog, null); LinearLayout WebViewDialogLayout = (LinearLayout) changelogView .findViewById(R.id.WebViewDialogLayout); WebViewDialogLayout.setPadding(5, 5, 5, 5); WebView changelogWebView = (WebView) changelogView .findViewById(R.id.LicensesView); changelogWebView.loadData(String.format("%s", Description), "text/html", "utf-8"); changelogWebView.setPadding(5, 5, 5, 5); changelogWebView.setBackgroundColor(0); changelogWebView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); changelogWebView.setLongClickable(false); updateDialogBuilder.setView(changelogView).setCancelable(true) .setCancelable(false) .setNegativeButton("Dismiss", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setPositiveButton("Update Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri .parse("market://details?id=com.njlabs.amrita.aid"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); } }); AlertDialog alert = updateDialogBuilder.create(); alert.setTitle("Update Available"); alert.setIcon(R.mipmap.ic_launcher); alert.show(); } } } catch (Exception e) { Ln.e(e); } } }); } }); }
From source file:eu.trentorise.smartcampus.launcher.AppFragment.java
private void showDisclaimer() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); WebView wv = new WebView(getActivity()); wv.loadData(getString(R.string.disclaimer), "text/html; charset=UTF-8", "utf-8"); builder//.setTitle(android.R.string.dialog_alert_title) .setView(wv)// w ww.j av a2 s.c om // .setMessage(R.string.welcome_msg) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { arg0.dismiss(); getActivity().finish(); } }).setPositiveButton(getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); getActivity().finish(); } }); builder.create().show(); }
From source file:eu.trentorise.smartcampus.launcher.AppFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { AboutFragment newFragment;//www. j a v a 2s. c om Bundle args; FragmentTransaction transaction; // Handle item selection switch (item.getItemId()) { case R.id.settings: startActivity(new Intent(getSherlockActivity(), SettingsActivity.class)); return true; case R.id.about: // Intent browserIntent = new Intent(Intent.ACTION_VIEW, // Uri.parse(getString(R.string.smartcampus_url_credits))); // startActivity(browserIntent); newFragment = new AboutFragment(); args = new Bundle(); newFragment.setArguments(args); transaction = getSherlockActivity().getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, newFragment); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.addToBackStack(null); transaction.commit(); return true; case R.id.help: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // TextView tv = new TextView(getActivity()); // tv.setPadding(20, 20, 20, 20); // tv.setTextSize(18f); // tv.setText(Html.fromHtml(getString(R.string.about_2))); WebView wv = new WebView(getActivity()); wv.loadData(getString(R.string.about_2), "text/html; charset=UTF-8", "utf-8"); //tv.setMovementMethod(LinkMovementMethod.getInstance()); builder.setTitle(android.R.string.dialog_alert_title).setView(wv).create().show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:edu.tjhsst.ion.gcmFrame.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(getResources().getColor(R.color.navbar_color)); }//w w w. j a va2s .co m // requestWindowFeature(Window.FEATURE_NO_TITLE); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { Log.i(TAG, "Google token sent"); } else { Toast.makeText(getApplicationContext(), getString(R.string.token_error_message), Toast.LENGTH_LONG).show(); } } }; if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); if (ni != null) { NetworkInfo.State state = ni.getState(); if (state == null || state != NetworkInfo.State.CONNECTED) { // record the fact that there is no connection isConnected = false; } } } SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.ION_SETUP, false); webView = (WebView) findViewById(R.id.webview); webView.setInitialScale(1); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } StringBuilder uaString = new StringBuilder(webView.getSettings().getUserAgentString()); uaString.append(" - IonAndroid: gcmFrame ("); if (sentToken) { uaString.append("appRegistered:True"); } else { uaString.append("appRegistered:False"); } uaString.append(" osVersion:").append(System.getProperty("os.version")); uaString.append(" apiLevel:").append(android.os.Build.VERSION.SDK_INT); uaString.append(" Device:").append(android.os.Build.DEVICE); uaString.append(" Model:").append(android.os.Build.MODEL); uaString.append(" Product:").append(android.os.Build.PRODUCT); uaString.append(")"); webView.getSettings().setUserAgentString(uaString.toString()); webView.setNetworkAvailable(isConnected); webView.addJavascriptInterface(new WebAppInterface(this), "IonAndroidInterface"); webView.loadUrl(MainActivity.ION_HOST); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, "Loading " + url); if (!isConnected) { String html = getHtml("offline.html"); html = html.replaceAll("\\[url\\]", url); view.loadData(html, "text/html", "utf-8"); return true; } else if (url.contains(ION_HOST)) { // keep in WebView webView.loadUrl(url); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); return true; } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // if (errorCode == ERROR_TIMEOUT) view.stopLoading(); // may not be needed String html = getHtml("timeout.html"); html = html.replaceAll("\\[url\\]", failingUrl); html = html.replaceAll("\\[desc\\]", description); view.loadData(html, "text/html", "utf-8"); } }); }
From source file:microsoft.aspnet.signalr.client.test.integration.android.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: startActivity(new Intent(this, SignalRPreferenceActivity.class)); return true; case R.id.menu_run_tests: if (ApplicationContext.getServerUrl().trim().equals("")) { startActivity(new Intent(this, SignalRPreferenceActivity.class)); } else {// w w w. j av a2 s. c om 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: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. ja v a 2 s . c o 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:org.cyanogenmod.theme.chooser.ChooserBrowseFragment.java
private void launchGetThemesWebView() { Context context = getActivity(); if (context == null) return;/* www. j av a 2s . c o m*/ final WebView webView = new WebView(context); String html = createGetThemesHtml(context); webView.loadData(html.toString(), "text/html; charset=UTF-8", null); // Setup the dialog AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setView(webView); Dialog dialog = alert.create(); dialog.show(); }