summaryrefslogtreecommitdiff
path: root/tests/CtsUiAutomatorTest/testapp/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/CtsUiAutomatorTest/testapp/src')
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/LaunchedActivity.java31
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/MainActivity.java60
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/SinglePaneDetailActivity.java56
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test1DetailFragment.java80
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test2DetailFragment.java153
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test3DetailFragment.java134
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test4DetailFragment.java178
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test5DetailFragment.java151
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test6DetailFragment.java50
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestGenericDetailFragment.java176
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestItems.java128
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestListFragment.java105
-rw-r--r--tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestTimeoutFragment.java74
13 files changed, 1376 insertions, 0 deletions
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/LaunchedActivity.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/LaunchedActivity.java
new file mode 100644
index 0000000..ca48974
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/LaunchedActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class LaunchedActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.launched_activity);
+ }
+
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/MainActivity.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/MainActivity.java
new file mode 100644
index 0000000..097d15a
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/MainActivity.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.view.WindowManager;
+
+public class MainActivity extends FragmentActivity implements TestListFragment.Callbacks {
+
+ private boolean mTwoPane;
+ public static final String LOG_TAG = "UiAutomatorApp";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // If the device is locked, this attempts to dismiss the KeyGuard
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
+ WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
+ setContentView(R.layout.list_activity);
+
+ if (findViewById(R.id.test_detail_container) != null) {
+ mTwoPane = true;
+ ((TestListFragment) getSupportFragmentManager().findFragmentById(R.id.item_list))
+ .setActivateOnItemClick(true);
+ }
+ }
+
+ @Override
+ public void onItemSelected(String id) {
+ if (mTwoPane) {
+ Fragment fragment = TestItems.getFragment(id);
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.test_detail_container, fragment).commit();
+ } else {
+ Intent detailIntent = new Intent(this, SinglePaneDetailActivity.class);
+ detailIntent.putExtra("item_id", id);
+ startActivity(detailIntent);
+ }
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/SinglePaneDetailActivity.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/SinglePaneDetailActivity.java
new file mode 100644
index 0000000..d45ac2b
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/SinglePaneDetailActivity.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.NavUtils;
+import android.view.Menu;
+import android.view.MenuItem;
+
+public class SinglePaneDetailActivity extends FragmentActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.singlepane_activity);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+
+ if (savedInstanceState == null) {
+ Fragment fragment = TestItems.getFragment(getIntent().getStringExtra("item_id"));
+ getSupportFragmentManager().beginTransaction()
+ .add(R.id.test_results_detail_container, fragment).commit();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.test_results_detail_activity, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test1DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test1DetailFragment.java
new file mode 100644
index 0000000..e547434
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test1DetailFragment.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class Test1DetailFragment extends Fragment {
+
+ public static final String ARG_ITEM_ID = "item_id";
+ private Button mSubmitButton;
+ private EditText mEditText;
+ TestItems.TestItem mItem;
+
+ public Test1DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments().containsKey(ARG_ITEM_ID)) {
+ mItem = TestItems.getTest(getArguments().getString(ARG_ITEM_ID));
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test1_detail_fragment, container, false);
+ if (mItem != null) {
+ ((EditText) rootView.findViewById(R.id.test1TextField)).setText(mItem.mName);
+
+ mSubmitButton = (Button) rootView.findViewById(R.id.test1SubmitButton);
+ mEditText = (EditText) rootView.findViewById(R.id.test1TextField);
+ mEditText.setText("");
+ mSubmitButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final String savedInput = mEditText.getText().toString();
+ // clear so we won't be confused by the input text in
+ // validation
+ mEditText.setText("");
+ // close soft keyboard
+ InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
+ // display the submitted text
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.item1_dialog_title);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(savedInput);
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+ });
+ }
+ return rootView;
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test2DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test2DetailFragment.java
new file mode 100644
index 0000000..969a5aa
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test2DetailFragment.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.AlertDialog;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+public class Test2DetailFragment extends Fragment {
+ public static final String ARG_ITEM_ID = "item_id";
+ private Button mButton1, mButton2, mButton3, mDynaButton;
+
+ public Test2DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.test2_detail_activity, menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setMessage(item.getTitle());
+ builder.setPositiveButton(R.string.OK, null);
+ AlertDialog diag = builder.create();
+ diag.show();
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test2_detail_fragment, container, false);
+
+ mButton1 = (Button) rootView.findViewById(R.id.test2button1);
+ mButton2 = (Button) rootView.findViewById(R.id.test2button2);
+ mButton3 = (Button) rootView.findViewById(R.id.test2button3);
+ mDynaButton = (Button) rootView.findViewById(R.id.test2dynaButton);
+
+ mButton1.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button1);
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+ });
+
+ mButton1.setOnLongClickListener(new Button.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button1long);
+ AlertDialog diag = builder.create();
+ diag.show();
+ return true;
+ }
+ });
+
+ mButton2.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button2);
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+ });
+
+ mButton2.setOnLongClickListener(new Button.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button2long);
+ AlertDialog diag = builder.create();
+ diag.show();
+ return true;
+ }
+ });
+
+ mButton3.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button3);
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+ });
+
+ mButton3.setOnLongClickListener(new Button.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(R.string.button3long);
+ AlertDialog diag = builder.create();
+ diag.show();
+ return true;
+ }
+ });
+
+ mDynaButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mDynaButton.setText(R.string.buttonAfter);
+ mDynaButton.setContentDescription(getString(R.string.buttonAfter));
+ }
+ });
+
+ return rootView;
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test3DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test3DetailFragment.java
new file mode 100644
index 0000000..f90709b
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test3DetailFragment.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.SystemClock;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+
+public class Test3DetailFragment extends Fragment {
+
+ public static final String ARG_ITEM_ID = "item_id";
+ private TextView mTextClock;
+ private Button mSubmitButton;
+ private EditText mEditText;
+ private long mCurrentTime;
+ private final Object sync = new Object();
+ private boolean mRunCounter = true;
+
+ public Test3DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.test2_detail_activity, menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.dialog_title_result);
+ builder.setMessage(item.getTitle());
+ builder.setPositiveButton(R.string.OK, null);
+ AlertDialog diag = builder.create();
+ diag.show();
+ return super.onOptionsItemSelected(item);
+ }
+
+ private final Handler mHandler = new Handler();
+
+ final Runnable mClockRunnable = new Runnable() {
+ @Override
+ public void run() {
+ // call the activity method that updates the UI
+ updateClockOnUi();
+ }
+ };
+
+ private void updateClockOnUi() {
+ synchronized (sync) {
+ mTextClock.setText("" + mCurrentTime);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test3_detail_fragment, container, false);
+ mTextClock = (TextView) rootView.findViewById(R.id.test3ClockTextView);
+ mSubmitButton = (Button) rootView.findViewById(R.id.test3SubmitButton);
+ mEditText = (EditText) rootView.findViewById(R.id.test3TextField);
+ mSubmitButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // close soft keyboard
+ InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
+
+ // display the submitted text
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.test3_dialog_title);
+ builder.setPositiveButton(R.string.OK, null);
+ CharSequence inputText = mEditText.getText();
+ if (inputText != null && !inputText.toString().isEmpty()) {
+ long inputTime = Long.parseLong(inputText.toString());
+ builder.setMessage("" + (mCurrentTime - inputTime));
+ } else {
+ builder.setMessage("<NO DATA>");
+ }
+ AlertDialog diag = builder.create();
+ diag.show();
+ mEditText.setText("");
+ mRunCounter = false;
+ }
+ });
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (mRunCounter) {
+ synchronized (sync) {
+ mCurrentTime = SystemClock.elapsedRealtime();
+ }
+ mHandler.post(mClockRunnable);
+ SystemClock.sleep(100);
+ }
+ }
+ }).start();
+
+ return rootView;
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test4DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test4DetailFragment.java
new file mode 100644
index 0000000..ce535c4
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test4DetailFragment.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.ActionBar;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+public class Test4DetailFragment extends Fragment implements ActionBar.TabListener {
+ public static final String ARG_ITEM_ID = "item_id";
+
+ /**
+ * The {@link android.support.v4.view.PagerAdapter} that will provide
+ * fragments for each of the sections. We use a
+ * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
+ * will keep every loaded fragment in memory. If this becomes too memory
+ * intensive, it may be best to switch to a
+ * {@link android.support.v4.app.FragmentStatePagerAdapter}.
+ */
+ SectionsPagerAdapter mSectionsPagerAdapter;
+
+ /**
+ * The {@link ViewPager} that will host the section contents.
+ */
+ ViewPager mViewPager;
+
+ public Test4DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onDestroyView() {
+ getActivity().getActionBar().removeAllTabs();
+ super.onDestroyView();
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+
+ View rootView = inflater.inflate(R.layout.test4_detail_fragment, container, false);
+
+ // Set up the action bar.
+ final ActionBar actionBar = getActivity().getActionBar();
+ if (actionBar.getTabCount() > 0) {
+ return rootView;
+ }
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+
+ // Create the adapter that will return a fragment for each of the three
+ // primary sections of the app.
+ mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity().getSupportFragmentManager());
+
+ // Set up the ViewPager with the sections adapter.
+ mViewPager = (ViewPager) rootView.findViewById(R.id.test_4_detail_container);
+ mViewPager.setAdapter(mSectionsPagerAdapter);
+
+ // When swiping between different sections, select the corresponding
+ // tab. We can also use ActionBar.Tab#select() to do this if we have a
+ // reference to the Tab.
+ mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ actionBar.setSelectedNavigationItem(position);
+ }
+ });
+
+ // For each of the sections in the app, add a tab to the action bar.
+ for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
+ // Create a tab with text corresponding to the page title defined by
+ // the adapter. Also specify this Activity object, which implements
+ // the TabListener interface, as the listener for when this tab is
+ // selected.
+ actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i))
+ .setTabListener(this));
+ }
+ return rootView;
+ }
+
+ @Override
+ public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
+ }
+
+ @Override
+ public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
+ }
+
+ @Override
+ public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
+ }
+
+ /**
+ * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
+ * one of the primary sections of the app.
+ */
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int i) {
+ Fragment fragment = new DummySectionFragment();
+ Bundle args = new Bundle();
+ args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public int getCount() {
+ return 4;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return getString(R.string.title_section1).toUpperCase();
+ case 1:
+ return getString(R.string.title_section2).toUpperCase();
+ case 2:
+ return getString(R.string.title_section3).toUpperCase();
+ case 3:
+ return getString(R.string.title_section4).toUpperCase();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * A dummy fragment representing a section of the app, but that simply
+ * displays dummy text.
+ */
+ public static class DummySectionFragment extends Fragment {
+ public DummySectionFragment() {
+ }
+
+ public static final String ARG_SECTION_NUMBER = "section_number";
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ TextView textView = new TextView(getActivity());
+ textView.setGravity(Gravity.CENTER);
+ Bundle args = getArguments();
+ textView.setText("[ " + Integer.toString(args.getInt(ARG_SECTION_NUMBER)) + " ]");
+ return textView;
+ }
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test5DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test5DetailFragment.java
new file mode 100644
index 0000000..ad22078
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test5DetailFragment.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.AlertDialog;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.ImageButton;
+import android.widget.SeekBar;
+import android.widget.Spinner;
+
+public class Test5DetailFragment extends Fragment {
+
+ public static final String ARG_ITEM_ID = "item_id";
+
+ class PointerEvent {
+ int startX;
+ int startY;
+ int endX;
+ int endY;
+ }
+
+ private final PointerEvent mPointerEvent = new PointerEvent();
+
+ public Test5DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test5_detail_fragment, container, false);
+
+ // Set the content description for the following
+ Spinner spinner = (Spinner) rootView.findViewById(R.id.test_5_spinner);
+ spinner.setContentDescription("Spinner");
+ ImageButton imageButton = (ImageButton) rootView.findViewById(R.id.test_5_imageButton);
+ imageButton.setContentDescription("Image button");
+
+ // Each time this view is displayed, reset the following states
+ SeekBar seekBar = (SeekBar) rootView.findViewById(R.id.test_5_seekBar);
+ seekBar.setProgress(50);
+ seekBar.setContentDescription("Progress is 50 %");
+ CheckBox checkbox = (CheckBox) rootView.findViewById(R.id.test_5_checkBox);
+ checkbox.setChecked(false);
+
+ // Register click event handlers for the following
+ Button button = (Button) rootView.findViewById(R.id.test_5_button1);
+ button.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // we want an artificial crash
+ throw new RuntimeException("Artificial crash to test UiWatcher");
+ }
+ });
+
+ imageButton.setOnTouchListener(new ImageButton.OnTouchListener() {
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ resetTouchResults();
+ collectStartAction(event, v);
+ } else if (event.getAction() == MotionEvent.ACTION_UP) {
+ collectEndAction(event, v);
+ displayTouchResults();
+ }
+ return false;
+ }
+ });
+
+ return rootView;
+ }
+
+ private void displayTouchResults() {
+ StringBuilder output = new StringBuilder();
+
+ output.append(String.format("%d,%d:%d,%d\n",
+ mPointerEvent.startX, mPointerEvent.startY, mPointerEvent.endX,
+ mPointerEvent.endY));
+
+ // display the submitted text
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.drag_item_touch_dialog_title);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(output.toString());
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+
+ /**
+ * Clears all collected pointer results
+ */
+ private void resetTouchResults() {
+ mPointerEvent.startX = mPointerEvent.startY =
+ mPointerEvent.endX = mPointerEvent.endY = -1;
+ }
+
+ /**
+ * Collects pointer touch information converting from relative to absolute before
+ * storing it as starting touch coordinates.
+ *
+ * @param event
+ * @param view
+ * @param pointerIndex
+ */
+ private void collectStartAction(MotionEvent event, View view) {
+ int offsetInScreen[] = new int[2];
+ view.getLocationOnScreen(offsetInScreen);
+ mPointerEvent.startX = (int)(event.getX() + offsetInScreen[0]);
+ mPointerEvent.startY = (int)(event.getY() + offsetInScreen[1]);
+ }
+
+ /**
+ * Collects pointer touch information converting from relative to absolute before
+ * storing it as ending touch coordinates.
+ *
+ * @param event
+ * @param view
+ * @param pointerIndex
+ */
+ private void collectEndAction(MotionEvent event, View view) {
+ int offsetInScreen[] = new int[2];
+ view.getLocationOnScreen(offsetInScreen);
+ mPointerEvent.endX = (int)(event.getX() + offsetInScreen[0]);
+ mPointerEvent.endY = (int)(event.getY() + offsetInScreen[1]);
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test6DetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test6DetailFragment.java
new file mode 100644
index 0000000..ed47734
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/Test6DetailFragment.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebView;
+
+public class Test6DetailFragment extends Fragment {
+ public static final String ARG_ITEM_ID = "item_id";
+ private final static String PAGE = "<html><body>"
+ + "This is test <b>6</b> for WebView text traversal test."
+ + "<p/><a href=\"http://google.com\">This is a link to google</a><br/>"
+ + "<h5>This is h5 text</h5>"
+ + "<a href=\"http://yahoo.com\">This is a link to yahoo</a>"
+ + "<p/><h4>This is h4 text</h4>" + "</body></html>";
+
+ public Test6DetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test6_detail_fragment, container, false);
+ WebView wv = (WebView) rootView.findViewById(R.id.test6WebView);
+ wv.loadData(PAGE, "text/html", null);
+ return rootView;
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestGenericDetailFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestGenericDetailFragment.java
new file mode 100644
index 0000000..6113ca2
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestGenericDetailFragment.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.AlertDialog;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+public class TestGenericDetailFragment extends Fragment {
+ public static final String ARG_ITEM_ID = "item_id";
+ TestItems.TestItem mItem;
+
+ private class PointerEvent {
+ int startX;
+ int startY;
+ int endX;
+ int endY;
+ }
+
+ private final PointerEvent[] mPointerEvents = new PointerEvent[10];
+
+ public TestGenericDetailFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments().containsKey(ARG_ITEM_ID)) {
+ mItem = TestItems.getTest(getArguments().getString(ARG_ITEM_ID));
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View rootView = inflater.inflate(R.layout.test_results_detail_fragment, container, false);
+ if (mItem != null) {
+ ((TextView) rootView.findViewById(R.id.testResultsTextView)).setText(mItem.mName);
+ }
+
+ // listen to touch events to verify the multiPointerGesture APIs
+ // Since API Level 18
+ rootView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+
+ switch(event.getAction() & MotionEvent.ACTION_MASK) {
+ case MotionEvent.ACTION_DOWN:
+ // Reset any collected touch coordinate results on the primary touch down
+ resetTouchResults();
+ // collect this event
+ collectStartAction(event, v, 0);
+ break;
+
+ case MotionEvent.ACTION_POINTER_DOWN:
+ // collect this event
+ collectStartAction(event, v, getPointerIndex(event));
+ break;
+
+ case MotionEvent.ACTION_POINTER_UP:
+ // collect this event
+ collectEndAction(event, v, getPointerIndex(event));
+ break;
+
+ case MotionEvent.ACTION_UP:
+ // collect this event
+ collectEndAction(event, v, 0);
+ // on the primary touch up display results collected for all pointers
+ displayTouchResults();
+ break;
+ }
+ return true;
+ }
+ });
+
+ return rootView;
+ }
+
+ /**
+ * Displays collected results from all pointers into a dialog view in the following
+ * format: "startX,startY:endX,endY" where each line represent data for a pointer if
+ * multiple pointers (fingers) were detected.
+ */
+ private void displayTouchResults() {
+ StringBuilder output = new StringBuilder();
+ for (int x = 0; x < mPointerEvents.length; x++) {
+ if (mPointerEvents[x].startX == -1)
+ break;
+
+ output.append(String.format("%d,%d:%d,%d\n",
+ mPointerEvents[x].startX, mPointerEvents[x].startY, mPointerEvents[x].endX,
+ mPointerEvents[x].endY));
+ }
+
+ // display the submitted text
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(R.string.generic_item_touch_dialog_title);
+ builder.setPositiveButton(R.string.OK, null);
+ builder.setMessage(output.toString());
+ AlertDialog diag = builder.create();
+ diag.show();
+ }
+
+ /**
+ * Clears all collected pointer results
+ */
+ private void resetTouchResults() {
+ for (int x = 0; x < mPointerEvents.length; x++) {
+ if (mPointerEvents[x] == null)
+ mPointerEvents[x] = new PointerEvent();
+ mPointerEvents[x].startX = mPointerEvents[x].startY =
+ mPointerEvents[x].endX = mPointerEvents[x].endY = -1;
+ }
+ }
+
+ /**
+ * Collects pointer touch information converting from relative to absolute before
+ * storing it as starting touch coordinates.
+ *
+ * @param event
+ * @param view
+ * @param pointerIndex
+ */
+ private void collectStartAction(MotionEvent event, View view, int pointerIndex) {
+ int offsetInScreen[] = new int[2];
+ view.getLocationOnScreen(offsetInScreen);
+ mPointerEvents[getPointerId(event)].startX =
+ (int)(event.getX(pointerIndex) + offsetInScreen[0]);
+ mPointerEvents[getPointerId(event)].startY =
+ (int)(event.getY(pointerIndex) + offsetInScreen[1]);
+ }
+
+ /**
+ * Collects pointer touch information converting from relative to absolute before
+ * storing it as ending touch coordinates.
+ *
+ * @param event
+ * @param view
+ * @param pointerIndex
+ */
+ private void collectEndAction(MotionEvent event, View view, int pointerIndex) {
+ int offsetInScreen[] = new int[2];
+ view.getLocationOnScreen(offsetInScreen);
+ mPointerEvents[getPointerId(event)].endX =
+ (int)(event.getX(pointerIndex) + offsetInScreen[0]);
+ mPointerEvents[getPointerId(event)].endY =
+ (int)(event.getY(pointerIndex) + offsetInScreen[1]);
+ }
+
+ private int getPointerId(MotionEvent event) {
+ return event.getPointerId(getPointerIndex(event));
+ }
+
+ private int getPointerIndex(MotionEvent event) {
+ return ((event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
+ >> MotionEvent.ACTION_POINTER_INDEX_SHIFT);
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestItems.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestItems.java
new file mode 100644
index 0000000..17ef46d
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestItems.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TestItems {
+ private static String LOG_TAG = TestItems.class.getSimpleName();
+ private static List<TestItem> ITEMS = new ArrayList<TestItem>();
+ private static Map<String, TestItem> ITEM_MAP = new HashMap<String, TestItem>();
+
+ public static class TestItem {
+ public String mId;
+ public String mName;
+ private final Class<Fragment> mClassFragment;
+ public String mTestDescription;
+
+ @SuppressWarnings("unchecked")
+ public TestItem(String id, String name, Class<?> clsf) {
+ mId = id;
+ mName = name;
+ mClassFragment = (Class<Fragment>) clsf;
+ }
+
+ @Override
+ public String toString() {
+ return mName;
+ }
+ }
+
+ static {
+ addTestItem(new TestItem("1", "Test 1", Test1DetailFragment.class));
+ addTestItem(new TestItem("2", "Test 2", Test2DetailFragment.class));
+ addTestItem(new TestItem("3", "Test 3", Test3DetailFragment.class));
+ addTestItem(new TestItem("4", "Test 4", Test4DetailFragment.class));
+ addTestItem(new TestItem("5", "Test 5", Test5DetailFragment.class));
+ addTestItem(new TestItem("6", "Test 6", Test6DetailFragment.class));
+ addTestItem(new TestItem("7", "Test 7", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("8", "Test 8", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("9", "Test 9", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("10", "Test 10", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("11", "Test 11", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("12", "Test 12", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("13", "Test 13", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("14", "Test 14", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("15", "Test 15", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("16", "Test 16", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("17", "Test 17", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("18", "Test 18", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("19", "Test 19", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("20", "Test 20", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("21", "Test 21", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("22", "Test 22", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("23", "Test 23", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("24", "Test 24", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("25", "Test 25", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("26", "Test 26", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("27", "Test 27", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("28", "Test 28", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("29", "Test 29", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("30", "Test 30", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("31", "Test 31", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("32", "Test 32", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("33", "Test 33", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("34", "Test 34", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("35", "Test 35", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("36", "Test 36", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("37", "Test 37", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("38", "Test 38", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("39", "Test 39", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("40", "Test 40", TestGenericDetailFragment.class));
+ addTestItem(new TestItem("41", "Timeout Test", TestTimeoutFragment.class));
+ }
+
+ private static void addTestItem(TestItem item) {
+ ITEMS.add(item);
+ ITEM_MAP.put(item.mId, item);
+ }
+
+ public static List<TestItem> getTests() {
+ return ITEMS;
+ }
+
+ public static TestItem getTest(String id) {
+ return ITEM_MAP.get(id);
+ }
+
+ public static TestItem getTest(int pos) {
+ return ITEMS.get(pos);
+ }
+
+ public static Fragment getFragment(String id) {
+ try {
+ Fragment fragment = getTest(id).mClassFragment.newInstance();
+ Bundle arguments = new Bundle();
+ arguments.putString("item_id", id);
+ fragment.setArguments(arguments);
+ return fragment;
+ } catch (InstantiationException e) {
+ Log.e(LOG_TAG, "Exception", e);
+ return null;
+ } catch (IllegalAccessException e) {
+ Log.e(LOG_TAG, "Exception", e);
+ return null;
+ }
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestListFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestListFragment.java
new file mode 100644
index 0000000..f93dd04
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestListFragment.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.ListFragment;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+public class TestListFragment extends ListFragment {
+
+ private static final String STATE_ACTIVATED_POSITION = "activated_position";
+
+ private Callbacks mCallbacks = sDummyCallbacks;
+ private int mActivatedPosition = ListView.INVALID_POSITION;
+
+ public interface Callbacks {
+
+ public void onItemSelected(String id);
+ }
+
+ private static Callbacks sDummyCallbacks = new Callbacks() {
+ @Override
+ public void onItemSelected(String id) {
+ }
+ };
+
+ public TestListFragment() {
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setListAdapter(new ArrayAdapter<TestItems.TestItem>(getActivity(),
+ R.layout.simple_list_item_selected, R.id.label, TestItems.getTests()));
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedState) {
+ super.onViewCreated(view, savedState);
+ if (savedState != null && savedState.containsKey(STATE_ACTIVATED_POSITION)) {
+ setActivatedPosition(savedState.getInt(STATE_ACTIVATED_POSITION));
+ }
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
+
+ @Override
+ public void onListItemClick(ListView listView, View view, int position, long id) {
+ super.onListItemClick(listView, view, position, id);
+ mCallbacks.onItemSelected(TestItems.getTest(position).mId);
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if (mActivatedPosition != ListView.INVALID_POSITION) {
+ outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
+ }
+ }
+
+ public void setActivateOnItemClick(boolean activateOnItemClick) {
+ getListView().setChoiceMode(
+ activateOnItemClick ? ListView.CHOICE_MODE_SINGLE : ListView.CHOICE_MODE_NONE);
+ }
+
+ public void setActivatedPosition(int position) {
+ if (position == ListView.INVALID_POSITION) {
+ getListView().setItemChecked(mActivatedPosition, false);
+ } else {
+ getListView().setItemChecked(position, true);
+ }
+
+ mActivatedPosition = position;
+ }
+}
diff --git a/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestTimeoutFragment.java b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestTimeoutFragment.java
new file mode 100644
index 0000000..3b3fd8b
--- /dev/null
+++ b/tests/CtsUiAutomatorTest/testapp/src/com/android/uiautomator/tests/cts/testapp/TestTimeoutFragment.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.uiautomator.tests.cts.testapp;
+
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class TestTimeoutFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ View v = inflater.inflate(R.layout.test_timeout_fragment, container, false);
+
+ Button goButton = (Button)v.findViewById(R.id.go_btn);
+ goButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ doAction(v);
+ }
+ });
+
+ return v;
+ }
+
+ public void doAction(View v) {
+ String delayText = ((EditText)getView().findViewById(R.id.delay)).getText().toString();
+ final int delayValue = delayText.isEmpty() ? 0 : Integer.parseInt(delayText);
+
+ new StartActivityDelayed(delayValue).execute();
+ }
+
+ private class StartActivityDelayed extends AsyncTask<Void, Void, Void> {
+ private final long mDelay;
+
+ public StartActivityDelayed(int delay) {
+ mDelay = delay;
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Thread.sleep(mDelay);
+ } catch (InterruptedException e) { }
+
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ getActivity().startActivity(new Intent(getActivity(), LaunchedActivity.class));
+ }
+ }
+}