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