1/* 2 * Copyright (C) 2016 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 17package android.text.method; 18 19import android.app.Instrumentation; 20import android.test.ActivityInstrumentationTestCase2; 21import android.text.format.DateUtils; 22import android.view.KeyEvent; 23import android.widget.EditText; 24import android.widget.TextViewActivity; 25 26import com.android.frameworks.coretests.R; 27 28public abstract class KeyListenerTestCase extends 29 ActivityInstrumentationTestCase2<TextViewActivity> { 30 31 protected TextViewActivity mActivity; 32 protected Instrumentation mInstrumentation; 33 protected EditText mTextView; 34 35 public KeyListenerTestCase() { 36 super(TextViewActivity.class); 37 } 38 39 @Override 40 protected void setUp() throws Exception { 41 super.setUp(); 42 43 mActivity = getActivity(); 44 mInstrumentation = getInstrumentation(); 45 mTextView = (EditText) mActivity.findViewById(R.id.textview); 46 47 mActivity.runOnUiThread(new Runnable() { 48 public void run() { 49 // Ensure that the screen is on for this test. 50 mTextView.setKeepScreenOn(true); 51 } 52 }); 53 54 assertTrue(mActivity.waitForWindowFocus(5 * DateUtils.SECOND_IN_MILLIS)); 55 } 56 57 protected static KeyEvent getKey(int keycode, int metaState) { 58 long currentTime = System.currentTimeMillis(); 59 return new KeyEvent(currentTime, currentTime, KeyEvent.ACTION_DOWN, keycode, 60 0 /* repeat */, metaState); 61 } 62} 63