LeadingMarginSpan.java revision 7b5676e4d40a09ccdbc8b6f691a3d8be23e480d3
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
17package android.text.style;
18
19import android.graphics.Paint;
20import android.graphics.Canvas;
21import android.os.Parcel;
22import android.text.Layout;
23import android.text.ParcelableSpan;
24import android.text.TextUtils;
25
26public interface LeadingMarginSpan
27extends ParagraphStyle
28{
29    public int getLeadingMargin(boolean first);
30    public void drawLeadingMargin(Canvas c, Paint p,
31                                  int x, int dir,
32                                  int top, int baseline, int bottom,
33                                  CharSequence text, int start, int end,
34                                  boolean first, Layout layout);
35
36
37    public interface LeadingMarginSpan2 extends LeadingMarginSpan, WrapTogetherSpan {
38        public int getLeadingMarginLineCount();
39    };
40
41    public static class Standard implements LeadingMarginSpan, ParcelableSpan {
42        private final int mFirst, mRest;
43
44        public Standard(int first, int rest) {
45            mFirst = first;
46            mRest = rest;
47        }
48
49        public Standard(int every) {
50            this(every, every);
51        }
52
53        public Standard(Parcel src) {
54            mFirst = src.readInt();
55            mRest = src.readInt();
56        }
57
58        public int getSpanTypeId() {
59            return TextUtils.LEADING_MARGIN_SPAN;
60        }
61
62        public int describeContents() {
63            return 0;
64        }
65
66        public void writeToParcel(Parcel dest, int flags) {
67            dest.writeInt(mFirst);
68            dest.writeInt(mRest);
69        }
70
71        public int getLeadingMargin(boolean first) {
72            return first ? mFirst : mRest;
73        }
74
75        public void drawLeadingMargin(Canvas c, Paint p,
76                                      int x, int dir,
77                                      int top, int baseline, int bottom,
78                                      CharSequence text, int start, int end,
79                                      boolean first, Layout layout) {
80            ;
81        }
82    }
83}
84