• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.IntRange;
20 import android.annotation.Px;
21 
22 /**
23  * Paragraph affecting span that changes the position of the tab with respect to
24  * the leading margin of the line. <code>TabStopSpan</code> will only affect the first tab
25  * encountered on the first line of the text.
26  */
27 @android.ravenwood.annotation.RavenwoodKeepWholeClass
28 public interface TabStopSpan extends ParagraphStyle {
29 
30     /**
31      * Returns the offset of the tab stop from the leading margin of the line, in pixels.
32      *
33      * @return the offset, in pixels
34      */
getTabStop()35     int getTabStop();
36 
37     /**
38      * The default implementation of TabStopSpan that allows setting the offset of the tab stop
39      * from the leading margin of the first line of text.
40      * <p>
41      * Let's consider that we have the following text: <i>"\tParagraph text beginning with tab."</i>
42      * and we want to move the tab stop with 100px. This can be achieved like this:
43      * <pre>
44      * SpannableString string = new SpannableString("\tParagraph text beginning with tab.");
45      * string.setSpan(new TabStopSpan.Standard(100), 0, string.length(),
46      * Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</pre>
47      * <img src="{@docRoot}reference/android/images/text/style/tabstopspan.png" />
48      * <figcaption>Text with a tab stop and a <code>TabStopSpan</code></figcaption>
49      */
50     class Standard implements TabStopSpan {
51 
52         @Px
53         private int mTabOffset;
54 
55         /**
56          * Constructs a {@link TabStopSpan.Standard} based on an offset.
57          *
58          * @param offset the offset of the tab stop from the leading margin of
59          *               the line, in pixels
60          */
Standard(@ntRangefrom = 0) int offset)61         public Standard(@IntRange(from = 0) int offset) {
62             mTabOffset = offset;
63         }
64 
65         @Override
getTabStop()66         public int getTabStop() {
67             return mTabOffset;
68         }
69 
70         @Override
toString()71         public String toString() {
72             return "TabStopSpan.Standard{tabOffset=" + getTabStop() + '}';
73         }
74     }
75 }
76