static boolean isViewVisible(View view) { return view.getGlobalVisibleRect(new Rect()); } }
@Override public boolean dispatchTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { View v = getCurrentFocus(); if ( v instanceof EditText) { Rect outRect = new Rect(); v.getGlobalVisibleRect(outRect); if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) { v.clearFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } } return super.dispatchTouchEvent( event ); }
@Override public void getOutline(View view, Outline outline) { Rect rect = new Rect(); view.getGlobalVisibleRect(rect); int leftMargin = 0; int topMargin = 0; Rect selfRect = new Rect(leftMargin, topMargin, rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin); if(mRect!=null){ selfRect = mRect; } outline.setRoundRect(selfRect, mRadius); } }
private static boolean isFullyVisible(View parent, View child) { parent.getGlobalVisibleRect(locationParent); locationParent.left += parent.getPaddingLeft(); locationParent.right -= parent.getPaddingRight(); locationParent.top += parent.getPaddingTop(); locationParent.bottom -= parent.getPaddingBottom(); child.getGlobalVisibleRect(locationChild); return locationParent.contains(locationChild) && child.getWidth() == locationChild.width() && child.getHeight() == locationChild.height(); }
/** * @return true if the given view is visible to user, false otherwise. The logic is leveraged from * {@link View#isVisibleToUser()}. */ private static boolean isVisibleToUser(View view) { if (view.getWindowVisibility() != View.VISIBLE) { return false; } Object current = view; while (current instanceof View) { final View currentView = (View) current; if (currentView.getAlpha() <= 0 || currentView.getVisibility() != View.VISIBLE) { return false; } current = currentView.getParent(); } return view.getGlobalVisibleRect(sDummyRect); }
@Override public void getOutline(final View view, final Outline outline) { Rect selfRect; if(mRect!=null){ selfRect = mRect; }else{ Rect rect = new Rect(); view.getGlobalVisibleRect(rect); selfRect = RectUtils.getOvalRect(rect); } outline.setOval(selfRect); }
@Override public boolean dispatchTouchEvent(MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { View v = mActivity.getCurrentFocus(); if(v instanceof DetailedChipView) { Rect outRect = new Rect(); v.getGlobalVisibleRect(outRect); if (!outRect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY())) { ((DetailedChipView) v).fadeOut(); } } if (v instanceof ChipsInputEditText) { Rect outRect = new Rect(); v.getGlobalVisibleRect(outRect); if (!outRect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY()) && !((ChipsInputEditText) v).isFilterableListVisible()) { InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } } return mLocalCallback.dispatchTouchEvent(motionEvent); }
anchorView.getGlobalVisibleRect(rect); int[] location = new int[2]; mFloatingDecorView.getLocationOnScreen(location);
public void explode(final View view) { Rect r = new Rect(); view.getGlobalVisibleRect(r); int[] location = new int[2]; getLocationOnScreen(location); r.offset(-location[0], -location[1]); r.inset(-mExpandInset[0], -mExpandInset[1]); int startDelay = 100; ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { Random random = new Random(); @Override public void onAnimationUpdate(ValueAnimator animation) { view.setTranslationX((random.nextFloat() - 0.5f) * view.getWidth() * 0.05f); view.setTranslationY((random.nextFloat() - 0.5f) * view.getHeight() * 0.05f); } }); animator.start(); view.animate().setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start(); explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION); }
mHeaderView.findViewById(R.id.material_drawer_account_header_current).getGlobalVisibleRect(targetRect); Rect fromRect = new Rect(); view.getGlobalVisibleRect(fromRect); Rect rootRect = new Rect(); mHeaderView.getGlobalVisibleRect(rootRect);
@Implementation protected boolean getGlobalVisibleRect(Rect rect, Point globalOffset) { if (globalVisibleRect == null) { return directly().getGlobalVisibleRect(rect, globalOffset); } if (!globalVisibleRect.isEmpty()) { rect.set(globalVisibleRect); if (globalOffset != null) { rect.offset(-globalOffset.x, -globalOffset.y); } return true; } rect.setEmpty(); return false; }
@Override public void requestChildFocus(View child, View focused) { /* * Normally a ScrollView will scroll the child into view. * Prevent this when a MessageWebView is first touched, * assuming it already is at least partially in view. * */ if (mSkipWebViewScroll && focused instanceof MessageWebView && focused.getGlobalVisibleRect(new Rect())) { mSkipWebViewScroll = false; super.requestChildFocus(child, child); ViewParent parent = getParent(); if (parent != null) { parent.requestChildFocus(this, focused); } } else { super.requestChildFocus(child, focused); } }
bean.statusBarHeight = bean.originRect.top; view.getGlobalVisibleRect(bean.originRect); bean.originWidth = view.getWidth(); bean.originHeight = view.getHeight();
viewport.offset(tmpLocation[0], tmpLocation[1]); boolean isVisible = targetView.getGlobalVisibleRect(visible); if (!isVisible) {
@Test public void setsGlobalVisibleRect() { Rect globalVisibleRect = new Rect(); shadowOf(view).setGlobalVisibleRect(new Rect()); assertThat(view.getGlobalVisibleRect(globalVisibleRect)) .isFalse(); assertThat(globalVisibleRect.isEmpty()) .isTrue(); assertThat(view.getGlobalVisibleRect(globalVisibleRect, new Point(1, 1))) .isFalse(); assertThat(globalVisibleRect.isEmpty()) .isTrue(); shadowOf(view).setGlobalVisibleRect(new Rect(1, 2, 3, 4)); assertThat(view.getGlobalVisibleRect(globalVisibleRect)) .isTrue(); assertThat(globalVisibleRect) .isEqualTo(new Rect(1, 2, 3, 4)); assertThat(view.getGlobalVisibleRect(globalVisibleRect, new Point(1, 1))) .isTrue(); assertThat(globalVisibleRect) .isEqualTo(new Rect(0, 1, 2, 3)); }
@Test public void usesDefaultGlobalVisibleRect() { final ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class); final Activity activity = activityController.get(); activity.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); activityController.setup(); Rect globalVisibleRect = new Rect(); assertThat(view.getGlobalVisibleRect(globalVisibleRect)) .isTrue(); assertThat(globalVisibleRect) .isEqualTo(new Rect(0, 25, DeviceConfig.DEFAULT_SCREEN_SIZE.width, DeviceConfig.DEFAULT_SCREEN_SIZE.height)); }
targetView.getGlobalVisibleRect(bean.targetRect); bean.targetWidth = bean.targetRect.right - bean.targetRect.left; bean.targetHeight = bean.targetRect.bottom - bean.targetRect.top;
private void letsExplodeIt(View clickedView) { // save rect of view in screen coordinated final Rect viewRect = new Rect(); clickedView.getGlobalVisibleRect(viewRect); final Explode explode = new Explode(); explode.setEpicenterCallback(new Transition.EpicenterCallback() { @Override public Rect onGetEpicenter(Transition transition) { return viewRect; } }); explode.excludeTarget(clickedView, true); TransitionSet set = new TransitionSet() .addTransition(explode) .addTransition(new Fade().addTarget(clickedView)) .addListener(new TransitionListenerAdapter() { @Override public void onTransitionEnd(Transition transition) { transition.removeListener(this); getActivity().onBackPressed(); } }); TransitionManager.beginDelayedTransition(mRecyclerView, set); // remove all views from Recycler View mRecyclerView.setAdapter(null); }
float getY(View view) { Rect rect = new Rect(); view.getGlobalVisibleRect(rect); float y = rect.top; if (y <= 0) { y = ViewCompat.getY(view); } return y; }
float getX(View view) { Rect rect = new Rect(); view.getGlobalVisibleRect(rect); float x = rect.left; if (x <= 0) { x = ViewCompat.getX(view); } return x; }