Home | History | Annotate | Download | only in style
      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.os.Parcel;
     20 import android.text.ParcelableSpan;
     21 import android.text.TextPaint;
     22 import android.text.TextUtils;
     23 
     24 public class BackgroundColorSpan extends CharacterStyle
     25         implements UpdateAppearance, ParcelableSpan {
     26 
     27     private final int mColor;
     28 
     29     public BackgroundColorSpan(int color) {
     30         mColor = color;
     31     }
     32 
     33     public BackgroundColorSpan(Parcel src) {
     34         mColor = src.readInt();
     35     }
     36 
     37     public int getSpanTypeId() {
     38         return getSpanTypeIdInternal();
     39     }
     40 
     41     /** @hide */
     42     public int getSpanTypeIdInternal() {
     43         return TextUtils.BACKGROUND_COLOR_SPAN;
     44     }
     45 
     46     public int describeContents() {
     47         return 0;
     48     }
     49 
     50     public void writeToParcel(Parcel dest, int flags) {
     51         writeToParcelInternal(dest, flags);
     52     }
     53 
     54     /** @hide */
     55     public void writeToParcelInternal(Parcel dest, int flags) {
     56         dest.writeInt(mColor);
     57     }
     58 
     59     public int getBackgroundColor() {
     60         return mColor;
     61     }
     62 
     63     @Override
     64     public void updateDrawState(TextPaint ds) {
     65         ds.bgColor = mColor;
     66     }
     67 }
     68