1 // CHECKSTYLE:OFF Generated code
2 /* This file is auto-generated from SingleSupportFragmentTestActivity.java.  DO NOT MODIFY. */
3 
4 /*
5  * Copyright (C) 2016 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 package androidx.leanback.app;
20 
21 import android.app.Activity;
22 import android.app.Fragment;
23 import android.app.FragmentTransaction;
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.util.Log;
27 
28 import androidx.leanback.test.R;
29 
30 public class SingleFragmentTestActivity extends Activity {
31 
32     /**
33      * Fragment that will be added to activity
34      */
35     public static final String EXTRA_FRAGMENT_NAME = "fragmentName";
36 
37     public static final String EXTRA_ACTIVITY_LAYOUT = "activityLayout";
38 
39     public static final String EXTRA_UI_VISIBILITY = "uiVisibility";
40 
41     public static final String EXTRA_OVERRIDDEN_SAVED_INSTANCE_STATE =
42             "overriddenSavedInstanceState";
43 
44     private static final String TAG = "TestActivity";
45 
overrideSavedInstance(Bundle savedInstance)46     private Bundle overrideSavedInstance(Bundle savedInstance) {
47         Intent intent = getIntent();
48         if (intent != null) {
49             Bundle b = intent.getBundleExtra(EXTRA_OVERRIDDEN_SAVED_INSTANCE_STATE);
50             if (b != null) {
51                 return b;
52             }
53         }
54         return savedInstance;
55     }
56 
57     @Override
onCreate(Bundle savedInstanceState)58     public void onCreate(Bundle savedInstanceState) {
59         savedInstanceState = overrideSavedInstance(savedInstanceState);
60         super.onCreate(savedInstanceState);
61         Log.d(TAG, "onCreate " + this);
62         Intent intent = getIntent();
63 
64         final int uiOptions = intent.getIntExtra(EXTRA_UI_VISIBILITY, 0);
65         if (uiOptions != 0) {
66             getWindow().getDecorView().setSystemUiVisibility(uiOptions);
67         }
68 
69         setContentView(intent.getIntExtra(EXTRA_ACTIVITY_LAYOUT, R.layout.single_fragment));
70         if (savedInstanceState == null && findViewById(R.id.main_frame) != null) {
71             try {
72                 Fragment fragment = (Fragment) Class.forName(
73                         intent.getStringExtra(EXTRA_FRAGMENT_NAME)).newInstance();
74                 FragmentTransaction ft = getFragmentManager().beginTransaction();
75                 ft.replace(R.id.main_frame, fragment);
76                 ft.commit();
77             } catch (Exception ex) {
78                 ex.printStackTrace();
79                 finish();
80             }
81         }
82     }
83 
84     @Override
onRestoreInstanceState(Bundle savedInstanceState)85     protected void onRestoreInstanceState(Bundle savedInstanceState) {
86         super.onRestoreInstanceState(overrideSavedInstance(savedInstanceState));
87     }
88 
performSaveInstanceState()89     public Bundle performSaveInstanceState() {
90         Bundle state = new Bundle();
91         onSaveInstanceState(state);
92         return state;
93     }
94 
getTestFragment()95     public Fragment getTestFragment() {
96         return getFragmentManager().findFragmentById(R.id.main_frame);
97     }
98 }
99