Example usage for android.text Spanned SPAN_INCLUSIVE_INCLUSIVE

List of usage examples for android.text Spanned SPAN_INCLUSIVE_INCLUSIVE

Introduction

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

Prototype

int SPAN_INCLUSIVE_INCLUSIVE

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

Click Source Link

Document

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

Usage

From source file:com.zyz.mobile.book.UserBookData.java

/**
 * draw the specified {@code UserSpan} on the spannable
 *
 * @param userSpan the span to be drawn// w w w .  j a  va2  s .  c om
 */
private void updateSpannable(UserSpan userSpan) {
    if (userSpan.isStyleSpan()) {
        mSpannable.setSpan(userSpan.getObject(), userSpan.getStart(), userSpan.getEnd(),
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
}

From source file:cn.wjh1119.bestnews.ui.fragment.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {

        //?????view
        FetchDetailDataFromSqlTask fetchDetailDataFromSqlTask = new FetchDetailDataFromSqlTask();
        fetchDetailDataFromSqlTask//  w w  w .j a  v a2s  .  com
                .setOnDataFinishedListener(new FetchDetailDataFromSqlTask.OnDataFinishedListener() {
                    @Override
                    public void onDataSuccessfully(HashMap data) {

                        String title = data.get("title").toString();
                        String source = data.get("source").toString();
                        String pubDate = data.get("pubDate").toString();
                        String content = data.get("content").toString();
                        String link = data.get("link").toString();
                        //                    BitmapDrawable drawable = (BitmapDrawable) data.get("drawable");
                        Object imageTextFromSql = data.get("imageUrl");
                        String imageUrl = null;
                        if (imageTextFromSql != null) {
                            imageUrl = data.get("imageUrl").toString();
                        }

                        mTitleView.setText(title);
                        mTitleView.setFocusable(true);
                        mTitleView.setFocusableInTouchMode(true);
                        mTitleView.requestFocus();
                        TextPaint paint = mTitleView.getPaint();
                        paint.setFakeBoldText(true);
                        mSourceView.setText(source);
                        mPubDateView.setText(pubDate);
                        mContentView.setText(content);

                        if (imageUrl != null) {
                            Bitmap bitmap = imageManager.showCacheBitmap(imageUrl);
                            if (bitmap != null) {
                                mImageView.setImageBitmap(bitmap);

                            } else {
                                imageManager.downloadImage(imageUrl, new ImageManager.onImageLoaderListener() {

                                    @Override
                                    public void onImageLoader(Bitmap bitmap, String url) {
                                        if (bitmap != null) {
                                            mImageView.setImageBitmap(bitmap);
                                        } else {
                                            mImageView.setImageResource(R.mipmap.picture_fail_loading);
                                        }
                                    }
                                });
                            }
                        }

                        SpannableStringBuilder ssb = new SpannableStringBuilder("??");
                        ssb.setSpan(new URLSpan(link), 0, ssb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                        ForegroundColorSpan span = new ForegroundColorSpan(Color.BLUE);
                        ssb.setSpan(span, 0, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                        mLinkView.setText(ssb);
                        // ??MovementMethod
                        mLinkView.setMovementMethod(LinkMovementMethod.getInstance());
                        // ??ClickableSpan
                        mLinkView.setHighlightColor(0xff8FABCC);
                    }

                    @Override
                    public void onDataFailed() {

                    }
                });
        fetchDetailDataFromSqlTask.execute(data);
    }
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar_detail);

    // We need to start the enter transition after the data has loaded
    if (mTransitionAnimation) {
        activity.supportStartPostponedEnterTransition();

        if (null != toolbarView) {
            activity.setSupportActionBar(toolbarView);
            activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
            activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    } else {
        if (null != toolbarView) {
            Menu menu = toolbarView.getMenu();
            if (null != menu)
                menu.clear();
        }
    }
}

From source file:com.amazon.android.ui.widget.EllipsizedTextView.java

/**
 * Sets ellipsis properties.//from ww  w.  j a  v  a  2  s.c  o  m
 *
 * @param widthMeasureSpec  Ellipsis width.
 * @param heightMeasureSpec Ellipsis height.
 * @param layout            Layout for ellipsis.
 * @param lastLine          Last line length for ellipsis.
 * @param maxLines          Max lines in ellipsis.
 */
private void setEllipsis(int widthMeasureSpec, int heightMeasureSpec, Layout layout, int lastLine,
        int maxLines) {

    mIsEllipsized = true;
    setFocusable(true);
    setClickable(true);
    final SpannableString ss = new SpannableString(mCharSequence);
    String visibleText = mCharSequence.toString();

    mEllipsisImage = new StateImageSpan(getContext(), mGuillemetDrawableId, ImageSpan.ALIGN_BASELINE);

    final SpannableStringBuilder spannedText = new SpannableStringBuilder();
    int ellipsisIndex = layout.getLineStart(Math.min(lastLine + 1, maxLines));

    // Keep chopping words off until the ellipsis is on a visible line or there is only one
    // line left.
    do {
        // Only truncate the last line for long description.
        if (lastLine >= maxLines) {
            // Getting the first word break index before the last index of maxline.
            int safeBreakIndex = breakBefore(visibleText, ellipsisIndex, BreakIterator.getWordInstance());
            final int maxLineStart = layout.getLineStart(maxLines - 1);

            // If this check pass, it means we just truncated a word that is longer than a line.
            if (safeBreakIndex < maxLineStart) {
                // Need to check character by character and break in the middle now. Checking
                // word by word should cover most cases, only do this if a word is longer than
                // line width.
                safeBreakIndex = breakBefore(visibleText, ellipsisIndex, BreakIterator.getCharacterInstance());
            }
            ellipsisIndex = safeBreakIndex;
        }

        visibleText = visibleText.substring(0, ellipsisIndex);
        final CharSequence charOutput = ss.subSequence(0, ellipsisIndex);

        // Re-add ellipsis and convert to image
        spannedText.replace(0, spannedText.length(), charOutput);
        spannedText.append(ELLIPSIS);

        spannedText.setSpan(mEllipsisImage, ellipsisIndex, ellipsisIndex + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        // Reset text and re-measure.
        super.setText(spannedText, BufferType.SPANNABLE);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    } while (getLineCount() > getMaxLines() && getLineCount() > 1);
    requestFocus();
}

From source file:com.marshalchen.common.uimodule.modifysys.PagerTitleStrip.java

SpannableString changeSpanString(String temp, int position, int color) {

    try {/*ww w. ja va 2s  .c  o  m*/
        temp = temp.replaceAll("-", " - ");

        SpannableString ss = new SpannableString(temp);
        Matrix matrix = new Matrix();

        matrix.postRotate(180);

        Bitmap bitmaporg = BitmapFactory.decodeResource(getResources(), R.drawable.ico_arrow2x);
        if (color == 2) {
            bitmaporg = BitmapFactory.decodeResource(getResources(), R.drawable.ico_arrow_grey2x);
        }
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmaporg, 0, 0, bitmaporg.getWidth(), bitmaporg.getHeight(),
                matrix, true);
        BitmapDrawable bmd = new BitmapDrawable(getResources(), resizedBitmap);
        BitmapDrawable bm = new BitmapDrawable(getResources(), bitmaporg);
        Drawable drawable = position == 0 ? bm : bmd;
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 12 / 10,
                drawable.getIntrinsicHeight() * 12 / 10);
        ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);

        ss.setSpan(imageSpan, temp.indexOf("-"), temp.indexOf("-") + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return ss;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e, "");
        return null;
    }
}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString toFriendlySnackbarString(Context context, String input) {
    final ForegroundColorSpan whiteSpan = new ForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorAccent));
    final SpannableString snackbarText = new SpannableString(input);
    snackbarText.setSpan(whiteSpan, 0, snackbarText.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    return snackbarText;
}

From source file:com.filemanager.free.activities.TextReader.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.prev:
        // upButton
        if (mCurrent > 0) {

            // setting older span back before setting new one
            Map.Entry keyValueOld = (Map.Entry) nodes.get(mCurrent).getKey();
            mInput.getText().setSpan(//  ww w  .jav a  2  s . c o m
                    theme1 == 0 ? new BackgroundColorSpan(Color.YELLOW) : new BackgroundColorSpan(Color.LTGRAY),
                    (Integer) keyValueOld.getKey(), (Integer) keyValueOld.getValue(),
                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);

            // highlighting previous element in list
            Map.Entry keyValueNew = (Map.Entry) nodes.get(--mCurrent).getKey();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(
                                getResources().getColor(R.color.search_text_highlight, getTheme())),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            } else {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(ContextCompat.getColor(c, R.color.search_text_highlight)),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }
        }
        break;
    case R.id.next:
        // downButton
        if (mCurrent < nodes.size() - 1) {

            // setting older span back before setting new one
            if (mCurrent != -1) {

                Map.Entry keyValueOld = (Map.Entry) nodes.get(mCurrent).getKey();
                mInput.getText().setSpan(
                        theme1 == 0 ? new BackgroundColorSpan(Color.YELLOW)
                                : new BackgroundColorSpan(Color.LTGRAY),
                        (Integer) keyValueOld.getKey(), (Integer) keyValueOld.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }

            Map.Entry keyValueNew = (Map.Entry) nodes.get(++mCurrent).getKey();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(
                                getResources().getColor(R.color.search_text_highlight, getTheme())),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            } else {
                mInput.getText().setSpan(
                        new BackgroundColorSpan(ContextCompat.getColor(c, R.color.search_text_highlight)),
                        (Integer) keyValueNew.getKey(), (Integer) keyValueNew.getValue(),
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }

            // scrolling to the highlighted element
            DisplayMetrics displayMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            scrollView.scrollTo(0, (Integer) keyValueNew.getValue() + mInput.getLineHeight()
                    - displayMetrics.heightPixels / 2);
        }
        break;
    case R.id.close:
        onDestroyActionMode();
        // closeButton
        findViewById(R.id.searchview).setVisibility(View.GONE);
        break;
    default:
        return;
    }
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private void setupEditText() {
    final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
    EditTextEnterHandler.attach(mEditText, new EnterListener() {
        @Override/*w  ww.  ja  va2  s . c o m*/
        public void onHitEnter() {
            updateStatus();
        }
    }, sendByEnter);
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {

        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            setMenu();
            updateTextCount();
            if (s instanceof Spannable && count == 1 && before == 0) {
                final ImageSpan[] imageSpans = ((Spannable) s).getSpans(start, start + count, ImageSpan.class);
                if (imageSpans.length == 1) {
                    final Intent intent = new Intent(ComposeActivity.this, ImagePickerActivity.class);
                    intent.setAction(ImagePickerActivity.INTENT_ACTION_GET_IMAGE);
                    intent.setData(Uri.parse(imageSpans[0].getSource()));
                    startActivityForResult(intent, REQUEST_PICK_IMAGE);
                    ((Spannable) s).setSpan(new MarkForDeleteSpan(), start, start + count,
                            Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                }
            }
        }

        @Override
        public void afterTextChanged(final Editable s) {
            mTextChanged = s.length() == 0;
            final MarkForDeleteSpan[] deletes = s.getSpans(0, s.length(), MarkForDeleteSpan.class);
            for (MarkForDeleteSpan delete : deletes) {
                s.delete(s.getSpanStart(delete), s.getSpanEnd(delete));
            }
        }
    });
    mEditText.setCustomSelectionActionModeCallback(this);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyParagraphSpacing(TextView textView, float multiplier) {
    final SpannableStringBuilder builder = SpannableStringBuilder.valueOf(textView.getText());
    int prevLineBreak, currLineBreak = 0;
    for (int i = 0, j = builder.length(); i < j; i++) {
        if (builder.charAt(i) == '\n') {
            prevLineBreak = currLineBreak;
            currLineBreak = i;/* w ww .  ja  v  a2s  .  c  o m*/
            if (currLineBreak > 0) {
                builder.setSpan(new ParagraphSpacingSpan(multiplier), prevLineBreak, currLineBreak,
                        Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            }
        }
    }
    textView.setText(builder);
}