GuidedStepSupportFragmentTestActivity.java revision 8619e0ef7062b6a714f22af993e4b440fae7ef08
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.content.Intent;
18import android.os.Bundle;
19
20import androidx.fragment.app.FragmentActivity;
21
22public class GuidedStepSupportFragmentTestActivity extends FragmentActivity {
23
24    /**
25     * Frst Test that will be included in this Activity
26     */
27    public static final String EXTRA_TEST_NAME = "testName";
28    /**
29     * True(default) to addAsRoot() for first Test, false to use add()
30     */
31    public static final String EXTRA_ADD_AS_ROOT = "addAsRoot";
32
33    /**
34     * Layout direction
35     */
36    public static final String EXTRA_LAYOUT_DIRECTION = "layoutDir";
37
38    @Override
39    protected void onCreate(Bundle savedInstanceState) {
40        super.onCreate(savedInstanceState);
41
42        Intent intent = getIntent();
43
44        int layoutDirection = intent.getIntExtra(EXTRA_LAYOUT_DIRECTION, -1);
45        if (layoutDirection != -1) {
46            findViewById(android.R.id.content).setLayoutDirection(layoutDirection);
47        }
48        if (savedInstanceState == null) {
49            String firstTestName = intent.getStringExtra(EXTRA_TEST_NAME);
50            if (firstTestName != null) {
51                GuidedStepTestSupportFragment testFragment = new GuidedStepTestSupportFragment(firstTestName);
52                if (intent.getBooleanExtra(EXTRA_ADD_AS_ROOT, true)) {
53                    GuidedStepTestSupportFragment.addAsRoot(this, testFragment, android.R.id.content);
54                } else {
55                    GuidedStepTestSupportFragment.add(getSupportFragmentManager(), testFragment,
56                            android.R.id.content);
57                }
58            }
59        }
60    }
61}
62