List of usage examples for android.view View getRootView
public View getRootView()
Finds the topmost view in the current view hierarchy.
From source file:Main.java
public static Bitmap getViewBitmap(View view) { View rootView = view.getRootView(); view.invalidate();/*w w w . j a v a 2 s.c o m*/ rootView.setDrawingCacheEnabled(true); return rootView.getDrawingCache(); }
From source file:Main.java
public static Bitmap getBitmap(View view) { final View layout = view.getRootView(); layout.setDrawingCacheEnabled(true); final Bitmap bitmap = layout.getDrawingCache(); return bitmap; }
From source file:Main.java
/** * Returns the text content of the view with the given resourceId. *//* w w w .j av a 2 s .c o m*/ private static String getText(View view, int resourceId) { view = view.getRootView(); TextView textView = TextView.class.cast(view.findViewById(resourceId)); return textView.getText().toString(); }
From source file:Main.java
private static void setMeasureSpec(View view) { view.measure(View.MeasureSpec.makeMeasureSpec(view.getRootView().getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); }
From source file:Main.java
public static int getStatusBarHeight(View view) { Rect rectangle = new Rect(); view.getRootView().getWindowVisibleDisplayFrame(rectangle); return rectangle.top; }
From source file:Main.java
public static void hideSoftKeyboard(Context context, View view) { // Hide soft keyboard if keyboard is up if (isKeyboardShown(view.getRootView())) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }/*ww w . j av a 2 s. com*/ }
From source file:Main.java
public final static int[] getPopupPosition(View anchor, int gravity) { int[] position = new int[2]; int windowWidth = anchor.getRootView().getMeasuredWidth(); int windowHeight = anchor.getRootView().getMeasuredHeight(); int anchorWidth = anchor.getMeasuredWidth(); int anchorHeight = anchor.getMeasuredHeight(); int[] location = new int[2]; anchor.getLocationInWindow(location); if (Gravity.LEFT == (gravity & Gravity.LEFT)) { position[0] = location[0];//w w w .ja v a 2 s .co m } else if (Gravity.RIGHT == (gravity & Gravity.RIGHT)) { position[0] = windowWidth - location[0] - anchorWidth; } if (Gravity.TOP == (gravity & Gravity.TOP)) { position[1] = location[1] + anchorHeight; } else if (Gravity.BOTTOM == (gravity & Gravity.BOTTOM)) { position[1] = windowHeight - location[1]; } return position; }
From source file:Main.java
public static Bitmap getScaledScreenshot(final Activity activity, int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) { final View someView = activity.findViewById(android.R.id.content); final View rootView = someView.getRootView(); final boolean originalCacheState = rootView.isDrawingCacheEnabled(); rootView.setDrawingCacheEnabled(true); rootView.buildDrawingCache(true);/*from w ww.jav a 2 s. c o m*/ // We could get a null or zero px bitmap if the rootView hasn't been measured // appropriately, or we grab it before layout. // This is ok, and we should handle it gracefully. final Bitmap original = rootView.getDrawingCache(); Bitmap scaled = null; if (null != original && original.getWidth() > 0 && original.getHeight() > 0) { if (relativeScaleIfTrue) { scaleWidth = original.getWidth() / scaleWidth; scaleHeight = original.getHeight() / scaleHeight; } if (scaleWidth > 0 && scaleHeight > 0) { try { scaled = Bitmap.createScaledBitmap(original, scaleWidth, scaleHeight, false); } catch (OutOfMemoryError error) { Log.i(LOGTAG, "Not enough memory to produce scaled image, returning a null screenshot"); } } } if (!originalCacheState) { rootView.setDrawingCacheEnabled(false); } return scaled; }
From source file:ggikko.me.steppertest.stepper.SteppersView.java
protected static int findUnusedId(View view) { while (view.getRootView().findViewById(++fID) != null) ;/*from w w w. j ava2 s .com*/ return fID; }
From source file:Main.java
/** * Remove the keyboard explicitly.//from w w w . j a v a 2s. c om */ public static void hideKeyBoard(Activity mActivity, View mGetView) { try { ((InputMethodManager) mActivity.getSystemService(Activity.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mGetView.getRootView().getWindowToken(), 0); } catch (Exception e) { e.printStackTrace(); } }