1 /* This file is auto-generated from GuidedStepHalfScreenActivity.java.  DO NOT MODIFY. */
2 
3 /*
4  * Copyright (C) 2014 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package com.example.android.leanback;
20 
21 import android.support.v4.app.FragmentActivity;
22 import android.support.v4.app.FragmentManager;
23 import android.content.Context;
24 import android.graphics.drawable.Drawable;
25 import android.os.Bundle;
26 import android.support.v17.leanback.app.GuidedStepSupportFragment;
27 import android.support.v17.leanback.widget.GuidanceStylist;
28 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
29 import android.support.v17.leanback.widget.GuidedAction;
30 import android.util.Log;
31 
32 import java.util.List;
33 
34 /**
35  * Activity that showcases different aspects of GuidedStepSupportFragments in half
36  * screen mode. This is achieved by setting the theme for this activity
37  * to {@code Theme.Example.Leanback.GuidedStep.Half}.
38  */
39 public class GuidedStepSupportHalfScreenActivity extends FragmentActivity {
40     private static final String TAG = "leanback.GuidedStepSupportHalfScreenActivity";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         Log.v(TAG, "onCreate");
45         super.onCreate(savedInstanceState);
46         setContentView(R.layout.guided_step_activity);
47         GuidedStepSupportFragment.addAsRoot(this, new FirstStepFragment(), R.id.lb_guidedstep_host);
48     }
49 
50     public static class FirstStepFragment extends GuidedStepSupportFragment {
51 
52        @Override
onCreateGuidance(Bundle savedInstanceState)53         public Guidance onCreateGuidance(Bundle savedInstanceState) {
54             String title = getString(R.string.guidedstep_first_title);
55             String breadcrumb = getString(R.string.guidedstep_first_breadcrumb);
56             String description = getString(R.string.guidedstep_first_description);
57             Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
58             return new Guidance(title, description, breadcrumb, icon);
59         }
60 
61         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)62         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
63             Context context = getActivity();
64             actions.add(new GuidedAction.Builder(context)
65                     .clickAction(GuidedAction.ACTION_ID_CONTINUE)
66                     .description("Just do it")
67                     .build());
68             actions.add(new GuidedAction.Builder(context)
69                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
70                     .description("Never mind")
71                     .build());
72         }
73 
FirstStepFragment()74         public FirstStepFragment() {
75             setEntranceTransitionType(GuidedStepSupportFragment.SLIDE_FROM_BOTTOM);
76         }
77 
78         /**
79          * This fragment could be used by an activity using theme
80          * {@code Theme.Leanback.GuidedStep.Half} or something else (BrowseActivity).
81          * In order to provide a consistent half screen experience under
82          * both scenarios, we override onProvideTheme method.
83          */
84         @Override
onProvideTheme()85         public int onProvideTheme() {
86             return R.style.Theme_Example_Leanback_GuidedStep_Half;
87         }
88 
89         @Override
onGuidedActionClicked(GuidedAction action)90         public void onGuidedActionClicked(GuidedAction action) {
91             FragmentManager fm = getFragmentManager();
92             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
93                 GuidedStepSupportFragment.add(fm, new SecondStepFragment(), R.id.lb_guidedstep_host);
94             } else if (action.getId() == GuidedAction.ACTION_ID_CANCEL){
95                 finishGuidedStepSupportFragments();
96             }
97         }
98     }
99 
100     public static class SecondStepFragment extends GuidedStepSupportFragment {
101 
102         @Override
onProvideTheme()103         public int onProvideTheme() {
104             return R.style.Theme_Example_Leanback_GuidedStep_Half;
105         }
106 
107         @Override
onCreateGuidance(Bundle savedInstanceState)108         public Guidance onCreateGuidance(Bundle savedInstanceState) {
109             String title = getString(R.string.guidedstep_second_title);
110             String breadcrumb = getString(R.string.guidedstep_second_breadcrumb);
111             String description = getString(R.string.guidedstep_second_description);
112             Drawable icon = getActivity().getResources().getDrawable(R.drawable.ic_main_icon);
113             return new Guidance(title, description, breadcrumb, icon);
114         }
115 
116         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)117         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
118             Context context = getActivity();
119             actions.add(new GuidedAction.Builder(context)
120                     .clickAction(GuidedAction.ACTION_ID_FINISH)
121                     .description("Done")
122                     .build());
123             actions.add(new GuidedAction.Builder(context)
124                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
125                     .description("Never mind")
126                     .build());
127         }
128 
129         @Override
onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState)130         public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
131             actions.add(new GuidedAction.Builder(getActivity())
132                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
133                     .description("Cancel")
134                     .build());
135         }
136 
137         @Override
onGuidedActionClicked(GuidedAction action)138         public void onGuidedActionClicked(GuidedAction action) {
139             FragmentManager fm = getFragmentManager();
140             fm.popBackStack();
141         }
142     }
143 }
144