Home | History | Annotate | Download | only in cts
      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.app.Activity;
     20 import android.assist.common.Utils;
     21 import android.content.ComponentName;
     22 import android.content.Intent;
     23 import android.content.pm.PackageManager;
     24 import android.os.Bundle;
     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 Activity {
     33     static final String TAG = "TestStartActivity";
     34 
     35     private ScrollView mScrollView;
     36     private TextView mTextView;
     37 
     38     @Override
     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 =  (TextView) findViewById(R.id.text_view);
     52                 mScrollView = (ScrollView) 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 = (WebView) findViewById(R.id.webview);
     65                     webview.setWebViewClient(new WebViewClient() {
     66                         @Override
     67                         public void onPageFinished(WebView view, String url) {
     68                             sendBroadcast(new Intent(Utils.TEST_ACTIVITY_LOADED));
     69                         }
     70                     });
     71                     webview.loadData(Utils.WEBVIEW_HTML, "text/html", "UTF-8");
     72                 }
     73                 return;
     74         }
     75     }
     76 
     77     @Override
     78     protected void onResume() {
     79         super.onResume();
     80         Log.i(TAG, " in onResume");
     81     }
     82 
     83     public void startTest(String testCaseName) {
     84         Log.i(TAG, "Starting test activity for TestCaseType = " + testCaseName);
     85         Intent intent = new Intent();
     86         intent.putExtra(Utils.TESTCASE_TYPE, testCaseName);
     87         intent.setAction("android.intent.action.START_TEST_" + testCaseName);
     88         intent.setComponent(new ComponentName("android.assist.service",
     89                 "android.assist." + Utils.getTestActivity(testCaseName)));
     90         startActivity(intent);
     91     }
     92 
     93     public void start3pApp(String testCaseName) {
     94         Intent intent = new Intent();
     95         intent.putExtra(Utils.TESTCASE_TYPE, testCaseName);
     96         intent.setAction("android.intent.action.TEST_APP_" + testCaseName);
     97         intent.setComponent(Utils.getTestAppComponent(testCaseName));
     98         startActivity(intent);
     99     }
    100 
    101     public void start3pAppWithColor(String testCaseName, int color) {
    102         Intent intent = new Intent();
    103         intent.setAction("android.intent.action.TEST_APP_" + testCaseName);
    104         intent.putExtra(Utils.SCREENSHOT_COLOR_KEY, color);
    105         intent.setComponent(Utils.getTestAppComponent(testCaseName));
    106         startActivity(intent);
    107     }
    108 
    109     @Override
    110     protected void onPause() {
    111         Log.i(TAG, " in onPause");
    112         super.onPause();
    113     }
    114 
    115     @Override
    116     protected void onStart() {
    117         super.onStart();
    118         Log.i(TAG, " in onStart");
    119     }
    120 
    121     @Override protected void onRestart() {
    122         super.onRestart();
    123         Log.i(TAG, " in onRestart");
    124     }
    125 
    126     @Override
    127     protected void onStop() {
    128         Log.i(TAG, " in onStop");
    129         super.onStop();
    130     }
    131 
    132     @Override
    133     protected void onDestroy() {
    134         Log.i(TAG, " in onDestroy");
    135         super.onDestroy();
    136     }
    137 
    138     public void scrollText(int scrollX, int scrollY, boolean scrollTextView,
    139             boolean scrollScrollView) {
    140         if (scrollTextView) {
    141             if (scrollX < 0 || scrollY < 0) {
    142                 scrollX = mTextView.getWidth();
    143                 scrollY = mTextView.getLayout().getLineTop(mTextView.getLineCount()) - mTextView.getHeight();
    144             }
    145             Log.i(TAG, "Scrolling text view to " + scrollX + ", " + scrollY);
    146             mTextView.scrollTo(scrollX, scrollY);
    147         } else if (scrollScrollView) {
    148             if (scrollX < 0 || scrollY < 0) {
    149                 Log.i(TAG, "Scrolling scroll view to bottom right");
    150                 mScrollView.fullScroll(View.FOCUS_DOWN);
    151                 mScrollView.fullScroll(View.FOCUS_RIGHT);
    152             } else {
    153                 Log.i(TAG, "Scrolling scroll view to " + scrollX + ", " + scrollY);
    154                 mScrollView.scrollTo(scrollX, scrollY);
    155             }
    156         }
    157     }
    158 }
    159