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 
17 package com.android.dialer.common;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.view.View;
22 import android.view.inputmethod.InputMethodManager;
23 
24 /** Utility class for commons functions used with Android UI. */
25 public class UiUtil {
26 
27   /** Hides the android keyboard. */
hideKeyboardFrom(Context context, View view)28   public static void hideKeyboardFrom(Context context, View view) {
29     InputMethodManager imm =
30         (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
31     imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
32   }
33 
34   /** Opens the android keyboard. */
showKeyboardFrom(Context context, View view)35   public static void showKeyboardFrom(Context context, View view) {
36     InputMethodManager inputMethodManager =
37         (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
38     inputMethodManager.showSoftInput(view, 0);
39   }
40 
41   /** Force open the android keyboard. */
forceOpenKeyboardFrom(Context context, View view)42   public static void forceOpenKeyboardFrom(Context context, View view) {
43     InputMethodManager inputMethodManager =
44         (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
45     inputMethodManager.toggleSoftInputFromWindow(
46         view.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
47   }
48 }
49