1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15package android.support.v17.leanback.supportleanbackshowcase.app.wizard; 16 17import android.os.Bundle; 18import android.os.Handler; 19import android.support.annotation.NonNull; 20import android.support.v17.leanback.app.GuidedStepFragment; 21import android.support.v17.leanback.supportleanbackshowcase.R; 22import android.support.v17.leanback.widget.GuidanceStylist; 23import android.support.v17.leanback.widget.GuidedAction; 24import android.support.v17.leanback.widget.GuidedActionsStylist; 25 26import java.util.List; 27 28/** 29 * This is the third screen of the rental wizard which will display a progressbar while waiting for 30 * the server to process the rental. The server communication is faked for the sake of this example 31 * by waiting four seconds until continuing. 32 */ 33public class WizardExample3rdStepFragment extends WizardExampleBaseStepFragment { 34 35 private static final int ACTION_ID_PROCESSING = 1; 36 private final Handler mFakeHttpHandler = new Handler(); 37 38 @Override 39 public void onStart() { 40 super.onStart(); 41 42 // Fake Http call by creating some sort of delay. 43 mFakeHttpHandler.postDelayed(fakeHttpRequestRunnable, 4000L); 44 } 45 46 @Override 47 public GuidedActionsStylist onCreateActionsStylist() { 48 GuidedActionsStylist stylist = new GuidedActionsStylist() { 49 @Override 50 public int onProvideItemLayoutId() { 51 return R.layout.wizard_progress_action_item; 52 } 53 54 }; 55 return stylist; 56 } 57 58 @Override 59 public int onProvideTheme() { 60 return R.style.Theme_Example_LeanbackWizard_NoSelector; 61 } 62 63 @Override 64 public void onStop() { 65 super.onStop(); 66 67 // Make sure to cancel the execution of the Runnable in case the fragment is stopped. 68 mFakeHttpHandler.removeCallbacks(fakeHttpRequestRunnable); 69 } 70 71 @NonNull 72 @Override 73 public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { 74 GuidanceStylist.Guidance guidance = new GuidanceStylist.Guidance(mMovie.getTitle(), 75 getString(R.string.wizard_example_just_a_second), 76 mMovie.getBreadcrump(), null); 77 return guidance; 78 } 79 80 @Override 81 public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) { 82 GuidedAction action = new GuidedAction.Builder(getActivity()) 83 .id(ACTION_ID_PROCESSING) 84 .title(R.string.wizard_example_processing) 85 .infoOnly(true) 86 .build(); 87 actions.add(action); 88 } 89 90 private final Runnable fakeHttpRequestRunnable = new Runnable() { 91 @Override 92 public void run() { 93 GuidedStepFragment fragment = new WizardExample4thStepFragment(); 94 fragment.setArguments(getArguments()); 95 add(getFragmentManager(), fragment); 96 } 97 }; 98 99} 100