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