ViewPagerTabs.java revision 64355c717f4f739baae02d347744cfcc577ffe0b
1429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell/*
2429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * Copyright (C) 2014 The Android Open Source Project
3429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell *
4429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * Licensed under the Apache License, Version 2.0 (the "License");
5429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * you may not use this file except in compliance with the License.
6429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * You may obtain a copy of the License at
7429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell *
8429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell *      http://www.apache.org/licenses/LICENSE-2.0
9429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell *
10429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * Unless required by applicable law or agreed to in writing, software
11429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * distributed under the License is distributed on an "AS IS" BASIS,
12429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * See the License for the specific language governing permissions and
14429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * limitations under the License.
15429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell */
16429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellpackage com.android.contacts.common.list;
17429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
18429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.content.Context;
19429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.content.res.ColorStateList;
20429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.content.res.TypedArray;
21429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.graphics.Outline;
22429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.support.v4.view.PagerAdapter;
23429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.support.v4.view.ViewPager;
24429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.util.AttributeSet;
25429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.util.TypedValue;
26429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.view.Gravity;
27429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.view.View;
28429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.view.ViewOutlineProvider;
29429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.widget.FrameLayout;
30429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.widget.HorizontalScrollView;
31429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.widget.LinearLayout;
32429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.widget.TextView;
33429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport android.widget.Toast;
34429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
35429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellimport com.android.contacts.common.R;
36429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
37429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell/**
38429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * Lightweight implementation of ViewPager tabs. This looks similar to traditional actionBar tabs,
39429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * but allows for the view containing the tabs to be placed anywhere on screen. Text-related
40429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * attributes can also be assigned in XML - these will get propogated to the child TextViews
41429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell * automatically.
42429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell */
43429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwellpublic class ViewPagerTabs extends HorizontalScrollView implements ViewPager.OnPageChangeListener {
44429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
45429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    ViewPager mPager;
46429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private ViewPagerTabStrip mTabStrip;
47429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
48429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    /**
49429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell     * Linearlayout that will contain the TextViews serving as tabs. This is the only child
50429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell     * of the parent HorizontalScrollView.
51429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell     */
52429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    final int mTextStyle;
53429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    final ColorStateList mTextColor;
54429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    final int mTextSize;
55429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    final boolean mTextAllCaps;
56429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    int mPrevSelected = -1;
57429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    int mSidePadding;
58429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
59429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private static final ViewOutlineProvider VIEW_BOUNDS_OUTLINE_PROVIDER =
60429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            new ViewOutlineProvider() {
61429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        @Override
62429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        public void getOutline(View view, Outline outline) {
63429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            outline.setRect(0, 0, view.getWidth(), view.getHeight());
64429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
65429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    };
66429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
67429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private static final int TAB_SIDE_PADDING_IN_DPS = 10;
68429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
69429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    // TODO: This should use <declare-styleable> in the future
70429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private static final int[] ATTRS = new int[] {
71429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        android.R.attr.textSize,
72429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        android.R.attr.textStyle,
73429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        android.R.attr.textColor,
74429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        android.R.attr.textAllCaps
75429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    };
76429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
77429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    /**
78429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell     * Simulates actionbar tab behavior by showing a toast with the tab title when long clicked.
79429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell     */
80429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private class OnTabLongClickListener implements OnLongClickListener {
81429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final int mPosition;
82429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
83429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        public OnTabLongClickListener(int position) {
84429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            mPosition = position;
85429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
86429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
87429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        @Override
88429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        public boolean onLongClick(View v) {
89429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            final int[] screenPos = new int[2];
90429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            getLocationOnScreen(screenPos);
91429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
92429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            final Context context = getContext();
93429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            final int width = getWidth();
94429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            final int height = getHeight();
95429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
96429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
97429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            Toast toast = Toast.makeText(context, mPager.getAdapter().getPageTitle(mPosition),
98429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell                    Toast.LENGTH_SHORT);
99429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
100429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            // Show the toast under the tab
101429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
102429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell                    (screenPos[0] + width / 2) - screenWidth / 2, screenPos[1] + height);
103429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
104429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            toast.show();
105429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            return true;
106429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
107429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
108429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
109429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public ViewPagerTabs(Context context) {
110429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        this(context, null);
111429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
112429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
113429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public ViewPagerTabs(Context context, AttributeSet attrs) {
114429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        this(context, attrs, 0);
115429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
116429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
117429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) {
118429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        super(context, attrs, defStyle);
119429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        setFillViewport(true);
120429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
121429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mSidePadding = (int) (getResources().getDisplayMetrics().density * TAB_SIDE_PADDING_IN_DPS);
122429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
123429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
124429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTextSize = a.getDimensionPixelSize(0, 0);
125429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTextStyle = a.getInt(1, 0);
126429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTextColor = a.getColorStateList(2);
127429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTextAllCaps = a.getBoolean(3, false);
128429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
129429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTabStrip = new ViewPagerTabStrip(context);
130429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        addView(mTabStrip,
131429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell                new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
132429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        a.recycle();
133429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
134429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        // enable shadow casting from view bounds
135429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        setOutlineProvider(VIEW_BOUNDS_OUTLINE_PROVIDER);
136429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
137429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
138429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public void setViewPager(ViewPager viewPager) {
139429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mPager = viewPager;
140429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        addTabs(mPager.getAdapter());
141429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
142429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
143429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private void addTabs(PagerAdapter adapter) {
144429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTabStrip.removeAllViews();
145429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
146429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final int count = adapter.getCount();
147429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        for (int i = 0; i < count; i++) {
148429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            addTab(adapter.getPageTitle(i), i);
149429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
150429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
151429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
152429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    private void addTab(CharSequence tabTitle, final int position) {
153429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final TextView textView = new TextView(getContext());
154429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setText(tabTitle);
155429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setBackgroundResource(R.drawable.view_pager_tab_background);
156429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setGravity(Gravity.CENTER);
157429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setOnClickListener(new OnClickListener() {
158429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            @Override
159429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            public void onClick(View v) {
1604d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee                mPager.setCurrentItem(getRtlPosition(position));
161429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            }
162429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        });
163429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
164429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setOnLongClickListener(new OnTabLongClickListener(position));
165429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
166429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        // Assign various text appearance related attributes to child views.
167429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        if (mTextStyle > 0) {
168429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            textView.setTypeface(textView.getTypeface(), mTextStyle);
169429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
170429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        if (mTextSize > 0) {
171429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
172429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
173429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        if (mTextColor != null) {
174429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            textView.setTextColor(mTextColor);
175429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
176429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setAllCaps(mTextAllCaps);
177429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        textView.setPadding(mSidePadding, 0, mSidePadding, 0);
178429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTabStrip.addView(textView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
179429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell                LayoutParams.MATCH_PARENT, 1));
180429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        // Default to the first child being selected
181429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        if (position == 0) {
182429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            mPrevSelected = 0;
183429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            textView.setSelected(true);
184429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
185429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
186429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
187429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    @Override
188429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
1894d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee        position = getRtlPosition(position);
190429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        int tabStripChildCount = mTabStrip.getChildCount();
191429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
192429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            return;
193429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
194429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
195429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mTabStrip.onPageScrolled(position, positionOffset, positionOffsetPixels);
196429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
197429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
198429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    @Override
199429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public void onPageSelected(int position) {
2004d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee        position = getRtlPosition(position);
20164355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner        int tabStripChildCount = mTabStrip.getChildCount();
20264355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner        if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
20364355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner            return;
20464355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner        }
20564355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner
20664355c717f4f739baae02d347744cfcc577ffe0bJay Shrauner        if (mPrevSelected >= 0 && mPrevSelected < tabStripChildCount) {
207429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell            mTabStrip.getChildAt(mPrevSelected).setSelected(false);
208429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        }
209429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final View selectedChild = mTabStrip.getChildAt(position);
210429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        selectedChild.setSelected(true);
211429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
212429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        // Update scroll position
213429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        final int scrollPos = selectedChild.getLeft() - (getWidth() - selectedChild.getWidth()) / 2;
214429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        smoothScrollTo(scrollPos, 0);
215429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell        mPrevSelected = position;
216429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
217429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
218429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    @Override
219429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    public void onPageScrollStateChanged(int state) {
220429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell    }
2214d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee
2224d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee    private int getRtlPosition(int position) {
2234d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee        if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
2244d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee            return mTabStrip.getChildCount() - 1 - position;
2254d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee        }
2264d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee        return position;
2274d0ec405721176fcbf4c70bade5d34da68d523c3Yorke Lee    }
228429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell}
229429302fd99805fc6d88e974335289e22ff59c1eeBrian Attwell
230