SupportLeanbackDemos: guidedstep changes

1. no longer provide a view to host background view
2. add demo of checkbox
3. add demo of customize Ime options.

Change-Id: I76dbbbd7e341906ff4e7b8923b1ddc2c01026f44
diff --git a/samples/SupportLeanbackDemos/res/layout/browse.xml b/samples/SupportLeanbackDemos/res/layout/browse.xml
index 1642c44..ca19691 100644
--- a/samples/SupportLeanbackDemos/res/layout/browse.xml
+++ b/samples/SupportLeanbackDemos/res/layout/browse.xml
@@ -27,11 +27,6 @@
 	    android:layout_height="match_parent"
 	/>
 
-  <!-- container for hosting GuidedStepFragment background -->
-  <FrameLayout android:id="@+id/lb_guidedstep_background"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent" />
-
   <!-- container for hosting GuidedStepFragment -->
   <FrameLayout android:id="@+id/lb_guidedstep_host"
     android:layout_width="match_parent"
diff --git a/samples/SupportLeanbackDemos/res/layout/browse_support.xml b/samples/SupportLeanbackDemos/res/layout/browse_support.xml
index b0c72a4..23058ad 100644
--- a/samples/SupportLeanbackDemos/res/layout/browse_support.xml
+++ b/samples/SupportLeanbackDemos/res/layout/browse_support.xml
@@ -29,11 +29,6 @@
 	    android:layout_height="match_parent"
 	/>
 
-  <!-- container for hosting GuidedStepFragment background -->
-  <FrameLayout android:id="@+id/lb_guidedstep_background"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent" />
-
   <!-- container for hosting GuidedStepFragment -->
   <FrameLayout android:id="@+id/lb_guidedstep_host"
     android:layout_width="match_parent"
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java
index 66888ab..734ec34 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepActivity.java
@@ -25,13 +25,16 @@
 import android.os.Bundle;
 import android.support.v17.leanback.app.GuidedStepFragment;
 import android.support.v17.leanback.widget.GuidedAction;
+import android.support.v17.leanback.widget.GuidedActionsStylist;
 import android.support.v17.leanback.widget.GuidanceStylist;
 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
+import android.support.v17.leanback.widget.GuidedActionsStylist.ViewHolder;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.inputmethod.EditorInfo;
 
 import java.util.List;
 
@@ -52,8 +55,6 @@
     private static final String[] OPTION_NAMES = { "Option A", "Option B", "Option C" };
     private static final String[] OPTION_DESCRIPTIONS = { "Here's one thing you can do",
             "Here's another thing you can do", "Here's one more thing you can do" };
-    private static final int[] OPTION_DRAWABLES = { R.drawable.ic_guidedstep_option_a,
-            R.drawable.ic_guidedstep_option_b, R.drawable.ic_guidedstep_option_c };
 
     private static final String TAG = GuidedStepActivity.class.getSimpleName();
 
@@ -136,13 +137,12 @@
                 .build());
     }
 
-    private static void addCheckedAction(List<GuidedAction> actions, int iconResId, Context context,
-            String title, String desc) {
+    private static void addCheckedAction(List<GuidedAction> actions, Context context,
+            String title, String desc, int checkSetId) {
         actions.add(new GuidedAction.Builder()
                 .title(title)
                 .description(desc)
-                .checkSetId(OPTION_CHECK_SET_ID)
-                .iconResourceId(iconResId, context)
+                .checkSetId(checkSetId)
                 .build());
     }
 
@@ -181,14 +181,24 @@
             }
         }
 
-        @Override
-        protected int getContainerIdForBackground() {
-            return R.id.lb_guidedstep_background;
-        }
     }
 
     public static class SecondStepFragment extends GuidedStepFragment {
 
+        public GuidedActionsStylist onCreateActionsStylist() {
+            return new GuidedActionsStylist() {
+                protected void setupImeOptions(GuidedActionsStylist.ViewHolder vh,
+                        GuidedAction action) {
+                    if (action.getId() == PASSWORD) {
+                        vh.getEditableDescriptionView().setImeActionLabel("Confirm!",
+                                EditorInfo.IME_ACTION_DONE);
+                    } else {
+                        super.setupImeOptions(vh, action);
+                    }
+                }
+            };
+        }
+
         @Override
         public Guidance onCreateGuidance(Bundle savedInstanceState) {
             String title = getString(R.string.guidedstep_second_title);
@@ -311,12 +321,16 @@
                     .focusable(false)
                     .build());
             for (int i = 0; i < OPTION_NAMES.length; i++) {
-                addCheckedAction(actions, OPTION_DRAWABLES[i], getActivity(), OPTION_NAMES[i],
-                        OPTION_DESCRIPTIONS[i]);
+                addCheckedAction(actions, getActivity(), OPTION_NAMES[i],
+                        OPTION_DESCRIPTIONS[i], GuidedAction.DEFAULT_CHECK_SET_ID);
                 if (i == DEFAULT_OPTION) {
                     actions.get(actions.size() -1).setChecked(true);
                 }
             }
+            for (int i = 0; i < OPTION_NAMES.length; i++) {
+                addCheckedAction(actions, getActivity(), OPTION_NAMES[i],
+                        OPTION_DESCRIPTIONS[i], GuidedAction.CHECKBOX_CHECK_SET_ID);
+            }
         }
 
         @Override
@@ -334,7 +348,7 @@
                 arguments.putInt(FourthStepFragment.EXTRA_OPTION, mSelectedOption);
                 f.setArguments(arguments);
                 GuidedStepFragment.add(fm, f, R.id.lb_guidedstep_host);
-            } else {
+            } else if (action.getCheckSetId() == GuidedAction.DEFAULT_CHECK_SET_ID) {
                 mSelectedOption = getSelectedActionPosition()-1;
             }
         }
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java
index 70a0db8..3975dd6 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/GuidedStepSupportActivity.java
@@ -27,13 +27,16 @@
 import android.os.Bundle;
 import android.support.v17.leanback.app.GuidedStepSupportFragment;
 import android.support.v17.leanback.widget.GuidedAction;
+import android.support.v17.leanback.widget.GuidedActionsStylist;
 import android.support.v17.leanback.widget.GuidanceStylist;
 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
+import android.support.v17.leanback.widget.GuidedActionsStylist.ViewHolder;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.inputmethod.EditorInfo;
 
 import java.util.List;
 
@@ -54,8 +57,6 @@
     private static final String[] OPTION_NAMES = { "Option A", "Option B", "Option C" };
     private static final String[] OPTION_DESCRIPTIONS = { "Here's one thing you can do",
             "Here's another thing you can do", "Here's one more thing you can do" };
-    private static final int[] OPTION_DRAWABLES = { R.drawable.ic_guidedstep_option_a,
-            R.drawable.ic_guidedstep_option_b, R.drawable.ic_guidedstep_option_c };
 
     private static final String TAG = GuidedStepSupportActivity.class.getSimpleName();
 
@@ -138,13 +139,12 @@
                 .build());
     }
 
-    private static void addCheckedAction(List<GuidedAction> actions, int iconResId, Context context,
-            String title, String desc) {
+    private static void addCheckedAction(List<GuidedAction> actions, Context context,
+            String title, String desc, int checkSetId) {
         actions.add(new GuidedAction.Builder()
                 .title(title)
                 .description(desc)
-                .checkSetId(OPTION_CHECK_SET_ID)
-                .iconResourceId(iconResId, context)
+                .checkSetId(checkSetId)
                 .build());
     }
 
@@ -183,14 +183,24 @@
             }
         }
 
-        @Override
-        protected int getContainerIdForBackground() {
-            return R.id.lb_guidedstep_background;
-        }
     }
 
     public static class SecondStepFragment extends GuidedStepSupportFragment {
 
+        public GuidedActionsStylist onCreateActionsStylist() {
+            return new GuidedActionsStylist() {
+                protected void setupImeOptions(GuidedActionsStylist.ViewHolder vh,
+                        GuidedAction action) {
+                    if (action.getId() == PASSWORD) {
+                        vh.getEditableDescriptionView().setImeActionLabel("Confirm!",
+                                EditorInfo.IME_ACTION_DONE);
+                    } else {
+                        super.setupImeOptions(vh, action);
+                    }
+                }
+            };
+        }
+
         @Override
         public Guidance onCreateGuidance(Bundle savedInstanceState) {
             String title = getString(R.string.guidedstep_second_title);
@@ -313,12 +323,16 @@
                     .focusable(false)
                     .build());
             for (int i = 0; i < OPTION_NAMES.length; i++) {
-                addCheckedAction(actions, OPTION_DRAWABLES[i], getActivity(), OPTION_NAMES[i],
-                        OPTION_DESCRIPTIONS[i]);
+                addCheckedAction(actions, getActivity(), OPTION_NAMES[i],
+                        OPTION_DESCRIPTIONS[i], GuidedAction.DEFAULT_CHECK_SET_ID);
                 if (i == DEFAULT_OPTION) {
                     actions.get(actions.size() -1).setChecked(true);
                 }
             }
+            for (int i = 0; i < OPTION_NAMES.length; i++) {
+                addCheckedAction(actions, getActivity(), OPTION_NAMES[i],
+                        OPTION_DESCRIPTIONS[i], GuidedAction.CHECKBOX_CHECK_SET_ID);
+            }
         }
 
         @Override
@@ -336,7 +350,7 @@
                 arguments.putInt(FourthStepFragment.EXTRA_OPTION, mSelectedOption);
                 f.setArguments(arguments);
                 GuidedStepSupportFragment.add(fm, f, R.id.lb_guidedstep_host);
-            } else {
+            } else if (action.getCheckSetId() == GuidedAction.DEFAULT_CHECK_SET_ID) {
                 mSelectedOption = getSelectedActionPosition()-1;
             }
         }