package com.basic.security.utils;
|
|
import android.app.Activity;
|
import android.content.Context;
|
import android.view.MotionEvent;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.view.inputmethod.InputMethodManager;
|
import android.widget.EditText;
|
|
import com.basic.security.base.BaseApplication;
|
|
public class KeyboardUtil {
|
|
public static void showKeyboard() {
|
InputMethodManager imm = (InputMethodManager) BaseApplication.getApplication().activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
}
|
|
|
public static void setupUI(final View view) {
|
// if (1!=1) {
|
// return;
|
// }
|
// Set up touch listener for non-text box views to hide keyboard.
|
if (!(view instanceof EditText)) {
|
view.setOnTouchListener(new View.OnTouchListener() {
|
public boolean onTouch(View v, MotionEvent event) {
|
// System.out.println("KeyboardUtil.onTouch setOnTouchListener view="+v + ", parent="+view.getParent());
|
KeyboardUtil.hideSoftKeyboard();
|
return false;
|
}
|
});
|
}
|
//If a layout container, iterate over children and seed recursion.
|
if (view instanceof ViewGroup) {
|
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
|
View innerView = ((ViewGroup) view).getChildAt(i);
|
setupUI(innerView);
|
}
|
}
|
}
|
|
|
public static void hideSoftKeyboard() {
|
Activity activity = BaseApplication.getApplication().activity;
|
InputMethodManager inputMethodManager =
|
(InputMethodManager) activity.getSystemService(
|
Activity.INPUT_METHOD_SERVICE);
|
View view = activity.getCurrentFocus();
|
if (view != null) {
|
inputMethodManager.hideSoftInputFromWindow(
|
view.getWindowToken(), 0);
|
}
|
}
|
|
|
}
|