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, ImageGetter imageGetter, TagHandler tagHandler) 

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.handlerexploit.news.data.models.Article.java

public Article(JSONObject jsonObject) throws JSONException, ParseException {

    // TODO Clean this up

    link = jsonObject.getString("link");
    pubDate = simpleDateFormat.parse(jsonObject.getString("pubDate"));
    description = jsonObject.getString("description");
    String[] splitString = jsonObject.getString("title").split("-");
    source = splitString[splitString.length - 1].trim();
    title = jsonObject.getString("title").replace(source, "").replace("-", " ").replace("  ", " ").trim();
    Html.fromHtml(getDescription(), new ImageGetter() {
        public Drawable getDrawable(String source) {
            if (imageThumbnailUrl == null) {
                imageThumbnailUrl = source;
            }/* w  w  w  .  ja  v  a  2s .  co  m*/
            return null;
        }
    }, null);
}

From source file:it.scoppelletti.mobilepower.app.HelpActivity.java

/**
 * Creazione dell’attività.
 * /*from w w  w  . ja  v  a  2  s  .com*/
 * @param savedInstanceState Stato dell’istanza.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    TextView textControl;
    MarketTagHandler tagHandler;

    super.onCreate(savedInstanceState);

    setTheme(AppUtils.getActivityTheme());
    setContentView(R.layout.textview);

    textControl = (TextView) findViewById(R.id.txt_content);
    textControl.setKeyListener(null);
    textControl.setAutoLinkMask(Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);

    tagHandler = new MarketTagHandler();
    textControl.setText(Html.fromHtml(buildText(), null, tagHandler));
    tagHandler.addLinks(textControl, myFullPkgName);
}

From source file:it.scoppelletti.mobilepower.app.ReleaseNoteActivity.java

/**
 * Creazione dell’attività.
 * /* www . ja v  a  2  s .  co  m*/
 * @param savedInstanceState Stato dell’istanza.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    String notes;
    TextView textControl;
    Button button;
    MarketTagHandler tagHandler;

    super.onCreate(savedInstanceState);

    setTheme(AppUtils.getActivityTheme());
    setContentView(R.layout.releasenotes);

    textControl = (TextView) findViewById(R.id.txt_content);
    textControl.setKeyListener(null);
    textControl.setAutoLinkMask(Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);

    notes = getIntent().getStringExtra(ReleaseNoteActivity.EXTRA_RELEASENOTES);
    if (!StringUtils.isBlank(notes)) {
        tagHandler = new MarketTagHandler();
        textControl.setText(Html.fromHtml(notes, null, tagHandler));
        tagHandler.addLinks(textControl, AppUtils.getFullPackageName(this, false));
    }

    button = (Button) findViewById(R.id.cmd_continue);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:it.scoppelletti.mobilepower.app.AboutActivity.java

/**
 * Creazione dell’attività.
 * /*www .  j a v  a  2  s . c o m*/
 * @param savedInstanceState Stato dell’istanza.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    TextView textControl;
    MarketTagHandler tagHandler;

    super.onCreate(savedInstanceState);

    setTheme(AppUtils.getActivityTheme());
    setContentView(R.layout.textview);

    textControl = (TextView) findViewById(R.id.txt_content);
    textControl.setKeyListener(null);
    textControl.setAutoLinkMask(Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);

    tagHandler = new MarketTagHandler();
    textControl.setText(Html.fromHtml(buildText(), null, tagHandler));
    tagHandler.addLinks(textControl, AppUtils.getFullPackageName(this, false));
}

From source file:info.schnatterer.nusic.android.util.TextUtil.java

/**
 * Similar to {@link android.text.Html#fromHtml(String)}, but provides
 * support for more HTML-tags such as lists.
 * /*w  w w  .ja v a  2s. co m*/
 * @param string
 * @return
 */
public static CharSequence fromHtml(String string) {
    return Html.fromHtml(string.replaceFirst("<title>.*</title>", ""), null, new MyTagHandler());
}

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter("reply")
public static void setReply(TextView textView, @Nullable String reply) {
    if (TextUtils.isEmpty(reply)) {
        textView.setText(null);//from www . j a  v  a  2  s  . c  o m
    } else {
        // use GlideImageGetter to show images in TextView
        textView.setText(
                Html.fromHtml(reply, new GlideImageGetter(textView.getContext(), textView), new TagHandler()));
    }
}

From source file:com.brodev.socialapp.view.BlogDetail.java

private void initView() {
    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(blog.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, blog.getUser_image_path(), R.drawable.loading);
    }/*  w w w  . j a va 2s  .  c o  m*/
    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(blog.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.blog_content_detail);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, blog.getText(), content);
    content.setTag(0);
    content.setText(Html.fromHtml(blog.getText(), ig, null));

    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(blog.getTime_stamp());

    // set short text
    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(blog.getFull_name());

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(blog.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(blog.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

}

From source file:org.peterbaldwin.client.android.delicious.WebPageTitleRequest.java

/**
 * {@inheritDoc}//from   w  ww.j  a va2s.  c om
 */
public void run() {
    try {
        DefaultHttpClient client = new DefaultHttpClient();
        client.setRedirectHandler(this);
        try {
            HttpGet request = new HttpGet(mUrl);

            // Set a generic User-Agent to avoid being 
            // redirected to a mobile UI.
            request.addHeader("User-Agent", "Mozilla/5.0");

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            StatusLine statusLine = response.getStatusLine();
            try {
                int statusCode = statusLine.getStatusCode();
                if (statusCode != HttpStatus.SC_OK) {
                    throw new IOException("Unexpected response code: " + statusCode);
                }

                // Send redirect before checking content type
                // because the redirect is important even if the
                // title cannot be extracted.
                if (mRedirectLocation != null && !mUrl.equals(mRedirectLocation)) {
                    int what = HANDLE_REDIRECT;
                    Object obj = mRedirectLocation;
                    Message msg = mHandler.obtainMessage(what, obj);
                    msg.sendToTarget();
                }
                Header contentType = entity.getContentType();
                if (contentType != null) {
                    String value = contentType.getValue();
                    if (!isHtml(value)) {
                        // This is important because the user might try
                        // bookmarking a video or another large file.
                        throw new IOException("Unsupported content type: " + value);
                    }
                } else {
                    throw new IOException("Content type is missing");
                }
                String source = EntityUtils.toString(entity);
                Html.ImageGetter imageGetter = null;
                Html.TagHandler tagHandler = this;
                Html.fromHtml(source, imageGetter, tagHandler);
            } finally {
                if (entity != null) {
                    entity.consumeContent();
                }
            }
        } finally {
            client.getConnectionManager().shutdown();
        }
    } catch (TerminateParser e) {
        // Thrown by handleTag to terminate parser early.
    } catch (IOException e) {
        Log.e(LOG_TAG, "i/o error", e);
    } catch (RuntimeException e) {
        Log.e(LOG_TAG, "runtime error", e);
    } catch (Error e) {
        Log.e(LOG_TAG, "severe error", e);
    } finally {
        Message msg = mHandler.obtainMessage(HANDLE_TITLE, mTitle);
        msg.sendToTarget();
    }
}

From source file:com.brodev.socialapp.view.MarketPlaceDetail.java

private void initView() {

    ImageView userImage = (ImageView) this.findViewById(R.id.image_user);

    if (!"".equals(marketPlace.getUser_image_path())) {
        networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading);
    }//ww  w. j  a v  a2s.  c  o m

    userImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    // set title
    TextView title = (TextView) this.findViewById(R.id.title);
    title.setText(marketPlace.getTitle());
    colorView.changeColorText(title, user.getColor());

    // set content
    TextView content = (TextView) this.findViewById(R.id.content);

    // interesting part starts from here here:
    Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content);

    content.setTag(0);
    content.setText(Html.fromHtml(marketPlace.getText(), ig, null));

    TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp);
    timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on"));
    TextView timestamp = (TextView) findViewById(R.id.time_stamp);
    timestamp.setText(marketPlace.getTime_stamp());
    TextView price = (TextView) this.findViewById(R.id.price);

    if (marketPlace.getPrice() == 0) {
        price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free"));
    } else {
        price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice());
    }

    TextView locationTxt = (TextView) findViewById(R.id.txtLocation);
    locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location"));
    TextView txtLocation = (TextView) this.findViewById(R.id.location);
    String location = marketPlace.getCountry_name();

    if (!marketPlace.getCountry_child_name().equals("")) {
        location += " > " + marketPlace.getCountry_child_name();
    }
    if (!marketPlace.getCity_name().equals("")) {
        location += " > " + marketPlace.getCity_name();
    }

    txtLocation.setText(location);
    // set short text
    TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname);
    fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by"));

    TextView shortText = (TextView) findViewById(R.id.fullName);
    shortText.setText(marketPlace.getFull_name());
    colorView.changeColorText(shortText, user.getColor());

    shortText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class);
            intent.putExtra("user_id", marketPlace.getUser_id());
            startActivity(intent);
            return false;
        }
    });

    TextView total_like = (TextView) findViewById(R.id.total_like);
    total_like.setText(String.valueOf(marketPlace.getTotal_like()));
    colorView.changeColorText(total_like, user.getColor());

    TextView total_comment = (TextView) findViewById(R.id.total_comment);
    total_comment.setText(String.valueOf(marketPlace.getTotal_comment()));
    colorView.changeColorText(total_comment, user.getColor());

    ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt);
    ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt);
    colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor());

    //get list images
    if (!marketPlace.getImages().equals("")) {
        LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages);
        JSONObject objOutputImage = null;
        try {
            JSONArray objImages = new JSONArray(marketPlace.getImages());
            for (int i = 0; i < objImages.length(); i++) {
                objOutputImage = objImages.getJSONObject(i);
                ImageView imageView = new ImageView(getApplicationContext());

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        (int) getResources().getDimension(R.dimen.marketplace_image),
                        (int) getResources().getDimension(R.dimen.marketplace_image));

                lp.setMargins(5, 5, 5, 0);

                imageView.setLayoutParams(lp);

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                final String imagePath = objOutputImage.getString("image_path");
                networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading);

                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), ImageActivity.class);
                        intent.putExtra("image", imagePath);
                        intent.putExtra("title", marketPlace.getTitle());
                        startActivity(intent);
                    }
                });

                listImages.addView(imageView);

            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE);
        this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE);
    }

}

From source file:com.bt.heliniumstudentapp.UpdateClass.java

@Override
protected void onPostExecute(String html) {
    if (html != null) {
        try {//from   w ww. j  a va2s  .c o  m
            final JSONObject json = (JSONObject) new JSONTokener(html).nextValue();

            versionName = json.optString("version_name");
            final int versionCode = json.optInt("version_code");

            try {
                final int currentVersionCode = context.getPackageManager()
                        .getPackageInfo(context.getPackageName(), 0).versionCode;

                if (versionCode > currentVersionCode) {
                    if (!settings)
                        updateDialog.show();

                    updateDialog.setTitle(context.getString(R.string.update) + ' ' + versionName);

                    final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du);
                    contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor));
                    contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() {

                        @Override
                        public void handleTag(boolean opening, String tag, Editable output,
                                XMLReader xmlReader) {
                            if ("li".equals(tag))
                                if (opening)
                                    output.append(" \u2022 ");
                                else
                                    output.append("\n");
                        }
                    }));

                    updateDialog.setCanceledOnTouchOutside(true);

                    updateDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);

                    updateDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                            .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
                } else if (settings) {
                    updateDialog.setTitle(context.getString(R.string.update_no));

                    final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du);
                    contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor));
                    contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() {

                        @Override
                        public void handleTag(boolean opening, String tag, Editable output,
                                XMLReader xmlReader) {
                            if ("li".equals(tag))
                                if (opening)
                                    output.append(" \u2022 ");
                                else
                                    output.append("\n");
                        }
                    }));

                    updateDialog.setCanceledOnTouchOutside(true);
                }
            } catch (NameNotFoundException e) {
                Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();
            }
        } catch (JSONException e) {
            Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();
        }
    } else if (settings) {
        updateDialog.cancel();

        final AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(
                new ContextThemeWrapper(context, MainActivity.themeDialog));

        updateDialogBuilder.setTitle(context.getString(R.string.update));

        updateDialogBuilder.setMessage(R.string.error_update);

        updateDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                downloadAPK();
            }
        });

        updateDialogBuilder.setNegativeButton(android.R.string.no, null);

        final AlertDialog updateDialog = updateDialogBuilder.create();

        updateDialog.setCanceledOnTouchOutside(true);
        updateDialog.show();

        updateDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
        updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
    }
}