• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // CHECKSTYLE:OFF Generated code
2 /* This file is auto-generated from GuidedStepHalfScreenActivity.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.FragmentManager;
24 import android.content.Context;
25 import android.graphics.drawable.Drawable;
26 import android.os.Bundle;
27 import android.support.v17.leanback.app.GuidedStepSupportFragment;
28 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
29 import android.support.v17.leanback.widget.GuidedAction;
30 import android.support.v4.content.res.ResourcesCompat;
31 import android.util.Log;
32 
33 import java.util.List;
34 
35 /**
36  * Activity that showcases different aspects of GuidedStepSupportFragments in half
37  * screen mode. This is achieved by setting the theme for this activity
38  * to {@code Theme.Example.Leanback.GuidedStep.Half}.
39  */
40 public class GuidedStepSupportHalfScreenActivity extends FragmentActivity {
41     private static final String TAG = "leanback.GuidedStepSupportHalfScreenActivity";
42 
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         Log.v(TAG, "onCreate");
46         super.onCreate(savedInstanceState);
47         setContentView(R.layout.guided_step_activity);
48         GuidedStepSupportFragment.addAsRoot(this, new FirstStepFragment(), R.id.lb_guidedstep_host);
49     }
50 
51     public static class FirstStepFragment extends GuidedStepSupportFragment {
52 
53        @Override
onCreateGuidance(Bundle savedInstanceState)54         public Guidance onCreateGuidance(Bundle savedInstanceState) {
55             String title = getString(R.string.guidedstep_first_title);
56             String breadcrumb = getString(R.string.guidedstep_first_breadcrumb);
57             String description = getString(R.string.guidedstep_first_description);
58             final Context context = getActivity();
59             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
60                     R.drawable.ic_main_icon, context.getTheme());
61             return new Guidance(title, description, breadcrumb, icon);
62         }
63 
64         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)65         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
66             Context context = getActivity();
67             actions.add(new GuidedAction.Builder(context)
68                     .clickAction(GuidedAction.ACTION_ID_CONTINUE)
69                     .description("Just do it")
70                     .build());
71             actions.add(new GuidedAction.Builder(context)
72                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
73                     .description("Never mind")
74                     .build());
75         }
76 
FirstStepFragment()77         public FirstStepFragment() {
78             setEntranceTransitionType(GuidedStepSupportFragment.SLIDE_FROM_BOTTOM);
79         }
80 
81         /**
82          * This fragment could be used by an activity using theme
83          * {@code Theme.Leanback.GuidedStep.Half} or something else (BrowseActivity).
84          * In order to provide a consistent half screen experience under
85          * both scenarios, we override onProvideTheme method.
86          */
87         @Override
onProvideTheme()88         public int onProvideTheme() {
89             return R.style.Theme_Example_Leanback_GuidedStep_Half;
90         }
91 
92         @Override
onGuidedActionClicked(GuidedAction action)93         public void onGuidedActionClicked(GuidedAction action) {
94             FragmentManager fm = getFragmentManager();
95             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
96                 GuidedStepSupportFragment.add(fm, new SecondStepFragment(), R.id.lb_guidedstep_host);
97             } else if (action.getId() == GuidedAction.ACTION_ID_CANCEL){
98                 finishGuidedStepSupportFragments();
99             }
100         }
101     }
102 
103     public static class SecondStepFragment extends GuidedStepSupportFragment {
104 
105         @Override
onProvideTheme()106         public int onProvideTheme() {
107             return R.style.Theme_Example_Leanback_GuidedStep_Half;
108         }
109 
110         @Override
onCreateGuidance(Bundle savedInstanceState)111         public Guidance onCreateGuidance(Bundle savedInstanceState) {
112             String title = getString(R.string.guidedstep_second_title);
113             String breadcrumb = getString(R.string.guidedstep_second_breadcrumb);
114             String description = getString(R.string.guidedstep_second_description);
115             final Context context = getActivity();
116             Drawable icon = ResourcesCompat.getDrawable(context.getResources(),
117                     R.drawable.ic_main_icon, context.getTheme());
118             return new Guidance(title, description, breadcrumb, icon);
119         }
120 
121         @Override
onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)122         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
123             Context context = getActivity();
124             actions.add(new GuidedAction.Builder(context)
125                     .clickAction(GuidedAction.ACTION_ID_FINISH)
126                     .description("Done")
127                     .build());
128             actions.add(new GuidedAction.Builder(context)
129                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
130                     .description("Never mind")
131                     .build());
132         }
133 
134         @Override
onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState)135         public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) {
136             actions.add(new GuidedAction.Builder(getActivity())
137                     .clickAction(GuidedAction.ACTION_ID_CANCEL)
138                     .description("Cancel")
139                     .build());
140         }
141 
142         @Override
onGuidedActionClicked(GuidedAction action)143         public void onGuidedActionClicked(GuidedAction action) {
144             FragmentManager fm = getFragmentManager();
145             fm.popBackStack();
146         }
147     }
148 }
149