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.graphics.Paint; 20 import android.graphics.Canvas; 21 import android.os.Parcel; 22 import android.text.Layout; 23 import android.text.ParcelableSpan; 24 import android.text.TextUtils; 25 26 public class QuoteSpan implements LeadingMarginSpan, ParcelableSpan { 27 private static final int STRIPE_WIDTH = 2; 28 private static final int GAP_WIDTH = 2; 29 30 private final int mColor; 31 32 public QuoteSpan() { 33 super(); 34 mColor = 0xff0000ff; 35 } 36 37 public QuoteSpan(int color) { 38 super(); 39 mColor = color; 40 } 41 42 public QuoteSpan(Parcel src) { 43 mColor = src.readInt(); 44 } 45 46 public int getSpanTypeId() { 47 return TextUtils.QUOTE_SPAN; 48 } 49 50 public int describeContents() { 51 return 0; 52 } 53 54 public void writeToParcel(Parcel dest, int flags) { 55 dest.writeInt(mColor); 56 } 57 58 public int getColor() { 59 return mColor; 60 } 61 62 public int getLeadingMargin(boolean first) { 63 return STRIPE_WIDTH + GAP_WIDTH; 64 } 65 66 public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, 67 int top, int baseline, int bottom, 68 CharSequence text, int start, int end, 69 boolean first, Layout layout) { 70 Paint.Style style = p.getStyle(); 71 int color = p.getColor(); 72 73 p.setStyle(Paint.Style.FILL); 74 p.setColor(mColor); 75 76 c.drawRect(x, top, x + dir * STRIPE_WIDTH, bottom, p); 77 78 p.setStyle(style); 79 p.setColor(color); 80 } 81 } 82