1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15package androidx.leanback.app; 16 17import android.os.Bundle; 18import android.view.LayoutInflater; 19import android.view.View; 20import android.view.ViewGroup; 21 22import androidx.fragment.app.FragmentActivity; 23import androidx.fragment.app.FragmentManager; 24import androidx.leanback.widget.GuidanceStylist.Guidance; 25import androidx.leanback.widget.GuidedAction; 26 27import java.util.HashMap; 28import java.util.List; 29 30public class GuidedStepTestSupportFragment extends GuidedStepSupportFragment { 31 32 private static final String KEY_TEST_NAME = "key_test_name"; 33 34 private static final HashMap<String, Provider> sTestMap = new HashMap<String, Provider>(); 35 36 public static class Provider { 37 38 GuidedStepTestSupportFragment mFragment; 39 40 public void onCreate(Bundle savedInstanceState) { 41 } 42 43 public void onSaveInstanceState(Bundle outState) { 44 } 45 46 public Guidance onCreateGuidance(Bundle savedInstanceState) { 47 return new Guidance("", "", "", null); 48 } 49 50 public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) { 51 } 52 53 public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) { 54 } 55 56 public void onGuidedActionClicked(GuidedAction action) { 57 } 58 59 public boolean onSubGuidedActionClicked(GuidedAction action) { 60 return true; 61 } 62 63 public void onCreateView(LayoutInflater inflater, ViewGroup container, 64 Bundle savedInstanceState, View result) { 65 } 66 67 public void onDestroyView() { 68 } 69 70 public void onDestroy() { 71 } 72 73 public void onStart() { 74 } 75 76 public void onStop() { 77 } 78 79 public void onResume() { 80 } 81 82 public void onPause() { 83 } 84 85 public void onViewStateRestored(Bundle bundle) { 86 } 87 88 public void onDetach() { 89 } 90 91 public GuidedStepTestSupportFragment getFragment() { 92 return mFragment; 93 } 94 95 public FragmentActivity getActivity() { 96 return mFragment.getActivity(); 97 } 98 99 public FragmentManager getFragmentManager() { 100 return mFragment.getFragmentManager(); 101 } 102 } 103 104 public static void setupTest(String testName, Provider provider) { 105 sTestMap.put(testName, provider); 106 } 107 108 public static void clearTests() { 109 sTestMap.clear(); 110 } 111 112 CharSequence mTestName; 113 Provider mProvider; 114 115 public GuidedStepTestSupportFragment() { 116 } 117 118 public GuidedStepTestSupportFragment(String testName) { 119 setTestName(testName); 120 } 121 122 public void setTestName(CharSequence testName) { 123 mTestName = testName; 124 } 125 126 public CharSequence getTestName() { 127 return mTestName; 128 } 129 130 @Override 131 public void onCreate(Bundle savedInstanceState) { 132 if (savedInstanceState != null) { 133 mTestName = savedInstanceState.getCharSequence(KEY_TEST_NAME, null); 134 } 135 mProvider = sTestMap.get(mTestName); 136 if (mProvider == null) { 137 throw new IllegalArgumentException("you must setupTest()"); 138 } 139 mProvider.mFragment = this; 140 super.onCreate(savedInstanceState); 141 mProvider.onCreate(savedInstanceState); 142 } 143 144 @Override 145 public void onSaveInstanceState(Bundle outState) { 146 super.onSaveInstanceState(outState); 147 outState.putCharSequence(KEY_TEST_NAME, mTestName); 148 mProvider.onSaveInstanceState(outState); 149 } 150 151 @Override 152 public Guidance onCreateGuidance(Bundle savedInstanceState) { 153 Guidance g = mProvider.onCreateGuidance(savedInstanceState); 154 if (g == null) { 155 g = new Guidance("", "", "", null); 156 } 157 return g; 158 } 159 160 @Override 161 public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) { 162 mProvider.onCreateActions(actions, savedInstanceState); 163 } 164 165 @Override 166 public void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState) { 167 mProvider.onCreateButtonActions(actions, savedInstanceState); 168 } 169 170 @Override 171 public void onGuidedActionClicked(GuidedAction action) { 172 mProvider.onGuidedActionClicked(action); 173 } 174 175 @Override 176 public boolean onSubGuidedActionClicked(GuidedAction action) { 177 return mProvider.onSubGuidedActionClicked(action); 178 } 179 180 @Override 181 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { 182 View view = super.onCreateView(inflater, container, state); 183 mProvider.onCreateView(inflater, container, state, view); 184 return view; 185 } 186 187 @Override 188 public void onDestroyView() { 189 mProvider.onDestroyView(); 190 super.onDestroyView(); 191 } 192 193 @Override 194 public void onDestroy() { 195 mProvider.onDestroy(); 196 super.onDestroy(); 197 } 198 199 @Override 200 public void onPause() { 201 mProvider.onPause(); 202 super.onPause(); 203 } 204 205 @Override 206 public void onResume() { 207 super.onResume(); 208 mProvider.onResume(); 209 } 210 211 @Override 212 public void onStart() { 213 super.onStart(); 214 mProvider.onStart(); 215 } 216 217 @Override 218 public void onStop() { 219 mProvider.onStop(); 220 super.onStop(); 221 } 222 223 @Override 224 public void onDetach() { 225 mProvider.onDetach(); 226 super.onDetach(); 227 } 228 229 @Override 230 public void onViewStateRestored(Bundle bundle) { 231 super.onViewStateRestored(bundle); 232 mProvider.onViewStateRestored(bundle); 233 } 234} 235 236