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
20package com.example.android.leanback;
21
22import android.support.v4.app.FragmentActivity;
23import android.support.v4.app.FragmentManager;
24import android.content.Context;
25import android.graphics.drawable.Drawable;
26import android.os.Bundle;
27import android.support.v17.leanback.app.GuidedStepSupportFragment;
28import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
29import android.support.v17.leanback.widget.GuidedAction;
30import android.support.v4.content.res.ResourcesCompat;
31import android.util.Log;
32
33import 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 */
40public class GuidedStepSupportHalfScreenActivity extends FragmentActivity {
41    private static final String TAG = "leanback.GuidedStepSupportHalfScreenActivity";
42
43    @Override
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
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
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
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
88        public int onProvideTheme() {
89            return R.style.Theme_Example_Leanback_GuidedStep_Half;
90        }
91
92        @Override
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
106        public int onProvideTheme() {
107            return R.style.Theme_Example_Leanback_GuidedStep_Half;
108        }
109
110        @Override
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
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
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
143        public void onGuidedActionClicked(GuidedAction action) {
144            FragmentManager fm = getFragmentManager();
145            fm.popBackStack();
146        }
147    }
148}
149