1fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb/*
2fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * Copyright (C) 2010 The Android Open Source Project
3fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb *
427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License"); you may not
527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * use this file except in compliance with the License. You may obtain a copy of
627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * the License at
7fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb *
827b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * http://www.apache.org/licenses/LICENSE-2.0
9fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb *
10fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * Unless required by applicable law or agreed to in writing, software
1127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1327b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * License for the specific language governing permissions and limitations under
1427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * the License.
15fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */
16fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
17fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbpackage com.android.browser;
18fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
19678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolbimport com.android.browser.TabBar.TabView;
20678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb
2127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolbimport android.animation.ObjectAnimator;
22fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.content.Context;
23fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.util.AttributeSet;
24fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.view.View;
25fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.widget.HorizontalScrollView;
26fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.widget.LinearLayout;
27fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
28fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb/**
29fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * custom view for displaying tabs in the tabbed title bar
30fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */
31fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbpublic class TabScrollView extends HorizontalScrollView {
32fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
33fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    private LinearLayout mContentView;
34fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    private int mSelected;
3527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    private int mAnimationDuration;
362b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb    private int mTabOverlap;
37fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
38fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    /**
39fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param context
40fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param attrs
41fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param defStyle
42fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     */
43fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    public TabScrollView(Context context, AttributeSet attrs, int defStyle) {
44fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        super(context, attrs, defStyle);
45fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        init(context);
46fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
47fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
48fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    /**
49fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param context
50fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param attrs
51fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     */
52fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    public TabScrollView(Context context, AttributeSet attrs) {
53fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        super(context, attrs);
54fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        init(context);
55fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
56fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
57fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    /**
58fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     * @param context
59fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb     */
60fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    public TabScrollView(Context context) {
61fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        super(context);
62fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        init(context);
63fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
64fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
65fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    private void init(Context ctx) {
6627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        mAnimationDuration = ctx.getResources().getInteger(
6727b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb                R.integer.tab_animation_duration);
682b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        mTabOverlap = (int) ctx.getResources().getDimension(R.dimen.tab_overlap);
69fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        setHorizontalScrollBarEnabled(false);
702b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        setOverScrollMode(OVER_SCROLL_NEVER);
71e398956c248808b95aa3d81403c3ba3884670199Romain Guy        mContentView = new TabLayout(ctx);
72fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        mContentView.setOrientation(LinearLayout.HORIZONTAL);
7327b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        mContentView.setLayoutParams(
7427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb                new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
75f558f0d9372ecf4eeba86dd52bf67f38ff79c0b8Michael Kolb        mContentView.setPadding(
76f558f0d9372ecf4eeba86dd52bf67f38ff79c0b8Michael Kolb                (int) ctx.getResources().getDimension(R.dimen.tab_first_padding_left),
77f558f0d9372ecf4eeba86dd52bf67f38ff79c0b8Michael Kolb                0, 0, 0);
78fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        addView(mContentView);
79fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        mSelected = -1;
8027b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        // prevent ProGuard from removing the property methods
8127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        setScroll(getScroll());
82fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
83fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
84fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    @Override
85fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
86fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        super.onLayout(changed, left, top, right, bottom);
87fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        ensureChildVisible(getSelectedTab());
88fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
89fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
90678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb    // in case of a configuration change, adjust tab width
91678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb    protected void updateLayout() {
92678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb        final int count = mContentView.getChildCount();
93678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb        for (int i = 0; i < count; i++) {
94678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb            final TabView tv = (TabView) mContentView.getChildAt(i);
95678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb            tv.updateLayoutParams();
96678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb        }
97678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb        ensureChildVisible(getSelectedTab());
98678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb    }
99678afc88c00b339950b41e5be9a3e165d580f7bfMichael Kolb
100fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    void setSelectedTab(int position) {
101fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        View v = getSelectedTab();
102fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        if (v != null) {
103b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb            v.setActivated(false);
104fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        }
105fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        mSelected = position;
106fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        v = getSelectedTab();
107fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        if (v != null) {
108b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb            v.setActivated(true);
109fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        }
110fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        requestLayout();
111fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
112fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
113ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb    int getChildIndex(View v) {
114ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb        return mContentView.indexOfChild(v);
115ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb    }
116ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb
117fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    View getSelectedTab() {
118fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        if ((mSelected >= 0) && (mSelected < mContentView.getChildCount())) {
119fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            return mContentView.getChildAt(mSelected);
120fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        } else {
121fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            return null;
122fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        }
123fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
124fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
125fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    void clearTabs() {
126fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        mContentView.removeAllViews();
127fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
128fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
129fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    void addTab(View tab) {
130fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        mContentView.addView(tab);
131b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb        tab.setActivated(false);
132fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
133fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
134fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    void removeTab(View tab) {
135bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb        int ix = mContentView.indexOfChild(tab);
136bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb        if (ix == mSelected) {
137bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb            mSelected = -1;
138bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb        } else if (ix < mSelected) {
139bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb            mSelected--;
140bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb        }
141599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck        mContentView.removeView(tab);
142fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
143fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
14427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    private void ensureChildVisible(View child) {
145fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        if (child != null) {
146fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            int childl = child.getLeft();
147fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            int childr = childl + child.getWidth();
148fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            int viewl = getScrollX();
149fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            int viewr = viewl + getWidth();
150fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            if (childl < viewl) {
151fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb                // need scrolling to left
15227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb                animateScroll(childl);
153fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            } else if (childr > viewr) {
154fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb                // need scrolling to right
15527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb                animateScroll(childr - viewr + viewl);
156fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb            }
157fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb        }
158fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb    }
159fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb
160599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// TODO: These animations are broken and don't work correctly, removing for now
161599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//       as animateOut is actually causing issues
162599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//    private void animateIn(View tab) {
163599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        ObjectAnimator animator = ObjectAnimator.ofInt(tab, "TranslationX", 500, 0);
164599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.setDuration(mAnimationDuration);
165599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.start();
166599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//    }
167599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//
168599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//    private void animateOut(final View tab) {
169599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        ObjectAnimator animator = ObjectAnimator.ofInt(
170599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//                tab, "TranslationX", 0, getScrollX() - tab.getRight());
171599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.setDuration(mAnimationDuration);
172599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.addListener(new AnimatorListenerAdapter() {
173599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//            @Override
174599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//            public void onAnimationEnd(Animator animation) {
175599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//                mContentView.removeView(tab);
176599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//            }
177599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        });
178599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.setInterpolator(new AccelerateInterpolator());
179599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//        animator.start();
180599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck//    }
18127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb
18227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    private void animateScroll(int newscroll) {
183b3a00ab2336bdb2871924232b744160f47116a78Chet Haase        ObjectAnimator animator = ObjectAnimator.ofInt(this, "scroll", getScrollX(), newscroll);
184b3a00ab2336bdb2871924232b744160f47116a78Chet Haase        animator.setDuration(mAnimationDuration);
18527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        animator.start();
18627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    }
18727b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb
18827b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    /**
18927b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb     * required for animation
19027b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb     */
19127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    public void setScroll(int newscroll) {
19227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        scrollTo(newscroll, getScrollY());
19327b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    }
19427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb
19527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    /**
19627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb     * required for animation
19727b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb     */
19827b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    public int getScroll() {
19927b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb        return getScrollX();
20027b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb    }
20127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb
202e398956c248808b95aa3d81403c3ba3884670199Romain Guy    @Override
203e398956c248808b95aa3d81403c3ba3884670199Romain Guy    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
204e398956c248808b95aa3d81403c3ba3884670199Romain Guy        super.onScrollChanged(l, t, oldl, oldt);
205e398956c248808b95aa3d81403c3ba3884670199Romain Guy
206e398956c248808b95aa3d81403c3ba3884670199Romain Guy        // TabViews base their drawing based on their absolute position within the
207e398956c248808b95aa3d81403c3ba3884670199Romain Guy        // window. When hardware accelerated, we need to recreate their display list
208e398956c248808b95aa3d81403c3ba3884670199Romain Guy        // when they scroll
209e398956c248808b95aa3d81403c3ba3884670199Romain Guy        if (isHardwareAccelerated()) {
210e398956c248808b95aa3d81403c3ba3884670199Romain Guy            int count = mContentView.getChildCount();
211e398956c248808b95aa3d81403c3ba3884670199Romain Guy            for (int i = 0; i < count; i++) {
212e398956c248808b95aa3d81403c3ba3884670199Romain Guy                mContentView.getChildAt(i).invalidate();
213e398956c248808b95aa3d81403c3ba3884670199Romain Guy            }
214e398956c248808b95aa3d81403c3ba3884670199Romain Guy        }
215e398956c248808b95aa3d81403c3ba3884670199Romain Guy    }
216e398956c248808b95aa3d81403c3ba3884670199Romain Guy
2172b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb    class TabLayout extends LinearLayout {
2182b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
2192b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        public TabLayout(Context context) {
2202b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            super(context);
2212b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            setChildrenDrawingOrderEnabled(true);
2222b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        }
2232b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
2242b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        @Override
2252b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        protected void onMeasure(int hspec, int vspec) {
2262b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            super.onMeasure(hspec, vspec);
2272b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            int w = getMeasuredWidth();
2282b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            w -= Math.max(0, mContentView.getChildCount() - 1) * mTabOverlap;
2292b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            setMeasuredDimension(w, getMeasuredHeight());
2302b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        }
2312b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
2322b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        @Override
2332b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
2342b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            super.onLayout(changed, left, top, right, bottom);
2352b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            if (getChildCount() > 1) {
2362b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                int nextLeft = getChildAt(0).getRight() - mTabOverlap;
2372b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                for (int i = 1; i < getChildCount(); i++) {
2382b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                    View tab = getChildAt(i);
2392b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                    int w = tab.getRight() - tab.getLeft();
2402b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                    tab.layout(nextLeft, tab.getTop(), nextLeft + w, tab.getBottom());
2412b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                    nextLeft += w - mTabOverlap;
2422b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                }
2432b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            }
2442b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        }
2452b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
2462b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        @Override
2472b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        protected int getChildDrawingOrder(int count, int i) {
2482b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            int next = -1;
249075d493d738fc43bfb6bff56fa302bcb1d5ab7e7Mathew Inwood            if ((i == (count - 1)) && (mSelected >= 0) && (mSelected < count)) {
2502b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                next = mSelected;
2512b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            } else {
2522b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                next = count - i - 1;
253075d493d738fc43bfb6bff56fa302bcb1d5ab7e7Mathew Inwood                if (next <= mSelected && next > 0) {
2542b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                    next--;
2552b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb                }
2562b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            }
2572b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb            return next;
2582b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb        }
2592b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
2602b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb    }
2612b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb
262fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb}
263