List of usage examples for android.view View getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:Main.java
/** * Returns display metrics for the specified view. * //from ww w. j a v a 2s . c om * @param view An instance of View (must be the child of an Activity). * * @return DisplayMetrics instance, or null if there was a problem. */ public static DisplayMetrics getDisplayMetrics(View view) { if (view == null) return null; Context context = view.getContext(); if (!(context instanceof Activity)) return null; DisplayMetrics metrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics); return metrics; }
From source file:Main.java
/** * Explicitly request that the current input method's soft input area be * shown to the user, if needed.// w w w.j a v a2 s. c o m * * @param view * The currently focused view, which would like to receive soft * keyboard input. */ public static void showKeyboard(View view) { view.requestFocus(); InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.RESULT_UNCHANGED_SHOWN); }
From source file:Main.java
/** * Request to hide the soft input window from the context of the window that * is currently accepting input./*from ww w.j av a2s . c o m*/ * * @param view * he currently focused view, which would like to receive soft * keyboard input. */ public static void hideKeyboard(View view) { if (view != null) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
From source file:Main.java
public static void showKeyboard(View view) { if (view == null) { return;//from www. jav a 2s. c om } InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (!imm.isActive()) { return; } imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); }
From source file:Main.java
public static void paddingForNavBar(View view) { if (isCanHaveTransparentDecor()) { int height = getNavBarHeight(view.getContext()); view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom() + height); }//from w w w .j a v a 2 s . c o m }
From source file:Main.java
public static void showInput(View view) { if (view == null) return;//ww w . j ava 2 s . co m InputMethodManager inputMethodManager = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED); }
From source file:Main.java
public static void closeSoftKeyboard(Context context) { if (context == null || !(context instanceof Activity) || ((Activity) context).getCurrentFocus() == null) { return;//from w ww . j a v a 2 s .c o m } try { View view = ((Activity) context).getCurrentFocus(); InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); view.clearFocus(); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean showSoftInput(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); return imm.showSoftInput(view, 2); } else {/* ww w.ja v a 2 s .c om*/ return false; } }
From source file:Main.java
/** * Try to send an {@link AccessibilityEvent} * for a {@link View}./* w ww.j a va2 s .c om*/ * * @param view The View that will dispatch the AccessibilityEvent * @return true if the AccessibilityEvent was dispatched */ @SuppressWarnings("UnusedReturnValue") public static boolean sendAccessibilityEvent(View view) { final AccessibilityManager accessibilityManager = (AccessibilityManager) view.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); if (!accessibilityManager.isEnabled()) return false; final AccessibilityEvent accessibilityEvent = AccessibilityEvent .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); accessibilityEvent.setClassName(view.getClass().getName()); accessibilityEvent.setPackageName(view.getContext().getPackageName()); view.dispatchPopulateAccessibilityEvent(accessibilityEvent); accessibilityManager.sendAccessibilityEvent(accessibilityEvent); return true; }
From source file:cn.bingoogolapple.scaffolding.util.DrawableUtil.java
public static void tintBackground(View view, @ColorRes int colorResId) { ViewCompat.setBackground(view, tintDrawable(view.getContext(), view.getBackground(), colorResId)); }