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.pursuer.reader.easyrss.data.parser.ItemJSONParser.java

public void parse() throws JsonParseException, IOException {
    Item item = new Item();
    int level = 0;
    boolean found = false;
    while (parser.nextToken() != null) {
        final String name = parser.getCurrentName();
        switch (parser.getCurrentToken()) {
        case START_OBJECT:
        case START_ARRAY:
            level++;//  www . j a v a  2  s. c o  m
            break;
        case END_OBJECT:
        case END_ARRAY:
            level--;
            break;
        case VALUE_STRING:
            if (level == 1 && "continuation".equals(name)) {
                if (listener != null) {
                    listener.onListContinuationRetrieved(parser.getText());
                }
            } else if (level == 3) {
                if ("id".equals(name)) {
                    final String text = parser.getText();
                    item.setUid(text.substring(text.lastIndexOf('/') + 1));
                } else if ("title".equals(name)) {
                    item.setTitle(Html.fromHtml(parser.getText()).toString());
                } else if ("timestampUsec".equals(name)) {
                    item.setTimestamp(Long.valueOf(parser.getText()));
                } else if ("author".equals(name)) {
                    item.setAuthor(Html.fromHtml(parser.getText()).toString());
                }
            } else if (level == 4) {
                if ("content".equals(name)) {
                    item.setContent(parser.getText());
                } else if ("streamId".equals(name)) {
                    item.setSourceUri(parser.getText());
                } else if ("title".equals(name)) {
                    item.setSourceTitle(Html.fromHtml(parser.getText()).toString());
                }
            } else if (level == 5 && "href".equals(name)) {
                item.setHref(parser.getText());
            }
            break;
        case FIELD_NAME:
            if (level == 1 && "items".equals(name)) {
                found = true;
            } else if (level == 3 && "categories".equals(name)) {
                parser.nextToken();
                if (parser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_ARRAY) {
                        if (parser.getCurrentToken() == JsonToken.VALUE_STRING) {
                            final String category = parser.getText();
                            if (DataUtils.isReadUid(category)) {
                                item.getState().setRead(true);
                            } else if (DataUtils.isStarredUid(category)) {
                                item.getState().setStarred(true);
                            } else if (DataUtils.isTagUid(category)) {
                                item.addTag(category);
                            }
                        }
                    }
                }
            } else if (level == 3 && "enclosure".equals(name)) {
                parser.nextToken();
                if (parser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_ARRAY) {
                    }
                }
            }
        default:
            break;
        }
        if (level == 2) {
            if (item.getUid() != null && listener != null) {
                listener.onItemRetrieved(item);
            }
            item = new Item();
        }
    }
    parser.close();
    if (!found) {
        throw new IllegalStateException("Invalid JSON input");
    }
}

From source file:am.roadpolice.roadpolice.ViolationInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_violation_info);

    DialogRateUs.showRateUs(getApplicationContext(), getSupportFragmentManager());

    // Customize Action Bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(0xFF1A237E));
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(Html.fromHtml("<small>" + getString(R.string.title_activity_info) + "</small>"));

    final Intent intent = getIntent();
    // Get Data which is sent from MainActivity.
    mAutoLogin = intent.getBooleanExtra(EXTRA_AUTO_LOGIN, false);
    ArrayList<ViolationInfo> violationList = intent.getParcelableArrayListExtra(EXTRA_VIOLATION_INFO_LIST);

    ViolationInfoAdapter adapter = new ViolationInfoAdapter(getApplicationContext(), violationList);

    ListView listView = (ListView) findViewById(R.id.listViewViolationInfo);
    listView.setOnItemClickListener(this);
    listView.setEmptyView(findViewById(R.id.textViewEmpty));
    listView.setAdapter(adapter);/*from  w  w  w .j  ava  2 s .  c  om*/
}

From source file:com.android.leanlauncher.SettingsActivity.java

private void displayAboutDialog() {
    findPreference(getString(R.string.pref_about))
            .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override/*  w w  w  . j av a 2s .c o m*/
                public boolean onPreferenceClick(Preference preference) {
                    String about = String.format(getString(R.string.about_application),
                            BuildConfig.VERSION_NAME);

                    AlertDialog d = new AlertDialog.Builder(SettingsActivity.this)
                            .setIcon(R.mipmap.ic_launcher_home).setCancelable(true)
                            .setTitle(R.string.application_name).setMessage(Html.fromHtml(about)).create();
                    d.show();
                    ((TextView) d.findViewById(android.R.id.message))
                            .setMovementMethod(LinkMovementMethod.getInstance());

                    return false;
                }
            });
}

From source file:com.bingzer.android.eula.EulaFragment.java

@Override
public void onResume() {
    super.onResume();
    textView.postDelayed(new Runnable() {
        @Override/* w ww.j a  va 2  s.  c o  m*/
        public void run() {
            String eulaRaw = Res.readRaw(getRawEulaResourceId()).toString();
            String eulaText = eulaRaw.replaceAll("%APP_NAME%", Res.getApplicationName())
                    .replaceAll("%APP_VERSION%", Res.getVersionName());

            textView.setText(Html.fromHtml(eulaRaw));
            agreeButton.setEnabled(true);
        }
    }, 1000);
}

From source file:color.kidpaint.com.kidpaintcolor.dialog.DialogTermsOfUseAndService.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//w  ww .j av  a  2 s . c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());

    builder.setTitle(R.string.terms_of_use_and_service_title);
    View view = inflater.inflate(R.layout.dialog_terms_of_use_and_service, null);

    TextView termsOfUseAndServiceTextView = (TextView) view
            .findViewById(R.id.terms_of_use_and_service_tview_Text);
    termsOfUseAndServiceTextView.setText(R.string.terms_of_use_and_service_content);

    TextView termsOfUseAndServiceUrlTextView = (TextView) view
            .findViewById(R.id.terms_of_use_and_service_tview_Url);
    termsOfUseAndServiceUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());
    Resources resources = getActivity().getResources();
    String paintroidTermsOfUseAndService = String.format(
            resources.getString(R.string.terms_of_use_and_service_link_template),
            resources.getString(R.string.terms_of_use_and_service_url),
            resources.getString(R.string.terms_of_use_and_service_url_text));
    termsOfUseAndServiceUrlTextView.append(Html.fromHtml(paintroidTermsOfUseAndService));
    termsOfUseAndServiceUrlTextView.append("\n\n");
    String aboutCatroid = String.format(resources.getString(R.string.about_link_template),
            resources.getString(R.string.catroid_url), resources.getString(R.string.about_catroid_url_text));
    termsOfUseAndServiceUrlTextView.append(Html.fromHtml(aboutCatroid));
    termsOfUseAndServiceUrlTextView.append("\n");

    builder.setView(view);
    builder.setNeutralButton(R.string.done, this);

    return builder.create();

}

From source file:com.bdevlin.apps.ui.fragments.HelpListFragment.java

private void updateText() {
    // mHelpText = (TextView) getView().findViewById(R.id.help_text);
    mHelpText = (WebView) getView().findViewById(R.id.webView1);
    mHelpText.getSettings().setJavaScriptEnabled(false);

    CharSequence text = Utils.bold(Utils.italic(getResources().getString(R.string.about_eula)),
            Utils.color(Color.RED, getResources().getString(R.string.about_licenses)));
    CharSequence yourHtml = "<table>table</table>";

    CharSequence content = getContent();
    ;/*www . ja  va  2 s  .co  m*/
    SpannedString sstr = SpannedString.valueOf(content);
    SpannedString message = SpannedString.valueOf(mMessage);
    SpannedString message2 = SpannedString.valueOf(text);
    SpannedString message3 = SpannedString.valueOf(yourHtml);

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(Html.fromHtml(Html.toHtml(message)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message2)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message3)));
    aboutBody.append(Html.fromHtml(Html.toHtml(sstr)));
    aboutBody.setSpan(new StyleSpan(Typeface.ITALIC), 0, aboutBody.length(), 0);
    // mHelpText.setText(aboutBody);
    // mHelpText.loadData(Html.toHtml(aboutBody), "text/html", null);

    mHelpText.loadUrl("file:///android_asset/" + mTitle + ".html", null);

    //mHelpText.loadUrl("http://www.choosemyplate.gov/tools-supertracker");

}

From source file:de.wikilab.android.friendica01.activity.UserProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    userId = getIntent().getStringExtra("userId");
    Log.i(TAG, "loading profile for userId=" + userId);

    setContentView(R.layout.userprofile);

    Button btn;/* w ww.j  a  v  a  2 s.co  m*/
    btn = (Button) findViewById(R.id.btn_nav_1);
    if (btn != null) {
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                findViewById(R.id.content_fragment_1).setVisibility(View.VISIBLE);
                findViewById(R.id.content_fragment_2).setVisibility(View.GONE);
            }
        });
        btn = (Button) findViewById(R.id.btn_nav_2);
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                findViewById(R.id.content_fragment_1).setVisibility(View.GONE);
                findViewById(R.id.content_fragment_2).setVisibility(View.VISIBLE);
            }
        });
    }

    final TwAjax t = new TwAjax(this, true, true);
    t.getUrlContent(Max.getServer(this) + "/api/users/show/" + userId, new Runnable() {
        @Override
        public void run() {

            try {
                JSONObject j = (JSONObject) t.getJsonResult();

                ((TextView) findViewById(R.id.profile_name)).setText(
                        Html.fromHtml("<b>" + j.getString("name") + "</b><br>" + j.getString("screen_name")));
                ((TextView) findViewById(R.id.header_text)).setText(j.getString("name") + "'s profile");

                ((ImageView) findViewById(R.id.profile_image)).setImageURI(
                        Uri.parse("file://" + Max.IMG_CACHE_DIR + "/friend_pi_" + j.getString("id") + "_.jpg"));

                String key, tx = "";
                Iterator<String> iter = j.keys();
                while (iter.hasNext()) {
                    key = iter.next();
                    tx += "<br><b>" + key + ":</b> " + String.valueOf(j.get(key));
                }

                ((TextView) findViewById(R.id.profile_content)).setText(Html.fromHtml(tx));

            } catch (Exception e) {

                ((TextView) findViewById(R.id.profile_content))
                        .setText(Html.fromHtml("<b>Error loading profile data!</b><br><br>" + e.toString()
                                + "<br><br>" + Max.Hexdump(t.getResult().getBytes())));

            }

        }
    });
}

From source file:br.com.PartoHumanizado.fragment.EnviarPlanoDePartoFragment.java

private void updateText() {

    StringBuilder builder = new StringBuilder();
    builder.append(getText("Trabalho de Parto", PlanoDePartoFragment.PREFERENCES_FILE_TRABALHO_DE_PARTO,
            R.array.trabalhoDeParto))// w w w .j a  v a 2  s .c o m
            .append(getText("Durante o Parto", PlanoDePartoFragment.PREFERENCES_FILE_PARTO,
                    R.array.duranteParto))
            .append(getText("Ps-Parto", PlanoDePartoFragment.PREFERENCES_FILE_POS_PARTO, R.array.posParto))
            .append(getText("Cuidados com o Beb", PlanoDePartoFragment.PREFERENCES_FILE_CUIDADOS_COM_BEBE,
                    R.array.cuidadosComBebe))
            .append(getText("Caso de Cesrea", PlanoDePartoFragment.PREFERENCES_FILE_CASO_CESAREA,
                    R.array.casoCesarea));

    texto.setText(Html.fromHtml(builder.toString()));
}

From source file:com.android.talkbacktests.testsession.TestSessionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    final View view = inflater.inflate(R.layout.fragment_test_content, container, false);

    final BaseTestContent content = TestController.getInstance().getSessionById(mSessionId)
            .getTestContent(mContentIndex);

    final TextView description = (TextView) (view.findViewById(R.id.contentContainer)
            .findViewById(R.id.description));
    description.setText(Html.fromHtml(content.getDescription()));
    description.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView subtitle = (TextView) (view.findViewById(R.id.contentContainer).findViewById(R.id.title));
    subtitle.setText(content.getSubtitle());

    final Button previous = (Button) view.findViewById(R.id.previous);
    previous.setOnClickListener(this);

    final Button next = (Button) view.findViewById(R.id.next);
    next.setOnClickListener(this);

    assignButtonText(previous, next);//  ww  w .  j  av  a2 s. c  o m

    final ViewGroup contentArea = (ViewGroup) view.findViewById(R.id.content_area);
    contentArea.addView(content.getView(inflater, contentArea, getContext()));

    return view;
}

From source file:com.manning.androidhacks.hack004.preference.AboutDialog.java

@Override
protected View onCreateDialogView() {
    LinearLayout layout = new LinearLayout(mContext);
    layout.setOrientation(LinearLayout.VERTICAL);
    TextView splashText = new TextView(mContext);
    String fmt = "Version %s<br />" + "<a href=\"http://manning.com/sessa\">MoreInfo</a>";
    try {/*from  www  .j a v a  2s  .  c o m*/
        String pkg = mContext.getPackageName();
        mVersionNumber = mContext.getPackageManager().getPackageInfo(pkg, 0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    if (mVersionNumber != null) {
        String aboutMsg = String.format(fmt, mVersionNumber);
        splashText.setText(Html.fromHtml(aboutMsg));
        splashText.setMovementMethod(LinkMovementMethod.getInstance());
    }

    layout.addView(splashText);

    return layout;
}