1 /* 2 * Copyright (C) 2011 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 android.theme.cts; 18 19 import android.app.ActionBar; 20 import android.app.ActionBar.Tab; 21 import android.app.FragmentTransaction; 22 23 /** 24 * Implementation of the {@link ActivityTestInfo} interface for {@link ActionBar} tests. 25 */ 26 public class ActionBarModifier implements ActivityTestInfo { 27 /** 28 * Runs the basic test case that performs no modifications on the {@link ActionBar}. 29 */ 30 public static final int BASIC = 0; 31 32 /** 33 * Runs the test that turns the icon on the {@link ActionBar} into the up icon version. 34 */ 35 public static final int DISPLAY_HOME_AS_UP = 1; 36 37 /** 38 * Runs the test that displays tabs in the {@link ActionBar}. 39 */ 40 public static final int TABS = 2; 41 42 /** 43 * Runs the test that displays a list ({@link Spinner}-style) in the {@link ActionBar}. 44 */ 45 public static final int LIST = 3; 46 47 /** 48 * Runs the test that displays only the icon and not the title in the {@link ActionBar}. 49 */ 50 public static final int NO_TITLE = 4; 51 52 /** 53 * Runs the test that displays only the icon in the {@link ActionBar}. 54 */ 55 public static final int NO_ICON = 5; 56 57 /** 58 * Runs the test that displays action items in the {@link ActionBar}. 59 */ 60 public static final int ACTION_ITEMS = 6; 61 62 /** 63 * Runs the test that displays a {@link SearchView} as an action view in the {@link ActionBar}. 64 */ 65 public static final int ACTION_VIEW = 7; 66 67 /** 68 * Runs the test that displays a {@link SearchView} as a collapsable action view (opened) in 69 * the {@link ActionBar}. 70 */ 71 public static final int COLLAPSED_ACTION_VIEW = 8; 72 73 private String mTestname; 74 private int mTestType; 75 76 /** 77 * Creates an ActionBarModifier with the specified testname and test type. 78 * @param testname The unique name of hte test. 79 * @param testType The type of test to run based on the public constants of ActionBarModifier. 80 */ 81 public ActionBarModifier(String testname, int testType) { 82 mTestname = testname; 83 mTestType = testType; 84 } 85 86 public String getTestName() { 87 return mTestname; 88 } 89 @Override 90 public void modifyActivity(SnapshotActivity activity) { 91 ActionBar actionBar = activity.getActionBar(); 92 93 if (actionBar == null) { 94 return; 95 } 96 97 // based on which test was asked, performs a different sequence of actions 98 switch (mTestType) { 99 case BASIC: 100 break; 101 case DISPLAY_HOME_AS_UP: 102 actionBar.setDisplayHomeAsUpEnabled(true); 103 break; 104 case TABS: 105 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 106 actionBar.setDisplayShowTitleEnabled(false); 107 actionBar.addTab(actionBar.newTab().setText("First") 108 .setTabListener(new MyTabListener())); 109 actionBar.addTab(actionBar.newTab().setText("Second") 110 .setTabListener(new MyTabListener())); 111 actionBar.addTab(actionBar.newTab().setText("Third") 112 .setTabListener(new MyTabListener())); 113 break; 114 case LIST: 115 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 116 break; 117 case NO_TITLE: 118 actionBar.setDisplayShowTitleEnabled(false); 119 break; 120 case NO_ICON: 121 actionBar.setDisplayShowHomeEnabled(false); 122 break; 123 // for the last three test, a state is set because these ones must be set up 124 // in Activity.onCreateOptionsMenu. A flag is sent that is then checked later 125 // in the Activity lifecycle 126 case ACTION_ITEMS: 127 case ACTION_VIEW: 128 case COLLAPSED_ACTION_VIEW: 129 activity.setActionItemState(mTestType); 130 } 131 } 132 133 /** 134 * Stub class that exists since tabs need to have a listener. Does nothing. 135 */ 136 private class MyTabListener implements ActionBar.TabListener { 137 public void onTabSelected(Tab tab, FragmentTransaction ft) { 138 // do nothing 139 } 140 141 public void onTabUnselected(Tab tab, FragmentTransaction ft) { 142 // do nothing 143 } 144 145 public void onTabReselected(Tab tab, FragmentTransaction ft) { 146 // do nothing 147 } 148 } 149 150 } 151