• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.text.style;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.text.ParcelableSpan;
22 import android.text.TextPaint;
23 import android.text.TextUtils;
24 
25 /**
26  * The span that moves the position of the text baseline lower.
27  * <p>
28  * The span can be used like this:
29  * <pre>{@code
30  *  SpannableString string = new SpannableString("☕- C8H10N4O2\n");
31  *string.setSpan(new SubscriptSpan(), 4, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
32  *string.setSpan(new SubscriptSpan(), 6, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
33  *string.setSpan(new SubscriptSpan(), 9, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
34  *string.setSpan(new SubscriptSpan(), 11, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);}</pre>
35  * <img src="{@docRoot}reference/android/images/text/style/subscriptspan.png" />
36  * <figcaption>Text with <code>SubscriptSpan</code>.</figcaption>
37  * Note: Since the span affects the position of the text, if the text is on the last line of a
38  * TextView, it may appear cut.
39  */
40 @android.ravenwood.annotation.RavenwoodKeepWholeClass
41 public class SubscriptSpan extends MetricAffectingSpan implements ParcelableSpan {
42 
43     /**
44      * Creates a {@link SubscriptSpan}.
45      */
SubscriptSpan()46     public SubscriptSpan() {
47     }
48 
49     /**
50      * Creates a {@link SubscriptSpan} from a parcel.
51      */
SubscriptSpan(@onNull Parcel src)52     public SubscriptSpan(@NonNull Parcel src) {
53     }
54 
55     @Override
getSpanTypeId()56     public int getSpanTypeId() {
57         return getSpanTypeIdInternal();
58     }
59 
60     /** @hide */
61     @Override
getSpanTypeIdInternal()62     public int getSpanTypeIdInternal() {
63         return TextUtils.SUBSCRIPT_SPAN;
64     }
65 
66     @Override
describeContents()67     public int describeContents() {
68         return 0;
69     }
70 
71     @Override
writeToParcel(Parcel dest, int flags)72     public void writeToParcel(Parcel dest, int flags) {
73         writeToParcelInternal(dest, flags);
74     }
75 
76     /** @hide */
77     @Override
writeToParcelInternal(Parcel dest, int flags)78     public void writeToParcelInternal(Parcel dest, int flags) {
79     }
80 
81     @Override
updateDrawState(@onNull TextPaint textPaint)82     public void updateDrawState(@NonNull TextPaint textPaint) {
83         textPaint.baselineShift -= (int) (textPaint.ascent() / 2);
84     }
85 
86     @Override
updateMeasureState(@onNull TextPaint textPaint)87     public void updateMeasureState(@NonNull TextPaint textPaint) {
88         textPaint.baselineShift -= (int) (textPaint.ascent() / 2);
89     }
90 
91     @Override
toString()92     public String toString() {
93         return "SubscriptSpan{}";
94     }
95 }
96