1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.support.v17.leanback.app;
17
18import android.app.Activity;
19import android.app.Fragment;
20import android.app.FragmentTransaction;
21import android.content.Intent;
22import android.os.Bundle;
23import android.support.v17.leanback.test.R;
24import android.util.Log;
25
26public class SingleFragmentTestActivity extends Activity {
27
28    /**
29     * Fragment that will be added to activity
30     */
31    public static final String EXTRA_FRAGMENT_NAME = "fragmentName";
32
33    public static final String EXTRA_ACTIVITY_LAYOUT = "activityLayout";
34
35    public static final String EXTRA_UI_VISIBILITY = "uiVisibility";
36    private static final String TAG = "TestActivity";
37
38    @Override
39    public void onCreate(Bundle savedInstanceState) {
40        super.onCreate(savedInstanceState);
41        Log.d(TAG, "onCreate " + this);
42        Intent intent = getIntent();
43
44        final int uiOptions = intent.getIntExtra(EXTRA_UI_VISIBILITY, 0);
45        if (uiOptions != 0) {
46            getWindow().getDecorView().setSystemUiVisibility(uiOptions);
47        }
48
49        setContentView(intent.getIntExtra(EXTRA_ACTIVITY_LAYOUT, R.layout.single_fragment));
50        if (savedInstanceState == null && findViewById(R.id.main_frame) != null) {
51            try {
52                Fragment fragment = (Fragment) Class.forName(
53                        intent.getStringExtra(EXTRA_FRAGMENT_NAME)).newInstance();
54                FragmentTransaction ft = getFragmentManager().beginTransaction();
55                ft.replace(R.id.main_frame, fragment);
56                ft.commit();
57            } catch (Exception ex) {
58                ex.printStackTrace();
59                finish();
60            }
61        }
62    }
63
64    public Fragment getTestFragment() {
65        return getFragmentManager().findFragmentById(R.id.main_frame);
66    }
67}
68