2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.text.style;
19 import android.graphics.Canvas;
20 import android.graphics.Paint;
21 import android.os.Parcel;
22 import android.text.Layout;
23 import android.text.ParcelableSpan;
24 import android.text.Spanned;
25 import android.text.TextUtils;
27 public class BulletSpan implements LeadingMarginSpan, ParcelableSpan {
28 private final int mGapWidth;
29 private final boolean mWantColor;
30 private final int mColor;
32 private static final int BULLET_RADIUS = 3;
33 public static final int STANDARD_GAP_WIDTH = 2;
36 mGapWidth = STANDARD_GAP_WIDTH;
41 public BulletSpan(int gapWidth) {
47 public BulletSpan(int gapWidth, int color) {
53 public BulletSpan(Parcel src) {
54 mGapWidth = src.readInt();
55 mWantColor = src.readInt() != 0;
56 mColor = src.readInt();
59 public int getSpanTypeId() {
60 return TextUtils.BULLET_SPAN;
63 public int describeContents() {
67 public void writeToParcel(Parcel dest, int flags) {
68 dest.writeInt(mGapWidth);
69 dest.writeInt(mWantColor ? 1 : 0);
70 dest.writeInt(mColor);
73 public int getLeadingMargin(boolean first) {
74 return 2 * BULLET_RADIUS + mGapWidth;
77 public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
78 int top, int baseline, int bottom,
79 CharSequence text, int start, int end,
80 boolean first, Layout l) {
81 if (((Spanned) text).getSpanStart(this) == start) {
82 Paint.Style style = p.getStyle();
86 oldcolor = p.getColor();
90 p.setStyle(Paint.Style.FILL);
92 c.drawCircle(x + dir * BULLET_RADIUS, (top + bottom) / 2.0f,