List of usage examples for android.webkit WebView loadDataWithBaseURL
public void loadDataWithBaseURL(@Nullable String baseUrl, String data, @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl)
From source file:com.ubikod.urbantag.ContentViewerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); /* If we are coming from Notification delete notification */ if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_CONTENT_NOTIF) { NotificationHelper notificationHelper = new NotificationHelper(this); notificationHelper.closeContentNotif(); } else if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_PLACE_NOTIF) { NotificationHelper notificationHelper = new NotificationHelper(this); notificationHelper.closePlaceNotif(); }/* ww w . j a v a 2 s.c om*/ /* Fetch content info */ ContentManager contentManager = new ContentManager(new DatabaseHelper(this, null)); Log.i(UrbanTag.TAG, "View content : " + extras.getInt(CONTENT_ID)); this.content = contentManager.get(extras.getInt(CONTENT_ID)); if (this.content == null) { Toast.makeText(this, R.string.error_occured, Toast.LENGTH_SHORT).show(); finish(); return; } setTitle(content.getName()); com.actionbarsherlock.app.ActionBar actionBar = this.getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.content_viewer); /* Find webview and create url for content */ final WebView webView = (WebView) findViewById(R.id.webview); final String URL = UrbanTag.API_URL + ACTION_GET_CONTENT.replaceAll("%", "" + this.content.getId()); /* Display progress animation */ final ProgressDialog progress = ProgressDialog.show(this, "", this.getResources().getString(R.string.loading_content), false, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { timeOutHandler.interrupt(); webView.stopLoading(); ContentViewerActivity.this.finish(); } }); /* Go fetch content */ contentFetcher = new Thread(new Runnable() { DefaultHttpClient httpClient; @Override public void run() { Looper.prepare(); Log.i(UrbanTag.TAG, "Fetching content..."); httpClient = new DefaultHttpClient(); try { String responseBody = httpClient.execute(new HttpGet(URL), new BasicResponseHandler()); webView.loadDataWithBaseURL("fake://url/for/encoding/hack...", responseBody, mimeType, encoding, ""); timeOutHandler.interrupt(); if (progress.isShowing()) progress.dismiss(); } catch (ClientProtocolException cpe) { new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); timeOutHandler.interrupt(); progress.cancel(); } catch (IOException ioe) { new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); timeOutHandler.interrupt(); progress.cancel(); } Looper.loop(); } }); contentFetcher.start(); /* TimeOut Handler */ timeOutHandler = new Thread(new Runnable() { private int INCREMENT = 1000; @Override public void run() { Looper.prepare(); try { for (int time = 0; time < TIMEOUT; time += INCREMENT) { Thread.sleep(INCREMENT); } Log.w(UrbanTag.TAG, "TimeOut !"); new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); contentFetcher.interrupt(); progress.cancel(); } catch (InterruptedException e) { e.printStackTrace(); } Looper.loop(); } }); timeOutHandler.start(); }
From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override// w ww . ja v a 2 s. c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false); if (mItem != null) { // set the views ViewSample viewSample = mItem.getViewSample(); final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder); viewSample.createViews(getActivity(), viewsHolder); // load the CSS styling for the sample String css = ViewsData.getCSS(getActivity(), mItem); // Set up syntax highlighting WebView cssView = (WebView) rootView.findViewById(R.id.css_style); WebSettings s = cssView.getSettings(); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); s.setUseWideViewPort(false); s.setAllowFileAccess(true); s.setBuiltInZoomControls(true); s.setSupportZoom(true); s.setSupportMultipleWindows(false); s.setJavaScriptEnabled(true); StringBuilder contentString = new StringBuilder(); contentString.append("<html><head>"); contentString.append( "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> "); contentString.append( "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> "); contentString.append( "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> "); contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>"); contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", " ") .replaceAll("\t", " ")); contentString.append("</code> </html> "); cssView.getSettings().setUseWideViewPort(true); cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html", StringUtil.EMPTY, StringUtil.EMPTY); // to aid in styling the css text shows in the textview, set its // ID. Eventually will not be needed. if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) { PixateFreestyle.setStyleId(cssView, "css-style", true); } // Style viewSample.style(css); } return rootView; }
From source file:org.mozilla.focus.webkit.ErrorPage.java
public static void loadErrorPage(final WebView webView, final String desiredURL, final int errorCode) { final Pair<Integer, Integer> errorResourceIDs = errorDescriptionMap.get(errorCode); if (errorResourceIDs == null) { throw new IllegalArgumentException( "Cannot load error description for unsupported errorcode=" + errorCode); }//from w ww . j av a 2 s . c o m // This is quite hacky: ideally we'd just load the css file directly using a '<link rel="stylesheet"'. // However webkit thinks it's still loading the original page, which can be an https:// page. // If mixed content blocking is enabled (which is probably what we want in Focus), then webkit // will block file:///android_res/ links from being loaded - which blocks our css from being loaded. // We could hack around that by enabling mixed content when loading an error page (and reenabling it // once that's loaded), but doing that correctly and reliably isn't particularly simple. Loading // the css data and stuffing it into our html is much simpler, especially since we're already doing // string substitutions. // As an added bonus: file:/// URIs are broken if the app-ID != app package, see: // https://code.google.com/p/android/issues/detail?id=211768 (this breaks loading css via file:/// // references when running debug builds, and probably klar too) - which means this wouldn't // be possible even if we hacked around the mixed content issues. final String cssString = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage_style, null); final Map<String, String> substitutionMap = new ArrayMap<>(); final Resources resources = webView.getContext().getResources(); substitutionMap.put("%page-title%", resources.getString(R.string.errorpage_title)); substitutionMap.put("%button%", resources.getString(R.string.errorpage_refresh)); substitutionMap.put("%messageShort%", resources.getString(errorResourceIDs.first)); substitutionMap.put("%messageLong%", resources.getString(errorResourceIDs.second, desiredURL)); substitutionMap.put("%css%", cssString); final String errorPage = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage, substitutionMap); // We could load the raw html file directly into the webview using a file:///android_res/ // URI - however we'd then need to do some JS hacking to do our String substitutions. Moreover // we'd have to deal with the mixed-content issues detailed above in that case. webView.loadDataWithBaseURL(desiredURL, errorPage, "text/html", "UTF8", desiredURL); }
From source file:org.mozilla.focus.webview.ErrorPage.java
public static void loadErrorPage(final WebView webView, final String desiredURL, final int errorCode) { final Pair<Integer, Integer> errorResourceIDs = errorDescriptionMap.get(errorCode); if (errorResourceIDs == null) { throw new IllegalArgumentException( "Cannot load error description for unsupported errorcode=" + errorCode); }//from www. j ava 2 s .c om // This is quite hacky: ideally we'd just load the css file directly using a '<link rel="stylesheet"'. // However WebView thinks it's still loading the original page, which can be an https:// page. // If mixed content blocking is enabled (which is probably what we want in Focus), then webkit // will block file:///android_res/ links from being loaded - which blocks our css from being loaded. // We could hack around that by enabling mixed content when loading an error page (and reenabling it // once that's loaded), but doing that correctly and reliably isn't particularly simple. Loading // the css data and stuffing it into our html is much simpler, especially since we're already doing // string substitutions. // As an added bonus: file:/// URIs are broken if the app-ID != app package, see: // https://code.google.com/p/android/issues/detail?id=211768 (this breaks loading css via file:/// // references when running debug builds, and probably klar too) - which means this wouldn't // be possible even if we hacked around the mixed content issues. final String cssString = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage_style, null); final Map<String, String> substitutionMap = new ArrayMap<>(); final Resources resources = webView.getContext().getResources(); substitutionMap.put("%page-title%", resources.getString(R.string.errorpage_title)); substitutionMap.put("%button%", resources.getString(R.string.errorpage_refresh)); substitutionMap.put("%messageShort%", resources.getString(errorResourceIDs.first)); substitutionMap.put("%messageLong%", resources.getString(errorResourceIDs.second, desiredURL)); substitutionMap.put("%css%", cssString); final String errorPage = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage, substitutionMap); // We could load the raw html file directly into the webview using a file:///android_res/ // URI - however we'd then need to do some JS hacking to do our String substitutions. Moreover // we'd have to deal with the mixed-content issues detailed above in that case. webView.loadDataWithBaseURL(desiredURL, errorPage, "text/html", "UTF8", desiredURL); }
From source file:terse.a1.TerseActivity.java
private void viewPath9display(String path, LayoutParams widgetParams) { String explain;// w ww.ja v a 2 s . co m if (terp_error != null) { explain = "terp_error = " + terp_error; } else { try { terp.say("Sending to terp: %s", path); final Dict d = terp.handleUrl(path, taQuery); explain = "DEFAULT EXPLANATION:\n\n" + d.toString(); Str TYPE = d.cls.terp.newStr("type"); Str VALUE = d.cls.terp.newStr("value"); Str TITLE = d.cls.terp.newStr("title"); Str type = (Str) d.dict.get(TYPE); Ur value = d.dict.get(VALUE); Ur title = d.dict.get(TITLE); // { // double ticks = Static.floatAt(d, "ticks", -1); // double nanos = Static.floatAt(d, "nanos", -1); // Toast.makeText( // getApplicationContext(), // Static.fmt("%d ticks, %.3f secs", (long) ticks, // (double) nanos / 1e9), Toast.LENGTH_SHORT) // .show(); // } if (type.str.equals("list") && value instanceof Vec) { final ArrayList<Ur> v = ((Vec) value).vec; final ArrayList<String> labels = new ArrayList<String>(); final ArrayList<String> links = new ArrayList<String>(); for (int i = 0; i < v.size(); i++) { Ur item = v.get(i); String label = item instanceof Str ? ((Str) item).str : item.toString(); if (item instanceof Vec && ((Vec) item).vec.size() == 2) { // OLD STYLE label = ((Vec) item).vec.get(0).toString(); Matcher m = LINK_P.matcher(label); if (m.lookingAt()) { label = m.group(2) + " " + m.group(3); } label += " [" + ((Vec) item).vec.get(1).toString().length() + "]"; links.add(null); // Use old style, not links. } else { // NEW STYLE label = item.toString(); if (label.charAt(0) == '/') { String link = Terp.WHITE_PLUS.split(label, 2)[0]; links.add(link); } else { links.add(""); } } labels.add(label); } if (labels.size() != links.size()) terp.toss("lables#%d links#%d", labels.size(), links.size()); ListView listv = new ListView(this); listv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, labels)); listv.setLayoutParams(widgetParams); listv.setTextFilterEnabled(true); listv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); String toast_text = ((TextView) view).getText().toString(); // if (v.get(position) instanceof Vec) { if (links.get(position) == null) { // OLD STYLE Vec pair = (Vec) v.get(position); if (pair.vec.size() == 2) { if (pair.vec.get(0) instanceof Str) { String[] words = ((Str) pair.vec.get(0)).str.split("\\|"); Log.i("TT-WORDS", terp.arrayToString(words)); toast_text += "\n\n" + Static.arrayToString(words); if (words[1].equals("link")) { Uri uri = new Uri.Builder().scheme("terse").path(words[2]).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } } } else { // NEW STYLE terp.say("NEW STYLE LIST SELECT #%d link=<%s> label=<%s>", position, links.get(position), labels.get(position)); if (links.get(position).length() > 0) { Uri uri = new Uri.Builder().scheme("terse").path(links.get(position)).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } // } // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); } }); setContentView(listv); return; } else if (type.str.equals("edit") && value instanceof Str) { final EditText ed = new EditText(this); ed.setText(taSaveMe == null ? value.toString() : taSaveMe); ed.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); ed.setLayoutParams(widgetParams); // ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); ed.setTextAppearance(this, R.style.teletype); ed.setBackgroundColor(Color.BLACK); ed.setGravity(Gravity.TOP); ed.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); ed.setVerticalFadingEdgeEnabled(true); ed.setVerticalScrollBarEnabled(true); ed.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" // button // if ((event.getAction() == KeyEvent.ACTION_DOWN) // && // (keyCode == KeyEvent.KEYCODE_ENTER)) { // // Perform action on key press // Toast.makeText(TerseActivity.this, ed.getText(), // Toast.LENGTH_SHORT).show(); // return true; // } return false; } }); Button btn = new Button(this); btn.setText("Save"); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Perform action on clicks String text = ed.getText().toString(); text = Parser.charSubsts(text); Toast.makeText(TerseActivity.this, text, Toast.LENGTH_SHORT).show(); String action = stringAt(d, "action"); String query = ""; String f1 = stringAt(d, "field1"); String v1 = stringAt(d, "value1"); String f2 = stringAt(d, "field2"); String v2 = stringAt(d, "value2"); f1 = (f1 == null) ? "f1null" : f1; v1 = (v1 == null) ? "v1null" : v1; f2 = (f2 == null) ? "f2null" : f2; v2 = (v2 == null) ? "v2null" : v2; startTerseActivity(action, query, stringAt(d, "field1"), stringAt(d, "value1"), stringAt(d, "field2"), stringAt(d, "value2"), "text", text); } }); LinearLayout linear = new LinearLayout(this); linear.setOrientation(LinearLayout.VERTICAL); linear.addView(btn); linear.addView(ed); setContentView(linear); return; } else if (type.str.equals("draw") && value instanceof Vec) { Vec v = ((Vec) value); DrawView dv = new DrawView(this, v.vec, d); dv.setLayoutParams(widgetParams); setContentView(dv); return; } else if (type.str.equals("live")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); TerseSurfView tsv = new TerseSurfView(this, blk, event); setContentView(tsv); return; } else if (type.str.equals("fnord")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); FnordView fnord = new FnordView(this, blk, event); setContentView(fnord); return; } else if (type.str.equals("world") && value instanceof Str) { String newWorld = value.toString(); if (Terp.WORLD_P.matcher(newWorld).matches()) { world = newWorld; resetTerp(); explain = Static.fmt("Switching to world <%s>\nUse menu to go Home.", world); Toast.makeText(getApplicationContext(), explain, Toast.LENGTH_LONG).show(); } else { terp.toss("Bad world syntax (must be 3 letters then 0 to 3 digits: <%s>", newWorld); } // Fall thru for explainv.setText(explain). } else if (type.str.equals("text")) { explain = "<<< " + title + " >>>\n\n" + value.toString(); // Fall thru for explainv.setText(explain). } else if (type.str.equals("html")) { final WebView webview = new WebView(this); // webview.loadData(value.toString(), "text/html", null); webview.loadDataWithBaseURL("terse://terse", value.toString(), "text/html", "UTF-8", null); webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // terp.say("WebView UrlLoading: url=%s", url); URI uri = URI.create("" + url); // terp.say("WebView UrlLoading: URI=%s", uri); terp.say("WebView UrlLoading: getPath=%s", uri.getPath()); terp.say("WebView UrlLoading: getQuery=%s", uri.getQuery()); // Toast.makeText(getApplicationContext(), // uri.toASCIIString(), Toast.LENGTH_SHORT) // .show(); // webview.invalidate(); // // TextView quick = new // TextView(TerseActivity.this); // quick.setText(uri.toASCIIString()); // quick.setBackgroundColor(Color.BLACK); // quick.setTextColor(Color.WHITE); // setContentView(quick); startTerseActivity(uri.getPath(), uri.getQuery()); return true; } }); // webview.setWebChromeClient(new WebChromeClient()); webview.getSettings().setBuiltInZoomControls(true); // webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDefaultFontSize(18); webview.getSettings().setNeedInitialFocus(true); webview.getSettings().setSupportZoom(true); webview.getSettings().setSaveFormData(true); setContentView(webview); // ScrollView scrollv = new ScrollView(this); // scrollv.addView(webview); // setContentView(scrollv); return; } else { explain = "Unknown page type: " + type.str + " with vaule type: " + value.cls + "\n\n##############\n\n"; explain += value.toString(); // Fall thru for explainv.setText(explain). } } catch (Exception ex) { ex.printStackTrace(); explain = Static.describe(ex); } } TextView explainv = new TextView(this); explainv.setText(explain); explainv.setBackgroundColor(Color.BLACK); explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); explainv.setTextColor(Color.YELLOW); SetContentViewWithHomeButtonAndScroll(explainv); }
From source file:com.nextgis.mobile.fragment.AttributesFragment.java
private void setAttributes() { if (mAttributes == null) return;/*from www . j a v a 2s . c om*/ mAttributes.removeAllViews(); int[] attrs = new int[] { android.R.attr.textColorPrimary }; TypedArray ta = getContext().obtainStyledAttributes(attrs); String textColor = Integer.toHexString(ta.getColor(0, Color.BLACK)).substring(2); ta.recycle(); final WebView webView = new WebView(getContext()); webView.setVerticalScrollBarEnabled(false); String data = "<!DOCTYPE html><html><head><meta charset='utf-8'><style>body{word-wrap:break-word;color:#" + textColor + ";font-family:Roboto Light,sans-serif;font-weight:300;line-height:1.15em}.flat-table{table-layout:fixed;margin-bottom:20px;width:100%;border-collapse:collapse;border:none;box-shadow:inset 1px -1px #ccc,inset -1px 1px #ccc}.flat-table td{box-shadow:inset -1px -1px #ccc,inset -1px -1px #ccc;padding:.5em}.flat-table tr{-webkit-transition:background .3s,box-shadow .3s;-moz-transition:background .3s,box-shadow .3s;transition:background .3s,box-shadow .3s}</style></head><body><table class='flat-table'><tbody>"; FragmentActivity activity = getActivity(); if (null == activity) return; ((MainActivity) activity).setSubtitle(String.format(getString(R.string.features_count_attributes), mItemPosition + 1, mFeatureIDs.size())); checkNearbyItems(); try { data = parseAttributes(data); } catch (RuntimeException e) { e.printStackTrace(); } data += "</tbody></table></body></html>"; webView.loadDataWithBaseURL(null, data, "text/html", "UTF-8", null); mAttributes.addView(webView); webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webView.setBackgroundColor(Color.TRANSPARENT); } public boolean shouldOverrideUrlLoading(WebView view, String url) { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } }); IGISApplication app = (GISApplication) getActivity().getApplication(); final Map<String, Integer> mAttaches = new HashMap<>(); PhotoGallery.getAttaches(app, mLayer, mItemId, mAttaches, false); if (mAttaches.size() > 0) { final PhotoPicker gallery = new PhotoPicker(getActivity(), true); int px = ControlHelper.dpToPx(16, getResources()); gallery.setDefaultPreview(true); gallery.setPadding(px, 0, px, 0); gallery.post(new Runnable() { @Override public void run() { gallery.restoreImages(new ArrayList<>(mAttaches.keySet())); } }); mAttributes.addView(gallery); } }
From source file:org.botlibre.sdk.activity.ChatActivity.java
/** * Clear the log.//from w w w .j a v a 2s. c o m */ public void clear(View view) { WebView log = (WebView) findViewById(R.id.logText); log.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); }
From source file:com.ifeel.healthy.SelectionFragment.java
private void openHtml(String htmlFile, String title) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(title);//from w w w . j av a 2 s. co m WebView wv = new WebView(getActivity()); // loading the html file String htmlData = readAsset(htmlFile); //wv.loadUrl("http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=ifeelmobiltec-20&marketplace=amazon®ion=US&placement=B007S088F4&asins=B007S088F4&linkId=JCQFMHWLLV5N2SZO&show_border=true&link_opens_in_new_window=true"); wv.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null); alert.setView(wv); alert.setNegativeButton(getActivity().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alert.create(); alert.show(); }
From source file:org.botlibre.sdk.activity.ChatActivity.java
public void resetChat(View view) { ChatConfig config = new ChatConfig(); config.instance = instance.id;//from w w w. ja v a 2 s . c o m config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; } if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; config.speak = !MainActivity.deviceVoice; HttpAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); EditText v = (EditText) findViewById(R.id.messageText); v.setText(""); this.messages.clear(); runOnUiThread(new Runnable() { @Override public void run() { ListView list = (ListView) findViewById(R.id.chatList); ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged(); list.invalidateViews(); } }); WebView responseView = (WebView) findViewById(R.id.responseText); responseView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); }
From source file:org.botlibre.sdk.activity.ChatActivity.java
public void submitChat() { ChatConfig config = new ChatConfig(); config.instance = this.instance.id; config.conversation = MainActivity.conversation; config.speak = !MainActivity.deviceVoice; config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; }//from w w w . j a v a 2 s . c om if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; EditText v = (EditText) findViewById(R.id.messageText); config.message = v.getText().toString().trim(); if (config.message.equals("")) { return; } this.messages.add(config); runOnUiThread(new Runnable() { @Override public void run() { ListView list = (ListView) findViewById(R.id.chatList); ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged(); list.invalidateViews(); } }); Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); config.emote = emoteSpin.getSelectedItem().toString(); HttpChatAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); v.setText(""); emoteSpin.setSelection(0); resetToolbar(); WebView responseView = (WebView) findViewById(R.id.responseText); responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null); //Check the volume AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); if (volume <= 3 && volumeChecked) { Toast.makeText(this, "Please check 'Media' volume", Toast.LENGTH_LONG).show(); volumeChecked = false; } //stop letting the mic on. stopListening(); //its Important for "sleep" "scream" ...etc commands. //this will turn off the mic MainActivity.listenInBackground = false; }