• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.os.Parcelable;
22 import android.text.ParcelableSpan;
23 import android.text.TextPaint;
24 import android.text.TextUtils;
25 
26 /**
27  * A SuggestionRangeSpan is used to show which part of an EditText is affected by a suggestion
28  * popup window.
29  */
30 @android.ravenwood.annotation.RavenwoodKeepWholeClass
31 public final class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpan {
32     private int mBackgroundColor;
33 
SuggestionRangeSpan()34     public SuggestionRangeSpan() {
35         // 0 is a fully transparent black. Has to be set using #setBackgroundColor
36         mBackgroundColor = 0;
37     }
38 
39     /** @hide */
SuggestionRangeSpan(@onNull Parcel src)40     public SuggestionRangeSpan(@NonNull Parcel src) {
41         mBackgroundColor = src.readInt();
42     }
43 
44     public static final @NonNull Parcelable.Creator<SuggestionRangeSpan>
45             CREATOR = new Parcelable.Creator<SuggestionRangeSpan>() {
46                 @Override
47                 public SuggestionRangeSpan createFromParcel(Parcel source) {
48                     return new SuggestionRangeSpan(source);
49                 }
50 
51                 @Override
52                 public SuggestionRangeSpan[] newArray(int size) {
53                     return new SuggestionRangeSpan[size];
54                 }
55             };
56 
57     @Override
describeContents()58     public int describeContents() {
59         return 0;
60     }
61 
62     @Override
writeToParcel(@onNull Parcel dest, int flags)63     public void writeToParcel(@NonNull Parcel dest, int flags) {
64         writeToParcelInternal(dest, flags);
65     }
66 
67     /** @hide */
writeToParcelInternal(Parcel dest, int flags)68     public void writeToParcelInternal(Parcel dest, int flags) {
69         dest.writeInt(mBackgroundColor);
70     }
71 
72     @Override
getSpanTypeId()73     public int getSpanTypeId() {
74         return getSpanTypeIdInternal();
75     }
76 
77     /** @hide */
getSpanTypeIdInternal()78     public int getSpanTypeIdInternal() {
79         return TextUtils.SUGGESTION_RANGE_SPAN;
80     }
81 
setBackgroundColor(int backgroundColor)82     public void setBackgroundColor(int backgroundColor) {
83         mBackgroundColor = backgroundColor;
84     }
85 
getBackgroundColor()86     public int getBackgroundColor() {
87         return mBackgroundColor;
88     }
89 
90     @Override
updateDrawState(@onNull TextPaint tp)91     public void updateDrawState(@NonNull TextPaint tp) {
92         tp.bgColor = mBackgroundColor;
93     }
94 }
95