當前位置: 首頁>>代碼示例>>Java>>正文


Java Spanned類代碼示例

本文整理匯總了Java中android.text.Spanned的典型用法代碼示例。如果您正苦於以下問題:Java Spanned類的具體用法?Java Spanned怎麽用?Java Spanned使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Spanned類屬於android.text包,在下文中一共展示了Spanned類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setEditable

import android.text.Spanned; //導入依賴的package包/類
/**
 * Input frame character length limit
 *
 * @param mEdit     EditText
 * @param maxLength maxLength
 */
public void setEditable(EditText mEdit, int maxLength) {
    if (mEdit.getText().length() < maxLength) {
        mEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength) {
        }});
        mEdit.setCursorVisible(true);
        mEdit.setFocusableInTouchMode(true);
        mEdit.requestFocus();
    } else {
        mEdit.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
            }
        }});
        mEdit.setCursorVisible(false);
        mEdit.setFocusableInTouchMode(false);
        mEdit.clearFocus();
    }
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:26,代碼來源:StringUtils.java

示例2: initMarqueeView3

import android.text.Spanned; //導入依賴的package包/類
private void initMarqueeView3() {
    SimpleMF<Spanned> marqueeFactory3 = new SimpleMF<>(MainActivity.this);
    List<Spanned> datas3 = new ArrayList<>();
    datas3.add(Html.fromHtml("<font color=\"#ff0000\">《賦得古原草送別》</font>"));
    datas3.add(Html.fromHtml("<font color=\"#00ff00\">離離原上草,</font>一歲一枯榮。"));
    datas3.add(Html.fromHtml("野火燒不盡,<font color=\"#0000ff\">春風吹又生。</font>"));
    datas3.add(Html.fromHtml("<font color=\"#333333\">遠芳侵古道,晴翠接荒城。</font>"));
    datas3.add(Html.fromHtml("<font color=\"#ffffff\">又送王孫去,萋萋滿別情。</font>"));
    marqueeFactory3.setData(datas3);
    marqueeView3.setMarqueeFactory(marqueeFactory3);
    marqueeView3.startFlipping();
    marqueeFactory3.setOnItemClickListener(new MarqueeFactory.OnItemClickListener<TextView, Spanned>() {
        @Override
        public void onItemClickListener(MarqueeFactory.ViewHolder<TextView, Spanned> holder) {
            Toast.makeText(MainActivity.this, holder.data, Toast.LENGTH_SHORT).show();
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:MainActivity.java

示例3: drawLeadingMargin

import android.text.Spanned; //導入依賴的package包/類
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
                              int top, int baseline, int bottom,
                              CharSequence text, int start, int end,
                              boolean first, Layout layout) {
    int st = ((Spanned) text).getSpanStart(this);
    int itop = layout.getLineTop(layout.getLineForOffset(st));

    if (dir < 0)
        x -= mBitmap.getWidth();

    int delta = totalHeight - mBitmap.getHeight();

    if (delta > 0) {
        if (mVerticalAlignment == ALIGN_TOP) {
            c.drawBitmap(mBitmap, x, itop, p);
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            c.drawBitmap(mBitmap, x, itop + delta / 2, p);
        } else {
            c.drawBitmap(mBitmap, x, itop + delta, p);
        }
    } else {
        c.drawBitmap(mBitmap, x, itop, p);
    }
}
 
開發者ID:pan2yong22,項目名稱:AndroidUtilCode-master,代碼行數:25,代碼來源:SpanUtils.java

示例4: prepareMainMessageString

import android.text.Spanned; //導入依賴的package包/類
/**
 * Prepares text to be displayed as the infobar's main message, including setting up a
 * clickable link if the infobar requires it.
 */
private CharSequence prepareMainMessageString() {
    SpannableStringBuilder fullString = new SpannableStringBuilder();

    if (mMessageMainText != null) fullString.append(mMessageMainText);

    // Concatenate the text to display for the link and make it clickable.
    if (!TextUtils.isEmpty(mMessageLinkText)) {
        if (fullString.length() > 0) fullString.append(" ");
        int spanStart = fullString.length();

        fullString.append(mMessageLinkText);
        fullString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View view) {
                mInfoBarView.onLinkClicked();
            }
        }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return fullString;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:26,代碼來源:InfoBarLayout.java

示例5: testTextDecorationLineLineThroughApplied

import android.text.Spanned; //導入依賴的package包/類
@Test
public void testTextDecorationLineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan[] underlineSpans =
      text.getSpans(0, text.length(), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan(textView, StrikethroughSpan.class);
  assertThat(underlineSpans).hasSize(0);
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:19,代碼來源:ReactTextTest.java

示例6: createMastodonApi

import android.text.Spanned; //導入依賴的package包/類
protected void createMastodonApi() {
    mastodonApiDispatcher = new Dispatcher();

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Spanned.class, new SpannedTypeAdapter())
            .create();

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    OkHttpClient.Builder okBuilder =
            OkHttpUtils.getCompatibleClientBuilder(preferences)
                    .addInterceptor(new AuthInterceptor(this))
                    .dispatcher(mastodonApiDispatcher);

    if (BuildConfig.DEBUG) {
        okBuilder.addInterceptor(
                new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC));
    }

    Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl())
            .client(okBuilder.build())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();

    mastodonApi = retrofit.create(MastodonApi.class);
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:27,代碼來源:BaseActivity.java

示例7: setText

import android.text.Spanned; //導入依賴的package包/類
public void setText(String text) {
    int startIndex = 0;
    while (true) {

        int start = text.indexOf("《");
        int end = text.indexOf("》");
        if (start < 0 || end < 0) {
            append(text.substring(startIndex));
            break;
        }

        append(text.substring(startIndex, start));

        SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1));
        spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        append(spanableInfo);
        //setMovementMethod()該方法必須調用,否則點擊事件不響應
        setMovementMethod(LinkMovementMethod.getInstance());
        text = text.substring(end + 1);

        LogUtils.e(spanableInfo.toString());
    }
}
 
開發者ID:zwmlibs,項目名稱:BookReader-master,代碼行數:24,代碼來源:BookContentTextView.java

示例8: readNode

import android.text.Spanned; //導入依賴的package包/類
private void readNode(Object node, Table table) {
    if (node instanceof TagNode) {
        TagNode tagNode = (TagNode) node;
        if (tagNode.getName().equals("td") || tagNode.getName().equals("th")) {
            Spanned result = this.getSpanner().fromTagNode(tagNode);
            table.addCell(result);
            return;
        }
        if (tagNode.getName().equals("tr")) {
            table.addRow();
        }
        for (Object child : tagNode.getChildTags()) {
            readNode(child, table);
        }
    }

}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:18,代碼來源:TableHandler.java

示例9: applyLink

import android.text.Spanned; //導入依賴的package包/類
private static final void applyLink(String url, int start, int end, Spannable text, final ColorStateList linkColor, final ColorStateList bgColor, QMUIOnSpanClickListener l) {
    text.setSpan(new StyleableURLSpan(url, l) {

        @Override
        public void updateDrawState(TextPaint ds) {
            if (linkColor != null) {
                int normalLinkColor = linkColor.getColorForState(new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed}, Color.TRANSPARENT);
                int pressedLinkColor = linkColor.getColorForState(new int[]{android.R.attr.state_pressed}, normalLinkColor);
                ds.linkColor = mPressed ? pressedLinkColor : normalLinkColor;
            }
            if (bgColor != null) {
                int normalBgColor = bgColor.getColorForState(new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed}, Color.TRANSPARENT);
                int pressedBgColor = bgColor.getColorForState(new int[]{android.R.attr.state_pressed}, normalBgColor);
                ds.bgColor = mPressed ? pressedBgColor : normalBgColor;
            }
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }

    }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:22,代碼來源:QMUILinkify.java

示例10: matchMention

import android.text.Spanned; //導入依賴的package包/類
public static Spannable matchMention(Spannable spannable) {
    String text = spannable.toString();

    Pattern pattern = Pattern.compile(MATCH_MENTION);
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start();
        int matcherEnd = matcher.end();
        spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        log("matchMention:" + str + " " + matcherStart + " " + matcherEnd);
    }

    return spannable;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:17,代碼來源:RichEditText.java

示例11: filter

import android.text.Spanned; //導入依賴的package包/類
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
	if (end - start == 1) {
		char c = source.charAt(0);
		if (c == '.' || c == ',') {
			onDotOrComma();
			return "";
		}
              if (isIncomeExpenseEnabled()) {
                  if (c == '-') {
                      setExpense();
                      return "";
                  }
                  if (c == '+') {
                      setIncome();
                      return "";
                  }
              }
	}
	return super.filter(source, start, end, dest, dstart, dend);
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:22,代碼來源:AmountInput.java

示例12: onUploadSuccess

import android.text.Spanned; //導入依賴的package包/類
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
    item.id = media.id;
    item.preview.setProgress(-1);
    item.readyStage = QueuedMedia.ReadyStage.UPLOADED;

    /* Add the upload URL to the text field. Also, keep a reference to the span so if the user
     * chooses to remove the media, the URL is also automatically removed. */
    item.uploadUrl = new URLSpan(media.textUrl);
    int end = 1 + media.textUrl.length();
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(' ');
    builder.append(media.textUrl);
    builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    int cursorStart = textEditor.getSelectionStart();
    int cursorEnd = textEditor.getSelectionEnd();
    textEditor.append(builder);
    textEditor.setSelection(cursorStart, cursorEnd);

    waitForMediaLatch.countDown();
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:21,代碼來源:ComposeActivity.java

示例13: fromHtml

import android.text.Spanned; //導入依賴的package包/類
public static Spanned fromHtml(String html){
    Spanned result;
    if (android.os.Build.VERSION.SDK_INT >= 24) {
       result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
    } else {
       result = Html.fromHtml(html);
    }
    return result;
}
 
開發者ID:dftec-es,項目名稱:planetcon,代碼行數:10,代碼來源:TextBuilder.java

示例14: buildWavingSpans

import android.text.Spanned; //導入依賴的package包/類
@SuppressWarnings("Range")          // Lint bug: the if makes sure waveCharDelay >= 0
private JumpingBeansSpan[] buildWavingSpans(SpannableStringBuilder sbb) {
    JumpingBeansSpan[] spans;
    if (waveCharDelay == DEFAULT_WAVE_CHAR_DELAY) {
        waveCharDelay = loopDuration / (3 * (endPos - startPos));
    }

    spans = new JumpingBeansSpan[endPos - startPos];
    for (int pos = startPos; pos < endPos; pos++) {
        JumpingBeansSpan jumpingBean =
                new JumpingBeansSpan(textView, loopDuration, pos - startPos, waveCharDelay, animRange);
        sbb.setSpan(jumpingBean, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spans[pos - startPos] = jumpingBean;
    }
    return spans;
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:17,代碼來源:JumpingBeans.java

示例15: filter

import android.text.Spanned; //導入依賴的package包/類
@Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                               int dend) {
        // check black-list set
        for (int i = 0; i < source.length(); i++) {
          //  LogUtil.e(Integer.toHexString(source.charAt(i)));
        }
     //   LogUtil.e(source.toString() + " length: " + source.toString().length() +
		 // " ;bytes length: " + source.toString().getBytes().length);
//        Iterator<String> iterator = filterSet.iterator();
//        while (iterator.hasNext()) {
//            String filter = iterator.next();
//            if (filter.equals(source.toString())) {
//                LogUtil.e(filter + " length: " + filter.length() +
//                        " ;bytes length: " + filter.getBytes().length);
//                for (int i= 0; i < source.length(); i++){
//                    LogUtil.e(Integer.toHexString(source.charAt(i)));
//                }
//                return "";
//            }
//        }
        if (filterSet.contains(source.toString())) {
            return "";
        }
        return source;
    }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:27,代碼來源:EmojiFilter.java


注:本文中的android.text.Spanned類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。