Merge "DO NOT MERGE ANYWHERE. Update prelease version to 23.2.0-SNAPSHOT" into mnc-ub-dev
diff --git a/design/src/android/support/design/widget/TabLayout.java b/design/src/android/support/design/widget/TabLayout.java
index d42108d..5640692 100755
--- a/design/src/android/support/design/widget/TabLayout.java
+++ b/design/src/android/support/design/widget/TabLayout.java
@@ -215,7 +215,6 @@
     private View.OnClickListener mTabClickListener;
 
     private ValueAnimatorCompat mScrollAnimator;
-    private ValueAnimatorCompat mIndicatorAnimator;
 
     public TabLayout(Context context) {
         this(context, null);
@@ -329,20 +328,30 @@
      * @param updateSelectedText Whether to update the text's selected state.
      */
     public void setScrollPosition(int position, float positionOffset, boolean updateSelectedText) {
-        if (mIndicatorAnimator != null && mIndicatorAnimator.isRunning()) {
-            return;
-        }
-        if (position < 0 || position >= mTabStrip.getChildCount()) {
+        setScrollPosition(position, positionOffset, updateSelectedText, true);
+    }
+
+    private void setScrollPosition(int position, float positionOffset, boolean updateSelectedText,
+            boolean updateIndicatorPosition) {
+        final int roundedPosition = Math.round(position + positionOffset);
+        if (roundedPosition < 0 || roundedPosition >= mTabStrip.getChildCount()) {
             return;
         }
 
-        // Set the indicator position and update the scroll to match
-        mTabStrip.setIndicatorPositionFromTabPosition(position, positionOffset);
+        // Set the indicator position, if enabled
+        if (updateIndicatorPosition) {
+            mTabStrip.setIndicatorPositionFromTabPosition(position, positionOffset);
+        }
+
+        // Now update the scroll position, canceling any running animation
+        if (mScrollAnimator != null && mScrollAnimator.isRunning()) {
+            mScrollAnimator.cancel();
+        }
         scrollTo(calculateScrollXForTab(position, positionOffset), 0);
 
-        // Update the 'selected state' view as we scroll
+        // Update the 'selected state' view as we scroll, if enabled
         if (updateSelectedText) {
-            setSelectedTabView(Math.round(position + positionOffset));
+            setSelectedTabView(roundedPosition);
         }
     }
 
@@ -1443,7 +1452,7 @@
         private int mIndicatorLeft = -1;
         private int mIndicatorRight = -1;
 
-        private ValueAnimatorCompat mCurrentAnimator;
+        private ValueAnimatorCompat mIndicatorAnimator;
 
         SlidingTabStrip(Context context) {
             super(context);
@@ -1476,6 +1485,10 @@
         }
 
         void setIndicatorPositionFromTabPosition(int position, float positionOffset) {
+            if (mIndicatorAnimator != null && mIndicatorAnimator.isRunning()) {
+                mIndicatorAnimator.cancel();
+            }
+
             mSelectedPosition = position;
             mSelectionOffset = positionOffset;
             updateIndicatorPosition();
@@ -1546,13 +1559,13 @@
         protected void onLayout(boolean changed, int l, int t, int r, int b) {
             super.onLayout(changed, l, t, r, b);
 
-            if (mCurrentAnimator != null && mCurrentAnimator.isRunning()) {
+            if (mIndicatorAnimator != null && mIndicatorAnimator.isRunning()) {
                 // If we're currently running an animation, lets cancel it and start a
                 // new animation with the remaining duration
-                mCurrentAnimator.cancel();
-                final long duration = mCurrentAnimator.getDuration();
+                mIndicatorAnimator.cancel();
+                final long duration = mIndicatorAnimator.getDuration();
                 animateIndicatorToPosition(mSelectedPosition,
-                        Math.round((1f - mCurrentAnimator.getAnimatedFraction()) * duration));
+                        Math.round((1f - mIndicatorAnimator.getAnimatedFraction()) * duration));
             } else {
                 // If we've been layed out, update the indicator position
                 updateIndicatorPosition();
@@ -1592,6 +1605,10 @@
         }
 
         void animateIndicatorToPosition(final int position, int duration) {
+            if (mIndicatorAnimator != null && mIndicatorAnimator.isRunning()) {
+                mIndicatorAnimator.cancel();
+            }
+
             final boolean isRtl = ViewCompat.getLayoutDirection(this)
                     == ViewCompat.LAYOUT_DIRECTION_RTL;
 
@@ -1645,15 +1662,8 @@
                         mSelectedPosition = position;
                         mSelectionOffset = 0f;
                     }
-
-                    @Override
-                    public void onAnimationCancel(ValueAnimatorCompat animator) {
-                        mSelectedPosition = position;
-                        mSelectionOffset = 0f;
-                    }
                 });
                 animator.start();
-                mCurrentAnimator = animator;
             }
         }
 
@@ -1746,7 +1756,12 @@
                 final boolean updateText = (mScrollState == ViewPager.SCROLL_STATE_DRAGGING)
                         || (mScrollState == ViewPager.SCROLL_STATE_SETTLING
                         && mPreviousScrollState == ViewPager.SCROLL_STATE_DRAGGING);
-                tabLayout.setScrollPosition(position, positionOffset, updateText);
+                // Update the indicator if we're not settling after being idle. This is caused
+                // from a setCurrentItem() call and will be handled by an animation from
+                // onPageSelected() instead.
+                final boolean updateIndicator = !(mScrollState == ViewPager.SCROLL_STATE_SETTLING
+                        && mPreviousScrollState == ViewPager.SCROLL_STATE_IDLE);
+                tabLayout.setScrollPosition(position, positionOffset, updateText, updateIndicator);
             }
         }
 
@@ -1756,8 +1771,10 @@
             if (tabLayout != null && tabLayout.getSelectedTabPosition() != position) {
                 // Select the tab, only updating the indicator if we're not being dragged/settled
                 // (since onPageScrolled will handle that).
-                tabLayout.selectTab(tabLayout.getTabAt(position),
-                        mScrollState == ViewPager.SCROLL_STATE_IDLE);
+                final boolean updateIndicator = mScrollState == ViewPager.SCROLL_STATE_IDLE
+                        || (mScrollState == ViewPager.SCROLL_STATE_SETTLING
+                        && mPreviousScrollState == ViewPager.SCROLL_STATE_IDLE);
+                tabLayout.selectTab(tabLayout.getTabAt(position), updateIndicator);
             }
         }
     }
diff --git a/v4/api/current.txt b/v4/api/current.txt
index 1d17a08..26e3e8cf 100644
--- a/v4/api/current.txt
+++ b/v4/api/current.txt
@@ -3415,6 +3415,7 @@
     method public static void setCompoundDrawablesRelative(android.widget.TextView, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable);
     method public static void setCompoundDrawablesRelativeWithIntrinsicBounds(android.widget.TextView, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable);
     method public static void setCompoundDrawablesRelativeWithIntrinsicBounds(android.widget.TextView, int, int, int, int);
+    method public static void setTextAppearance(android.widget.TextView, int);
   }
 
   public abstract interface TintableCompoundButton {
diff --git a/v4/api23/android/support/v4/widget/TextViewCompatApi23.java b/v4/api23/android/support/v4/widget/TextViewCompatApi23.java
new file mode 100644
index 0000000..8370bfc
--- /dev/null
+++ b/v4/api23/android/support/v4/widget/TextViewCompatApi23.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.support.v4.widget;
+
+import android.support.annotation.IdRes;
+import android.support.annotation.NonNull;
+import android.widget.TextView;
+
+class TextViewCompatApi23 {
+    public static void setTextAppearance(@NonNull TextView textView, @IdRes int resId) {
+        textView.setTextAppearance(resId);
+    }
+}
diff --git a/v4/java/android/support/v4/widget/TextViewCompat.java b/v4/java/android/support/v4/widget/TextViewCompat.java
index d8c5385..621ee66 100644
--- a/v4/java/android/support/v4/widget/TextViewCompat.java
+++ b/v4/java/android/support/v4/widget/TextViewCompat.java
@@ -18,6 +18,7 @@
 
 import android.graphics.drawable.Drawable;
 import android.os.Build;
+import android.support.annotation.IdRes;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.widget.TextView;
@@ -42,6 +43,7 @@
                 int start, int top, int end, int bottom);
         int getMaxLines(TextView textView);
         int getMinLines(TextView textView);
+        void setTextAppearance(@NonNull TextView textView, @IdRes int resId);
     }
 
     static class BaseTextViewCompatImpl implements TextViewCompatImpl {
@@ -74,6 +76,11 @@
         public int getMinLines(TextView textView) {
             return TextViewCompatDonut.getMinLines(textView);
         }
+
+        @Override
+        public void setTextAppearance(TextView textView, int resId) {
+            TextViewCompatDonut.setTextAppearance(textView, resId);
+        }
     }
 
     static class JbTextViewCompatImpl extends BaseTextViewCompatImpl {
@@ -137,11 +144,20 @@
         }
     }
 
+    static class Api23TextViewCompatImpl extends JbMr2TextViewCompatImpl {
+        @Override
+        public void setTextAppearance(@NonNull TextView textView, @IdRes int resId) {
+            TextViewCompatApi23.setTextAppearance(textView, resId);
+        }
+    }
+
     static final TextViewCompatImpl IMPL;
 
     static {
         final int version = Build.VERSION.SDK_INT;
-        if (version >= 18) {
+        if (version >= 23) {
+            IMPL = new Api23TextViewCompatImpl();
+        } else if (version >= 18) {
             IMPL = new JbMr2TextViewCompatImpl();
         } else if (version >= 17) {
             IMPL = new JbMr1TextViewCompatImpl();
@@ -231,4 +247,19 @@
     public static int getMinLines(@NonNull TextView textView) {
         return IMPL.getMinLines(textView);
     }
+
+    /**
+     * Sets the text appearance from the specified style resource.
+     * <p>
+     * Use a framework-defined {@code TextAppearance} style like
+     * {@link android.R.style#TextAppearance_Material_Body1 @android:style/TextAppearance.Material.Body1}
+     * or see {@link android.R.styleable#TextAppearance TextAppearance} for the
+     * set of attributes that can be used in a custom style.
+     *
+     * @param textView The TextView against which to invoke the method.
+     * @param resId    The resource identifier of the style to apply.
+     */
+    public static void setTextAppearance(@NonNull TextView textView, @IdRes int resId) {
+        IMPL.setTextAppearance(textView, resId);
+    }
 }
diff --git a/v4/java/android/support/v4/widget/TextViewCompatDonut.java b/v4/java/android/support/v4/widget/TextViewCompatDonut.java
index 9a36e82..ba155fe 100644
--- a/v4/java/android/support/v4/widget/TextViewCompatDonut.java
+++ b/v4/java/android/support/v4/widget/TextViewCompatDonut.java
@@ -91,4 +91,8 @@
         }
         return -1;
     }
+
+    static void setTextAppearance(TextView textView, int resId) {
+        textView.setTextAppearance(textView.getContext(), resId);
+    }
 }