Merge "Move PreferenceGroupAdapter creation out of PreferenceScreen"
diff --git a/v17/leanback/res/values-en-rAU/strings.xml b/v17/leanback/res/values-en-rAU/strings.xml
new file mode 100644
index 0000000..ed22ccd
--- /dev/null
+++ b/v17/leanback/res/values-en-rAU/strings.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+Copyright (C) 2014 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.
+ -->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="orb_search_action" msgid="5651268540267663887">"Search Action"</string>
+    <string name="lb_search_bar_hint" msgid="8325490927970116252">"Search"</string>
+    <string name="lb_search_bar_hint_speech" msgid="5511270823320183816">"Speak to search"</string>
+    <string name="lb_search_bar_hint_with_title" msgid="1627103380996590035">"Search <xliff:g id="SEARCH_CONTEXT">%1$s</xliff:g>"</string>
+    <string name="lb_search_bar_hint_with_title_speech" msgid="2712734639766312034">"Speak to search <xliff:g id="SEARCH_CONTEXT">%1$s</xliff:g>"</string>
+    <string name="lb_control_display_fast_forward_multiplier" msgid="4541442045214207774">"%1$dX"</string>
+    <string name="lb_control_display_rewind_multiplier" msgid="3097220783222910245">"%1$dX"</string>
+    <string name="lb_playback_controls_play" msgid="731953341987346903">"Play"</string>
+    <string name="lb_playback_controls_pause" msgid="6189521112079849518">"Pause"</string>
+    <string name="lb_playback_controls_fast_forward" msgid="8569951318244687220">"Fast-Forward"</string>
+    <string name="lb_playback_controls_fast_forward_multiplier" msgid="1058753672110224526">"Fast Forward %1$dX"</string>
+    <string name="lb_playback_controls_rewind" msgid="2227196334132350684">"Rewind"</string>
+    <string name="lb_playback_controls_rewind_multiplier" msgid="1640629531440849942">"Rewind %1$dX"</string>
+    <string name="lb_playback_controls_skip_next" msgid="2946499493161095772">"Skip Next"</string>
+    <string name="lb_playback_controls_skip_previous" msgid="2326801832933178348">"Skip Previous"</string>
+    <string name="lb_playback_controls_more_actions" msgid="2330770008796987655">"More Actions"</string>
+    <string name="lb_playback_controls_thumb_up" msgid="6530420347129222601">"Deselect Thumb Up"</string>
+    <string name="lb_playback_controls_thumb_up_outline" msgid="1577637924003500946">"Select Thumb Up"</string>
+    <string name="lb_playback_controls_thumb_down" msgid="4498041193172964797">"Deselect Thumb Down"</string>
+    <string name="lb_playback_controls_thumb_down_outline" msgid="2936020280629424365">"Select Thumb Down"</string>
+    <string name="lb_playback_controls_repeat_none" msgid="87476947476529036">"Repeat None"</string>
+    <string name="lb_playback_controls_repeat_all" msgid="6730354406289599000">"Repeat All"</string>
+    <string name="lb_playback_controls_repeat_one" msgid="3285202316452203619">"Repeat One"</string>
+    <string name="lb_playback_controls_shuffle_enable" msgid="1099874107835264529">"Enable Shuffle"</string>
+    <string name="lb_playback_controls_shuffle_disable" msgid="8388150597335115226">"Disable Shuffle"</string>
+    <string name="lb_playback_controls_high_quality_enable" msgid="202415780019335254">"Enable High Quality"</string>
+    <string name="lb_playback_controls_high_quality_disable" msgid="8637371582779057866">"Disable High Quality"</string>
+    <string name="lb_playback_controls_closed_captioning_enable" msgid="2429655367176440226">"Enable Closed Captioning"</string>
+    <string name="lb_playback_controls_closed_captioning_disable" msgid="6133362019475930048">"Disable Closed Captioning"</string>
+</resources>
diff --git a/v17/leanback/src/android/support/v17/leanback/widget/GridLayoutManager.java b/v17/leanback/src/android/support/v17/leanback/widget/GridLayoutManager.java
index b0849e9..ad2211c 100644
--- a/v17/leanback/src/android/support/v17/leanback/widget/GridLayoutManager.java
+++ b/v17/leanback/src/android/support/v17/leanback/widget/GridLayoutManager.java
@@ -418,7 +418,8 @@
     private RecyclerView.State mState;
     private RecyclerView.Recycler mRecycler;
 
-    private boolean mInLayout = false;
+    private boolean mInLayout;
+    private boolean mInScroll;
     private boolean mInFastRelayout;
     /**
      * During full layout pass, when GridView had focus: onLayoutChildren will
@@ -1752,6 +1753,7 @@
             return 0;
         }
         saveContext(recycler, state);
+        mInScroll = true;
         int result;
         if (mOrientation == HORIZONTAL) {
             result = scrollDirectionPrimary(dx);
@@ -1759,6 +1761,7 @@
             result = scrollDirectionSecondary(dx);
         }
         leaveContext();
+        mInScroll = false;
         return result;
     }
 
@@ -1768,6 +1771,7 @@
         if (!mLayoutEnabled || !hasDoneFirstLayout()) {
             return 0;
         }
+        mInScroll = true;
         saveContext(recycler, state);
         int result;
         if (mOrientation == VERTICAL) {
@@ -1776,6 +1780,7 @@
             result = scrollDirectionSecondary(dy);
         }
         leaveContext();
+        mInScroll = false;
         return result;
     }
 
@@ -2144,7 +2149,7 @@
             // scroll to a view whose item has been removed.
             return true;
         }
-        if (!mInLayout && !mInSelection) {
+        if (!mInLayout && !mInSelection && !mInScroll) {
             scrollToView(child, true);
         }
         return true;
diff --git a/v17/tests/res/layout/horizontal_grid.xml b/v17/tests/res/layout/horizontal_grid.xml
index 5119f79..6c4eaf1 100644
--- a/v17/tests/res/layout/horizontal_grid.xml
+++ b/v17/tests/res/layout/horizontal_grid.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
-  <android.support.v17.leanback.widget.HorizontalGridView
+  <android.support.v17.leanback.widget.HorizontalGridViewEx
       android:id="@+id/gridview"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
diff --git a/v17/tests/res/layout/horizontal_grid_testredundantappendremove2.xml b/v17/tests/res/layout/horizontal_grid_testredundantappendremove2.xml
index b539f3c..fdfc0ea 100644
--- a/v17/tests/res/layout/horizontal_grid_testredundantappendremove2.xml
+++ b/v17/tests/res/layout/horizontal_grid_testredundantappendremove2.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
-  <android.support.v17.leanback.widget.HorizontalGridView
+  <android.support.v17.leanback.widget.HorizontalGridViewEx
       android:id="@+id/gridview"
       android:layout_width="960dp"
       android:layout_height="492dp"
diff --git a/v17/tests/res/layout/vertical_grid.xml b/v17/tests/res/layout/vertical_grid.xml
index 85e1d46..f4c0065 100644
--- a/v17/tests/res/layout/vertical_grid.xml
+++ b/v17/tests/res/layout/vertical_grid.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
-  <android.support.v17.leanback.widget.VerticalGridView
+  <android.support.v17.leanback.widget.VerticalGridViewEx
       android:id="@+id/gridview"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
diff --git a/v17/tests/res/layout/vertical_grid_testredundantappendremove.xml b/v17/tests/res/layout/vertical_grid_testredundantappendremove.xml
index 4ce56c5..bf056f8 100644
--- a/v17/tests/res/layout/vertical_grid_testredundantappendremove.xml
+++ b/v17/tests/res/layout/vertical_grid_testredundantappendremove.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
-  <android.support.v17.leanback.widget.VerticalGridView
+  <android.support.v17.leanback.widget.VerticalGridViewEx
       android:id="@+id/gridview"
       android:layout_width="960dp"
       android:layout_height="492dp"
diff --git a/v17/tests/res/layout/vertical_linear.xml b/v17/tests/res/layout/vertical_linear.xml
index b2c74df..0a1d00c 100644
--- a/v17/tests/res/layout/vertical_linear.xml
+++ b/v17/tests/res/layout/vertical_linear.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     >
-  <android.support.v17.leanback.widget.VerticalGridView
+  <android.support.v17.leanback.widget.VerticalGridViewEx
       android:id="@+id/gridview"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
diff --git a/v17/tests/src/android/support/v17/leanback/widget/GridActivity.java b/v17/tests/src/android/support/v17/leanback/widget/GridActivity.java
index ba6cd39..fdef479 100644
--- a/v17/tests/src/android/support/v17/leanback/widget/GridActivity.java
+++ b/v17/tests/src/android/support/v17/leanback/widget/GridActivity.java
@@ -21,7 +21,6 @@
 import android.support.v17.leanback.widget.BaseGridView;
 import android.support.v17.leanback.widget.OnChildSelectedListener;
 import android.app.Activity;
-import android.content.Context;
 import android.content.Intent;
 import android.graphics.Color;
 import android.os.Bundle;
@@ -38,6 +37,7 @@
  * @hide from javadoc
  */
 public class GridActivity extends Activity {
+
     private static final String TAG = "GridActivity";
 
     public static final String EXTRA_LAYOUT_RESOURCE_ID = "layoutResourceId";
@@ -46,11 +46,13 @@
     public static final String EXTRA_ITEMS_FOCUSABLE = "itemsFocusable";
     public static final String EXTRA_STAGGERED = "staggered";
     public static final String EXTRA_REQUEST_LAYOUT_ONFOCUS = "requestLayoutOnFocus";
+    public static final String EXTRA_REQUEST_FOCUS_ONLAYOUT = "requstFocusOnLayout";
     public static final String SELECT_ACTION = "android.test.leanback.widget.SELECT";
 
     static final int DEFAULT_NUM_ITEMS = 100;
     static final boolean DEFAULT_STAGGERED = true;
     static final boolean DEFAULT_REQUEST_LAYOUT_ONFOCUS = false;
+    static final boolean DEFAULT_REQUEST_FOCUS_ONLAYOUT = false;
 
     private static final boolean DEBUG = false;
 
@@ -59,6 +61,7 @@
     int mNumItems;
     boolean mStaggered;
     boolean mRequestLayoutOnFocus;
+    boolean mRequestFocusOnLayout;
 
     int[] mGridViewLayoutSize;
     BaseGridView mGridView;
@@ -92,6 +95,8 @@
         mStaggered = intent.getBooleanExtra(EXTRA_STAGGERED, DEFAULT_STAGGERED);
         mRequestLayoutOnFocus = intent.getBooleanExtra(EXTRA_REQUEST_LAYOUT_ONFOCUS,
                 DEFAULT_REQUEST_LAYOUT_ONFOCUS);
+        mRequestFocusOnLayout = intent.getBooleanExtra(EXTRA_REQUEST_FOCUS_ONLAYOUT,
+                DEFAULT_REQUEST_FOCUS_ONLAYOUT);
         mItemLengths = intent.getIntArrayExtra(EXTRA_ITEMS);
         mItemFocusables = intent.getBooleanArrayExtra(EXTRA_ITEMS_FOCUSABLE);
 
@@ -200,7 +205,18 @@
         @Override
         public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
             if (DEBUG) Log.v(TAG, "createViewHolder " + viewType);
-            TextView textView = new TextView(parent.getContext());
+            TextView textView = new TextView(parent.getContext()) {
+                @Override
+                protected void onLayout(boolean change, int left, int top, int right, int bottom) {
+                    super.onLayout(change, left, top, right, bottom);
+                    if (mRequestFocusOnLayout) {
+                        if (hasFocus()) {
+                            clearFocus();
+                            requestFocus();
+                        }
+                    }
+                }
+            };
             textView.setTextColor(Color.BLACK);
             textView.setOnFocusChangeListener(mItemFocusChangeListener);
             return new ViewHolder(textView);
diff --git a/v17/tests/src/android/support/v17/leanback/widget/GridWidgetTest.java b/v17/tests/src/android/support/v17/leanback/widget/GridWidgetTest.java
index 178d59a..80fc63f 100644
--- a/v17/tests/src/android/support/v17/leanback/widget/GridWidgetTest.java
+++ b/v17/tests/src/android/support/v17/leanback/widget/GridWidgetTest.java
@@ -1089,4 +1089,48 @@
 
     }
 
+    public void testSmoothscrollerInterrupted() throws Throwable {
+        mInstrumentation = getInstrumentation();
+        Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
+        intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID,
+                R.layout.vertical_linear);
+        intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true);
+        int[] items = new int[100];
+        for (int i = 0; i < items.length; i++) {
+            items[i] = 680;
+        }
+        intent.putExtra(GridActivity.EXTRA_ITEMS, items);
+        intent.putExtra(GridActivity.EXTRA_STAGGERED, false);
+        mOrientation = BaseGridView.VERTICAL;
+        mNumRows = 1;
+
+        initActivity(intent);
+
+        mGridView.setSelectedPositionSmooth(0);
+        waitForScrollIdle(mVerifyLayout);
+        assertTrue(mGridView.getChildAt(0).hasFocus());
+
+        // Pressing lots of key to make sure smooth scroller is running
+        for (int i = 0; i < 20; i++) {
+            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+        }
+        Thread.sleep(100);
+        int total = 0;
+        while (mGridView.getLayoutManager().isSmoothScrolling() ||
+                mGridView.getScrollState() != BaseGridView.SCROLL_STATE_IDLE) {
+            if ((total += 10) >= WAIT_FOR_SCROLL_IDLE_TIMEOUT_MS) {
+                throw new RuntimeException("waitForScrollIdle Timeout");
+            }
+            try {
+                // Repeatedly pressing to make sure pending keys does not drop to zero.
+                Thread.sleep(10);
+                sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+            } catch (InterruptedException ex) {
+                break;
+            }
+        }
+
+        assertTrue("LinearSmoothScroller would not use many RV.smoothScrollBy() calls",
+                ((VerticalGridViewEx) mGridView).mSmoothScrollByCalled < 10);
+    }
 }
diff --git a/v17/tests/src/android/support/v17/leanback/widget/HorizontalGridViewEx.java b/v17/tests/src/android/support/v17/leanback/widget/HorizontalGridViewEx.java
new file mode 100644
index 0000000..2c49283
--- /dev/null
+++ b/v17/tests/src/android/support/v17/leanback/widget/HorizontalGridViewEx.java
@@ -0,0 +1,27 @@
+package android.support.v17.leanback.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+class HorizontalGridViewEx extends HorizontalGridView {
+
+    public int mSmoothScrollByCalled;
+
+    public HorizontalGridViewEx(Context context) {
+        super(context);
+    }
+
+    public HorizontalGridViewEx(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public HorizontalGridViewEx(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    public void smoothScrollBy(int dx, int dy) {
+        mSmoothScrollByCalled++;
+        super.smoothScrollBy(dx, dy);
+    }
+}
\ No newline at end of file
diff --git a/v17/tests/src/android/support/v17/leanback/widget/VerticalGridViewEx.java b/v17/tests/src/android/support/v17/leanback/widget/VerticalGridViewEx.java
new file mode 100644
index 0000000..e262d54
--- /dev/null
+++ b/v17/tests/src/android/support/v17/leanback/widget/VerticalGridViewEx.java
@@ -0,0 +1,27 @@
+package android.support.v17.leanback.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+class VerticalGridViewEx extends VerticalGridView {
+
+    public int mSmoothScrollByCalled;
+
+    public VerticalGridViewEx(Context context) {
+        super(context);
+    }
+
+    public VerticalGridViewEx(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public VerticalGridViewEx(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    public void smoothScrollBy(int dx, int dy) {
+        mSmoothScrollByCalled++;
+        super.smoothScrollBy(dx, dy);
+    }
+}
\ No newline at end of file
diff --git a/v7/appcompat/res/values-en-rAU/strings.xml b/v7/appcompat/res/values-en-rAU/strings.xml
new file mode 100644
index 0000000..a85156e
--- /dev/null
+++ b/v7/appcompat/res/values-en-rAU/strings.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--  Copyright (C) 2012 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.
+ -->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="abc_action_mode_done" msgid="4076576682505996667">"Done"</string>
+    <string name="abc_action_bar_home_description" msgid="4600421777120114993">"Navigate home"</string>
+    <string name="abc_action_bar_up_description" msgid="1594238315039666878">"Navigate up"</string>
+    <string name="abc_action_menu_overflow_description" msgid="3588849162933574182">"More options"</string>
+    <string name="abc_toolbar_collapse_description" msgid="1603543279005712093">"Collapse"</string>
+    <string name="abc_action_bar_home_description_format" msgid="1397052879051804371">"%1$s, %2$s"</string>
+    <string name="abc_action_bar_home_subtitle_description_format" msgid="6623331958280229229">"%1$s, %2$s, %3$s"</string>
+    <string name="abc_searchview_description_search" msgid="8264924765203268293">"Search"</string>
+    <string name="abc_search_hint" msgid="7723749260725869598">"Search…"</string>
+    <string name="abc_searchview_description_query" msgid="2550479030709304392">"Search query"</string>
+    <string name="abc_searchview_description_clear" msgid="3691816814315814921">"Clear query"</string>
+    <string name="abc_searchview_description_submit" msgid="8928215447528550784">"Submit query"</string>
+    <string name="abc_searchview_description_voice" msgid="893419373245838918">"Voice search"</string>
+    <string name="abc_activitychooserview_choose_application" msgid="2031811694353399454">"Choose an app"</string>
+    <string name="abc_activity_chooser_view_see_all" msgid="7468859129482906941">"See all"</string>
+    <string name="abc_shareactionprovider_share_with_application" msgid="7165123711973476752">"Share with %s"</string>
+    <string name="abc_shareactionprovider_share_with" msgid="3421042268587513524">"Share with"</string>
+</resources>
diff --git a/v7/mediarouter/res/values-en-rAU/strings.xml b/v7/mediarouter/res/values-en-rAU/strings.xml
new file mode 100644
index 0000000..f5a8531
--- /dev/null
+++ b/v7/mediarouter/res/values-en-rAU/strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--  Copyright (C) 2013 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.
+ -->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="mr_system_route_name" msgid="5441529851481176817">"System"</string>
+    <string name="mr_user_route_category_name" msgid="7498112907524977311">"Devices"</string>
+    <string name="mr_media_route_button_content_description" msgid="8327680881775995150">"Cast"</string>
+    <string name="mr_media_route_chooser_title" msgid="7106830097177242655">"Connect to device"</string>
+    <string name="mr_media_route_chooser_searching" msgid="7553005460920830010">"Searching for devices…"</string>
+    <string name="mr_media_route_controller_disconnect" msgid="109793632378378069">"Disconnect"</string>
+    <string name="mr_media_route_controller_stop" msgid="5398645111664294430">"Stop casting"</string>
+    <string name="mr_media_route_controller_settings_description" msgid="379358765881274425">"Route settings"</string>
+    <string name="mr_media_route_controller_play" msgid="5214423499524760404">"Play"</string>
+    <string name="mr_media_route_controller_pause" msgid="8315773974194466049">"Pause"</string>
+</resources>