List of usage examples for android.text Html fromHtml
@Deprecated public static Spanned fromHtml(String source)
From source file:com.liato.bankdroid.banking.banks.AvanzaMini.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }/*ww w. j a v a 2 s . co m*/ urlopen = login(); String response = null; Matcher matcher; try { response = urlopen.open("https://www.avanza.se/mini/mitt_konto/index.html"); matcher = reAvanzaMini.matcher(response); if (matcher.find()) { int count = 1; Matcher submatcher = accountsAvanzaMini.matcher(matcher.group(1)); while (submatcher.find()) { accounts.add(new Account(Html.fromHtml(submatcher.group(1)).toString().trim(), Helpers.parseBalance(submatcher.group(2)), Integer.toString(count))); balance = balance.add(Helpers.parseBalance(submatcher.group(2))); count++; } } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } finally { super.updateComplete(); } }
From source file:fr.outadev.skinswitch.network.MojangConnectionHandler.java
/** * Send a completed challenge to the website for validation. * * @param challenge the challenge that was answered. * @param answer the answer./*w w w. j av a 2s . c o m*/ * @throws InvalidMojangChallengeAnswerException if the answer wasn't the right one. */ public void validateChallenge(LoginChallenge challenge, String answer) throws InvalidMojangChallengeAnswerException, HttpRequest.HttpRequestException { Map<String, String> data = new HashMap<String, String>(); data.put("answer", answer); data.put("questionId", challenge.getId()); data.put("authenticityToken", challenge.getAuthToken()); String body = HttpRequest.post(BASE_URL + "/challenge").userAgent(getUserAgent()).followRedirects(false) .form(data).body(); if (body.equals("Security challenge passed.")) { Log.i(ConnectionHandler.TAG, "challenge validated"); } else { String error; try { JSONObject errorObject = (JSONObject) new JSONTokener(body).nextValue(); if (errorObject != null && errorObject.getString("error") != null) { error = Html.fromHtml(errorObject.getString("error")).toString().trim(); } else { throw new Exception(); } } catch (Exception e) { error = Html.fromHtml(body).toString().trim(); } Log.e(ConnectionHandler.TAG, "challenge error: " + error); throw new InvalidMojangChallengeAnswerException(error); } }
From source file:com.shearosario.tothepathandback.DisplayDirectionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_directions); getActionBar().setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();/*from w w w . jav a 2s . com*/ /*if(intent.hasExtra("origin")) { double[] temp = intent.getDoubleArrayExtra("origin"); origin = new LatLng (temp[0], temp[1]); } if (intent.hasExtra("destination")) { double[] temp = intent.getDoubleArrayExtra("destination"); destination = new LatLng (temp[0], temp[1]); }*/ String linkCollection = null; String nodeCollection = null; String points = null; if (intent.hasExtra("GuidanceLinkCollection")) linkCollection = intent.getStringExtra("GuidanceLinkCollection"); if (intent.hasExtra("GuidanceNodeCollection")) nodeCollection = intent.getStringExtra("GuidanceNodeCollection"); if (intent.hasExtra("shapePoints")) points = intent.getStringExtra("shapePoints"); gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.directionsView)).getMap(); gMap.setMyLocationEnabled(false); gMap.setBuildingsEnabled(false); gMap.getUiSettings().setZoomControlsEnabled(false); TextView textView = (TextView) findViewById(R.id.osm_guidance); textView.setText(Html.fromHtml("Data provided by OpenStreetMap contributors " + "<a href=\"http://www.openstreetmap.org/copyright\">License</a>")); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView = (TextView) findViewById(R.id.guidance_text); textView.setText( Html.fromHtml("Guidance Courtesy of " + "<a href=\"http://www.mapquest.com\">MapQuest</a>")); textView.setMovementMethod(LinkMovementMethod.getInstance()); PolylineOptions rectOptions = new PolylineOptions(); markers = new ArrayList<Marker>(); try { JSONArray jGuidanceLinkCollection = new JSONArray(linkCollection); JSONArray jGuidanceNodeCollection = new JSONArray(nodeCollection); JSONArray jShapePoints = new JSONArray(points); int lastIndex = 0; for (int i = 0; i < jGuidanceNodeCollection.length(); i++) { JSONObject nodeObject = jGuidanceNodeCollection.getJSONObject(i); JSONArray linkIds = nodeObject.getJSONArray("linkIds"); int linkIndex = 0; if (linkIds.length() != 0) linkIndex = linkIds.getInt(0); else continue; JSONObject linkObject = jGuidanceLinkCollection.getJSONObject(linkIndex); int shapeIndex = linkObject.getInt("shapeIndex"); // The index of a specific shape point is i/2, so multiply by 2 to get the beginning index in shapePoints // evens are lat and odds are lng double lat = jShapePoints.getDouble((shapeIndex * 2)); double lng = jShapePoints.getDouble((shapeIndex * 2) + 1); lastIndex = ((shapeIndex * 2) + 1); if (i == 0) { Marker temp = gMap .addMarker(new MarkerOptions().position(new LatLng(lat, lng)).title("Origin")); markers.add(temp); } else if (nodeObject.isNull("infoCollection") == false) { Marker temp = gMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)) .title(nodeObject.getJSONArray("infoCollection").getString(0))); markers.add(temp); } } for (int i = 0; i < lastIndex; i++) { double lat = jShapePoints.getDouble(i); i++; double lng = jShapePoints.getDouble(i); rectOptions.add(new LatLng(lat, lng)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } gMap.addPolyline(rectOptions); markersIndex = 0; gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markers.get(markersIndex).getPosition(), 17)); markers.get(markersIndex).showInfoWindow(); gMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker arg0) { if (arg0 != null) { for (int i = 0; i < markers.size(); i++) { if (markers.get(i).equals(arg0)) { markersIndex = i; break; } } if (markersIndex == 0) { findViewById(R.id.button_nextStep).setEnabled(true); findViewById(R.id.button_previousStep).setEnabled(false); } else if (markersIndex == (markers.size() - 1)) { findViewById(R.id.button_nextStep).setEnabled(false); findViewById(R.id.button_previousStep).setEnabled(true); } else { findViewById(R.id.button_nextStep).setEnabled(true); findViewById(R.id.button_previousStep).setEnabled(true); } gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(arg0.getPosition(), 17)); arg0.showInfoWindow(); return true; } return false; } }); }
From source file:com.naman14.algovisualizer.AlgoDescriptionFragment.java
private void addDescData(String algorithmKey) { if (descJson == null || descObject == null || getActivity() == null) { return;/*ww w. j a v a 2 s. co m*/ } rootView.removeAllViews(); try { JSONObject dataObject = descObject.getJSONObject(algorithmKey); Iterator<?> keys = dataObject.keys(); while (keys.hasNext()) { View descView = LayoutInflater.from(getActivity()).inflate(R.layout.item_code_desc, rootView, false); TextView title = (TextView) descView.findViewById(R.id.title); TextView desc = (TextView) descView.findViewById(R.id.desc); desc.setMovementMethod(LinkMovementMethod.getInstance()); String key = (String) keys.next(); title.setText(key); if (dataObject.get(key) instanceof JSONObject) { JSONObject jsonObject = dataObject.getJSONObject(key); String descString = ""; Iterator<?> complexityKeys = jsonObject.keys(); while (complexityKeys.hasNext()) { String complexityKey = (String) complexityKeys.next(); descString += " - "; descString += complexityKey; descString += " : "; descString += jsonObject.getString(complexityKey); descString += "<br>"; } desc.setText(Html.fromHtml(descString)); } else if (dataObject.get(key) instanceof JSONArray) { JSONArray array = dataObject.getJSONArray(key); String descString = ""; for (int i = 0; i < array.length(); i++) { descString += " - "; descString += array.getString(i); descString += "<br>"; } desc.setText(Html.fromHtml(descString)); } else if (dataObject.get(key) instanceof String) { desc.setText(Html.fromHtml(dataObject.getString(key))); } rootView.addView(descView); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.flurry.samples.analytics.PhotoDetailActivity.java
/** * Load Photo Details into View. Load photo from Picasso into View. */* www . j av a 2s . c o m*/ * @param photo Photo object */ public void loadPhotoDetails(final Photo photo) { flickrClient = new FlickrClient(); HashMap<String, String> fetchPhotoStatEventParams = new HashMap<>(2); fetchPhotoStatEventParams.put(AnalyticsHelper.PARAM_FETCH_PHOTO_ID, String.valueOf(photo.getPhotoId())); fetchPhotoStatEventParams.put(AnalyticsHelper.PARAM_FETCH_PHOTO_SECRET, String.valueOf(photo.getSecret())); AnalyticsHelper.logEvent(AnalyticsHelper.EVENT_FETCH_PHOTO_STATS, fetchPhotoStatEventParams, true); Log.i(LOG_TAG, "Logging event: " + AnalyticsHelper.EVENT_FETCH_PHOTO_STATS); flickrClient.getPhotoDetailFeed(photo.getPhotoId(), photo.getSecret(), new JsonHttpResponseHandler() { @Override public void onSuccess(int code, Header[] headers, JSONObject body) { AnalyticsHelper.endTimedEvent(AnalyticsHelper.EVENT_FETCH_PHOTO_STATS); if (body != null) { try { photo.setOwner(body.getJSONObject("photo").getJSONObject("owner").getString("realname")); photo.setDateTaken(body.getJSONObject("photo").getJSONObject("dates").getString("taken")); long datePosted = Long .parseLong(body.getJSONObject("photo").getJSONObject("dates").getString("posted")); Date date = new Date(datePosted * 1000L); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT-8")); } catch (JSONException e) { AnalyticsHelper.logError(LOG_TAG, "Deserialize photo detail JSONObject error.", e); } } else { AnalyticsHelper.logError(LOG_TAG, "Response body is null", null); } if (photo.getTitle() != null && !photo.getTitle().trim().equals("")) { title.setText(photo.getTitle()); } if (photo.getOwner() != null && !photo.getOwner().trim().equals("")) { owner.setText(Html.fromHtml("<b>By </b> " + photo.getOwner())); } if (photo.getDateTaken() != null && !photo.getDateTaken().trim().equals("")) { dateTaken.setText(Html.fromHtml("<b>Taken On </b> " + photo.getDateTaken().split(" ")[0])); } Picasso.with(PhotoDetailActivity.this).load(photo.getPhotoUrl()).error(R.drawable.noimage) .placeholder(R.drawable.noimage).into(photoImage); } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { AnalyticsHelper.logError(LOG_TAG, "Failure in fetching photo details", null); super.onFailure(statusCode, headers, responseString, throwable); } }); }
From source file:cc.mintcoin.wallet.ui.WalletDisclaimerFragment.java
private void updateView() { if (!isResumed()) return;/*from w ww . j a v a2s .c om*/ final boolean showBackup = config.remindBackup(); final boolean showDisclaimer = config.getDisclaimerEnabled(); final int progressResId; if (download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK) progressResId = 0; else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0) progressResId = R.string.blockchain_state_progress_problem_storage; else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0) progressResId = R.string.blockchain_state_progress_problem_network; else throw new IllegalStateException("download=" + download); final SpannableStringBuilder text = new SpannableStringBuilder(); if (progressResId != 0) text.append(Html.fromHtml("<b>" + getString(progressResId) + "</b>")); if (progressResId != 0 && (showBackup || showDisclaimer)) text.append('\n'); if (showBackup) text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup))); if (showBackup && showDisclaimer) text.append('\n'); if (showDisclaimer) text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety))); messageView.setText(text); final View view = getView(); final ViewParent parent = view.getParent(); final View fragment = parent instanceof FrameLayout ? (FrameLayout) parent : view; fragment.setVisibility(text.length() > 0 ? View.VISIBLE : View.GONE); }
From source file:com.qubittech.feelknit.app.MainActivity.java
@Override protected void onNavItemSelected(int id) { switch (id) { case 101://ww w . ja v a 2 s. com ShowProfileFragment(ApplicationHelper.getAvatar(getApplicationContext())); break; case 102: ShowCurrentFeelingsFragment(); break; case 103: StartUserFeelingsFragment(); break; case 104: showCommentsFeelingsFragment(); break; case 105: ShowRelatedFeelingFragment(); break; case 106: final Dialog d = new Dialog(this, R.style.CustomDialogTheme); d.setContentView(R.layout.custom_dialog); d.show(); TextView version = (TextView) d.findViewById(R.id.versionTextView); TextView saripaar = (TextView) d.findViewById(R.id.saripaar); TextView licenseLink = (TextView) d.findViewById(R.id.licenseLink); final TextView license = (TextView) d.findViewById(R.id.license); saripaar.setText(Html.fromHtml("<u>android-saripaar</u>")); licenseLink.setText(Html.fromHtml("(<u>license</u>)")); saripaar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Uri uriUrl = Uri.parse("https://github.com/ragunathjawahar/android-saripaar"); Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(launchBrowser); } }); license.setText("Copyright 2012 - 2015 Mobs and Geeks\n\n" + "Licensed under the Apache License, Version 2.0 (the \"License\");\n" + "you may not use this file except in compliance with the License.\n" + "You may obtain a copy of the License at\n" + "\n" + " http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + "Unless required by applicable law or agreed to in writing, software\n" + "distributed under the License is distributed on an \"AS IS\" BASIS,\n" + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + "See the License for the specific language governing permissions and\n" + "limitations under the License."); licenseLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { license.setVisibility(license.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); } }); try { version.setText(getApplicationContext().getPackageManager() .getPackageInfo(getApplicationContext().getPackageName(), 0).versionName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } TextView close_btn = (TextView) d.findViewById(R.id.okButton); close_btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { d.dismiss(); } }); } }
From source file:fi.mikuz.boarder.connection.ConnectionManager.java
public ConnectionManager(ConnectionListener connectionListener, final String url, final HashMap<String, String> sendList) { this.connectionListener = connectionListener; Thread t = new Thread() { public void run() { JSONObject json = new JSONObject(); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); if (sendList != null) { for (String key : sendList.keySet()) { json.put(key, sendList.get(key)); }/*from w w w. ja va 2 s .c om*/ } json.put(InternetMenu.HTML_FILTER, false); StringEntity se = new StringEntity(json.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Sending to " + url + ": " + json.toString()); HttpResponse response = httpclient.execute(httppost); InputStream in = response.getEntity().getContent(); //Get the data in the entity String result = convertStreamToString(in); try { if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Got from " + url + ": " + result); else Log.v(TAG, "Got answer from " + url); connectionSuccessfulResponse = new ConnectionSuccessfulResponse(new JSONObject(result), ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionSuccessful); } catch (JSONException e) { Log.e(TAG, "Couldn't convert to JSON object", e); connectionErrorResponse = new ConnectionErrorResponse(Html.fromHtml(result).toString(), url); mHandler.post(connectionError); } } catch (Exception e) { String error = "Cannot establish connection"; Log.e(TAG, error); connectionErrorResponse = new ConnectionErrorResponse(error, ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionError); } } }; t.start(); }
From source file:com.adkdevelopment.yalantisinternship.DetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.detail_fragment_task, container, false); ButterKnife.bind(this, rootView); Intent intent = getActivity().getIntent(); RSSNewsItem mNewsItem;/*w w w . jav a2s. c o m*/ if (intent.hasExtra(RSSNewsItem.TASKITEM)) { mNewsItem = intent.getParcelableExtra(RSSNewsItem.TASKITEM); // Time parsing and creating a nice textual version (should be changed to Calendar) String dateCreated = Utilities.getNiceDate(mNewsItem.getCreated()); String dateRegistered = Utilities.getNiceDate(mNewsItem.getRegistered()); String dateAssigned = Utilities.getNiceDate(mNewsItem.getAssigned()); task_title_text.setText(mNewsItem.getOwner()); task_status.setText(mNewsItem.getStatus()); task_created_date.setText(dateCreated); task_registered_date.setText(dateRegistered); task_assigned_date.setText(dateAssigned); task_responsible_name.setText(mNewsItem.getResponsible()); task_description.setText(Html.fromHtml(mNewsItem.getDescription())); } else { // If there is no outside intent - fetch example photos ArrayList<String> dummyPhotos = new ArrayList<>(); dummyPhotos.addAll(Arrays.asList(getResources().getStringArray(R.array.task_image_links))); mNewsItem = new RSSNewsItem(); mNewsItem.setPhoto(dummyPhotos); } // To boost performance as we know that size won't change recyclerView.setHasFixedSize(true); // Horizontal LayoutManager RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false); recyclerView.setLayoutManager(layoutManager); // Adapter with data about different activities PhotoAdapter photoAdapter = new PhotoAdapter(mNewsItem.getPhoto(), getContext()); recyclerView.setAdapter(photoAdapter); return rootView; }