List of usage examples for android.view View getHeight
@ViewDebug.ExportedProperty(category = "layout") public final int getHeight()
From source file:Main.java
public static void handleAutoCloseKeyboard(boolean isAutoCloseKeyboard, View currentFocusView, MotionEvent motionEvent, Object dialogOrActivity) { if (isAutoCloseKeyboard && motionEvent.getAction() == MotionEvent.ACTION_DOWN && currentFocusView != null && (currentFocusView instanceof EditText) && dialogOrActivity != null) { int[] leftTop = { 0, 0 }; currentFocusView.getLocationInWindow(leftTop); int left = leftTop[0]; int top = leftTop[1]; int bottom = top + currentFocusView.getHeight(); int right = left + currentFocusView.getWidth(); if (!(motionEvent.getX() > left && motionEvent.getX() < right && motionEvent.getY() > top && motionEvent.getY() < bottom)) { if (dialogOrActivity instanceof Dialog) { closeKeyboard((Dialog) dialogOrActivity); } else if (dialogOrActivity instanceof Activity) { closeKeyboard((Activity) dialogOrActivity); }/*w w w. ja v a 2s.co m*/ } } }
From source file:Main.java
public static void enterReveal(final View view) { view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/*w ww .ja v a 2 s . com*/ public void onGlobalLayout() { Animator animator = null; view.getViewTreeObserver().removeOnGlobalLayoutListener(this); int cx = view.getMeasuredWidth() / 2; int cy = view.getMeasuredHeight() / 2; try { final int finalRadius = Math.max(view.getWidth(), view.getHeight()) / 2 + 125; animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); } }); } catch (Exception ignored) { } view.setVisibility(View.VISIBLE); if (animator != null) { animator.start(); } } }); }
From source file:Main.java
private static boolean showToolTip(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; }/*from w w w . ja v a 2s .c o m*/ final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density); Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up // its height isn't factored in. cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight); } cheatSheet.show(); return true; }
From source file:Main.java
/** * Internal helper method to show the cheat sheet toast. */// ww w .ja va2 s . c om private static boolean show(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; } final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density); Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up // its height isn't factored in. cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight); } cheatSheet.show(); return true; }
From source file:com.agenmate.lollipop.util.ViewUtils.java
/** * Determines if two views intersect in the window. *///from w w w. j a v a 2 s . com public static boolean viewsIntersect(View view1, View view2) { if (view1 == null || view2 == null) return false; final int[] view1Loc = new int[2]; view1.getLocationOnScreen(view1Loc); final Rect view1Rect = new Rect(view1Loc[0], view1Loc[1], view1Loc[0] + view1.getWidth(), view1Loc[1] + view1.getHeight()); int[] view2Loc = new int[2]; view2.getLocationOnScreen(view2Loc); final Rect view2Rect = new Rect(view2Loc[0], view2Loc[1], view2Loc[0] + view2.getWidth(), view2Loc[1] + view2.getHeight()); return view1Rect.intersect(view2Rect); }
From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.dragdrop.BitmapUtils.java
/** * Returns a bitmap showing a screenshot of the view passed in. *//*from w ww.j av a 2s .c om*/ @NonNull static Bitmap getBitmapFromView(@NonNull final View v) { Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint p = new Paint(); p.setColor(ContextCompat.getColor(v.getContext(), R.color.colorAccent)); p.setAlpha(50); //v.setBackgroundColor(ContextCompat.getColor(v.getContext(), android.R.color.transparent)); v.draw(canvas); //canvas.drawCircle((float)(v.getWidth() / 2), (float)(v.getHeight() / 2), 10, p); canvas.drawRect(new Rect(0, 0, v.getWidth(), v.getHeight()), p); return bitmap; }
From source file:android.support.v7.testutils.TestUtilsMatchers.java
/** * Returns a matcher that matches <code>View</code>s which have background flat-filled * with the specific color./*from w ww . j av a 2 s. co m*/ */ public static Matcher isBackground(@ColorInt final int color) { return new BoundedMatcher<View, View>(View.class) { private String failedComparisonDescription; @Override public void describeTo(final Description description) { description.appendText("with background of color: "); description.appendText(failedComparisonDescription); } @Override public boolean matchesSafely(final View view) { Drawable drawable = view.getBackground(); if (drawable == null) { return false; } try { TestUtils.assertAllPixelsOfColor("", drawable, view.getWidth(), view.getHeight(), false, color, 0, true); // If we are here, the color comparison has passed. failedComparisonDescription = null; return true; } catch (Throwable t) { // If we are here, the color comparison has failed. failedComparisonDescription = t.getMessage(); return false; } } }; }
From source file:com.androidinspain.deskclock.Utils.java
/** * This method assumes the given {@code view} has already been layed out. * * @return a Bitmap containing an image of the {@code view} at its current size *///from ww w.j a va 2 s . co m public static Bitmap createBitmap(View view) { final Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), ARGB_8888); final Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Applies a circular mask to a view./*from w w w . j a v a2s .c o m*/ * <p/> * Note that this method only works on Lollipop and above; it will silently fail on older versions. * * @param view The view to apply the mask to. */ public static void applyCircularMask(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { view.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, view.getWidth(), view.getHeight()); } }); view.setClipToOutline(true); } }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Applies a rectangular rounded corners mask to a view. * <p/>//from www. j ava 2 s .c o m * Note that this method only works on Lollipop and above; it will silently fail on older versions. * * @param view The view to apply the mask to. */ public static void applyRoundedCornersMask(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { view.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15); } }); view.setClipToOutline(true); } }