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 
17 package androidx.core.view.inputmethod;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.widget.Button;
22 import android.widget.EditText;
23 
24 import androidx.annotation.RequiresApi;
25 import androidx.core.R;
26 import androidx.core.view.WindowCompat;
27 import androidx.core.view.WindowInsetsCompat;
28 import androidx.core.view.WindowInsetsControllerCompat;
29 
30 import org.jspecify.annotations.Nullable;
31 
32 @RequiresApi(30)
33 public class ImeSecondarySplitTestActivity extends Activity {
34 
35     EditText mEditText;
36 
37     Button mHideImeButton;
38 
39     @Override
onCreate(@ullable Bundle savedInstanceState)40     protected void onCreate(@Nullable Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42         setContentView(R.layout.ime_secondary_split_test_activity);
43         mEditText = findViewById(R.id.edit_text_id);
44         mHideImeButton = findViewById(R.id.hide_ime_id);
45         mHideImeButton.setOnClickListener(view -> hideIme());
46     }
47 
hideIme()48     private void hideIme() {
49         // Use WindowInsetsControllerCompat to hide ime.
50         WindowInsetsControllerCompat insetsController =
51                 WindowCompat.getInsetsController(getWindow(), mEditText);
52         insetsController.hide(WindowInsetsCompat.Type.ime());
53     }
54 }
55