| 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 | public interface TabStopSpan extends ParagraphStyle { |
| 28 | |
| 29 | /** |
| 30 | * Returns the offset of the tab stop from the leading margin of the line, in pixels. |
| 31 | * |
| 32 | * @return the offset, in pixels |
| 33 | */ |
| 34 | int getTabStop(); |
| 35 | |
| 36 | /** |
| 37 | * The default implementation of TabStopSpan that allows setting the offset of the tab stop |
| 38 | * from the leading margin of the first line of text. |
| 39 | * <p> |
| 40 | * Let's consider that we have the following text: <i>"\tParagraph text beginning with tab."</i> |
| 41 | * and we want to move the tab stop with 100px. This can be achieved like this: |
| 42 | * <pre> |
| 43 | * SpannableString string = new SpannableString("\tParagraph text beginning with tab."); |
| 44 | * string.setSpan(new TabStopSpan.Standard(100), 0, string.length(), |
| 45 | * Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</pre> |
| 46 | * <img src="{@docRoot}reference/android/images/text/style/tabstopspan.png" /> |
| 47 | * <figcaption>Text with a tab stop and a <code>TabStopSpan</code></figcaption> |
| 48 | */ |
| 49 | class Standard implements TabStopSpan { |
| 50 | |
| 51 | @Px |
| 52 | private int mTabOffset; |
| 53 | |
| 54 | /** |
| 55 | * Constructs a {@link TabStopSpan.Standard} based on an offset. |
| 56 | * |
| 57 | * @param offset the offset of the tab stop from the leading margin of |
| 58 | * the line, in pixels |
| 59 | */ |
| 60 | public Standard(@IntRange(from = 0) int offset) { |
| 61 | mTabOffset = offset; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int getTabStop() { |
| 66 | return mTabOffset; |
| 67 | } |
| 68 | } |
| 69 | } |