Android examples for android.text:SpannableString
Copies the spans from the region start...end in source to the region destoff...destoff+end-start in dest.
/*/*from ww w . ja v a 2 s . com*/ * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; import android.text.SpannedString; import android.text.TextUtils; import android.text.style.SuggestionSpan; public class Main{ /** * Copies the spans from the region start...end in * source to the region * destoff...destoff+end-start in dest. * @throws IndexOutOfBoundsException if any of the copied spans * are out of range in dest. */ public static void copyNonParagraphSuggestionSpansFrom(Spanned source, int start, int end, Spannable dest, int destoff) { Object[] spans = source.getSpans(start, end, SuggestionSpan.class); for (int i = 0; i < spans.length; i++) { int fl = source.getSpanFlags(spans[i]); if (0 != (fl & Spannable.SPAN_PARAGRAPH)) continue; int st = source.getSpanStart(spans[i]); int en = source.getSpanEnd(spans[i]); if (st < start) st = start; if (en > end) en = end; dest.setSpan(spans[i], st - start + destoff, en - start + destoff, fl); } } }