Example usage for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

Introduction

In this page you can find the example usage for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.

Prototype

int SPAN_EXCLUSIVE_EXCLUSIVE

To view the source code for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.

Click Source Link

Document

Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point.

Usage

From source file:org.sirimangalo.meditationplus.AdapterCommit.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View rowView = inflater.inflate(R.layout.list_item_commit, parent, false);

    final View shell = rowView.findViewById(R.id.detail_shell);

    rowView.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w ww  .j  a  v a  2 s . c  om*/
        public void onClick(View view) {
            boolean visible = shell.getVisibility() == View.VISIBLE;

            shell.setVisibility(visible ? View.GONE : View.VISIBLE);

            context.setCommitVisible(position, !visible);

        }
    });

    final JSONObject p = values.get(position);

    TextView title = (TextView) rowView.findViewById(R.id.title);
    TextView descV = (TextView) rowView.findViewById(R.id.desc);
    TextView defV = (TextView) rowView.findViewById(R.id.def);
    TextView usersV = (TextView) rowView.findViewById(R.id.users);
    TextView youV = (TextView) rowView.findViewById(R.id.you);

    try {

        if (p.getBoolean("open"))
            shell.setVisibility(View.VISIBLE);

        title.setText(p.getString("title"));
        descV.setText(p.getString("description"));

        String length = p.getString("length");
        String time = p.getString("time");
        final String cid = p.getString("cid");

        String def = "";

        boolean repeat = false;

        if (length.indexOf(":") > 0) {
            repeat = true;
            String[] lengtha = length.split(":");
            def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting";
        } else
            def += length + " minutes total meditation";

        String period = p.getString("period");

        String day = p.getString("day");

        if (period.equals("daily")) {
            if (repeat)
                def += " every day";
            else
                def += " per day";
        } else if (period.equals("weekly")) {
            if (repeat)
                def += " every " + dow[Integer.parseInt(day)];
            else
                def += " per week";
        } else if (period.equals("monthly")) {
            if (repeat)
                def += " on the " + day
                        + (day.substring(day.length() - 1).equals("1") ? "st"
                                : (day.substring(day.length() - 1).equals("2") ? "nd"
                                        : (day.substring(day.length() - 1).equals("3") ? "rd" : "th")))
                        + " day of the month";
            else
                def += " per month";
        } else if (period.equals("yearly")) {
            if (repeat)
                def += " on the " + day
                        + (day.substring(day.length() - 1).equals("1") ? "st"
                                : (day.substring(day.length() - 1).equals("2") ? "nd"
                                        : (day.substring(day.length() - 1).equals("3") ? "rd" : "th")))
                        + " day of the year";
            else
                def += " per year";
        }

        if (!time.equals("any")) {
            Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0]));
            utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1]));

            Calendar here = Calendar.getInstance();
            here.setTimeInMillis(utc.getTimeInMillis());

            int hours = here.get(Calendar.HOUR_OF_DAY);
            int minutes = here.get(Calendar.MINUTE);

            def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>("
                    + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " "
                    + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>";
        }

        defV.setText(Html.fromHtml(def));

        JSONObject usersJ = p.getJSONObject("users");

        ArrayList<String> committedArray = new ArrayList<String>();

        // collect into array

        for (int i = 0; i < usersJ.names().length(); i++) {
            try {
                String j = usersJ.names().getString(i);
                String k = j;
                //                    if(j.equals(p.getString("creator")))
                //                        k = "["+j+"]";
                committedArray.add(k);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        String text = context.getString(R.string.committed) + " ";

        // add spans

        int committed = -1;

        int pos = text.length(); // start after "Committed: "

        text += TextUtils.join(", ", committedArray);
        Spannable span = new SpannableString(text);

        span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: "

        for (int i = 0; i < committedArray.size(); i++) {
            try {

                final String oneCom = committedArray.get(i);
                String userCom = usersJ.getString(oneCom);
                //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", ""));

                //if(oneCom.replace("[","").replace("]","").equals(loggedUser))
                if (oneCom.equals(loggedUser))
                    committed = Integer.parseInt(userCom);

                int end = pos + oneCom.length();

                ClickableSpan clickable = new ClickableSpan() {

                    @Override
                    public void onClick(View widget) {
                        context.showProfile(oneCom);
                    }

                };
                span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                span.setSpan(new UnderlineSpan() {
                    public void updateDrawState(TextPaint tp) {
                        tp.setUnderlineText(false);
                    }
                }, pos, end, 0);

                String color = Utils.makeRedGreen(Integer.parseInt(userCom), true);

                span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                pos += oneCom.length() + 2;

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        usersV.setText(span);
        usersV.setMovementMethod(new LinkMovementMethod());

        if (loggedUser != null && loggedUser.length() > 0) {
            LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons);
            if (!usersJ.has(loggedUser)) {
                Button commitB = new Button(context);
                commitB.setId(R.id.commit_button);
                commitB.setText(R.string.commit);
                commitB.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                        nvp.add(new BasicNameValuePair("full_update", "true"));

                        context.doSubmit("commitform_" + cid, nvp, true);
                    }
                });
                bl.addView(commitB);
            } else {
                Button commitB = new Button(context);
                commitB.setId(R.id.uncommit_button);
                commitB.setText(R.string.uncommit);
                commitB.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                        nvp.add(new BasicNameValuePair("full_update", "true"));

                        context.doSubmit("uncommitform_" + cid, nvp, true);
                    }
                });
                bl.addView(commitB);
            }

            if (loggedUser.equals(p.getString("creator")) || context.isAdmin) {
                Button commitB2 = new Button(context);
                commitB2.setId(R.id.edit_commit_button);
                commitB2.setText(R.string.edit);
                commitB2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent i = new Intent(context, ActivityCommit.class);
                        i.putExtra("commitment", p.toString());
                        context.startActivity(i);
                    }
                });
                bl.addView(commitB2);

                Button commitB3 = new Button(context);
                commitB3.setId(R.id.uncommit_button);
                commitB3.setText(R.string.delete);
                commitB3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                        nvp.add(new BasicNameValuePair("full_update", "true"));

                        context.doSubmit("delcommitform_" + cid, nvp, true);
                    }
                });
                bl.addView(commitB3);
            }

        }

        if (committed > -1) {
            int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false));
            rowView.setBackgroundColor(color);
        }

        if (committed != -1) {
            youV.setText(String.format(context.getString(R.string.you_commit_x), committed));
            youV.setVisibility(View.VISIBLE);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return rowView;
}

From source file:com.ideascontest.navi.uask.MainQuestionAnswerAdapter.java

/**
 * OnBindViewHolder is called by the RecyclerView to display the data at the specified
 * position. In this method, we update the contents of the ViewHolder to display the correct
 * indices in the list for this particular position, using the "position" argument that is conveniently
 * passed into us./*ww  w  .j av  a 2s .  c  o m*/
 *
 * @param holder   The ViewHolder which should be updated to represent the contents of the
 *                 item at the given position in the data set.
 * @param position The position of the item within the adapter's data set.
 */
@Override
public void onBindViewHolder(QuestionTopAnswerHolder holder, int position) {

    Log.d(TAG, "#" + position);
    QuestionTopAnswerHolder questionTopAnswerHolder = (QuestionTopAnswerHolder) holder;
    final Context context = questionTopAnswerHolder.v.getContext();
    Log.d(TAG, "Category" + _category);
    switch (_category) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4: {
        if (position == 0) {
            /*  String infoText = (String) questionTopAnswerHolder.basicInfoText.getText();
              int count = infoText.split("\n").length;
              int upperLimit = (count > 5) ? MainAnswerAdapter.ordinalIndexOf(infoText, "\n", 5) : 140;
              if (infoText.length() > 140 || count > 5) {
                  infoText = infoText.substring(0, upperLimit) + "... " + "view more";
                    
                  SpannableString sText = new SpannableString(infoText);
                  ClickableSpan myClickableSpan = new ClickableSpan() {
                      @Override
                      public void onClick(View v) {
                          Log.d("MainCanvas Category", "clickable Span");
                          //finish();
                      }
                  };
                  int spanLowLimit = upperLimit + 4;
                  int spanHighLimit = upperLimit + 13;
                  sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                  sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0);
                  sText.setSpan(new ForegroundColorSpan( questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)), spanLowLimit, spanHighLimit, 0);
                  questionTopAnswerHolder.basicInfoText.setText(sText);
                  questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance());
              }*/
            String infoText = (String) questionTopAnswerHolder.basicInfoText.getText();
            int upperLimit = 150;
            if (infoText.length() > 150) {
                infoText = infoText.substring(0, upperLimit) + "... " + "view more";

                SpannableString sText = new SpannableString(infoText);
                ClickableSpan myClickableSpan = new ClickableSpan() {
                    @Override
                    public void onClick(View v) {
                        Log.d("Mainadapter Category", "clickable Span");
                        Intent intent = new Intent(context, ShowBasicInfo.class);
                        intent.putExtra("category", _category);
                        context.startActivity(intent);//finish();
                    }
                };
                int spanLowLimit = upperLimit + 4;
                int spanHighLimit = upperLimit + 13;
                sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0);
                sText.setSpan(
                        new ForegroundColorSpan(
                                questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)),
                        spanLowLimit, spanHighLimit, 0);
                questionTopAnswerHolder.basicInfoText.setText(sText);
                questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance());
            }

        } else {
            populateDynamicUiElements(questionTopAnswerHolder, (position - 1));
        }
    }
        break;
    case 5: {
        if (position == 0) {

            questionTopAnswerHolder.basicInfoText.setText("List of all non-categorical questions");
            questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM);
            questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE);
        } else {
            populateDynamicUiElements(questionTopAnswerHolder, (position - 1));
        }
    }
        break;
    case 6: {
        if (position == 0) {
            questionTopAnswerHolder.basicInfoText.setText("List of all questions asked by you.");
            questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM);
            questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE);
        } else {
            populateDynamicUiElements(questionTopAnswerHolder, (position - 1));
        }
    }
        break;
    case 7: {
        if (position == 0) {

            questionTopAnswerHolder.basicInfoText.setText("List of all questions answered by you.");
            questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM);
            questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE);
        } else {
            populateDynamicUiElements(questionTopAnswerHolder, (position - 1));
        }
    }
        break;
    case 8: {
        if (position == 0) {

            questionTopAnswerHolder.basicInfoText.setText(
                    "All the private questions asked by your faculty students. Visible only to fellow faculty students");
            questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM);
            questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE);
        } else {
            populateDynamicUiElements(questionTopAnswerHolder, (position - 1));
        }
    }
        break;
    default: {
        populateDynamicUiElements(questionTopAnswerHolder, position);
    }
        break;

    }

}

From source file:com.hannesdorfmann.home.HomeActivity.java

private void setNoFiltersVisiblity(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('\u08B4');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE),
                    filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)),
                    altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {
                @Override//from w ww .  j a  va  2  s .  co  m
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}

From source file:com.android.mail.browse.SendersView.java

private static void appendMessageInfo(SpannableStringBuilder sb, CharSequence text, Object span,
        boolean appendSplitToken, boolean convRead) {
    int startIndex = sb.length();
    if (appendSplitToken) {
        sb.append(sSendersSplitToken);//  w  ww .  j a va2 s . co  m
        sb.setSpan(CharacterStyle.wrap(convRead ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan),
                startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    startIndex = sb.length();
    sb.append(text);
    sb.setSpan(span, startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:com.ruesga.rview.misc.Formatter.java

@BindingAdapter("userMessage")
public static void toUserMessage(TextView view, String msg) {
    if (msg == null) {
        view.setText(null);//  w w w.jav  a  2s .co  m
        return;
    }

    String message = EmojiHelper.createEmoji(msg);

    // This process mimics the Gerrit formatting process done in class
    // ./gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java

    // Split message into paragraphs
    String[] paragraphs = StringHelper.obtainParagraphs(message);
    StringBuilder sb = new StringBuilder();
    boolean formattedMessage = false;
    for (String p : paragraphs) {
        if (StringHelper.isQuote(p)) {
            sb.append(StringHelper.obtainQuote(StringHelper.removeLineBreaks(p)));
            formattedMessage = true;
        } else if (StringHelper.isList(p)) {
            sb.append(p);
            formattedMessage = true;
        } else if (StringHelper.isPreFormat(p)) {
            sb.append(StringHelper.obtainPreFormatMessage(p));
            formattedMessage = true;
        } else {
            sb.append(p);
        }
        sb.append("\n\n");
    }

    String userMessage = StringHelper.removeExtraLines(sb.toString());
    if (!formattedMessage) {
        view.setText(userMessage);
        return;
    }

    if (sQuoteColor == -1) {
        sQuoteColor = ContextCompat.getColor(view.getContext(), R.color.quote);
        sQuoteWidth = (int) view.getContext().getResources().getDimension(R.dimen.quote_width);
        sQuoteMargin = (int) view.getContext().getResources().getDimension(R.dimen.quote_margin);
    }

    String[] lines = userMessage.split("\n");
    SpannableStringBuilder spannable = new SpannableStringBuilder(userMessage
            .replaceAll(StringHelper.NON_PRINTABLE_CHAR, "").replaceAll(StringHelper.NON_PRINTABLE_CHAR2, ""));

    // Pre-Format
    int start = 0;
    int spans = 0;
    while ((start = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start)) != -1) {
        int end = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start + 1);
        if (end == -1) {
            //? This is supposed to be formatted by us. Skip it
            break;
        }

        // Find quote token occurrences
        int offset = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, userMessage, 0, start);
        start -= offset;
        end -= offset;

        // Ensure bounds
        int spanStart = start - spans;
        int spanEnd = Math.min(end - spans - 1, spannable.length());
        if (spanStart < 0 || spanEnd < 0) {
            //Something was wrong. Skip it
            break;
        }
        spannable.setSpan(new RelativeSizeSpan(0.8f), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannable.setSpan(new TypefaceSpan("monospace"), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        start = end;
        spans++;
    }

    start = 0;
    for (String line : lines) {
        // Quotes
        int maxIndent = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, line);
        for (int i = 0; i < maxIndent; i++) {
            QuotedSpan span = new QuotedSpan(sQuoteColor, sQuoteWidth, sQuoteMargin);
            spannable.setSpan(span, start, Math.min(start + line.length() - maxIndent, spannable.length()),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        // List
        if (StringHelper.isList(line)) {
            spannable.replace(start, start + 1, "\u2022");
            spannable.setSpan(new LeadingMarginSpan.Standard(sQuoteMargin), start,
                    Math.min(start + line.length(), spannable.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        start += line.length() - maxIndent + 1;
    }

    view.setText(spannable);
}

From source file:fr.tvbarthel.apps.sayitfromthesky.activities.MainActivity.java

/**
 * Set the alpha of the action bar title.
 *
 * @param alpha a value between 0 and 1 that represents the alpha of the action bar title.
 *//* w w w.j a  v  a 2s.  com*/
private void setActionBarTitleAlpha(float alpha) {
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        mActionBarTitleColorSpan.setAlpha(alpha);
        mActionBarTitleSpannable.setSpan(mActionBarTitleColorSpan, 0, mActionBarTitleSpannable.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        actionBar.setTitle(mActionBarTitleSpannable);
    }

}

From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(GooglyPetEntry petSelected) {
    final int googlyName = petSelected.getName();
    mSelectedGooglyPet = petSelected.getPetId();

    final String petName = getResources().getString(googlyName);
    final String oogly = getResources().getString(R.string.googly_name_ext);
    mTitle = new SpannableString(getResources().getString(googlyName) + oogly);
    mTitle.setSpan(new StyleSpan(Typeface.BOLD), 0, petName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mTitle.setSpan(new TypefaceSpan("sans-serif-light"), petName.length() - 1, mTitle.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mActionBarIcon = petSelected.getBlackAndWhiteIcon();

    if (mPetTrackerFragment != null) {
        mPetTrackerFragment.setGooglyPet(mSelectedGooglyPet);
    }//w ww.ja v  a  2s  .  c  om
}

From source file:com.juick.android.TagsFragment.java

private void reloadTags(final View view) {
    final View selectedContainer = myView.findViewById(R.id.selected_container);
    final View progressAll = myView.findViewById(R.id.progress_all);
    Thread thr = new Thread(new Runnable() {

        public void run() {
            Bundle args = getArguments();
            MicroBlog microBlog;//w  ww  . ja  va 2s.  c om
            JSONArray json = null;
            final int tagsUID = showMine ? uid : 0;
            if (PointMessageID.CODE.equals(args.getString("microblog"))) {
                microBlog = MainActivity.microBlogs.get(PointMessageID.CODE);
                json = ((PointMicroBlog) microBlog).getUserTags(view, uidS);
            } else {
                microBlog = MainActivity.microBlogs.get(JuickMessageID.CODE);
                json = ((JuickMicroBlog) microBlog).getUserTags(view, tagsUID);
            }
            if (isAdded()) {
                final SpannableStringBuilder tagsSSB = new SpannableStringBuilder();
                if (json != null) {
                    try {
                        int cnt = json.length();
                        ArrayList<TagSort> sortables = new ArrayList<TagSort>();
                        for (int i = 0; i < cnt; i++) {
                            final String tagg = json.getJSONObject(i).getString("tag");
                            final int messages = json.getJSONObject(i).getInt("messages");
                            sortables.add(new TagSort(tagg, messages));
                        }
                        Collections.sort(sortables);
                        HashMap<String, Double> scales = new HashMap<String, Double>();
                        for (int sz = 0, sortablesSize = sortables.size(); sz < sortablesSize; sz++) {
                            TagSort sortable = sortables.get(sz);
                            if (sz < 10) {
                                scales.put(sortable.tag, 2.0);
                            } else if (sz < 20) {
                                scales.put(sortable.tag, 1.5);
                            }
                        }
                        int start = 0;
                        if (microBlog instanceof JuickMicroBlog
                                && getArguments().containsKey("add_system_tags")) {
                            start = -4;
                        }
                        for (int i = start; i < cnt; i++) {
                            final String tagg;
                            switch (i) {
                            case -4:
                                tagg = "public";
                                break;
                            case -3:
                                tagg = "friends";
                                break;
                            case -2:
                                tagg = "notwitter";
                                break;
                            case -1:
                                tagg = "readonly";
                                break;
                            default:
                                tagg = json.getJSONObject(i).getString("tag");
                                break;

                            }
                            int index = tagsSSB.length();
                            tagsSSB.append("*" + tagg);
                            tagsSSB.setSpan(new URLSpan(tagg) {
                                @Override
                                public void onClick(View widget) {
                                    onTagClick(tagg, tagsUID);
                                }
                            }, index, tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            Double scale = scales.get(tagg);
                            if (scale != null) {
                                tagsSSB.setSpan(new RelativeSizeSpan((float) scale.doubleValue()), index,
                                        tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                            tagOffsets.put(tagg, new TagOffsets(index, tagsSSB.length()));
                            tagsSSB.append(" ");

                        }
                    } catch (Exception ex) {
                        tagsSSB.append("Error: " + ex.toString());
                    }
                }
                if (getActivity() != null) {
                    // maybe already closed?
                    getActivity().runOnUiThread(new Runnable() {

                        public void run() {
                            TextView tv = (TextView) myView.findViewById(R.id.tags);
                            progressAll.setVisibility(View.GONE);
                            if (multi)
                                selectedContainer.setVisibility(View.VISIBLE);
                            tv.setText(tagsSSB, TextView.BufferType.SPANNABLE);
                            tv.setMovementMethod(LinkMovementMethod.getInstance());
                            MainActivity.restyleChildrenOrWidget(view);
                            final TextView selected = (TextView) myView.findViewById(R.id.selected);
                            selected.setVisibility(View.VISIBLE);
                        }
                    });
                }
            }
        }
    });
    thr.start();
}

From source file:piuk.blockchain.android.util.WalletUtils.java

public static Editable formatAddress(final String address, final int groupSize, final int lineSize) {
    final SpannableStringBuilder builder = new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);//from ww w. j  a  v  a 2  s . co m
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = end % lineSize == 0;
            builder.append(endOfLine ? "\n" : Constants.THIN_SPACE);
        }
    }

    return builder;
}

From source file:org.bobstuff.bobball.ActivityStateEnum.java

private void updateStatus(final GameState currGameState) {

    SpannableStringBuilder timeLeftStr = SpannableStringBuilder
            .valueOf(getString(R.string.timeLeftLabel, gameManager.timeLeft() / 10));

    SpannableStringBuilder livesStr = formatPerPlayer(getString(R.string.livesLabel), new playstat() {
        @Override/*  www. j  a va 2  s  . c  o  m*/
        public int call(Player p) {
            return p.getLives();
        }
    });
    SpannableStringBuilder scoreStr = formatPerPlayer(getString(R.string.scoreLabel), new playstat() {
        @Override
        public int call(Player p) {
            return p.getScore();
        }
    });

    SpannableStringBuilder clearedStr = formatPerPlayer(getString(R.string.areaClearedLabel), new playstat() {
        @Override
        public int call(Player p) {
            Grid grid = currGameState.getGrid();
            if (grid != null)
                return currGameState.getGrid().getPercentComplete(p.getPlayerId());
            else
                return 0;
        }
    });

    //display fps
    if (secretHandshake >= 3) {

        float fps = displayLoop.getFPS();
        int color = (fps < NUMBER_OF_FRAMES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN);
        SpannableString s = new SpannableString(String.format(" FPS: %2.1f", fps));

        s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        timeLeftStr.append(s);

        color = (gameManager.getUPS() < gameManager.NUMBER_OF_UPDATES_PER_SECOND * 0.98f ? Color.RED
                : Color.GREEN);
        s = new SpannableString(String.format(" UPS: %3.1f", gameManager.getUPS()));

        s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        timeLeftStr.append(s);
    }

    statusTopleft.setText(timeLeftStr);
    statusTopright.setText(livesStr);
    statusBotleft.setText(scoreStr);
    statusBotright.setText(clearedStr);
}