17053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta/* 27053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * Copyright (C) 2014 The Android Open Source Project 37053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * 47053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * Licensed under the Apache License, Version 2.0 (the "License"); 57053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * you may not use this file except in compliance with the License. 67053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * You may obtain a copy of the License at 77053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * 87053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * http://www.apache.org/licenses/LICENSE-2.0 97053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * 107053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * Unless required by applicable law or agreed to in writing, software 117053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * distributed under the License is distributed on an "AS IS" BASIS, 127053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * See the License for the specific language governing permissions and 147053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta * limitations under the License. 157053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta */ 167053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta 177053919a3a55ad1b58e6db701afda18850037732Deepanshu Guptapackage android.text; 187053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta 19476e582d2ffdf25102d4c55f8c242baa3d21d37fDeepanshu Guptaimport android.annotation.Nullable; 207053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta 217053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta// Based on the native implementation of TabStops in 227053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta// frameworks/base/core/jni/android_text_StaticLayout.cpp revision b808260 237053919a3a55ad1b58e6db701afda18850037732Deepanshu Guptapublic class TabStops { 247053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta @Nullable 257053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta private int[] mStops; 267053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta private final int mTabWidth; 277053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta 287053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta public TabStops(@Nullable int[] stops, int defaultTabWidth) { 297053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta mTabWidth = defaultTabWidth; 307053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta mStops = stops; 317053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta } 327053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta 337053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta public float width(float widthSoFar) { 347053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta if (mStops != null) { 357053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta for (int i : mStops) { 367053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta if (i > widthSoFar) { 377053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta return i; 387053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta } 397053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta } 407053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta } 417053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta // find the next tabStop after widthSoFar. 427053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta return (int) ((widthSoFar + mTabWidth) / mTabWidth) * mTabWidth; 437053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta } 447053919a3a55ad1b58e6db701afda18850037732Deepanshu Gupta} 45