Java Code Examples for android.view.View.getGlobalVisibleRect()

The following are Jave code examples for showing how to use getGlobalVisibleRect() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Expert-Android-Programming   File: PlaceDetailActivity.java   Source Code and License Vote up 8 votes
public int getVisiblePercent(View v) {

        Rect scrollBounds = new Rect();
        scrollView.getHitRect(scrollBounds);
        if (v.getLocalVisibleRect(scrollBounds)) {
            // Any portion of the imageView, even a single pixel, is within the visible window
        } else {
            // NONE of the imageView is within the visible window
            return -1;
        }

        if (v.isShown()) {
            Rect r = new Rect();
            v.getGlobalVisibleRect(r);
            double sVisible = r.width() * r.height();
            double sTotal = v.getWidth() * v.getHeight();

            MyLg.e(TAG, "sVisible " + sVisible + " sTotal" + sTotal);

            return (int) (100 * sVisible / sTotal) - 20;
        } else {
            return -1;
        }
    }
 
Example 2
Project: Password-Storage   File: RegistrationActivity.java   Source Code and License Vote up 7 votes
@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 );
}
 
Example 3
Project: Expert-Android-Programming   File: CollectionDetailActivity.java   Source Code and License Vote up 7 votes
public int getVisiblePercent(View v) {

        Rect scrollBounds = new Rect();
        scrollView.getHitRect(scrollBounds);
        if (v.getLocalVisibleRect(scrollBounds)) {
            // Any portion of the imageView, even a single pixel, is within the visible window
        } else {
            // NONE of the imageView is within the visible window
            return -1;
        }

        if (v.isShown()) {
            Rect r = new Rect();
            v.getGlobalVisibleRect(r);
            double sVisible = r.width() * r.height();
            double sTotal = v.getWidth() * v.getHeight();

            MyLg.e(TAG, "sVisible " + sVisible + " sTotal" + sTotal);

            return (int) (100 * sVisible / sTotal) - 20;
        } else {
            return -1;
        }
    }
 
Example 4
Project: q-mail   File: NonLockingScrollView.java   Source Code and License Vote up 6 votes
@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);
    }
}
 
Example 5
Project: Password-Storage   File: LoginActivity.java   Source Code and License Vote up 6 votes
@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 );
}
 
Example 6
Project: android_viewtracker   File: ExposureManager.java   Source Code and License Vote up 6 votes
/**
 * check the visible width and height of the view, compared with the its original width and height.
 *
 * @param view
 * @return
 */
private boolean checkExposureViewDimension(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    Rect GlobalVisibleRect = new Rect();
    boolean isVisibleRect = view.getGlobalVisibleRect(GlobalVisibleRect);
    if (isVisibleRect) {

        int visibleWidth = GlobalVisibleRect.width();
        int visibleHeight = GlobalVisibleRect.height();

        if ((visibleWidth * 1.00 / width > GlobalsContext.dimThreshold) && (visibleHeight * 1.00 / height > GlobalsContext.dimThreshold)) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 7
Project: RLibrary   File: ClipHelper.java   Source Code and License Vote up 6 votes
public static int[] init(View view) {
    if (view == null) {
        return new int[]{ScreenUtil.screenWidth / 2, ScreenUtil.screenHeight / 2, DEFAULT_RADIUS};
    }

    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);

    int height = view.getMeasuredHeight();
    int width = view.getMeasuredWidth();

    int r = Math.min(width, height);// / 2;
    int x = rect.left + width / 2;
    int y = rect.top + height / 2;

    return new int[]{x, y, r};
}
 
Example 8
Project: RLibrary   File: RRecyclerView.java   Source Code and License Vote up 6 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    if (mInterceptTouchListener != null) {
        mInterceptTouchListener.onTouch(this, e);
    }

    //项目特殊处理, 可以删除
    for (int i = 0; i < getChildCount(); i++) {
        View childAt = getChildAt(0);
        Rect rect = new Rect();
        childAt.getGlobalVisibleRect(rect);
        if (childAt instanceof RecyclerView && rect.contains(((int) e.getRawX()), (int) e.getRawY())) {
            //如果touch在另一个RecycleView上面, 那么不拦截事件
            return false;
        }
    }
    //--------end--------
    return super.onInterceptTouchEvent(e);
}
 
Example 9
Project: social-app-android   File: PostDetailsActivity.java   Source Code and License Vote up 5 votes
@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();
                hideKeyBoard();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}
 
Example 10
Project: PlayerBase   File: RenderViewOvalRectOutlineProvider.java   Source Code and License Vote up 5 votes
@Override
public void getOutline(View view, Outline outline) {
    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);

    Rect selfRect = RectUtils.getOvalRect(rect);

    if(mRect!=null){
        selfRect = mRect;
    }
    outline.setOval(selfRect);
}
 
Example 11
Project: Bigbang   File: XposedUniversalCopyHandler.java   Source Code and License Vote up 5 votes
private ArrayList<CopyNode> traverseNode(View nodeInfo, int screenWidth, int scerrnHeight) {
    ArrayList nodeList = new ArrayList();
    if(nodeInfo != null ) {
        if (!nodeInfo.isShown()){
            return nodeList;
        }
        if (nodeInfo instanceof ViewGroup){
            ViewGroup viewGroup = (ViewGroup) nodeInfo;
            for(int var4 = 0; var4 < viewGroup.getChildCount(); ++var4) {
                nodeList.addAll(this.traverseNode(viewGroup.getChildAt(var4), screenWidth, scerrnHeight));
            }
        }
        if(nodeInfo.getClass().getName() != null && nodeInfo.getClass().getName().equals("android.webkit.WebView")) {
            return nodeList;
        } else {
            String content = null;
            String description = content;
            if(nodeInfo.getContentDescription() != null) {
                description = content;
                if(!"".equals(nodeInfo.getContentDescription())) {
                    description = nodeInfo.getContentDescription().toString();
                }
            }

            content = description;
            String text=getTextInFilters(nodeInfo,mFilters);
            if(text != null) {
                content = description;
                if(!"".equals(text)) {
                    content = text.toString();
                }
            }

            if(content != null) {
                Rect var8 = new Rect();
                nodeInfo.getGlobalVisibleRect(var8);
                if(checkBound(var8, screenWidth, scerrnHeight)) {
                    nodeList.add(new CopyNode(var8, content));
                }
            }

            return nodeList;
        }
    } else {
        return nodeList;
    }
}
 
Example 12
Project: FreeStreams-TVLauncher   File: FocusedRelativeLayout.java   Source Code and License Vote up 5 votes
public Rect getDstRectAfterScale(boolean paramBoolean) {
	View localView = getSelectedView();
	if (null == localView)
		return null;
	Rect localRect1 = new Rect();
	Rect localRect2 = new Rect();
	if ((localView instanceof FocusedRelativeLayout.ScalePostionInterface)) {
		FocusedRelativeLayout.ScalePostionInterface localScalePostionInterface = (FocusedRelativeLayout.ScalePostionInterface) localView;
		localRect1 = localScalePostionInterface.getScaledRect(getItemScaleXValue(), getItemScaleYValue(), false);
	} else {
		localView.getGlobalVisibleRect(localRect1);
	}
	FocusedRelativeLayout.this.getGlobalVisibleRect(localRect2);
	localRect1.left -= localRect2.left;
	localRect1.right -= localRect2.left;
	localRect1.top -= localRect2.top;
	localRect1.bottom -= localRect2.top;
	localRect1.left += FocusedRelativeLayout.this.mScroller.getCurrX();
	localRect1.right += FocusedRelativeLayout.this.mScroller.getCurrX();
	if ((paramBoolean) && (isLastFrame())) {
		localRect1.top -= getSelectedShadowPaddingTop();
		localRect1.left -= getSelectedShadowPaddingLeft();
		localRect1.right += getSelectedShadowPaddingRight();
		localRect1.bottom += getSelectedShadowPaddingBottom();
	} else {
		localRect1.top -= getSelectedPaddingTop();
		localRect1.left -= getSelectedPaddingLeft();
		localRect1.right += getSelectedPaddingRight();
		localRect1.bottom += getSelectedPaddingBottom();
	}
	localRect1.left += getManualPaddingLeft();
	localRect1.right += getManualPaddingRight();
	localRect1.top += getManualPaddingTop();
	localRect1.bottom += getManualPaddingBottom();
	return localRect1;
}
 
Example 13
Project: FreeStreams-TVLauncher   File: FocusedRelativeLayout.java   Source Code and License Vote up 5 votes
private boolean containView(View paramView) {
	Rect localRect1 = new Rect();
	Rect localRect2 = new Rect();
	getGlobalVisibleRect(localRect1);
	paramView.getGlobalVisibleRect(localRect2);
	return (localRect1.left <= localRect2.left) && (localRect1.right >= localRect2.right) && (localRect1.top <= localRect2.top) && (localRect1.bottom >= localRect2.bottom);
}
 
Example 14
Project: exciting-app   File: AbsHListView.java   Source Code and License Vote up 5 votes
/**
 * Allows RemoteViews to scroll relatively to a position.
 */
protected void smoothScrollByOffset(int position) {
	int index = -1;
	if (position < 0) {
		index = getFirstVisiblePosition();
	} else if (position > 0) {
		index = getLastVisiblePosition();
	}

	if (index > -1) {
		View child = getChildAt(index - getFirstVisiblePosition());
		if (child != null) {
			Rect visibleRect = new Rect();
			if (child.getGlobalVisibleRect(visibleRect)) {
				// the child is partially visible
				int childRectArea = child.getWidth() * child.getHeight();
				int visibleRectArea = visibleRect.width()
						* visibleRect.height();
				float visibleArea = (visibleRectArea / (float) childRectArea);
				final float visibleThreshold = 0.75f;
				if ((position < 0) && (visibleArea < visibleThreshold)) {
					// the top index is not perceivably visible so offset
					// to account for showing that top index as well
					++index;
				} else if ((position > 0)
						&& (visibleArea < visibleThreshold)) {
					// the bottom index is not perceivably visible so offset
					// to account for showing that bottom index as well
					--index;
				}
			}
			smoothScrollToPosition(Math.max(0,
					Math.min(getCount(), index + position)));
		}
	}
}
 
Example 15
Project: PlayerBase   File: RenderViewRoundRectOutlineProvider.java   Source Code and License Vote up 5 votes
@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);
}
 
Example 16
Project: QiangHongBao   File: ExplosionFieldView.java   Source Code and License Vote up 5 votes
/**
 * 爆炸
 * @param view 爆炸view
 * @param isJitterAnima 是否执行抖动动画
 * @param listener 动画结束回调
 */
public void explode(final View view, boolean isJitterAnima, OnAnimationEndListener listener) {
    Rect r = new Rect();
    view.getGlobalVisibleRect(r); //view
    int[] location = new int[2];
    getLocationOnScreen(location);
    r.offset(-location[0], -location[1]);
    r.inset(-mExpandInset[0], -mExpandInset[1]);
    int startDelay = 100;

    if(isJitterAnima){
        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();
    }else{
        view.setScaleX(0);
        view.setScaleY(0);
        view.setAlpha(0);
    }

    explode(BitmapUtils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION, listener);
}
 
Example 17
Project: ZoomPreviewPicture   File: MyPagerAdaper.java   Source Code and License Vote up 5 votes
private void setRect(View view) {
    for (UserViewInfo s : mThumbViewInfoList) {
        Rect bounds = new Rect();
        view.getGlobalVisibleRect(bounds);
        s.setBounds(bounds);
    }
}
 
Example 18
Project: OSchina_resources_android   File: BranchPopupWindow.java   Source Code and License Vote up 5 votes
@Override
public void showAsDropDown(View anchor) {
    if(Build.VERSION.SDK_INT >= 24){
        Rect visibleFrame = new Rect();
        anchor.getGlobalVisibleRect(visibleFrame);
        int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
        setHeight(height);
    }

    super.showAsDropDown(anchor);
}
 
Example 19
Project: mvvm-template   File: ViewHelper.java   Source Code and License Vote up 4 votes
@NonNull @SuppressWarnings("WeakerAccess") public static Rect getLayoutPosition(@NonNull View view) {
    Rect myViewRect = new Rect();
    view.getGlobalVisibleRect(myViewRect);
    return myViewRect;
}
 
Example 20
Project: XERUNG   File: Utils.java   Source Code and License Vote up 2 votes
/**
 * 这里看似是得到控件相对的坐标,但是如果这个滑动条在可以上下滚动的布局中就会出现问题。
 * 因为这里的坐标都是死的,在上下滚动的view中父控件的top仍旧不变,但实际上是应该获得动态数值的。
 * @param myView
 * @return
 */
public static int getRelativeTop(View myView) {
	Rect bounds = new Rect();
	myView.getGlobalVisibleRect(bounds);
	return bounds.top;
}