Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 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 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.text.ParcelableSpan; |
| 22 | import android.text.TextPaint; |
| 23 | import 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 | */ |
| 31 | public class SuggestionRangeSpan extends CharacterStyle implements ParcelableSpan { |
Gilles Debunne | fa4e2d9 | 2011-09-08 18:34:22 -0700 | [diff] [blame] | 32 | private int mBackgroundColor; |
Gilles Debunne | 0eea668 | 2011-08-29 13:30:31 -0700 | [diff] [blame] | 33 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 34 | @UnsupportedAppUsage |
Gilles Debunne | fa4e2d9 | 2011-09-08 18:34:22 -0700 | [diff] [blame] | 35 | public SuggestionRangeSpan() { |
| 36 | // 0 is a fully transparent black. Has to be set using #setBackgroundColor |
| 37 | mBackgroundColor = 0; |
Gilles Debunne | 0eea668 | 2011-08-29 13:30:31 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 40 | @UnsupportedAppUsage |
Gilles Debunne | 0eea668 | 2011-08-29 13:30:31 -0700 | [diff] [blame] | 41 | public SuggestionRangeSpan(Parcel src) { |
| 42 | mBackgroundColor = src.readInt(); |
| 43 | } |
Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 44 | |
| 45 | @Override |
| 46 | public int describeContents() { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | @Override |
Gilles Debunne | 0eea668 | 2011-08-29 13:30:31 -0700 | [diff] [blame] | 51 | public void writeToParcel(Parcel dest, int flags) { |
Alan Viverette | a70d4a9 | 2015-06-02 16:11:00 -0700 | [diff] [blame] | 52 | writeToParcelInternal(dest, flags); |
| 53 | } |
| 54 | |
| 55 | /** @hide */ |
| 56 | public void writeToParcelInternal(Parcel dest, int flags) { |
Gilles Debunne | 0eea668 | 2011-08-29 13:30:31 -0700 | [diff] [blame] | 57 | dest.writeInt(mBackgroundColor); |
| 58 | } |
Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 59 | |
| 60 | @Override |
| 61 | public int getSpanTypeId() { |
Alan Viverette | a70d4a9 | 2015-06-02 16:11:00 -0700 | [diff] [blame] | 62 | return getSpanTypeIdInternal(); |
| 63 | } |
| 64 | |
| 65 | /** @hide */ |
| 66 | public int getSpanTypeIdInternal() { |
Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 67 | return TextUtils.SUGGESTION_RANGE_SPAN; |
| 68 | } |
Gilles Debunne | fa4e2d9 | 2011-09-08 18:34:22 -0700 | [diff] [blame] | 69 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 70 | @UnsupportedAppUsage |
Gilles Debunne | fa4e2d9 | 2011-09-08 18:34:22 -0700 | [diff] [blame] | 71 | public void setBackgroundColor(int backgroundColor) { |
| 72 | mBackgroundColor = backgroundColor; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void updateDrawState(TextPaint tp) { |
| 77 | tp.bgColor = mBackgroundColor; |
| 78 | } |
Gilles Debunne | 28294cc | 2011-08-24 12:02:05 -0700 | [diff] [blame] | 79 | } |