Debian Codegraph @

core/java/android/text/style/AccessibilityReplacementSpan.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 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.graphics.Canvas;
20 import android.graphics.Paint;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.text.ParcelableSpan;
24 import android.text.TextUtils;
25 import android.view.accessibility.AccessibilityNodeInfo;
26
27 /**
28 * This class serves as a parcelable placeholder for the {@link ReplacementSpan}.
29 *
30 * It is used to replace ReplacementSpans in {@link AccessibilityNodeInfo#setText(CharSequence)}.
31 *
32 * @hide
33 */
34 public class AccessibilityReplacementSpan extends ReplacementSpan
35 implements ParcelableSpan {
36
37 /**
38 * Sets the content description to the parent class.
39 *
40 * @param contentDescription The content description of the span this one replaces
41 */
42 public AccessibilityReplacementSpan(CharSequence contentDescription) {
43 this.setContentDescription(contentDescription);
44 }
45
46 /**
47 * Sets the content description to the parent class.
48 *
49 * @param p The parcel to de-serialize from
50 */
51 public AccessibilityReplacementSpan(Parcel p) {
52 final CharSequence contentDescription = p.readCharSequence();
53 this.setContentDescription(contentDescription);
54 }
55
56 @Override
57 public int getSpanTypeId() {
58 return getSpanTypeIdInternal();
59 }
60
61 @Override
62 public int getSpanTypeIdInternal() {
63 return TextUtils.ACCESSIBILITY_REPLACEMENT_SPAN;
64 }
65
66 @Override
67 public int describeContents() {
68 return 0;
69 }
70
71 @Override
72 public void writeToParcel(Parcel dest, int flags) {
73 writeToParcelInternal(dest, flags);
74 }
75
76 @Override
77 public void writeToParcelInternal(Parcel dest, int flags) {
78 dest.writeCharSequence(this.getContentDescription());
79 }
80
81 @Override
82 public int getSize(Paint paint, CharSequence text, int start, int end,
83 Paint.FontMetricsInt fm) {
84 return 0;
85 }
86
87 @Override
88 public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y,
89 int bottom, Paint paint) {
90 }
91
92 public static final @android.annotation.NonNull
93 Parcelable.Creator<AccessibilityReplacementSpan> CREATOR =
94 new Parcelable.Creator<AccessibilityReplacementSpan>() {
95 @Override
96 public AccessibilityReplacementSpan createFromParcel(Parcel parcel) {
97 return new AccessibilityReplacementSpan(parcel);
98 }
99
100 @Override
101 public AccessibilityReplacementSpan[] newArray(int size) {
102 return new AccessibilityReplacementSpan[size];
103 }
104 };
105 }