1 /*
2  * Copyright (C) 2018 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 com.android.wm.shell.flicker.testapp;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.view.View;
23 import android.view.WindowManager;
24 import android.view.inputmethod.InputMethodManager;
25 
26 public class ImeActivity extends Activity {
27     private static final String ACTION_OPEN_IME =
28             "com.android.wm.shell.flicker.testapp.action.OPEN_IME";
29     private static final String ACTION_CLOSE_IME =
30             "com.android.wm.shell.flicker.testapp.action.CLOSE_IME";
31 
32     private InputMethodManager mImm;
33     private View mEditText;
34 
35     @Override
onCreate(Bundle savedInstanceState)36     public void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         WindowManager.LayoutParams p = getWindow().getAttributes();
39         p.layoutInDisplayCutoutMode = WindowManager.LayoutParams
40                 .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
41         getWindow().setAttributes(p);
42         setContentView(R.layout.activity_ime);
43 
44         mEditText = findViewById(R.id.plain_text_input);
45         mImm = getSystemService(InputMethodManager.class);
46 
47         handleIntent(getIntent());
48     }
49 
50     @Override
onNewIntent(Intent intent)51     protected void onNewIntent(Intent intent) {
52         super.onNewIntent(intent);
53         handleIntent(intent);
54     }
55 
handleIntent(Intent intent)56     private void handleIntent(Intent intent) {
57         final String action = intent.getAction();
58         if (ACTION_OPEN_IME.equals(action)) {
59             mEditText.requestFocus();
60             mImm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED);
61         } else if (ACTION_CLOSE_IME.equals(action)) {
62             mImm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
63             mEditText.clearFocus();
64         }
65     }
66 }
67