1 /* 2 * Copyright (C) 2015 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.assist.cts; 18 19 import android.assist.common.Utils; 20 21 import android.app.Activity; 22 import android.app.assist.AssistStructure; 23 import android.app.assist.AssistStructure.ViewNode; 24 import android.content.Intent; 25 import android.content.ComponentName; 26 import android.content.pm.PackageManager; 27 import android.os.Bundle; 28 import android.util.Log; 29 import android.view.View; 30 import android.view.ViewGroup; 31 import android.view.Window; 32 import android.webkit.WebView; 33 import android.webkit.WebViewClient; 34 import android.widget.ScrollView; 35 import android.widget.TextView; 36 37 import java.lang.Override; 38 39 public class TestStartActivity extends Activity { 40 static final String TAG = "TestStartActivity"; 41 42 private ScrollView mScrollView; 43 private TextView mTextView; 44 45 @Override onCreate(Bundle savedInstanceState)46 public void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 Log.i(TAG, " in onCreate"); 49 // Set the respective view we want compared with the test activity 50 String testName = getIntent().getStringExtra(Utils.TESTCASE_TYPE); 51 switch (testName) { 52 case Utils.ASSIST_STRUCTURE: 53 setContentView(R.layout.test_app); 54 setTitle(R.string.testAppTitle); 55 return; 56 case Utils.TEXTVIEW: 57 setContentView(R.layout.text_view); 58 mTextView = (TextView) findViewById(R.id.text_view); 59 mScrollView = (ScrollView) findViewById(R.id.scroll_view); 60 setTitle(R.string.textViewActivityTitle); 61 return; 62 case Utils.LARGE_VIEW_HIERARCHY: 63 setContentView(R.layout.multiple_text_views); 64 setTitle(R.string.testAppTitle); 65 return; 66 case Utils.WEBVIEW: 67 if (getPackageManager().hasSystemFeature( 68 PackageManager.FEATURE_WEBVIEW)) { 69 setContentView(R.layout.webview); 70 setTitle(R.string.webViewActivityTitle); 71 WebView webview = (WebView) findViewById(R.id.webview); 72 webview.setWebViewClient(new WebViewClient() { 73 @Override 74 public void onPageFinished(WebView view, String url) { 75 sendBroadcast(new Intent(Utils.TEST_ACTIVITY_LOADED)); 76 } 77 }); 78 webview.loadData(Utils.WEBVIEW_HTML, "text/html", "UTF-8"); 79 } 80 return; 81 } 82 } 83 84 @Override onResume()85 protected void onResume() { 86 super.onResume(); 87 Log.i(TAG, " in onResume"); 88 } 89 startTest(String testCaseName)90 public void startTest(String testCaseName) { 91 Log.i(TAG, "Starting test activity for TestCaseType = " + testCaseName); 92 Intent intent = new Intent(); 93 intent.putExtra(Utils.TESTCASE_TYPE, testCaseName); 94 intent.setAction("android.intent.action.START_TEST_" + testCaseName); 95 intent.setComponent(new ComponentName("android.assist.service", 96 "android.assist." + Utils.getTestActivity(testCaseName))); 97 startActivity(intent); 98 } 99 start3pApp(String testCaseName)100 public void start3pApp(String testCaseName) { 101 Intent intent = new Intent(); 102 intent.putExtra(Utils.TESTCASE_TYPE, testCaseName); 103 intent.setAction("android.intent.action.TEST_APP_" + testCaseName); 104 intent.setComponent(Utils.getTestAppComponent(testCaseName)); 105 startActivity(intent); 106 } 107 start3pAppWithColor(String testCaseName, int color)108 public void start3pAppWithColor(String testCaseName, int color) { 109 Intent intent = new Intent(); 110 intent.setAction("android.intent.action.TEST_APP_" + testCaseName); 111 intent.putExtra(Utils.SCREENSHOT_COLOR_KEY, color); 112 intent.setComponent(Utils.getTestAppComponent(testCaseName)); 113 startActivity(intent); 114 } 115 116 @Override onPause()117 protected void onPause() { 118 Log.i(TAG, " in onPause"); 119 super.onPause(); 120 } 121 122 @Override onStart()123 protected void onStart() { 124 super.onStart(); 125 Log.i(TAG, " in onStart"); 126 } 127 onRestart()128 @Override protected void onRestart() { 129 super.onRestart(); 130 Log.i(TAG, " in onRestart"); 131 } 132 133 @Override onStop()134 protected void onStop() { 135 Log.i(TAG, " in onStop"); 136 super.onStop(); 137 } 138 139 @Override onDestroy()140 protected void onDestroy() { 141 Log.i(TAG, " in onDestroy"); 142 super.onDestroy(); 143 } 144 scrollText(int scrollX, int scrollY, boolean scrollTextView, boolean scrollScrollView)145 public void scrollText(int scrollX, int scrollY, boolean scrollTextView, 146 boolean scrollScrollView) { 147 if (scrollTextView) { 148 if (scrollX < 0 || scrollY < 0) { 149 scrollX = mTextView.getWidth(); 150 scrollY = mTextView.getLayout().getLineTop(mTextView.getLineCount()) - mTextView.getHeight(); 151 } 152 Log.i(TAG, "Scrolling text view to " + scrollX + ", " + scrollY); 153 mTextView.scrollTo(scrollX, scrollY); 154 } else if (scrollScrollView) { 155 if (scrollX < 0 || scrollY < 0) { 156 Log.i(TAG, "Scrolling scroll view to bottom right"); 157 mScrollView.fullScroll(View.FOCUS_DOWN); 158 mScrollView.fullScroll(View.FOCUS_RIGHT); 159 } else { 160 Log.i(TAG, "Scrolling scroll view to " + scrollX + ", " + scrollY); 161 mScrollView.scrollTo(scrollX, scrollY); 162 } 163 } 164 } 165 } 166