TabScrollView.java revision f558f0d9372ecf4eeba86dd52bf67f38ff79c0b8
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 1927b08397a287c46b2121738f653bfef0c08e6f29Michael Kolbimport android.animation.ObjectAnimator; 20fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.content.Context; 21fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.util.AttributeSet; 22fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.view.View; 23fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.widget.HorizontalScrollView; 24fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbimport android.widget.LinearLayout; 25fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 26fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb/** 27fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * custom view for displaying tabs in the tabbed title bar 28fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */ 29fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolbpublic class TabScrollView extends HorizontalScrollView { 30fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 318233facddcc51865d612a919d450db6954aa48e3Michael Kolb private Context mContext; 32fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb private LinearLayout mContentView; 33fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb private int mSelected; 3427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb private int mAnimationDuration; 352b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb private int mTabOverlap; 36fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 37fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb /** 38fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param context 39fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param attrs 40fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param defStyle 41fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */ 42fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb public TabScrollView(Context context, AttributeSet attrs, int defStyle) { 43fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb super(context, attrs, defStyle); 44fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb init(context); 45fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 46fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 47fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb /** 48fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param context 49fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param attrs 50fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */ 51fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb public TabScrollView(Context context, AttributeSet attrs) { 52fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb super(context, attrs); 53fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb init(context); 54fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 55fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 56fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb /** 57fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb * @param context 58fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb */ 59fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb public TabScrollView(Context context) { 60fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb super(context); 61fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb init(context); 62fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 63fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 64fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb private void init(Context ctx) { 658233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContext = 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); 712b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb mContentView = new TabLayout(mContext); 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 90fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb void setSelectedTab(int position) { 91fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb View v = getSelectedTab(); 92fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb if (v != null) { 93b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb v.setActivated(false); 94fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 95fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb mSelected = position; 96fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb v = getSelectedTab(); 97fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb if (v != null) { 98b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb v.setActivated(true); 99fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 100fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb requestLayout(); 101fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 102fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 103ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb int getChildIndex(View v) { 104ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb return mContentView.indexOfChild(v); 105ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb } 106ebba8b4e9dc4f78764d6cfb26738b54d04bc9d27Michael Kolb 107fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb View getSelectedTab() { 108fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb if ((mSelected >= 0) && (mSelected < mContentView.getChildCount())) { 109fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb return mContentView.getChildAt(mSelected); 110fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } else { 111fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb return null; 112fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 113fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 114fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 115fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb void clearTabs() { 116fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb mContentView.removeAllViews(); 117fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 118fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 119fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb void addTab(View tab) { 120fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb mContentView.addView(tab); 121b7b115e301334f813275aa13e7a2cc27bf15fe6aMichael Kolb tab.setActivated(false); 122fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 123fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 124fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb void removeTab(View tab) { 125bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb int ix = mContentView.indexOfChild(tab); 126bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb if (ix == mSelected) { 127bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb mSelected = -1; 128bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb } else if (ix < mSelected) { 129bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb mSelected--; 130bdc2a2420281c96a09bd00136cf9b1244b35ed2bMichael Kolb } 131599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck mContentView.removeView(tab); 132fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 133fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 13427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb private void ensureChildVisible(View child) { 135fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb if (child != null) { 136fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb int childl = child.getLeft(); 137fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb int childr = childl + child.getWidth(); 138fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb int viewl = getScrollX(); 139fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb int viewr = viewl + getWidth(); 140fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb if (childl < viewl) { 141fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb // need scrolling to left 14227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb animateScroll(childl); 143fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } else if (childr > viewr) { 144fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb // need scrolling to right 14527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb animateScroll(childr - viewr + viewl); 146fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 147fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 148fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb } 149fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb 150599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// TODO: These animations are broken and don't work correctly, removing for now 151599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// as animateOut is actually causing issues 152599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// private void animateIn(View tab) { 153599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// ObjectAnimator animator = ObjectAnimator.ofInt(tab, "TranslationX", 500, 0); 154599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.setDuration(mAnimationDuration); 155599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.start(); 156599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// } 157599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// 158599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// private void animateOut(final View tab) { 159599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// ObjectAnimator animator = ObjectAnimator.ofInt( 160599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// tab, "TranslationX", 0, getScrollX() - tab.getRight()); 161599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.setDuration(mAnimationDuration); 162599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.addListener(new AnimatorListenerAdapter() { 163599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// @Override 164599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// public void onAnimationEnd(Animator animation) { 165599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// mContentView.removeView(tab); 166599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// } 167599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// }); 168599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.setInterpolator(new AccelerateInterpolator()); 169599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// animator.start(); 170599e9105f538972be3e2eb96c651b9e12a3516cfJohn Reck// } 17127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb 17227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb private void animateScroll(int newscroll) { 173b3a00ab2336bdb2871924232b744160f47116a78Chet Haase ObjectAnimator animator = ObjectAnimator.ofInt(this, "scroll", getScrollX(), newscroll); 174b3a00ab2336bdb2871924232b744160f47116a78Chet Haase animator.setDuration(mAnimationDuration); 17527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb animator.start(); 17627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb } 17727b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb 17827b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb /** 17927b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * required for animation 18027b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb */ 18127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb public void setScroll(int newscroll) { 18227b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb scrollTo(newscroll, getScrollY()); 18327b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb } 18427b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb 18527b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb /** 18627b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb * required for animation 18727b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb */ 18827b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb public int getScroll() { 18927b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb return getScrollX(); 19027b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb } 19127b08397a287c46b2121738f653bfef0c08e6f29Michael Kolb 1922b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb class TabLayout extends LinearLayout { 1932b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 1942b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb public TabLayout(Context context) { 1952b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb super(context); 1962b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb setChildrenDrawingOrderEnabled(true); 1972b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 1982b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 1992b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb @Override 2002b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb protected void onMeasure(int hspec, int vspec) { 2012b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb super.onMeasure(hspec, vspec); 2022b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb int w = getMeasuredWidth(); 2032b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb w -= Math.max(0, mContentView.getChildCount() - 1) * mTabOverlap; 2042b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb setMeasuredDimension(w, getMeasuredHeight()); 2052b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2062b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 2072b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb @Override 2082b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 2092b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb super.onLayout(changed, left, top, right, bottom); 2102b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb if (getChildCount() > 1) { 2112b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb int nextLeft = getChildAt(0).getRight() - mTabOverlap; 2122b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb for (int i = 1; i < getChildCount(); i++) { 2132b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb View tab = getChildAt(i); 2142b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb int w = tab.getRight() - tab.getLeft(); 2152b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb tab.layout(nextLeft, tab.getTop(), nextLeft + w, tab.getBottom()); 2162b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb nextLeft += w - mTabOverlap; 2172b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2182b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2192b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2202b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 2212b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb @Override 2222b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb protected int getChildDrawingOrder(int count, int i) { 2232b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb int next = -1; 2242b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb if ((i == (count - 1)) && (mSelected >= 0)) { 2252b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb next = mSelected; 2262b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } else { 2272b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb next = count - i - 1; 2282b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb if (next <= mSelected) { 2292b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb next--; 2302b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2312b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2322b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb return next; 2332b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2342b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 2352b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb } 2362b5a13ab55991f55ab7afb107e4401c6fbb5ad64Michael Kolb 237fe25199a6f975c67d28afcc1de56b0f987b66cd8Michael Kolb} 238