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.BaseRemoteCallbackActivity; 20 import android.assist.common.Utils; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 import android.os.Bundle; 24 import android.os.RemoteCallback; 25 import android.util.Log; 26 import android.view.View; 27 import android.webkit.WebView; 28 import android.webkit.WebViewClient; 29 import android.widget.ScrollView; 30 import android.widget.TextView; 31 32 public class TestStartActivity extends BaseRemoteCallbackActivity { 33 static final String TAG = "TestStartActivity"; 34 35 private ScrollView mScrollView; 36 private TextView mTextView; 37 38 @Override onCreate(Bundle savedInstanceState)39 public void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 Log.i(TAG, " in onCreate"); 42 // Set the respective view we want compared with the test activity 43 String testName = getIntent().getStringExtra(Utils.TESTCASE_TYPE); 44 switch (testName) { 45 case Utils.ASSIST_STRUCTURE: 46 setContentView(R.layout.test_app); 47 setTitle(R.string.testAppTitle); 48 return; 49 case Utils.TEXTVIEW: 50 setContentView(R.layout.text_view); 51 mTextView = findViewById(R.id.text_view); 52 mScrollView = findViewById(R.id.scroll_view); 53 setTitle(R.string.textViewActivityTitle); 54 return; 55 case Utils.LARGE_VIEW_HIERARCHY: 56 setContentView(R.layout.multiple_text_views); 57 setTitle(R.string.testAppTitle); 58 return; 59 case Utils.WEBVIEW: 60 if (getPackageManager().hasSystemFeature( 61 PackageManager.FEATURE_WEBVIEW)) { 62 setContentView(R.layout.webview); 63 setTitle(R.string.webViewActivityTitle); 64 WebView webview = findViewById(R.id.webview); 65 webview.setWebViewClient(new WebViewClient() { 66 @Override 67 public void onPageFinished(WebView view, String url) { 68 TestStartActivity.this.notify(Utils.TEST_ACTIVITY_WEBVIEW_LOADED); 69 } 70 }); 71 webview.loadData(Utils.WEBVIEW_HTML, "text/html", "UTF-8"); 72 } 73 return; 74 } 75 } 76 77 @Override onResume()78 protected void onResume() { 79 super.onResume(); 80 Log.i(TAG, " in onResume"); 81 } 82 83 @Override onPause()84 protected void onPause() { 85 Log.i(TAG, " in onPause"); 86 super.onPause(); 87 } 88 89 @Override onStart()90 protected void onStart() { 91 super.onStart(); 92 Log.i(TAG, " in onStart"); 93 } 94 onRestart()95 @Override protected void onRestart() { 96 super.onRestart(); 97 Log.i(TAG, " in onRestart"); 98 } 99 100 @Override onStop()101 protected void onStop() { 102 Log.i(TAG, " in onStop"); 103 super.onStop(); 104 } 105 106 @Override onDestroy()107 protected void onDestroy() { 108 Log.i(TAG, " in onDestroy"); 109 super.onDestroy(); 110 } 111 scrollText(int scrollX, int scrollY, boolean scrollTextView, boolean scrollScrollView)112 public void scrollText(int scrollX, int scrollY, boolean scrollTextView, 113 boolean scrollScrollView) { 114 if (scrollX < 0 || scrollY < 0) { 115 scrollX = mTextView.getWidth(); 116 scrollY = mTextView.getLayout().getLineTop(mTextView.getLineCount()) - mTextView.getHeight(); 117 } 118 int finalScrollX = scrollX; 119 int finalScrollY = scrollY; 120 runOnUiThread(() -> { 121 if (scrollTextView) { 122 Log.i(TAG, "Scrolling text view to " + finalScrollX + ", " + finalScrollY); 123 mTextView.scrollTo(finalScrollX, finalScrollY); 124 } else if (scrollScrollView) { 125 if (finalScrollX < 0 || finalScrollY < 0) { 126 Log.i(TAG, "Scrolling scroll view to bottom right"); 127 mScrollView.fullScroll(View.FOCUS_DOWN); 128 mScrollView.fullScroll(View.FOCUS_RIGHT); 129 } else { 130 Log.i(TAG, "Scrolling scroll view to " + finalScrollX + ", " + finalScrollY); 131 mScrollView.scrollTo(finalScrollX, finalScrollY); 132 } 133 } 134 }); 135 } 136 } 137