Add grid manager demo to Support7Demo app

Change-Id: Ie90a4e2be35db1500adcf8e358b3d9d8fccc68b2
diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml
index 32c14ae..14076c3 100644
--- a/samples/Support7Demos/AndroidManifest.xml
+++ b/samples/Support7Demos/AndroidManifest.xml
@@ -204,6 +204,15 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".widget.GridLayoutManagerActivity"
+                  android:label="@string/grid_layout_manager"
+                  android:theme="@style/Theme.AppCompat">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.example.android.supportv7.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
         <activity android:name=".view.CardViewActivity"
                   android:label="@string/card_view"
                   android:theme="@style/Theme.AppCompat">
diff --git a/samples/Support7Demos/res/layout/activity_linear_layout_manager.xml b/samples/Support7Demos/res/layout/activity_base_layout_manager.xml
similarity index 88%
rename from samples/Support7Demos/res/layout/activity_linear_layout_manager.xml
rename to samples/Support7Demos/res/layout/activity_base_layout_manager.xml
index d671c73..f75018e 100644
--- a/samples/Support7Demos/res/layout/activity_linear_layout_manager.xml
+++ b/samples/Support7Demos/res/layout/activity_base_layout_manager.xml
@@ -21,6 +21,13 @@
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">
+        <CheckBox
+                android:focusable="true"
+                android:focusableInTouchMode="true"
+                android:id="@+id/enable_smooth_scroll"
+                android:text="smooth scroll"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
         <EditText
                 android:id="@+id/scroll_offset"
                 android:layout_width="wrap_content"
@@ -31,11 +38,10 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/spinner"/>
-        <CheckBox
-                android:id="@+id/enable_smooth_scroll"
-                android:text="smooth scroll"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"/>
+        <Button android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="scroll"
+                android:onClick="onScrollClicked"/>
     </LinearLayout>
 
     <android.support.v7.widget.RecyclerView
diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml
index 8530f00..04dad5d 100644
--- a/samples/Support7Demos/res/values/strings.xml
+++ b/samples/Support7Demos/res/values/strings.xml
@@ -97,7 +97,8 @@
 
     <string name="recycler_view">RecyclerView/RecyclerViewActivity</string>
     <string name="animated_recycler_view">RecyclerView/AnimatedRecyclerView</string>
-    <string name="linear_layout_manager">Linear Layout Manager</string>
+    <string name="linear_layout_manager">RecyclerView/Linear Layout Manager</string>
+    <string name="grid_layout_manager">RecyclerView/Grid Layout Manager</string>
     <string name="checkbox_orientation">Horz.</string>
     <string name="checkbox_reverse">Rev.</string>
     <string name="checkbox_layout_dir">Layout Dir</string>
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/widget/BaseLayoutManagerActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/widget/BaseLayoutManagerActivity.java
new file mode 100644
index 0000000..0a6ac6d
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/widget/BaseLayoutManagerActivity.java
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+package com.example.android.supportv7.widget;
+
+import com.example.android.supportv7.Cheeses;
+import com.example.android.supportv7.R;
+import com.example.android.supportv7.widget.adapter.SimpleStringAdapter;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+/**
+ * A simple activity that can be extended to demonstrate LayoutManagers.
+ * <p>
+ * It initializes a sample adapter and a list of configuration options. Extending activities can
+ * define the {@link ConfigToggle} list depending on its functionality.
+ */
+abstract public class BaseLayoutManagerActivity<T extends RecyclerView.LayoutManager>
+        extends Activity {
+
+    protected T mLayoutManager;
+
+    protected RecyclerView mRecyclerView;
+
+    private ConfigToggle[] mConfigToggles;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_base_layout_manager);
+        initToggles();
+        initRecyclerView();
+        initSpinner();
+    }
+
+    abstract protected T createLayoutManager();
+
+    private void initRecyclerView() {
+        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
+        mRecyclerView.setHasFixedSize(true);
+        mLayoutManager = createLayoutManager();
+        mRecyclerView.setLayoutManager(mLayoutManager);
+        mRecyclerView.setAdapter(createAdapter());
+        mRecyclerView.getItemAnimator().setSupportsChangeAnimations(true);
+        onRecyclerViewInit(mRecyclerView);
+    }
+
+    protected void onRecyclerViewInit(RecyclerView recyclerView) {
+
+    }
+
+    protected RecyclerView.Adapter createAdapter() {
+        return new SimpleStringAdapter(this, Cheeses.sCheeseStrings) {
+            @Override
+            public SimpleStringAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                    int viewType) {
+                final SimpleStringAdapter.ViewHolder vh = super
+                        .onCreateViewHolder(parent, viewType);
+                vh.itemView.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        final int pos = vh.getPosition();
+                        if (pos + 1 < getItemCount()) {
+                            swap(pos, pos + 1);
+                        }
+                        notifyItemChanged(pos);
+                    }
+                });
+                return vh;
+            }
+        };
+    }
+
+    private void initToggles() {
+        mConfigToggles = createConfigToggles();
+        RecyclerView configView = (RecyclerView) findViewById(R.id.config_recycler_view);
+        configView.setAdapter(mConfigAdapter);
+        configView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,
+                false));
+        configView.setHasFixedSize(true);
+    }
+
+    public void onScrollClicked(View view) {
+        final EditText scrollOffset = (EditText) findViewById(R.id.scroll_offset);
+        final CheckBox checkBox = (CheckBox) findViewById(R.id.enable_smooth_scroll);
+        final Spinner spinner = (Spinner) findViewById(R.id.spinner);
+
+        Integer offset = null;
+        String offsetString = scrollOffset.getText().toString();
+        try {
+            offset = Integer.parseInt(offsetString);
+        } catch (NumberFormatException ex) {
+
+        }
+        final boolean smooth = checkBox.isChecked();
+        if (offset == null) {
+            scrollToPosition(smooth, spinner.getSelectedItemPosition());
+        } else {
+            scrollToPositionWithOffset(smooth, spinner.getSelectedItemPosition(), offset);
+        }
+    }
+
+    private void initSpinner() {
+        final Spinner spinner = (Spinner) findViewById(R.id.spinner);
+        spinner.setAdapter(new BaseAdapter() {
+            @Override
+            public int getCount() {
+                return mRecyclerView.getAdapter().getItemCount();
+            }
+
+            @Override
+            public Integer getItem(int position) {
+                return position;
+            }
+
+            @Override
+            public long getItemId(int position) {
+                return position;
+            }
+
+            @Override
+            public View getView(int position, View convertView, ViewGroup parent) {
+                if (convertView == null) {
+                    convertView = new TextView(parent.getContext());
+                }
+                ((TextView) convertView).setText(" " + position + " ");
+                return convertView;
+            }
+        });
+    }
+
+    protected void scrollToPosition(boolean smooth, int position) {
+        if (smooth) {
+            mRecyclerView.smoothScrollToPosition(position);
+        } else {
+            mRecyclerView.scrollToPosition(position);
+        }
+    }
+
+    protected void scrollToPositionWithOffset(boolean smooth, int position, int offset) {
+        scrollToPosition(smooth, position);
+    }
+
+    abstract ConfigToggle[] createConfigToggles();
+
+    private class ConfigViewHolder extends RecyclerView.ViewHolder
+            implements CompoundButton.OnCheckedChangeListener {
+
+        private CheckBox mCheckBox;
+
+        private ConfigToggle mConfigToggle;
+
+        public ConfigViewHolder(View itemView) {
+            super(itemView);
+            mCheckBox = (CheckBox) itemView;
+            mCheckBox.setOnCheckedChangeListener(this);
+        }
+
+        public void bind(ConfigToggle toggle) {
+            mConfigToggle = toggle;
+            mCheckBox.setText(toggle.getText());
+            mCheckBox.setChecked(toggle.isChecked());
+        }
+
+        @Override
+        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+            if (mConfigToggle != null) {
+                mConfigToggle.onChange(isChecked);
+            }
+        }
+    }
+
+
+    public abstract static class ConfigToggle {
+
+        private String mLabel;
+
+        protected ConfigToggle(Context context, int labelId) {
+            mLabel = context.getResources().getString(labelId);
+        }
+
+        public String getText() {
+            return mLabel;
+        }
+
+        abstract public boolean isChecked();
+
+        abstract public void onChange(boolean newValue);
+    }
+
+
+    private RecyclerView.Adapter mConfigAdapter = new RecyclerView.Adapter<ConfigViewHolder>() {
+        @Override
+        public ConfigViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+            return new ConfigViewHolder(new CheckBox(parent.getContext()));
+        }
+
+        @Override
+        public void onBindViewHolder(ConfigViewHolder holder, int position) {
+            ConfigToggle toggle = mConfigToggles[position];
+            holder.bind(toggle);
+        }
+
+        @Override
+        public int getItemCount() {
+            return mConfigToggles.length;
+        }
+    };
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/widget/GridLayoutManagerActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/widget/GridLayoutManagerActivity.java
new file mode 100644
index 0000000..00cfbf8
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/widget/GridLayoutManagerActivity.java
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+package com.example.android.supportv7.widget;
+
+import com.example.android.supportv7.Cheeses;
+import com.example.android.supportv7.R;
+import com.example.android.supportv7.widget.adapter.SimpleStringAdapter;
+
+import android.support.v4.view.ViewCompat;
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * A sample Activity to demonstrate capabilities of {@link GridLayoutManager}.
+ */
+public class GridLayoutManagerActivity extends BaseLayoutManagerActivity<GridLayoutManager> {
+    SimpleStringAdapter mAdapter;
+    @Override
+    protected GridLayoutManager createLayoutManager() {
+        GridLayoutManager lm = new GridLayoutManager(this, 3);
+        lm.setReverseLayout(true);
+        lm.setSpanSizeLookup(mSpanSizeLookup);
+        return lm;
+    }
+
+    GridLayoutManager.SpanSizeLookup mSpanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
+        @Override
+        public int getSpanSize(int position) {
+            String item = mAdapter.getValueAt(position);
+            return 1 + (Math.abs(item.hashCode()) % mLayoutManager.getSpanCount());
+        }
+    };
+
+    @Override
+    ConfigToggle[] createConfigToggles() {
+        return new ConfigToggle[]{
+                new ConfigToggle(this, R.string.checkbox_orientation) {
+                    @Override
+                    public boolean isChecked() {
+                        return mLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL;
+                    }
+
+                    @Override
+                    public void onChange(boolean newValue) {
+                        mLayoutManager.setOrientation(newValue ? LinearLayoutManager.HORIZONTAL
+                                : LinearLayoutManager.VERTICAL);
+                    }
+                },
+                new ConfigToggle(this, R.string.checkbox_reverse) {
+                    @Override
+                    public boolean isChecked() {
+                        return mLayoutManager.getReverseLayout();
+                    }
+
+                    @Override
+                    public void onChange(boolean newValue) {
+                        mLayoutManager.setReverseLayout(newValue);
+                    }
+                },
+                new ConfigToggle(this, R.string.checkbox_layout_dir) {
+                    @Override
+                    public boolean isChecked() {
+                        return ViewCompat.getLayoutDirection(mRecyclerView) ==
+                                ViewCompat.LAYOUT_DIRECTION_RTL;
+                    }
+
+                    @Override
+                    public void onChange(boolean newValue) {
+                        ViewCompat.setLayoutDirection(mRecyclerView, newValue ?
+                                ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
+                    }
+                },
+                new ConfigToggle(this, R.string.checkbox_stack_from_end) {
+                    @Override
+                    public boolean isChecked() {
+                        return mLayoutManager.getStackFromEnd();
+                    }
+
+                    @Override
+                    public void onChange(boolean newValue) {
+                        mLayoutManager.setStackFromEnd(newValue);
+                    }
+                }
+        };
+    }
+
+    @Override
+    protected void scrollToPositionWithOffset(boolean smooth, int position, int offset) {
+        if (smooth) {
+            super.scrollToPositionWithOffset(smooth, position, offset);
+        } else {
+            mLayoutManager.scrollToPositionWithOffset(position, offset);
+        }
+    }
+
+    protected RecyclerView.Adapter createAdapter() {
+        mAdapter = new SimpleStringAdapter(this, Cheeses.sCheeseStrings) {
+            @Override
+            public SimpleStringAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                    int viewType) {
+                final SimpleStringAdapter.ViewHolder vh = super
+                        .onCreateViewHolder(parent, viewType);
+                vh.itemView.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        final int pos = vh.getPosition();
+                        if (pos + 1 < getItemCount()) {
+                            swap(pos, pos + 1);
+                        }
+                        notifyItemChanged(pos);
+                    }
+                });
+                return vh;
+            }
+        };
+        return mAdapter;
+    }
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/widget/LinearLayoutManagerActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/widget/LinearLayoutManagerActivity.java
index 8c2caa9..9aaa558 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/widget/LinearLayoutManagerActivity.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/widget/LinearLayoutManagerActivity.java
@@ -16,222 +16,61 @@
 
 package com.example.android.supportv7.widget;
 
-import com.example.android.supportv7.Cheeses;
-import com.example.android.supportv7.widget.adapter.SimpleStringAdapter;
 import com.example.android.supportv7.widget.decorator.DividerItemDecoration;
 
-import android.app.Activity;
-import android.os.Bundle;
 import android.support.v4.view.ViewCompat;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.EditText;
-import android.widget.Spinner;
-import android.widget.TextView;
-
 import com.example.android.supportv7.R;
 
 /**
- * A sample activity that uses {@link android.support.v7.widget.LinearLayoutManager}.
+ * A sample activity that uses {@link LinearLayoutManager}.
  */
-public class LinearLayoutManagerActivity extends Activity {
-
-    private RecyclerView.LayoutManager mListLayoutManager;
-
-    private ListWrapper mListWrapper;
-
-    private RecyclerView mRecyclerView;
-
+public class LinearLayoutManagerActivity extends BaseLayoutManagerActivity<LinearLayoutManager> {
     private DividerItemDecoration mDividerItemDecoration;
 
-    private ConfigToggle[] mConfigToggles;
+    @Override
+    protected LinearLayoutManager createLayoutManager() {
+        return new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
+    }
 
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_linear_layout_manager);
-        initConfig();
-        initRecyclerView();
-        initSpinner();
+    protected void onRecyclerViewInit(RecyclerView recyclerView) {
+        mDividerItemDecoration = new DividerItemDecoration(this, mLayoutManager.getOrientation());
+        recyclerView.addItemDecoration(mDividerItemDecoration);
     }
 
-    private void initRecyclerView() {
-        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
-        mRecyclerView.setHasFixedSize(true);
-        mListLayoutManager = new LinearLayoutManager(this);
-        mRecyclerView.setLayoutManager(mListLayoutManager);
-        mRecyclerView.setAdapter(new SimpleStringAdapter(this, Cheeses.sCheeseStrings) {
-            @Override
-            public SimpleStringAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
-                    int viewType) {
-                final SimpleStringAdapter.ViewHolder vh = super
-                        .onCreateViewHolder(parent, viewType);
-                vh.itemView.setOnClickListener(new View.OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        final int pos = vh.getPosition();
-                        if (pos + 1 < getItemCount()) {
-                            swap(pos, pos + 1);
-                        }
-                        notifyItemChanged(pos);
-                    }
-                });
-                return vh;
-            }
-        });
-        initListForLayoutManager();
-    }
-
-    private void initListForLayoutManager() {
-        mListWrapper = new ListWrapper() {
-            @Override
-            public int getOrientation() {
-                return lm().getOrientation();
-            }
-
-            @Override
-            public void setOrientation(int orientation) {
-                lm().setOrientation(orientation);
-            }
-
-            @Override
-            public boolean getReverseLayout() {
-                return lm().getReverseLayout();
-            }
-
-            @Override
-            public void setReverseLayout(boolean newValue) {
-                lm().setReverseLayout(newValue);
-            }
-
-            @Override
-            public boolean getStackFromEnd() {
-                return lm().getStackFromEnd();
-            }
-
-            @Override
-            public void setStackFromEnd(boolean newValue) {
-                lm().setStackFromEnd(newValue);
-            }
-
-            private LinearLayoutManager lm() {
-                return (LinearLayoutManager) mListLayoutManager;
-            }
-        };
-        if (mDividerItemDecoration != null) {
-            mRecyclerView.removeItemDecoration(mDividerItemDecoration);
-        }
-        mDividerItemDecoration = new DividerItemDecoration(this, mListWrapper.getOrientation());
-        mRecyclerView.addItemDecoration(mDividerItemDecoration);
-    }
-
-    private void initConfig() {
-        RecyclerView configView = (RecyclerView) findViewById(R.id.config_recycler_view);
-        initToggles();
-        configView.setAdapter(mConfigAdapter);
-        configView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,
-                false));
-        configView.setHasFixedSize(true);
-    }
-
-    private void initSpinner() {
-        final CheckBox checkBox = (CheckBox)
-                findViewById(R.id.enable_smooth_scroll);
-
-        final Spinner spinner = (Spinner) findViewById(R.id.spinner);
-        final EditText scrollOffset = (EditText) findViewById(R.id.scroll_offset);
-        spinner.setAdapter(new BaseAdapter() {
-            @Override
-            public int getCount() {
-                return mRecyclerView.getAdapter().getItemCount();
-            }
-
-            @Override
-            public Integer getItem(int position) {
-                return position;
-            }
-
-            @Override
-            public long getItemId(int position) {
-                return position;
-            }
-
-            @Override
-            public View getView(int position, View convertView, ViewGroup parent) {
-                if (convertView == null) {
-                    convertView = new TextView(parent.getContext());
-                }
-                ((TextView) convertView).setText("" + position);
-                return convertView;
-            }
-        });
-        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
-            @Override
-            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
-                int offset = Integer.MIN_VALUE;
-                String offsetString = scrollOffset.getText().toString();
-                try {
-                    offset = Integer.parseInt(offsetString);
-                } catch (NumberFormatException ex) {
-
-                }
-
-                if (offset == Integer.MIN_VALUE) {
-                    if (checkBox.isChecked()) {
-                        mRecyclerView.smoothScrollToPosition(position);
-                    } else {
-                        mRecyclerView.scrollToPosition(position);
-                    }
-                } else {
-                    // ignore offset until we add recycling list view with smooth scroll to offset
-                    mRecyclerView.smoothScrollToPosition(position);
-                }
-
-            }
-
-            @Override
-            public void onNothingSelected(AdapterView<?> parent) {
-
-            }
-        });
-    }
-
-    private void initToggles() {
-        mConfigToggles = new ConfigToggle[]{
-                new ConfigToggle(R.string.checkbox_orientation) {
+    @Override
+    BaseLayoutManagerActivity.ConfigToggle[] createConfigToggles() {
+        return new ConfigToggle[]{
+                new ConfigToggle(this, R.string.checkbox_orientation) {
                     @Override
                     public boolean isChecked() {
-                        return mListWrapper.getOrientation() == LinearLayoutManager.HORIZONTAL;
+                        return mLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL;
                     }
 
                     @Override
                     public void onChange(boolean newValue) {
-                        mListWrapper.setOrientation(newValue ? LinearLayoutManager.HORIZONTAL
+                        mLayoutManager.setOrientation(newValue ? LinearLayoutManager.HORIZONTAL
                                 : LinearLayoutManager.VERTICAL);
                         if (mDividerItemDecoration != null) {
-                            mDividerItemDecoration.setOrientation(mListWrapper.getOrientation());
+                            mDividerItemDecoration.setOrientation(mLayoutManager.getOrientation());
                         }
 
                     }
                 },
-                new ConfigToggle(R.string.checkbox_reverse) {
+                new ConfigToggle(this, R.string.checkbox_reverse) {
                     @Override
                     public boolean isChecked() {
-                        return mListWrapper.getReverseLayout();
+                        return mLayoutManager.getReverseLayout();
                     }
 
                     @Override
                     public void onChange(boolean newValue) {
-                        mListWrapper.setReverseLayout(newValue);
+                        mLayoutManager.setReverseLayout(newValue);
                     }
                 },
-                new ConfigToggle(R.string.checkbox_layout_dir) {
+                new ConfigToggle(this, R.string.checkbox_layout_dir) {
                     @Override
                     public boolean isChecked() {
                         return ViewCompat.getLayoutDirection(mRecyclerView) ==
@@ -244,103 +83,17 @@
                                 ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
                     }
                 },
-                new ConfigToggle(R.string.checkbox_stack_from_end) {
+                new ConfigToggle(this, R.string.checkbox_stack_from_end) {
                     @Override
                     public boolean isChecked() {
-                        return mListWrapper.getStackFromEnd();
+                        return mLayoutManager.getStackFromEnd();
                     }
 
                     @Override
                     public void onChange(boolean newValue) {
-                        mListWrapper.setStackFromEnd(newValue);
+                        mLayoutManager.setStackFromEnd(newValue);
                     }
                 }
         };
     }
-
-    private class ConfigViewHolder extends RecyclerView.ViewHolder
-            implements CompoundButton.OnCheckedChangeListener {
-
-        private CheckBox mCheckBox;
-
-        private ConfigToggle mConfigToggle;
-
-        public ConfigViewHolder(View itemView) {
-            super(itemView);
-            mCheckBox = (CheckBox) itemView;
-            mCheckBox.setOnCheckedChangeListener(this);
-        }
-
-        public void render(ConfigToggle toggle) {
-            mConfigToggle = toggle;
-            mCheckBox.setText(toggle.getText());
-            mCheckBox.setChecked(toggle.isChecked());
-        }
-
-        @Override
-        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-            if (mConfigToggle != null) {
-                mConfigToggle.onChange(isChecked);
-            }
-        }
-    }
-
-
-    private abstract class ConfigToggle {
-
-        private String mLabel;
-
-        protected ConfigToggle(int labelId) {
-            mLabel = getResources().getString(labelId);
-        }
-
-        public String getText() {
-            return mLabel;
-        }
-
-        abstract public boolean isChecked();
-
-        abstract public void onChange(boolean newValue);
-    }
-
-
-    private RecyclerView.Adapter mConfigAdapter = new RecyclerView.Adapter<ConfigViewHolder>() {
-        @Override
-        public ConfigViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-            return new ConfigViewHolder(new CheckBox(parent.getContext()));
-        }
-
-        @Override
-        public void onBindViewHolder(ConfigViewHolder holder, int position) {
-            ConfigToggle toggle = mConfigToggles[position];
-            holder.render(toggle);
-        }
-
-        @Override
-        public int getItemCount() {
-            return mConfigToggles.length;
-        }
-    };
-
-
-    /**
-     * To avoid adding interfaces to LayoutManager for the demo, we use this wrapper class to
-     * call different LayoutManagers
-     */
-    private static interface ListWrapper {
-
-        int getOrientation();
-
-        void setOrientation(int orientation);
-
-        boolean getReverseLayout();
-
-        void setReverseLayout(boolean newValue);
-
-        boolean getStackFromEnd();
-
-        void setStackFromEnd(boolean newValue);
-    }
-
-
 }
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/widget/adapter/SimpleStringAdapter.java b/samples/Support7Demos/src/com/example/android/supportv7/widget/adapter/SimpleStringAdapter.java
index a12e79d..49f1e19 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/widget/adapter/SimpleStringAdapter.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/widget/adapter/SimpleStringAdapter.java
@@ -33,7 +33,7 @@
     private ArrayList<String> mValues;
 
     public static class ViewHolder extends RecyclerView.ViewHolder {
-
+        public String mBoundString;
         public TextView mTextView;
 
         public ViewHolder(TextView v) {
@@ -47,6 +47,10 @@
         }
     }
 
+    public String getValueAt(int position) {
+        return mValues.get(position);
+    }
+
     public SimpleStringAdapter(Context context, String[] strings) {
         TypedValue val = new TypedValue();
         if (context.getTheme() != null) {
@@ -86,6 +90,7 @@
 
     @Override
     public void onBindViewHolder(ViewHolder holder, int position) {
+        holder.mBoundString = mValues.get(position);
         holder.mTextView.setText(position + ":" + mValues.get(position));
         holder.mTextView.setMinHeight((200 + mValues.get(position).length() * 10));
         holder.mTextView.setBackgroundColor(getBackgroundColor(position));
@@ -95,7 +100,7 @@
         switch (position % 4) {
             case 0: return Color.BLACK;
             case 1: return Color.RED;
-            case 2: return Color.GREEN;
+            case 2: return Color.DKGRAY;
             case 3: return Color.BLUE;
         }
         return Color.TRANSPARENT;