1 /* 2 * Copyright 2023 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 package android.view.inputmethod.ctstestlauncher; 17 18 import android.app.Activity; 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.graphics.Color; 22 import android.os.Bundle; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.view.inputmethod.cts.util.MockTestActivityUtil; 26 27 /** 28 * A test launcher activity which display a full screen handwriting delegator view. Handwriting on 29 * the view triggers the intent to open android.view.inputmethod.ctstestapp.MainActivity and start 30 * handwriting in the EditText in that activity. 31 */ 32 public final class LauncherActivity extends Activity { 33 34 @Override onCreate(Bundle savedInstanceState)35 public void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 38 // Intent to launch the ctstestapp MainActivity which contains a delegate editor. 39 Intent ctsTestAppIntent = new Intent(Intent.ACTION_MAIN); 40 ctsTestAppIntent.setComponent(new ComponentName( 41 "android.view.inputmethod.ctstestapp", 42 "android.view.inputmethod.ctstestapp.MainActivity")); 43 ctsTestAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 44 String privateImeOptions = 45 getIntent().getStringExtra(MockTestActivityUtil.EXTRA_KEY_PRIVATE_IME_OPTIONS); 46 if (privateImeOptions != null) { 47 ctsTestAppIntent.putExtra( 48 MockTestActivityUtil.EXTRA_KEY_PRIVATE_IME_OPTIONS, privateImeOptions); 49 } 50 if (getIntent().getBooleanExtra(MockTestActivityUtil.EXTRA_HANDWRITING_DELEGATE, false)) { 51 ctsTestAppIntent.putExtra(MockTestActivityUtil.EXTRA_HANDWRITING_DELEGATE, true); 52 } 53 if (getIntent().getBooleanExtra( 54 MockTestActivityUtil.EXTRA_HOME_HANDWRITING_DELEGATOR_ALLOWED, false)) { 55 ctsTestAppIntent.putExtra( 56 MockTestActivityUtil.EXTRA_HOME_HANDWRITING_DELEGATOR_ALLOWED, true); 57 } 58 59 // Full screen handwriting delegator view 60 View delegatorView = new View(this); 61 delegatorView.setBackgroundColor(Color.GREEN); 62 delegatorView.setHandwritingDelegatorCallback(() -> startActivity(ctsTestAppIntent)); 63 delegatorView.setAllowedHandwritingDelegatePackage("android.view.inputmethod.ctstestapp"); 64 delegatorView.setFitsSystemWindows(true); 65 setContentView(delegatorView, new ViewGroup.LayoutParams( 66 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 67 } 68 } 69