当前位置: 首页>>代码示例>>Java>>正文


Java SpannableString.length方法代码示例

本文整理汇总了Java中android.text.SpannableString.length方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableString.length方法的具体用法?Java SpannableString.length怎么用?Java SpannableString.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.SpannableString的用法示例。


在下文中一共展示了SpannableString.length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildActionTitle

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 *
 */
protected SpannableString buildActionTitle() {
    int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize);

    int mutIndex = 0;
    String format = "%s";
    if(isMute) {
        format = format + " #";
        mutIndex += 2;
    }

    SpannableString spannableString = new SpannableString(mTitleText);
    //EmoticonUtil.getTextFormat(mActionBarActivity, String.format(format, new Object[]{mTitleText}), dimensionPixelSize);
    if(isMute) {
        if(mMuteIcon == null) {
            mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon);
        }
        int length = spannableString.length() - mutIndex + 1;
        spannableString.setSpan(mMuteIcon, length, length + 1, SpannableStringBuilder.SPAN_POINT_MARK);
    }
    return spannableString;
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:25,代码来源:CCPActivityBase.java

示例2: contactToToken

import android.text.SpannableString; //导入方法依赖的package包/类
public static CharSequence contactToToken(Recipient c) {
  String name       = c.getName();
  String number     = c.getNumber();
  SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number));
  int len           = s.length();

  if (len == 0) {
    return s;
  }

  s.setSpan(new Annotation("number", c.getNumber()), 0, len,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return s;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:16,代码来源:RecipientsEditor.java

示例3: toToken

import android.text.SpannableString; //导入方法依赖的package包/类
public CharSequence toToken() {
    SpannableString s = new SpannableString(this.nameAndNumber);
    int len = s.length();

    if (len == 0) {
        return s;
    }

    if (person_id != -1) {
        s.setSpan(new Annotation("person_id",
                                 String.valueOf(person_id)),
                  0, len,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (name != null) {
        s.setSpan(new Annotation("name", name), 0, len,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (label != null) {
        s.setSpan(new Annotation("label", label.toString()), 0, len,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (number != null) {
        s.setSpan(new Annotation("number", number), 0, len,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    s.setSpan(new Annotation("bcc", String.valueOf(bcc)), 0, len,
              Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return s;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:32,代码来源:RecipientList.java

示例4: convertToString

import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public final CharSequence convertToString(Cursor cursor) {
    String name = cursor.getString(RecipientsAdapter.NAME_INDEX);
    int type = cursor.getInt(RecipientsAdapter.TYPE_INDEX);
    String number = cursor.getString(RecipientsAdapter.NUMBER_INDEX).trim();

    String label = cursor.getString(RecipientsAdapter.LABEL_INDEX);
    CharSequence displayLabel = Phones.getDisplayLabel(mContext, type, label);

    if (number.length() == 0) {
        return number;
    }

    SpannableString out = new SpannableString(RecipientList.Recipient.buildNameAndNumber(name, number));
    int len = out.length();

    if (!TextUtils.isEmpty(name)) {
        out.setSpan(new Annotation("name", name), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        out.setSpan(new Annotation("name", number), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    String person_id = cursor.getString(RecipientsAdapter.PERSON_ID_INDEX);
    out.setSpan(new Annotation("person_id", person_id), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    out.setSpan(new Annotation("number", number), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return out;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:35,代码来源:RecipientsAdapter.java

示例5: clickClickableSpan

import android.text.SpannableString; //导入方法依赖的package包/类
public static ViewAction clickClickableSpan(final CharSequence textToClick) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return instanceOf(TextView.class);
        }

        @Override
        public String getDescription() {
            return "clicking on a ClickableSpan";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView textView = (TextView) view;
            SpannableString spannableString = (SpannableString) textView.getText();

            if (spannableString.length() == 0) {
                // TextView is empty, nothing to do
                throw new NoMatchingViewException.Builder()
                        .includeViewHierarchy(true)
                        .withRootView(textView)
                        .build();
            }

            // Get the links inside the TextView and check if we find textToClick
            ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
            if (spans.length > 0) {
                ClickableSpan spanCandidate;
                for (ClickableSpan span : spans) {
                    spanCandidate = span;
                    int start = spannableString.getSpanStart(spanCandidate);
                    int end = spannableString.getSpanEnd(spanCandidate);
                    CharSequence sequence = spannableString.subSequence(start, end);
                    if (textToClick.toString().equals(sequence.toString())) {
                        span.onClick(textView);
                        return;
                    }
                }
            }

            // textToClick not found in TextView
            throw new NoMatchingViewException.Builder()
                    .includeViewHierarchy(true)
                    .withRootView(textView)
                    .build();

        }
    };
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:51,代码来源:EspressoTestUtils.java

示例6: convertToString

import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public final CharSequence convertToString(Cursor cursor) {
    String name = cursor.getString(RecipientsAdapter.NAME_INDEX);
    int type = cursor.getInt(RecipientsAdapter.TYPE_INDEX);
    String number = cursor.getString(RecipientsAdapter.NUMBER_INDEX).trim();

    String label = cursor.getString(RecipientsAdapter.LABEL_INDEX);
    CharSequence displayLabel = mContactAccessor.phoneTypeToString(mContext, type, label);

    if (number.length() == 0) {
        return number;
    }

    if (name == null) {
        name = "";
    } else {
        // Names with commas are the bane of the recipient editor's existence.
        // We've worked around them by using spans, but there are edge cases
        // where the spans get deleted. Furthermore, having commas in names
        // can be confusing to the user since commas are used as separators
        // between recipients. The best solution is to simply remove commas
        // from names.
        name = name.replace(", ", " ")
                   .replace(",", " ");  // Make sure we leave a space between parts of names.
    }

    String nameAndNumber = RecipientsFormatter.formatNameAndNumber(name, number);

    SpannableString out = new SpannableString(nameAndNumber);
    int len = out.length();

    if (!TextUtils.isEmpty(name)) {
        out.setSpan(new Annotation("name", name), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        out.setSpan(new Annotation("name", number), 0, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    String person_id = cursor.getString(RecipientsAdapter.CONTACT_ID_INDEX);
    out.setSpan(new Annotation("person_id", person_id), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    out.setSpan(new Annotation("label", displayLabel.toString()), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);              
    out.setSpan(new Annotation("number", number), 0, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return out;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:50,代码来源:RecipientsAdapter.java


注:本文中的android.text.SpannableString.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。