• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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  */
16 
17 package com.android.inputmethod.latin.settings;
18 
19 import android.app.Activity;
20 import android.app.Fragment;
21 import android.app.FragmentManager;
22 import android.content.Intent;
23 import android.os.Bundle;
24 
25 /**
26  * Test activity to use when testing preference fragments. <br/>
27  * Usage: <br/>
28  * Create an ActivityInstrumentationTestCase2 for this activity
29  * and call setIntent() with an intent that specifies the fragment to load in the activity.
30  * The fragment can then be obtained from this activity and used for testing/verification.
31  */
32 public final class TestFragmentActivity extends Activity {
33     /**
34      * The fragment name that should be loaded when starting this activity.
35      * This must be specified when starting this activity, as this activity is only
36      * meant to test fragments from instrumentation tests.
37      */
38     public static final String EXTRA_SHOW_FRAGMENT = "show_fragment";
39 
40     public Fragment mFragment;
41 
42     @Override
onCreate(final Bundle savedState)43     protected void onCreate(final Bundle savedState) {
44         super.onCreate(savedState);
45         final Intent intent = getIntent();
46         final String fragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
47         if (fragmentName == null) {
48             throw new IllegalArgumentException("No fragment name specified for testing");
49         }
50 
51         mFragment = Fragment.instantiate(this, fragmentName);
52         FragmentManager fragmentManager = getFragmentManager();
53         fragmentManager.beginTransaction().add(mFragment, fragmentName).commit();
54     }
55 }
56