Guest User

Untitled

a guest
Dec 11th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package com.instantag.instantags.utils;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.os.IBinder;
  6. import android.support.annotation.NonNull;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.view.inputmethod.InputMethodManager;
  10.  
  11. public class Keyboard {
  12. public static void enableInputMode(@NonNull Context context, @NonNull View viewToGainFocus) {
  13. viewToGainFocus.requestFocus();
  14. getInputMethodManager(context).showSoftInput(viewToGainFocus, InputMethodManager.SHOW_FORCED);
  15. }
  16.  
  17. public static void disableInputMode(@NonNull Activity activity, @NonNull View viewToLostFocus) {
  18. viewToLostFocus.clearFocus();
  19. getInputMethodManager(activity).hideSoftInputFromWindow(getIBinder(activity), 0);
  20. }
  21.  
  22. private static InputMethodManager getInputMethodManager(@NonNull Context context) {
  23. return (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
  24. }
  25.  
  26. private static IBinder getIBinder(@NonNull Activity activity) {
  27. View view = activity.getCurrentFocus();
  28. if (view == null) {
  29. view = new View(activity);
  30. }
  31. return view.getWindowToken();
  32. }
  33. }
Add Comment
Please, Sign In to add comment