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:color.kidpaint.com.kidpaintcolor.dialog.TextToolDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new CustomAlertDialogBuilder(mContext);
    builder.setTitle(R.string.text_tool_dialog_title);
    final View view = inflater.inflate(R.layout.dialog_text_tool, null);

    mTextEditText = (EditText) view.findViewById(R.id.text_tool_dialog_input_text);
    mTextEditText.addTextChangedListener(new TextWatcher() {
        @Override/*  www . j  a  v a2s.  c  o m*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String text = mTextEditText.getText().toString();
            mOnTextToolDialogChangedListener.setText(text);
            mText = text;
        }
    });

    mFontSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_font);
    ArrayAdapter<CharSequence> fontAdapter = ArrayAdapter.createFromResource(mContext,
            R.array.text_tool_font_array, android.R.layout.simple_spinner_item);
    fontAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mFontSpinner.setAdapter(fontAdapter);

    mFontSpinner.setBackgroundColor(Color.GRAY);
    mFontSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String font = parent.getItemAtPosition(position).toString();
            mOnTextToolDialogChangedListener.setFont(font);
            mFontIndex = position;
            if (mFontSpinnerInitialized)
                hideKeyboard();
            else
                mFontSpinnerInitialized = true;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    mUnderlinedToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_underlined);
    mUnderlinedToggleButton.setTextOn(Html
            .fromHtml("<u>" + getResources().getString(R.string.text_tool_dialog_underline_shortcut) + "</u>"));
    mUnderlinedToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean underlined = mUnderlinedToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setUnderlined(underlined);
            mUnderlined = underlined;
            hideKeyboard();
        }
    });

    mItalicToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_italic);
    mItalicToggleButton.setTextOn(Html
            .fromHtml("<i>" + getResources().getString(R.string.text_tool_dialog_italic_shortcut) + "</i>"));
    mItalicToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean italic = mItalicToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setItalic(italic);
            mItalic = italic;
            hideKeyboard();
        }
    });

    mBoldToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_bold);
    mBoldToggleButton.setTextOn(
            Html.fromHtml("<b>" + getResources().getString(R.string.text_tool_dialog_bold_shortcut) + "</b>"));
    mBoldToggleButton.setOnClickListener(new ToggleButton.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean bold = mBoldToggleButton.isChecked();
            mOnTextToolDialogChangedListener.setBold(bold);
            mBold = bold;
            hideKeyboard();
        }
    });

    mTextSizeSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_text_size);
    ArrayAdapter<CharSequence> textSizeAdapter = ArrayAdapter.createFromResource(mContext,
            R.array.text_tool_size_array, android.R.layout.simple_spinner_item);
    textSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mTextSizeSpinner.setAdapter(textSizeAdapter);

    mTextSizeSpinner.setBackgroundColor(Color.GRAY);
    mTextSizeSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            int size = Integer.parseInt(parent.getItemAtPosition(position).toString());
            mOnTextToolDialogChangedListener.setTextSize(size);
            mTextSizeIndex = position;
            if (mTextSizeSpinnerInitialized)
                hideKeyboard();
            else
                mTextSizeSpinnerInitialized = true;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

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

    Dialog textDialog = builder.create();
    WindowManager.LayoutParams window_params = textDialog.getWindow().getAttributes();
    textDialog.getWindow().setDimAmount(0.0f);
    textDialog.getWindow().setAttributes(window_params);

    return textDialog;
}

From source file:org.thomnichols.android.gmarks.WebViewLoginActivity.java

protected void showTwoFactorAuthDialog() {
    dismissWaitDialog();/*from w ww  .  j a  va 2s  . c o m*/

    final Intent launchAuthIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .setClassName(AUTHENTICATOR_PACKAGE, "com.google.android.apps.authenticator.AuthenticatorActivity");

    ResolveInfo ri = getPackageManager().resolveActivity(launchAuthIntent, 0);
    if (ri == null) {
        WebViewLoginActivity.this.showAuthenticatorMissingDialog();
        return;
    }
    Log.d(TAG, "Resolve info: " + ri);

    new AlertDialog.Builder(this).setTitle(R.string.two_factor_auth_dlg_title)
            .setMessage(Html.fromHtml(getString(R.string.two_factor_auth_dlg_msg))).setCancelable(true)
            .setNegativeButton(R.string.btn_cancel, new OnClickListener() {
                public void onClick(DialogInterface dlg, int _) {
                    dlg.dismiss();
                }
            }).setPositiveButton(R.string.btn_ok, new OnClickListener() {
                public void onClick(DialogInterface dlg, int _) {
                    //               dlg.dismiss();
                    try {
                        startActivity(launchAuthIntent);
                    } catch (ActivityNotFoundException ex) {
                        Log.d(TAG, "Activity not found", ex);
                        WebViewLoginActivity.this.showAuthenticatorMissingDialog();
                    }
                    //               catch ( Exception ex ) {
                    //                  Log.w(TAG,"Unexpected exception from activity launch",ex);
                    //               }
                }
            }).show();
}

From source file:com.liato.bankdroid.banking.banks.ICA.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());
    }/*from   ww w.j  a v  a2s.  c  om*/
    urlopen = login();
    String response = null;
    Matcher matcher;
    try {
        response = urlopen.open("https://www.ica.se/Mina-sidor/Konto--Saldo/");
        matcher = reAccounts.matcher(response);
        if (matcher.find()) {
            Account account = new Account("ICA Kort", Helpers.parseBalance(matcher.group(1)), "1");
            balance = balance.add(Helpers.parseBalance(matcher.group(1)));
            matcher = reTransactions.matcher(response);
            ArrayList<Transaction> transactions = new ArrayList<Transaction>();
            while (matcher.find()) {
                transactions.add(new Transaction(matcher.group(1).trim(),
                        Html.fromHtml(matcher.group(2)).toString().trim(),
                        Helpers.parseBalance(matcher.group(3))));
            }
            account.setTransactions(transactions);
            accounts.add(account);
        }
        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:com.adamkruger.myipaddressinfo.IPAddressInfoFragment.java

private void updateViewState() {
    View view = getView();//from  w w w  .ja  va  2  s .  c  o m
    if (view != null) {
        ((TextView) view.findViewById(R.id.ipValue)).setText(mIPAddress);
        ((TextView) view.findViewById(R.id.ispValue)).setText(mISP);
        ((TextView) view.findViewById(R.id.countryValue)).setText(mCountry);
        ((TextView) view.findViewById(R.id.cityValue)).setText(mCity);
        ((TextView) view.findViewById(R.id.regionValue)).setText(mRegion);
        ((TextView) view.findViewById(R.id.coordinatesValue)).setText(mLatLong.length() == 0 ? ""
                : Html.fromHtml(
                        String.format("<a href=\"%s\">%s</a>", mapLink(mLatLong, mIPAddress), mLatLong)));

        if (mLastUpdateTime != null) {
            TextView lastUpdateStatus = (TextView) view.findViewById(R.id.lastUpdateStatus);
            if (mLastUpdateTimedOut) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_timeout),
                                mLastUpdateElapsedTimeMs / 1000));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            } else if (mLastUpdateSucceeded) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_success),
                                mLastUpdateElapsedTimeMs));
                if (mLastUpdateElapsedTimeMs < 2000) {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.success_color));
                } else {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.warning_color));
                }
            } else {
                lastUpdateStatus.setText(String.format(
                        getResources().getString(R.string.last_update_status_fail), mLastUpdateElapsedTimeMs));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            }

            TextView lastUpdateTime = (TextView) view.findViewById(R.id.lastUpdateTime);
            lastUpdateTime.setText(
                    String.format(getResources().getString(R.string.last_update_time), mLastUpdateTime));
            String currentTime = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
                    .format(new Date());
            if (currentTime.equals(mLastUpdateTime)) {
                lastUpdateTime.setTextColor(mDefaultLastUpdateTimeColor);
            } else {
                lastUpdateTime.setTextColor(getResources().getColor(R.color.warning_color));
            }
        }
    }
}

From source file:com.xorcode.andtweet.FriendTimeline.java

/**
 * Insert a row from a JSONObject./*from  w  w w  .  j a  v a2  s.c  o m*/
 * 
 * @param jo
 * @return
 * @throws JSONException
 * @throws SQLiteConstraintException
 */
public Uri insertFromJSONObject(JSONObject jo) throws JSONException, SQLiteConstraintException {
    ContentValues values = new ContentValues();

    // Construct the Uri to existing record
    Long lTweetId = Long.parseLong(jo.getString("id"));
    Uri aTweetUri = ContentUris.withAppendedId(mContentUri, lTweetId);

    String message = Html.fromHtml(jo.getString("text")).toString();

    try {
        // TODO: Unify databases!
        switch (mTimelineType) {
        case AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS:
        case AndTweetDatabase.Tweets.TIMELINE_TYPE_MENTIONS:
            JSONObject user;
            user = jo.getJSONObject("user");

            values.put(AndTweetDatabase.Tweets._ID, lTweetId.toString());
            values.put(AndTweetDatabase.Tweets.AUTHOR_ID, user.getString("screen_name"));

            values.put(AndTweetDatabase.Tweets.MESSAGE, message);
            values.put(AndTweetDatabase.Tweets.SOURCE, jo.getString("source"));
            values.put(AndTweetDatabase.Tweets.TWEET_TYPE, mTimelineType);
            values.put(AndTweetDatabase.Tweets.IN_REPLY_TO_STATUS_ID, jo.getString("in_reply_to_status_id"));
            values.put(AndTweetDatabase.Tweets.IN_REPLY_TO_AUTHOR_ID, jo.getString("in_reply_to_screen_name"));
            values.put(AndTweetDatabase.Tweets.FAVORITED, jo.getBoolean("favorited") ? 1 : 0);
            break;
        case AndTweetDatabase.Tweets.TIMELINE_TYPE_MESSAGES:
            values.put(AndTweetDatabase.DirectMessages._ID, lTweetId.toString());
            values.put(AndTweetDatabase.DirectMessages.AUTHOR_ID, jo.getString("sender_screen_name"));
            values.put(AndTweetDatabase.DirectMessages.MESSAGE, message);
            break;
        }

        Long created = Date.parse(jo.getString("created_at"));
        values.put(AndTweetDatabase.Tweets.SENT_DATE, created);
    } catch (Exception e) {
        Log.e(TAG, "insertFromJSONObject: " + e.toString());
    }

    if ((mContentResolver.update(aTweetUri, values, null, null)) == 0) {
        // There was no such row so add new one
        mContentResolver.insert(mContentUri, values);
        mNewTweets++;
        switch (mTimelineType) {
        case AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS:
        case AndTweetDatabase.Tweets.TIMELINE_TYPE_MENTIONS:
            if (mTu.getUsername().equals(jo.getString("in_reply_to_screen_name"))
                    || message.contains("@" + mTu.getUsername())) {
                mReplies++;
            }
        }
    }
    return aTweetUri;
}

From source file:com.liato.bankdroid.banking.banks.Avanza.java

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);

    String response = null;/*w w  w . j  av  a2  s.  c om*/
    Matcher matcher;
    try {
        response = urlopen.open("https://www.avanza.se/aza/depa/depa.jsp?depotnr=" + account.getId());
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        String strDate = null;
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        strDate = sdf.format(cal.getTime());

        while (matcher.find()) {
            transactions.add(new Transaction(strDate, Html.fromHtml(matcher.group(1)).toString().trim(),
                    Helpers.parseBalance(matcher.group(2))));
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.liato.bankdroid.banking.banks.Handelsbanken.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }//from  w  ww.ja v  a  2s .  co m

    urlopen = login();
    Matcher matcher;
    try {
        matcher = reAccountsUrl.matcher(response);
        if (!matcher.find()) {
            throw new BankException(res.getText(R.string.unable_to_find).toString() + " accounts url.");
        }
        String strAccountsUrl = "https://m.handelsbanken.se/primary/_-" + matcher.group(1);
        response = urlopen.open(strAccountsUrl);
        matcher = reBalance.matcher(response);
        Integer accountId = 0;
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3).trim()), accountId.toString()));
            balance = balance.add(Helpers.parseBalance(matcher.group(3)));
            accountIds.add(matcher.group(1));
            accountId += 1;
        }
        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:co.uk.alt236.restclient4android.fragments.FragmentNetworkResult.java

private void displayNetworkResult(NetworkResult data) {
    if (data != null) {
        mTvResponseCode.setText(String.valueOf(data.getResponseCode()));
        mTvUrl.setText(data.getUrl());/*w  ww.  j a va 2s.c  o m*/

        displayResultBody(data.getResponseBody());

        ArrayList<Pair<String, String>> headers = data.getResponseHeaders();
        StringBuffer sb = new StringBuffer();

        if (headers != null) {
            for (Pair<String, String> pair : headers) {
                sb.append("<b>");
                sb.append(pair.first);
                sb.append("</b>");
                sb.append(": ");
                sb.append(pair.second);
                sb.append("<br>");
            }
        }

        mTvResponseHeaders.setText(Html.fromHtml(sb.toString()));

    } else {
        Log.e(TAG, "^ displayNetworkResult() Result was null!");
    }
}

From source file:com.eyekabob.ArtistInfo.java

/**
 * This method is called after the last.fm response is received. It will
 * parse the XML document response and put attributes on the Artist object.
 *//*from ww  w . j  a  va2 s  .  c  o m*/
protected void handleArtistResponse(JSONObject response) {
    try {
        JSONObject jsonArtist = response.optJSONObject("artist");
        if (jsonArtist == null) {
            Toast.makeText(this, R.string.no_results, Toast.LENGTH_SHORT).show();
            artistInfoReturned = true;
            dismissDialogIfReady();
            return;
        }
        artist.setName(jsonArtist.getString("name"));
        artist.setMbid(jsonArtist.getString("mbid"));
        artist.setUrl(jsonArtist.getString("url"));
        JSONObject jsonImage = EyekabobHelper.LastFM.getLargestJSONImage(jsonArtist.getJSONArray("image"));

        // Get artist image, if one exists.
        if (null != jsonImage) {
            new ArtistImageTask().execute(new URL(jsonImage.getString("#text")));
        } else {
            imageInfoReturned = true;
            dismissDialogIfReady();
        }

        JSONObject bio = jsonArtist.getJSONObject("bio");
        artist.setSummary(bio.getString("summary"));
        artist.setContent(bio.getString("content"));
    } catch (JSONException e) {
        Log.e(getClass().getName(), "", e);
    } catch (MalformedURLException e) {
        Log.e(getClass().getName(), "", e);
    }

    TextView artistNameView = (TextView) findViewById(R.id.infoMainHeader);
    artistNameView.setText(artist.getName());

    if (!(artist.getSummary() == null) && !artist.getSummary().equals("")) {
        TextView bioHeaderView = (TextView) findViewById(R.id.infoBioHeader);
        // TODO: I18N
        bioHeaderView.setText("Bio");
        TextView bioView = (TextView) findViewById(R.id.infoBioContent);
        String contentHtml = artist.getSummary();
        bioView.setText(Html.fromHtml(contentHtml));
        bioView.setVisibility(View.VISIBLE);
    }
    if (!(artist.getContent() == null) && !artist.getContent().equals("")) {
        ToggleButton tb = (ToggleButton) findViewById(R.id.infoBioToggleButton);
        tb.setVisibility(View.VISIBLE);
    }

    artistInfoReturned = true;
    dismissDialogIfReady();
}

From source file:com.yairkukielka.feedhungry.ListViewEntryArrayAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;/*from  w w w. java  2  s. co  m*/
    boolean makeAnimation = false;
    if (v == null) {
        makeAnimation = true;
        int numColumns = getContext().getResources().getInteger(R.integer.num_columns);
        if (numColumns == 1) {
            if (cards) {
                // cards style
                v = layoutInflater.inflate(R.layout.grid_item_layout, null);
            } else {
                v = layoutInflater.inflate(R.layout.list_item_layout, null);
            }
        } else {
            if (cards) {
                // width > 500dp
                v = layoutInflater.inflate(R.layout.grid_item_layout, null);
            } else {
                v = layoutInflater.inflate(R.layout.list_item_layout, null);
            }
        }
    }

    ViewHolder holder = (ViewHolder) v.getTag(R.id.id_holder);

    if (holder == null) {
        holder = new ViewHolder(v);
        holder.image.setDefaultImageResId(R.drawable.placeholder);
        v.setTag(R.id.id_holder, holder);
    }

    ListEntry entry = getItem(position);
    if (entry.getVisual() != null) {
        // there is an image
        holder.image.setImageUrl(entry.getVisual(), mImageLoader);
    } else {
        // no image found
        //         holder.image.setImageResource(R.drawable.black_pixel);
        holder.image.setImageDrawable(null);
    }

    String summary = getSummaryWithoutHTML(entry.getContent());
    // Spanned summary = Html.fromHtml(entry.getContent());
    // SpannableStringBuilder spanstr = new
    // SpannableStringBuilder(entry.getTitle());
    // spanstr.setSpan(new StyleSpan(Typeface.BOLD),0,
    // entry.getTitle().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // spanstr.append(". ");
    // spanstr.append(summary);
    // holder.title.setText(spanstr);

    if (entry.isPopular()) {
        holder.popular.setVisibility(View.VISIBLE);
    } else {
        holder.popular.setVisibility(View.INVISIBLE);
    }

    holder.title.setText(Html.fromHtml(entry.getTitle()));
    if (EMPTY_STRING.equals(summary)) {
        holder.summary.setVisibility(View.GONE);
    } else {
        holder.summary.setText(summary);
    }
    holder.date.setText(DateUtils.dateToString(entry.getPublished()));

    holder.checkRead.setOnCheckedChangeListener(null);
    if (!entry.isUnread()) {
        holder.checkRead.setChecked(true);
    } else {
        holder.checkRead.setChecked(false);
    }
    holder.checkRead.setOnCheckedChangeListener(new MyCheckReadListener(entry));
    holder.streamName.setText(entry.getOriginTitle());

    holder.saved.setOnClickListener(null);
    if (entry.isSaved()) {
        holder.saved.setImageResource(R.drawable.star_on);
        holder.saved.setTag(R.drawable.star_on);
    } else {
        holder.saved.setImageResource(R.drawable.star_off);
        holder.saved.setTag(R.drawable.star_off);
    }
    holder.saved.setOnClickListener(new MySaveListener(entry));
    if (v != null && makeAnimation) {
        animation.setDuration(400);
        v.startAnimation(animation);
    }
    return v;
}