blob: d958ddebaf5a4b8cea3e67344fb58140f00576cf [file] [log] [blame]
Gilles Debunne28294cc2011-08-24 12:02:05 -07001/*
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
17package android.text.style;
18
Mathew Inwoodefeab842018-08-14 15:21:30 +010019import android.annotation.UnsupportedAppUsage;
Gilles Debunne28294cc2011-08-24 12:02:05 -070020import android.os.Parcel;
21import android.text.ParcelableSpan;
22import android.text.TextPaint;
23import android.text.TextUtils;
24
25/**
26 * A SuggestionRangeSpan is used to show which part of an EditText is affected by a suggestion
27 * popup window.
28 *
29 * @hide
30 */
31public class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpan {
Gilles Debunnefa4e2d92011-09-08 18:34:22 -070032 private int mBackgroundColor;
Gilles Debunne0eea6682011-08-29 13:30:31 -070033
Mathew Inwoodefeab842018-08-14 15:21:30 +010034 @UnsupportedAppUsage
Gilles Debunnefa4e2d92011-09-08 18:34:22 -070035 public SuggestionRangeSpan() {
36 // 0 is a fully transparent black. Has to be set using #setBackgroundColor
37 mBackgroundColor = 0;
Gilles Debunne0eea6682011-08-29 13:30:31 -070038 }
39
Mathew Inwoodefeab842018-08-14 15:21:30 +010040 @UnsupportedAppUsage
Gilles Debunne0eea6682011-08-29 13:30:31 -070041 public SuggestionRangeSpan(Parcel src) {
42 mBackgroundColor = src.readInt();
43 }
Gilles Debunne28294cc2011-08-24 12:02:05 -070044
45 @Override
46 public int describeContents() {
47 return 0;
48 }
49
50 @Override
Gilles Debunne0eea6682011-08-29 13:30:31 -070051 public void writeToParcel(Parcel dest, int flags) {
Alan Viverettea70d4a92015-06-02 16:11:00 -070052 writeToParcelInternal(dest, flags);
53 }
54
55 /** @hide */
56 public void writeToParcelInternal(Parcel dest, int flags) {
Gilles Debunne0eea6682011-08-29 13:30:31 -070057 dest.writeInt(mBackgroundColor);
58 }
Gilles Debunne28294cc2011-08-24 12:02:05 -070059
60 @Override
61 public int getSpanTypeId() {
Alan Viverettea70d4a92015-06-02 16:11:00 -070062 return getSpanTypeIdInternal();
63 }
64
65 /** @hide */
66 public int getSpanTypeIdInternal() {
Gilles Debunne28294cc2011-08-24 12:02:05 -070067 return TextUtils.SUGGESTION_RANGE_SPAN;
68 }
Gilles Debunnefa4e2d92011-09-08 18:34:22 -070069
Mathew Inwoodefeab842018-08-14 15:21:30 +010070 @UnsupportedAppUsage
Gilles Debunnefa4e2d92011-09-08 18:34:22 -070071 public void setBackgroundColor(int backgroundColor) {
72 mBackgroundColor = backgroundColor;
73 }
74
75 @Override
76 public void updateDrawState(TextPaint tp) {
77 tp.bgColor = mBackgroundColor;
78 }
Gilles Debunne28294cc2011-08-24 12:02:05 -070079}