Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:com.thoughtmetric.tl.TLLib.java

public static Object[] parseEditText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context)
        throws IOException {
    // Although probably not THE worst hack I've written, this function ranks near the top.
    // TODO: rework this routine get rid of code duplication.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.setCookieStore(cookieStore);

    HttpGet httpGet = new HttpGet(url.toExternalForm());
    HttpResponse response = httpclient.execute(httpGet);

    handler.sendEmptyMessage(PROGRESS_DOWNLOADING);
    InputStream is = response.getEntity().getContent();

    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_PRIVATE);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    String line;/*from  www  . j a va 2  s . c o m*/
    String formStart = "<form action=\"/forum/edit.php";
    while ((line = br.readLine()) != null) {
        if (line.startsWith(formStart)) {
            Log.d(TAG, line);
            bw.write(line);
            break;
        }
    }

    String start = "\t\t<textarea";
    String end = "\t\t<p>";
    StringBuffer sb = new StringBuffer();
    while ((line = br.readLine()) != null) {
        if (line.startsWith(start)) {
            bw.write("</form>");
            int i = line.lastIndexOf('>');
            sb.append(Html.fromHtml(line.substring(i + 1)).toString());
            sb.append("\n");
            break;
        } else {
            bw.write(line);
        }
    }

    while ((line = br.readLine()) != null) {
        if (line.startsWith(end)) {
            break;
        }
        sb.append(Html.fromHtml(line).toString());
        sb.append("\n");
    }

    bw.flush();
    bw.close();

    if (handler != null)
        handler.sendEmptyMessage(PROGRESS_PARSING);

    Object[] ret = new Object[2];

    ret[0] = sb.toString();
    ret[1] = cleaner.clean(context.openFileInput(TEMP_FILE_NAME));
    return ret;
}

From source file:a.dev.mobile.thread.MainActivity.java

private void startDialogAbout() {
    // Get app version
    PackageManager pm = getPackageManager();
    String packageName = getPackageName();
    String versionName;//from   w ww.  ja  v  a  2  s . co  m
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "N/A";
    }
    final MaterialDialog materialDialog = new MaterialDialog(this);
    materialDialog.setBackgroundResource(R.color.background_nav);
    materialDialog.setTitle(Html.fromHtml(getString(R.string.app_name_and_version, versionName)));
    materialDialog.setMessage(
            Html.fromHtml(getString(R.string.about_body, Calendar.getInstance().get(Calendar.YEAR))));
    materialDialog.setCanceledOnTouchOutside(true);

    materialDialog.show();
}

From source file:net.olejon.mdapp.NotesEditActivity.java

private void getMedications() {
    try {/*from   w  ww  .j  av a2 s.  co  m*/
        int medicationsJsonArrayLength = mPatientMedicationsJsonArray.length();

        if (medicationsJsonArrayLength == 0) {
            mPatientMedicationsTextView.setVisibility(View.GONE);
        } else {
            mPatientMedicationsTextView.setVisibility(View.VISIBLE);

            final ArrayList<String> medicationsNamesArrayList = new ArrayList<>();
            final ArrayList<String> medicationsManufacturersArrayList = new ArrayList<>();

            final String[] medicationsNamesStringArrayList = new String[medicationsJsonArrayLength + 2];

            medicationsNamesStringArrayList[0] = getString(R.string.notes_edit_medications_dialog_interactions);
            medicationsNamesStringArrayList[1] = getString(R.string.notes_edit_medications_dialog_remove_all);

            for (int i = 0; i < medicationsJsonArrayLength; i++) {
                JSONObject medicationJsonObject = mPatientMedicationsJsonArray.getJSONObject(i);

                String name = medicationJsonObject.getString("name");
                String manufacturer = medicationJsonObject.getString("manufacturer");

                medicationsNamesArrayList.add(name);
                medicationsManufacturersArrayList.add(manufacturer);

                medicationsNamesStringArrayList[i + 2] = name;
            }

            String medicationsNames = "";

            for (int n = 0; n < medicationsNamesArrayList.size(); n++) {
                medicationsNames += medicationsNamesArrayList.get(n) + ", ";
            }

            medicationsNames = medicationsNames.replaceAll(", $", "");

            mPatientMedicationsTextView.setText(Html.fromHtml("<u>" + medicationsNames + "</u>"));

            mPatientMedicationsTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new MaterialDialog.Builder(mContext)
                            .title(getString(R.string.notes_edit_medications_dialog_title))
                            .items(medicationsNamesStringArrayList)
                            .itemsCallback(new MaterialDialog.ListCallback() {
                                @Override
                                public void onSelection(MaterialDialog materialDialog, View view, int i,
                                        CharSequence charSequence) {
                                    if (i == 0) {
                                        String medicationsInteractions = "";

                                        for (int n = 0; n < medicationsNamesArrayList.size(); n++) {
                                            medicationsInteractions += medicationsNamesArrayList.get(n)
                                                    .split(" ")[0] + " ";
                                        }

                                        medicationsInteractions = medicationsInteractions.trim();

                                        Intent intent = new Intent(mContext, InteractionsCardsActivity.class);
                                        intent.putExtra("search", medicationsInteractions);
                                        startActivity(intent);
                                    } else if (i == 1) {
                                        try {
                                            mPatientMedicationsJsonArray = new JSONArray("[]");

                                            getMedications();
                                        } catch (Exception e) {
                                            Log.e("NotesEditActivity", Log.getStackTraceString(e));
                                        }
                                    } else {
                                        int position = i - 2;

                                        String medicationName = medicationsNamesArrayList.get(position);
                                        String medicationManufacturer = medicationsManufacturersArrayList
                                                .get(position);

                                        SQLiteDatabase sqLiteDatabase = new SlDataSQLiteHelper(mContext)
                                                .getReadableDatabase();

                                        String[] queryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID };
                                        Cursor cursor = sqLiteDatabase.query(
                                                SlDataSQLiteHelper.TABLE_MEDICATIONS, queryColumns,
                                                SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " = "
                                                        + mTools.sqe(medicationName) + " AND "
                                                        + SlDataSQLiteHelper.MEDICATIONS_COLUMN_MANUFACTURER
                                                        + " = " + mTools.sqe(medicationManufacturer),
                                                null, null, null, null);

                                        if (cursor.moveToFirst()) {
                                            long id = cursor.getLong(cursor.getColumnIndexOrThrow(
                                                    SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                                            Intent intent = new Intent(mContext, MedicationActivity.class);

                                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                                if (mTools.getDefaultSharedPreferencesBoolean(
                                                        "MEDICATION_MULTIPLE_DOCUMENTS"))
                                                    intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                                                            | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                                            }

                                            intent.putExtra("id", id);
                                            startActivity(intent);
                                        }

                                        cursor.close();
                                        sqLiteDatabase.close();
                                    }
                                }
                            }).itemColorRes(R.color.dark_blue).show();
                }
            });
        }
    } catch (Exception e) {
        Log.e("NotesEditActivity", Log.getStackTraceString(e));
    }
}

From source file:com.wlcg.aroundme.cc.weather.YahooWeatherProvider.java

@Override
public WeatherInfo getWeatherInfo(Location location, boolean metricUnits) {
    mLocation = location;//from   ww w.j  a v  a  2 s .  c  om
    mMetricUnits = metricUnits;

    String language = getLanguage();
    String params = String.format(Locale.US, "\"%f %f\" and locale=\"%s\"", location.getLatitude(),
            location.getLongitude(), language);
    String url = URL_PLACEFINDER + Uri.encode(params);
    JSONObject results = fetchResults(url);
    if (results == null) {
        return null;
    }

    WeatherInfo info = null;
    try {
        JSONObject result = results.getJSONObject("Result");
        String woeid = result.getString("woeid");
        String city = result.getString("city");

        if (city == null) {
            city = result.getString("neighborhood");
        }

        // The city name in the placefinder result is HTML encoded :-(
        if (city != null) {
            city = Html.fromHtml(city).toString();
        }

        Log.d(TAG, "Resolved location " + location + " to " + city + " (" + woeid + ")");

        info = getWeatherInfo(woeid, city, metricUnits);
    } catch (JSONException e) {
        Log.e(TAG, "Received malformed placefinder data (location=" + location + ", lang=" + language + ")", e);
        info = null;
    }
    if (mWeatherDataChangedListener != null)
        mWeatherDataChangedListener.onDataChanged();
    return info;
}

From source file:fr.gotorennes.AbstractMapActivity.java

protected void populateItineraireDetails(Itineraire itineraire) {
    LinearLayout details = (LinearLayout) findViewById(R.id.details);
    for (final Etape etape : itineraire.etapes) {
        addEtapeOverlay(etape);//from   w w  w.j av  a 2 s  .co  m

        RelativeLayout view = (RelativeLayout) getLayoutInflater().inflate(R.layout.itineraire_listitem, null);

        ImageView lineIcon = (ImageView) view.findViewById(R.id.icon);
        if (etape.bitmapIcon != null) {
            lineIcon.setImageBitmap(etape.bitmapIcon);
        } else {
            lineIcon.setImageResource(etape.type.icon);
        }

        TextView name = (TextView) view.findViewById(R.id.name);
        name.setText(Html.fromHtml(Arret.getTime(etape.depart) + " : " + etape.adresseDepart + "<br />"
                + Arret.getTime(etape.arrivee) + " : " + etape.adresseArrivee));

        TextView duree = (TextView) view.findViewById(R.id.duree);
        duree.setText(etape.getDuree() + "min");

        TextView distance = (TextView) view.findViewById(R.id.distance);
        distance.setText(getFormattedDistance(etape.locationDepart, etape.locationArrivee));
        distance.setVisibility(
                etape.type == TypeEtape.PIETON || etape.type == TypeEtape.VELO ? View.VISIBLE : View.GONE);

        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Location depart = etape.locationDepart;
                centerMap(depart.latitude, depart.longitude);
            }
        });
        details.addView(view);
    }
    Location first = itineraire.etapes.get(0).locationDepart;
    centerMap(first.latitude, first.longitude);
}

From source file:com.alainesp.fan.sanderson.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (!item.isChecked()) {
        if (id != R.id.nav_about) {
            this.setTitle(item.getTitle());
            item.setChecked(true);//  www . ja v  a2  s .c o m
        }

        if (id == R.id.nav_main) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new SummaryFragment()).commit();
            app_state = APP_STATE_SUMMARY;
        } else if (id == R.id.nav_blog) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new BlogPostsFragment())
                    .commit();
            app_state = APP_STATE_BLOG;
        } else if (id == R.id.nav_events) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new EventsFragment()).commit();
            app_state = APP_STATE_EVENTS;
        } else if (id == R.id.nav_books) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new BooksFragment()).commit();
            app_state = APP_STATE_BOOKS;
        } else if (id == R.id.nav_twitter) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TwitterFragment()).commit();
            app_state = APP_STATE_TWITTER;
        } else if (id == R.id.nav_tor0) {
            Uri webpage = Uri.parse("http://www.tor.com/features/series/the-way-of-kings-reread-on-torcom/");
            Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
            if (isIntentSafe(webIntent))
                startActivity(webIntent);

            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TorWoKRereadFragment())
                    .commit();
            app_state = APP_STATE_WOK;
            this.setTitle("The Way of Kings Reread");
        } else if (id == R.id.nav_tor1) {
            //Uri webpage = Uri.parse("http://www.tor.com/series/words-of-radiance-reread-on-torcom/");
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TorWoRRereadFragment())
                    .commit();
            app_state = APP_STATE_WOR;
            this.setTitle("Words of Radiance Reread");
        } else if (id == R.id.nav_17shard)// TODO: Handle posts and news in the app
        {
            Uri webpage = Uri.parse("http://www.17thshard.com/forum/");
            Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
            if (isIntentSafe(webIntent))
                startActivity(webIntent);

            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new Shard17thFragment())
                    .commit();
            app_state = APP_STATE_17SHARD;
        } else if (id == R.id.nav_settings) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new SettingsFragment())
                    .commit();
            app_state = APP_STATE_SETTINGS;
        } else if (id == R.id.nav_about) {
            try {
                new AlertDialog.Builder(this).setTitle("About")
                        .setMessage(Html.fromHtml("<em>Fan of Sanderson</em> "
                                + getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " BETA"
                                + "<br/><br/>Application made by fans to fans.<br/><br/>"
                                + "Developer: Alain Espinosa &lt;alainesp@gmail.com&gt;"))
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();
            } catch (PackageManager.NameNotFoundException ignored) {
            }
        }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.bluetooth.mwoolley.microbitbledemo.ui.HrmListActivity.java

private void showMsg(final String msg) {
    Log.d(Constants.TAG, msg);//from   w  w  w  .j  av a  2 s.  c om
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ((TextView) HrmListActivity.this.findViewById(R.id.message)).setText(Html.fromHtml(msg));
        }
    });
}

From source file:com.bluetooth.mwoolley.microbitbledemo.ui.MainActivity.java

private void showMsg(final String msg) {
    Log.d(Constants.TAG, msg);//from   ww w . j a va2 s . co m
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ((TextView) MainActivity.this.findViewById(R.id.message)).setText(Html.fromHtml(msg));
        }
    });
}

From source file:de.wikilab.android.friendica01.Max.java

public static void alert(Context ctx, String text, String title, String okButtonText) {
    AlertDialog ad = new AlertDialog.Builder(ctx).create();
    ad.setCancelable(false); // This blocks the 'BACK' button  
    ad.setMessage(Html.fromHtml(text));
    ad.setTitle(title);/*from   w w w.  j a  v  a  2 s.com*/
    ad.setButton(okButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.show();
    ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_view_as_grid) {
        Intent i = new Intent(POIMapActivity.this, POIGridActivity.class);

        i.putExtra("playOn", mActionPlay);

        i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        // finish();
        overridePendingTransition(0, 0);

        startActivityForResult(i, 1);//from  w  w w  . jav a2  s  .  c om
        overridePendingTransition(0, 0);

    } else if (id == R.id.action_directions) {

        if (mActionDirections == 1) { // cancel directions action
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else if (mActionDirections == 0) { // set directions action on

            item.setIcon(R.drawable.ic_action_directions_pressed);
            mActionDirections = 1;

            gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage);
            if (gmm.myLocationEnabled && gmm.internetEnabled) {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.tap_route_destination),
                        Toast.LENGTH_SHORT).show();

            } else {
                tvMapMessage.setBackgroundColor(
                        POIMapActivity.this.getResources().getColor(R.color.red_transparent));

                item.setIcon(R.drawable.ic_action_directions);
                mActionDirections = 0;
                tvMapDirectionsInfo.setVisibility(View.INVISIBLE);

            }
        } else { // mActionDirections == 3
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        }

    } else if (id == R.id.action_play) {

        if (mActionPlay) { // cancel play mode
            gmm.addAllMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_play);
            mActionPlay = false;

            miDirections.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else {
            gmm.addPlayMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_pause_red);
            if (gmm.activePOIMarker != null) {
                drawUserDestRoute(gmm.activePOIMarker.getPosition());
            }
            mActionPlay = true;

        }

    } else if (id == R.id.action_google_map_type) {
        // get google map type names
        String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names);

        // creating and Building the Dialog
        AlertDialog.Builder builderMapType = new AlertDialog.Builder(this);
        builderMapType.setTitle(getResources().getString(R.string.action_google_map_type));
        builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {

                        if (item != selectedMapType) {
                            switchGoogleMapType(item);
                            // save selected type in settings
                            SharedPreferences preferences = PreferenceManager
                                    .getDefaultSharedPreferences(POIMapActivity.this);
                            SharedPreferences.Editor editor = preferences.edit();
                            editor.putString("googleMapType", String.valueOf(item));
                            editor.commit();
                        }
                        mapTypeDialog.dismiss();
                    }
                });
        mapTypeDialog = builderMapType.create();
        mapTypeDialog.show();

    } else if (id == R.id.action_legal_notices) {

        String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this);
        licenseDialog.setTitle(getString(R.string.action_legal_notices));
        licenseDialog.setMessage(licenseInfo);
        licenseDialog.show();

    } else if (id == R.id.action_scan_qr_code) {

        handleQRcodeScanRequest();

    } else if (id == R.id.action_about) {
        String about = getString(R.string.about_application);
        AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();

        alertDialog.setTitle(getString(R.string.action_about));
        alertDialog.setMessage(Html.fromHtml(about));

        alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
    }
    return super.onOptionsItemSelected(item);
}