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