• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // CHECKSTYLE:OFF Generated code
2 /* This file is auto-generated from GuidedStepActivity.java.  DO NOT MODIFY. */
3 
4 /*
5  * Copyright (C) 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 package com.example.android.leanback;
21 
22 import android.support.v4.app.FragmentActivity;
23 import android.support.v4.app.Fragment;
24 import android.support.v4.app.FragmentManager;
25 import android.content.Context;
26 import android.content.res.Configuration;
27 import android.graphics.drawable.Drawable;
28 import android.os.Bundle;
29 import android.support.v17.leanback.app.GuidedStepSupportFragment;
30 import android.support.v17.leanback.widget.GuidanceStylist;
31 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
32 import android.support.v17.leanback.widget.GuidedAction;
33 import android.support.v17.leanback.widget.GuidedActionsStylist;
34 import android.support.v17.leanback.widget.GuidedDatePickerAction;
35 import android.support.v4.content.res.ResourcesCompat;
36 import android.text.InputType;
37 import android.text.TextUtils;
38 import android.util.Log;
39 import android.view.LayoutInflater;
40 import android.view.View;
41 import android.view.ViewGroup;
42 import android.view.inputmethod.EditorInfo;
43 
44 import java.util.ArrayList;
45 import java.util.Calendar;
46 import java.util.List;
47 
48 /**
49  * Activity that showcases different aspects of GuidedStepSupportFragments.
50  */
51 public class GuidedStepSupportActivity extends FragmentActivity {
52 
53     private static final int BACK = 2;
54 
55     private static final int FIRST_NAME = 3;
56     private static final int LAST_NAME = 4;
57     private static final int PASSWORD = 5;
58     private static final int PAYMENT = 6;
59     private static final int NEW_PAYMENT = 7;
60     private static final int PAYMENT_EXPIRE = 8;
61 
62     private static final long RADIO_ID_BASE = 0;
63     private static final long CHECKBOX_ID_BASE = 100;
64 
65     private static final long DEFAULT_OPTION = RADIO_ID_BASE;
66 
67     private static final String[] OPTION_NAMES = { "Option A", "Option B", "Option C" };
68     private static final String[] OPTION_DESCRIPTIONS = { "Here's one thing you can do",
69             "Here's another thing you can do", "Here's one more thing you can do" };
70 
71     private static final String TAG = GuidedStepSupportActivity.class.getSimpleName();
72 
73     @Override
onCreate(Bundle savedInstanceState)74     protected void onCreate(Bundle savedInstanceState) {
75         Log.v(TAG, "onCreate");
76         super.onCreate(savedInstanceState);
77         setContentView(R.layout.guided_step_activity);
78         if (savedInstanceState == null) {
79             GuidedStepSupportFragment.addAsRoot(this, new FirstStepFragment(), R.id.lb_guidedstep_host);
80         }
81     }
82 
83     @Override
onConfigurationChanged(Configuration newConfig)84     public void onConfigurationChanged(Configuration newConfig) {
85         Log.v(TAG, "onConfigurationChanged");
86         super.onConfigurationChanged(newConfig);
87     }
88 
89     @Override
onSaveInstanceState(Bundle outState)90     protected void onSaveInstanceState(Bundle outState) {
91         Log.v(TAG, "onSaveInstanceState");
92         super.onSaveInstanceState(outState);
93     }
94 
95     @Override
onRestoreInstanceState(Bundle savedInstanceState)96     protected void onRestoreInstanceState(Bundle savedInstanceState) {
97         Log.v(TAG, "onRestoreInstanceState");
98         super.onRestoreInstanceState(savedInstanceState);
99     }
100 
addAction(List<GuidedAction> actions, long id, String title, String desc)101     private static GuidedAction addAction(List<GuidedAction> actions, long id, String title,
102             String desc) {
103         GuidedAction action;
104         actions.add(action = new GuidedAction.Builder(null)
105                 .id(id)
106                 .title(title)
107                 .description(desc)
108                 .build());
109         return action;
110     }
111 
addAction(List<GuidedAction> actions, long id, String title, String desc, List<GuidedAction> subActions)112     private static GuidedAction addAction(List<GuidedAction> actions, long id, String title,
113             String desc, List<GuidedAction> subActions) {
114         GuidedAction action;
115         actions.add(action = new GuidedAction.Builder(null)
116                 .id(id)
117                 .title(title)
118                 .description(desc)
119                 .subActions(subActions)
120                 .build());
121         return action;
122     }
123 
addEditableAction(Context context, List<GuidedAction> actions, long id, String title, String desc)124     private static GuidedAction addEditableAction(Context context, List<GuidedAction> actions,
125             long id, String title, String desc) {
126         GuidedAction action;
127         actions.add(action = new GuidedAction.Builder(context)
128                 .id(id)
129                 .title(title)
130                 .description(desc)
131                 .editable(true)
132                 .icon(R.drawable.lb_ic_search_mic)
133                 .build());
134         return action;
135     }
136 
addEditableAction(List<GuidedAction> actions, long id, String title, String editTitle, String desc)137     private static GuidedAction addEditableAction(List<GuidedAction> actions, long id, String title,
138             String editTitle, String desc) {
139         GuidedAction action;
140         actions.add(action = new GuidedAction.Builder(null)
141                 .id(id)
142                 .title(title)
143                 .editTitle(editTitle)
144                 .description(desc)
145                 .editable(true)
146                 .build());
147         return action;
148     }
149 
addEditableAction(List<GuidedAction> actions, long id, String title, String editTitle, int editInputType, String desc, String editDesc)150     private static GuidedAction addEditableAction(List<GuidedAction> actions, long id, String title,
151             String editTitle, int editInputType, String desc, String editDesc) {
152         GuidedAction action;
153         actions.add(action = new GuidedAction.Builder(null)
154                 .id(id)
155                 .title(title)
156                 .editTitle(editTitle)
157                 .editInputType(editInputType)
158                 .description(desc)
159                 .editDescription(editDesc)
160                 .editable(true)
161                 .build());
162         return action;
163     }
164 
addDatePickerAction(List<GuidedAction> actions, long id, String title)165     private static GuidedDatePickerAction addDatePickerAction(List<GuidedAction> actions, long id,
166             String title) {
167         GuidedDatePickerAction action;
168         actions.add(action = new GuidedDatePickerAction.Builder(null)
169                 .id(id)
170                 .title(title)
171                 .datePickerFormat("MY")
172                 .build());
173         return action;
174     }
175 
addEditableDescriptionAction(List<GuidedAction> actions, long id, String title, String desc, String editDescription, int descriptionEditInputType)176     private static GuidedAction addEditableDescriptionAction(List<GuidedAction> actions, long id,
177             String title, String desc, String editDescription, int descriptionEditInputType) {
178         GuidedAction action;
179         actions.add(action = new GuidedAction.Builder(null)
180                 .id(id)
181                 .title(title)
182                 .description(desc)
183                 .editDescription(editDescription)
184                 .descriptionEditInputType(descriptionEditInputType)
185                 .descriptionEditable(true)
186                 .build());
187         return action;
188     }
189 
addCheckedAction(List<GuidedAction> actions, long id, String title, String desc, int checkSetId)190     private static GuidedAction addCheckedAction(List<GuidedAction> actions, long id,
191             String title, String desc, int checkSetId) {
192         GuidedAction action;
193         actions.add(action = new GuidedAction.Builder(null)
194                 .id(id)
195                 .title(title)
196                 .description(desc)
197                 .checkSetId(checkSetId)
198                 .build());
199         return action;
200     }
201 
202     public static class FirstStepFragment extends GuidedStepSupportFragment {
203 
204         @Override
onProvideTheme()205         public int onProvideTheme() {
206             return R.style.Theme_Example_Leanback_GuidedStep_First;
207         }
208 
209         @Override
onCreateGuidance(Bundle savedInstanceState)210         public Guidance onCreateGuidance(Bundle savedInstanceState) {
211             String title = getString(R.string.guidedstep_first_title);
212             String breadcrumb = getString(R.string.guidedstep_first_breadcrumb);
213             String description = getString(R.string.guidedstep_first_description);
214             final Context context = getActivity();
215             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
216                     R.drawable.ic_main_icon, context.getTheme());
217             return new Guidance(title, description, breadcrumb, icon);
218         }
219 
220         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)221         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
222             Context context = getActivity();
223             actions.add(new GuidedAction.Builder(context)
224                     .clickAction(GuidedAction.ACTION_ID_CONTINUE)
225                     .description("Let's do it")
226                     .build());
227             actions.add(new GuidedAction.Builder(context)
228                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
229                     .description("Never mind")
230                     .build());
231         }
232 
233         @Override
onGuidedActionClicked(GuidedAction action)234         public void onGuidedActionClicked(GuidedAction action) {
235             FragmentManager fm = getFragmentManager();
236             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
237                 GuidedStepSupportFragment.add(fm, new SecondStepFragment(), R.id.lb_guidedstep_host);
238             } else if (action.getId() == GuidedAction.ACTION_ID_CANCEL){
239                 finishGuidedStepSupportFragments();
240             }
241         }
242     }
243 
244     public interface NewPaymentFragmentTarget {
onNewPaymentFragmentStarted()245         void onNewPaymentFragmentStarted();
onNewPaymentAdded(int selection)246         void onNewPaymentAdded(int selection);
247     }
248 
249     static ArrayList<String> sCards = new ArrayList<String>();
250     static int sSelectedCard = -1;
251     static {
252         sCards.add("Visa-1234");
253         sCards.add("Master-4321");
254     }
255 
256     public static class NewPaymentStepFragment extends GuidedStepSupportFragment {
257 
258         NewPaymentFragmentTarget mNewPaymentTarget;
259 
260         @Override
onCreate(Bundle savedInstance)261         public void onCreate(Bundle savedInstance) {
262             super.onCreate(savedInstance);
263             Fragment targetFragment = getTargetFragment();
264             if (targetFragment instanceof NewPaymentFragmentTarget) {
265                 mNewPaymentTarget = ((NewPaymentFragmentTarget) targetFragment);
266                 mNewPaymentTarget.onNewPaymentFragmentStarted();
267             }
268         }
269 
270         @Override
onCreateGuidance(Bundle savedInstanceState)271         public Guidance onCreateGuidance(Bundle savedInstanceState) {
272             String title = getString(R.string.guidedstep_newpayment_title);
273             String breadcrumb = getString(R.string.guidedstep_newpayment_breadcrumb);
274             String description = getString(R.string.guidedstep_newpayment_description);
275             final Context context = getActivity();
276             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
277                     R.drawable.ic_main_icon, context.getTheme());
278             return new Guidance(title, description, breadcrumb, icon);
279         }
280 
281         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)282         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
283             addEditableAction(actions, NEW_PAYMENT, "Input credit card number", "",
284                     InputType.TYPE_CLASS_NUMBER,
285                     "Input credit card number", "Input credit card number");
286             addDatePickerAction(actions, PAYMENT_EXPIRE, "Exp:");
287         }
288 
289         @Override
onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState)290         public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
291             Context context = getActivity();
292             actions.add(new GuidedAction.Builder(context).clickAction(GuidedAction.ACTION_ID_OK)
293                     .build());
294             actions.get(actions.size() - 1).setEnabled(false);
295         }
296 
297         @Override
onGuidedActionClicked(GuidedAction action)298         public void onGuidedActionClicked(GuidedAction action) {
299             if (action.getId() == GuidedAction.ACTION_ID_OK) {
300                 CharSequence desc = findActionById(NEW_PAYMENT).getDescription();
301                 String cardNumber = desc.subSequence(desc.length() - 4, desc.length()).toString();
302                 String card;
303                 if ((Integer.parseInt(cardNumber) & 1) == 0) {
304                     card = "Visa "+cardNumber;
305                 } else {
306                     card = "Master "+cardNumber;
307                 }
308                 int selection = sCards.size();
309                 sCards.add(card);
310                 if (mNewPaymentTarget != null) {
311                     mNewPaymentTarget.onNewPaymentAdded(selection);
312                 }
313                 popBackStackToGuidedStepSupportFragment(NewPaymentStepFragment.class,
314                         FragmentManager.POP_BACK_STACK_INCLUSIVE);
315             }
316         }
317 
318         @Override
onGuidedActionEditedAndProceed(GuidedAction action)319         public long onGuidedActionEditedAndProceed(GuidedAction action) {
320             if (action.getId() == NEW_PAYMENT) {
321                 CharSequence editTitle = action.getEditTitle();
322                 if (isCardNumberValid(editTitle)) {
323                     editTitle = editTitle.subSequence(editTitle.length() - 4, editTitle.length());
324                     action.setDescription("Visa XXXX-XXXX-XXXX-" + editTitle);
325                     updateOkButton(isExpDateValid(findActionById(PAYMENT_EXPIRE)));
326                     return GuidedAction.ACTION_ID_NEXT;
327                 } else if (editTitle.length() == 0) {
328                     action.setDescription("Input credit card number");
329                     updateOkButton(false);
330                     return GuidedAction.ACTION_ID_CURRENT;
331                 } else {
332                     action.setDescription("Error credit card number");
333                     updateOkButton(false);
334                     return GuidedAction.ACTION_ID_CURRENT;
335                 }
336             } else if (action.getId() == PAYMENT_EXPIRE) {
337                 updateOkButton(isExpDateValid(action) &&
338                         isCardNumberValid(findActionById(NEW_PAYMENT).getEditTitle()));
339             }
340             return GuidedAction.ACTION_ID_NEXT;
341         }
342 
isCardNumberValid(CharSequence number)343         boolean isCardNumberValid(CharSequence number) {
344             return TextUtils.isDigitsOnly(number) && number.length() == 16;
345         }
346 
isExpDateValid(GuidedAction action)347         boolean isExpDateValid(GuidedAction action) {
348             long date = ((GuidedDatePickerAction) action).getDate();
349             Calendar c = Calendar.getInstance();
350             c.setTimeInMillis(date);
351             return Calendar.getInstance().before(c);
352         }
353 
updateOkButton(boolean enabled)354         void updateOkButton(boolean enabled) {
355             findButtonActionById(GuidedAction.ACTION_ID_OK).setEnabled(enabled);
356             notifyButtonActionChanged(findButtonActionPositionById(GuidedAction.ACTION_ID_OK));
357         }
358     }
359 
360     public static class SecondStepFragment extends GuidedStepSupportFragment
361             implements NewPaymentFragmentTarget {
362 
363 
364         boolean mExpandPaymentListInOnCreateView;
365 
366         @Override
onNewPaymentAdded(int selection)367         public void onNewPaymentAdded(int selection) {
368             // if a new payment is added, we dont need expand the sub actions list.
369             mExpandPaymentListInOnCreateView = false;
370             sSelectedCard = selection;
371             updatePaymentAction(findActionById(PAYMENT));
372             findButtonActionById(GuidedAction.ACTION_ID_CONTINUE).setEnabled(sSelectedCard != -1);
373         }
374 
375         @Override
onNewPaymentFragmentStarted()376         public void onNewPaymentFragmentStarted() {
377             // if a new payment fragment is opened, when come back we should expand the payment
378             // sub actions list unless user created a new payment in onNewPaymentAdded
379             mExpandPaymentListInOnCreateView = true;
380         }
381 
382         @Override
onCreateActionsStylist()383         public GuidedActionsStylist onCreateActionsStylist() {
384             return new GuidedActionsStylist() {
385                 @Override
386                 protected void setupImeOptions(GuidedActionsStylist.ViewHolder vh,
387                         GuidedAction action) {
388                     if (action.getId() == PASSWORD) {
389                         vh.getEditableDescriptionView().setImeActionLabel("Confirm!",
390                                 EditorInfo.IME_ACTION_DONE);
391                     } else {
392                         super.setupImeOptions(vh, action);
393                     }
394                 }
395             };
396         }
397 
398         @Override
399         public Guidance onCreateGuidance(Bundle savedInstanceState) {
400             String title = getString(R.string.guidedstep_second_title);
401             String breadcrumb = getString(R.string.guidedstep_second_breadcrumb);
402             String description = getString(R.string.guidedstep_second_description);
403             final Context context = getActivity();
404             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
405                     R.drawable.ic_main_icon, context.getTheme());
406             return new Guidance(title, description, breadcrumb, icon);
407         }
408 
409         @Override
410         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
411             addEditableAction(getActivity(), actions, FIRST_NAME, "Pat", "Your first name");
412             addEditableAction(getActivity(), actions, LAST_NAME, "Smith", "Your last name");
413             List<GuidedAction> subActions = new ArrayList<GuidedAction>();
414             updatePaymentAction(addAction(actions, PAYMENT, "Select Payment", "", subActions));
415             addEditableDescriptionAction(actions, PASSWORD, "Password", "", "",
416                     InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
417         }
418 
419         @Override
420         public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
421             actions.add(new GuidedAction.Builder(getActivity())
422                     .clickAction(GuidedAction.ACTION_ID_CONTINUE)
423                     .description("Continue")
424                     .enabled(isPasswordValid() && isPaymentValid())
425                     .build());
426         }
427 
428         @Override
429         public void onGuidedActionClicked(GuidedAction action) {
430             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
431                 FragmentManager fm = getFragmentManager();
432                 GuidedStepSupportFragment.add(fm, new ThirdStepFragment(), R.id.lb_guidedstep_host);
433             }
434         }
435 
436         void updatePaymentAction(GuidedAction paymentAction) {
437             List<GuidedAction> subActions = paymentAction.getSubActions();
438             subActions.clear();
439             for (int i = 0; i < sCards.size(); i++) {
440                 addCheckedAction(subActions, -1, sCards.get(i), "",
441                         GuidedAction.DEFAULT_CHECK_SET_ID);
442                 if (i == sSelectedCard) {
443                     subActions.get(i).setChecked(true);
444                 }
445             }
446             addAction(subActions, NEW_PAYMENT, "Add New Card", "");
447             paymentAction.setDescription(sSelectedCard == -1 ? "" : sCards.get(sSelectedCard));
448         }
449 
450         @Override
451         public long onGuidedActionEditedAndProceed(GuidedAction action) {
452             if (action.getId() == PASSWORD) {
453                 CharSequence password = action.getEditDescription();
454                 if (password.length() > 0) {
455                     if (isPaymentValid()) {
456                         updateContinue(true);
457                         return GuidedAction.ACTION_ID_NEXT;
458                     } else {
459                         updateContinue(false);
460                         return GuidedAction.ACTION_ID_CURRENT;
461                     }
462                 } else {
463                     updateContinue(false);
464                     return GuidedAction.ACTION_ID_CURRENT;
465                 }
466             }
467             return GuidedAction.ACTION_ID_NEXT;
468         }
469 
470         @Override
471         public boolean onSubGuidedActionClicked(GuidedAction action) {
472             if (action.isChecked()) {
473                 String payment = action.getTitle().toString();
474                 for (int i = 0; i < sCards.size(); i++) {
475                     if (payment.equals(sCards.get(i))) {
476                         sSelectedCard = i;
477                         findActionById(PAYMENT).setDescription(payment);
478                         notifyActionChanged(findActionPositionById(PAYMENT));
479                         updateContinue(isPasswordValid());
480                         break;
481                     }
482                 }
483                 return true;
484             } else {
485                 FragmentManager fm = getFragmentManager();
486                 NewPaymentStepFragment newPaymentFragment = new NewPaymentStepFragment();
487                 newPaymentFragment.setTargetFragment(this, 0);
488                 GuidedStepSupportFragment.add(fm, newPaymentFragment, R.id.lb_guidedstep_host);
489                 return false;
490             }
491         }
492 
493         @Override
494         public View onCreateView(LayoutInflater inflater, ViewGroup container,
495                 Bundle savedInstanceState) {
496             View view = super.onCreateView(inflater, container, savedInstanceState);
497             if (mExpandPaymentListInOnCreateView) {
498                 expandAction(findActionById(PAYMENT), false);
499             }
500             return view;
501         }
502 
503         boolean isPaymentValid() {
504             CharSequence paymentType = findActionById(PAYMENT).getDescription();
505             return (paymentType.length() >= 4 &&
506                     paymentType.subSequence(0, 4).toString().equals("Visa")) ||
507                     (paymentType.length() >= 6 &&
508                     paymentType.subSequence(0, 6).toString().equals("Master"));
509         }
510 
511         boolean isPasswordValid() {
512             return findActionById(PASSWORD).getEditDescription().length() > 0;
513         }
514 
515         void updateContinue(boolean enabled) {
516             findButtonActionById(GuidedAction.ACTION_ID_CONTINUE).setEnabled(enabled);
517             notifyButtonActionChanged(findButtonActionPositionById(
518                     GuidedAction.ACTION_ID_CONTINUE));
519         }
520     }
521 
522     public static class ThirdStepFragment extends GuidedStepSupportFragment {
523 
524         private long mSelectedOption = DEFAULT_OPTION;
525 
526         @Override
527         public Guidance onCreateGuidance(Bundle savedInstanceState) {
528             String title = getString(R.string.guidedstep_third_title);
529             String breadcrumb = getString(R.string.guidedstep_third_breadcrumb);
530             String description = getString(R.string.guidedstep_third_description);
531             final Context context = getActivity();
532             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
533                     R.drawable.ic_main_icon, context.getTheme());
534             return new Guidance(title, description, breadcrumb, icon);
535         }
536 
537         @Override
538         public GuidanceStylist onCreateGuidanceStylist() {
539             return new GuidanceStylist() {
540                 @Override
541                 public int onProvideLayoutId() {
542                     return R.layout.guidedstep_second_guidance;
543                 }
544             };
545         }
546 
547         @Override
548         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
549             String desc = "The description can be quite long as well.  " +
550                     "Just be sure to set multilineDescription to true in the GuidedAction.";
551             actions.add(new GuidedAction.Builder(getActivity())
552                     .title("Note that Guided Actions can have titles that are quite long.")
553                     .description(desc)
554                     .multilineDescription(true)
555                     .infoOnly(true)
556                     .enabled(true)
557                     .focusable(false)
558                     .build());
559             for (int i = 0; i < OPTION_NAMES.length; i++) {
560                 addCheckedAction(actions, RADIO_ID_BASE + i, OPTION_NAMES[i],
561                         OPTION_DESCRIPTIONS[i], GuidedAction.DEFAULT_CHECK_SET_ID);
562                 if (i == DEFAULT_OPTION) {
563                     actions.get(actions.size() -1).setChecked(true);
564                 }
565             }
566             for (int i = 0; i < OPTION_NAMES.length; i++) {
567                 addCheckedAction(actions, CHECKBOX_ID_BASE + i, OPTION_NAMES[i],
568                         OPTION_DESCRIPTIONS[i], GuidedAction.CHECKBOX_CHECK_SET_ID);
569             }
570         }
571 
572         @Override
573         public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
574             actions.add(new GuidedAction.Builder(getActivity())
575                     .clickAction(GuidedAction.ACTION_ID_CONTINUE)
576                     .build());
577         }
578 
579         @Override
580         public void onGuidedActionClicked(GuidedAction action) {
581             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
582                 FragmentManager fm = getFragmentManager();
583                 FourthStepFragment f = new FourthStepFragment();
584                 Bundle arguments = new Bundle();
585                 arguments.putLong(FourthStepFragment.EXTRA_OPTION, mSelectedOption);
586                 f.setArguments(arguments);
587                 GuidedStepSupportFragment.add(fm, f, R.id.lb_guidedstep_host);
588             } else if (action.getCheckSetId() == GuidedAction.DEFAULT_CHECK_SET_ID) {
589                 mSelectedOption = action.getId();
590             }
591         }
592 
593     }
594 
595     public static class FourthStepFragment extends GuidedStepSupportFragment {
596         public static final String EXTRA_OPTION = "extra_option";
597 
598         public FourthStepFragment() {
599         }
600 
601         public long getOption() {
602             Bundle b = getArguments();
603             if (b == null) return 0;
604             return b.getLong(EXTRA_OPTION, 0);
605         }
606 
607         @Override
608         public Guidance onCreateGuidance(Bundle savedInstanceState) {
609             String title = getString(R.string.guidedstep_fourth_title);
610             String breadcrumb = getString(R.string.guidedstep_fourth_breadcrumb);
611             String description = "You chose: " + OPTION_NAMES[(int) getOption()];
612             final Context context = getActivity();
613             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
614                     R.drawable.ic_main_icon, context.getTheme());
615             return new Guidance(title, description, breadcrumb, icon);
616         }
617 
618         @Override
619         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
620             actions.add(new GuidedAction.Builder(getActivity())
621                     .clickAction(GuidedAction.ACTION_ID_FINISH)
622                     .description("All Done...")
623                     .build());
624             addAction(actions, BACK, "Start Over", "Let's try this again...");
625         }
626 
627         @Override
628         public void onGuidedActionClicked(GuidedAction action) {
629             if (action.getId() == GuidedAction.ACTION_ID_FINISH) {
630                 finishGuidedStepSupportFragments();
631             } else if (action.getId() == BACK) {
632                 // pop 4, 3, 2
633                 popBackStackToGuidedStepSupportFragment(SecondStepFragment.class,
634                         FragmentManager.POP_BACK_STACK_INCLUSIVE);
635             }
636         }
637 
638     }
639 
640 }
641