List of usage examples for android.app Activity getCurrentFocus
@Nullable
public View getCurrentFocus()
From source file:com.gm.goldencity.util.Utils.java
/** * Hide keyboard/* ww w . j a v a 2s . c o m*/ * * @param activity Activity */ public static void hideKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (null != view) hideKeyboard(activity, view); }
From source file:com.vuze.android.remote.AndroidUtilsUI.java
public static boolean handleBrokenListViewScrolling(Activity a, int keyCode) { // Hack for FireTV 1st Gen (and possibly others): // sometimes scrolling up/down stops being processed by ListView, // even though there's more list to show. Handle this manually // Dirty implemenation -- doesn't take into consideration disabled rows // or page-up/down/top/bottom key modifiers if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { ListView lv = null;/*from w w w . jav a 2s .c o m*/ View currentFocus = a.getCurrentFocus(); if (currentFocus instanceof ListView) { lv = (ListView) currentFocus; if (lv.getChoiceMode() == ListView.CHOICE_MODE_SINGLE) { int position = lv.getSelectedItemPosition(); if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { position--; } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { position++; } if (position > 0 && position < lv.getCount()) { lv.setSelection(position); return true; } } } // // For RecyclerView, we just need to scroll the next item into // // view, so that the super logic can find that the next down/up // // item exists. // // A PreCachingLayoutManager might also fix this problem // if (currentFocus != null && // currentFocus.getParent() instanceof RecyclerView) { // RecyclerView rv = (RecyclerView) currentFocus.getParent(); // RecyclerView.Adapter adapter = rv.getAdapter(); // if (adapter instanceof FlexibleRecyclerAdapter) { // int position = ((FlexibleRecyclerAdapter) adapter) // .getSelectedPosition(); // if (position >= 0) { // if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { // position--; // } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { // position++; // } // // if (position >= 0 && position < adapter.getItemCount()) { // rv.scrollToPosition(position); // Log.d(TAG, "handleBrokenListViewScrolling: DPAD HANDLED "); // return false; // } // } // } // } } return false; }
From source file:com.yanzhenjie.album.mvp.ActivitySource.java
@Override void closeInputMethod() { Activity activity = getHost(); View focusView = activity.getCurrentFocus(); if (focusView != null) { InputMethodManager manager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (manager != null) { manager.hideSoftInputFromWindow(focusView.getWindowToken(), 0); }/*from www.j a va 2 s . c o m*/ } }
From source file:org.badreader.client.fragments.BaseFragment.java
protected void hideKeyboard(Activity _activity) { try {/*from ww w . j a v a2s .c o m*/ InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0); } } catch (Exception e) { e.printStackTrace(); } }
From source file:timer.com.maydaysdk.MayDayMessageChatFragment.java
private void hideSoftKeyboard(Activity activity) { if (activity.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); }// ww w.j a v a 2 s . c o m }
From source file:org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment.java
public void hideKeyboard() { Activity activity = getActivity(); if (activity == null) { return;//from w ww .j ava2 s . co m } InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); // check if no view has focus View v = activity.getCurrentFocus(); if (v == null) return; inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); }
From source file:com.app.sample.chatting.widget.KJChatKeyboard.java
/** * ??//from w w w . j a v a2s.c om */ public void hideKeyboard(Context context) { Activity activity = (Activity) context; if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive() && activity.getCurrentFocus() != null) { imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } } }
From source file:com.ceino.chaperonandroid.activities.LicenseActivity.java
private void hideSoftKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); }
From source file:com.breadwallet.BreadWalletApp.java
public void hideKeyboard(Activity act) { Activity activity = act; if (activity == null) activity = MainActivity.app;/* www . j ava 2 s . c o m*/ if (activity == null) activity = IntroActivity.app; if (activity != null) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); return; } } Log.e(TAG, "hideKeyboard: FAILED"); }
From source file:org.kaaproject.kaa.demo.notification.KaaNotificationApp.java
public void showPopup(Activity context, long topicId, Notification notification) { ((TextView) popup.findViewById(R.id.popup_notification)).setText(notification.getMessage()); ((TextView) popup.findViewById(R.id.popup_topic)).setText(TopicInfoHolder.holder.getTopicName(topicId)); ((ImageView) popup.findViewById(R.id.popup_image)) .setImageBitmap(ImageCache.cache.getImage(notification.getImage())); View view = context.getCurrentFocus(); if (view != null) { popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0); }//from w ww . jav a 2 s . c o m }