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

The following are Jave code examples for showing how to use getLocalVisibleRect() 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: QSVideoPlayer   File: ListCalculator.java   Source Code and License Vote up 7 votes
private int getVisibilityPercents(View view) {
    final Rect currentViewRect = new Rect();

    int percents = 100;

    int height = (view == null || view.getVisibility() != View.VISIBLE) ? 0 : view.getHeight();

    if (height == 0) {
        return 0;
    }

    view.getLocalVisibleRect(currentViewRect);

    if (viewIsPartiallyHiddenTop(currentViewRect)) {
        // view is partially hidden behind the top edge
        percents = (height - currentViewRect.top) * 100 / height;
    } else if (viewIsPartiallyHiddenBottom(currentViewRect, height)) {
        percents = currentViewRect.bottom * 100 / height;
    }

    return percents;
}
 
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: TripleTap   File: FImageButton.java   Source Code and License Vote up 6 votes
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            updateBackground(pressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
            break;
        case MotionEvent.ACTION_MOVE:
            Rect r = new Rect();
            view.getLocalVisibleRect(r);
            if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() + 3 * mShadowHeight) &&
                    !r.contains((int) motionEvent.getX(), (int) motionEvent.getY() - 3 * mShadowHeight)) {
                updateBackground(unpressedDrawable);
                this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            }
            break;
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            updateBackground(unpressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            break;
    }
    return false;
}
 
Example 5
Project: Trivia-Knowledge   File: FButton.java   Source Code and License Vote up 6 votes
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            updateBackground(pressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
            break;
        case MotionEvent.ACTION_MOVE:
            Rect r = new Rect();
            view.getLocalVisibleRect(r);
            if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() + 3 * mShadowHeight) &&
                    !r.contains((int) motionEvent.getX(), (int) motionEvent.getY() - 3 * mShadowHeight)) {
                updateBackground(unpressedDrawable);
                this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            }
            break;
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            updateBackground(unpressedDrawable);
            this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom + mShadowHeight);
            break;
    }
    return false;
}
 
Example 6
Project: GitHub   File: Utils.java   Source Code and License Vote up 5 votes
static View getTheVisibileView(List<View> viewList) {
    Rect scrollBounds = new Rect();

    int listSize = viewList.size();
    for (int i = 0; i < listSize; ++i) {
        View view = viewList.get(i);
        if (view != null) {
            view.getHitRect(scrollBounds);
            if (view.getLocalVisibleRect(scrollBounds)) {
                return view;
            }
        }
    }
    return null;
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: AppMenuDragHelper.java   Source Code and License Vote up 5 votes
/**
 * @return Visible rect in screen coordinates for the given View.
 */
private Rect getScreenVisibleRect(View view) {
    view.getLocalVisibleRect(mScreenVisibleRect);
    view.getLocationOnScreen(mScreenVisiblePoint);
    mScreenVisibleRect.offset(mScreenVisiblePoint[0], mScreenVisiblePoint[1]);
    return mScreenVisibleRect;
}
 
Example 8
Project: OneWeather   File: VisibilityCheckUtil.java   Source Code and License Vote up 5 votes
public static int  checkVisibility(View view){

        Rect rect = new Rect();
        boolean b = view.getLocalVisibleRect(rect);
        LogUtil.d("VisibilityCheck", view.getClass().getSimpleName()+": "+ b +"   "+view.getWidth()+view.getHeight()+"  "+rect.toString());
        if(b){
            if(rect.width()==view.getMeasuredWidth() && rect.height()== view.getMeasuredHeight()){//这里用完全可见,也可调节比例
                return ALL_VISIBLE;
            }
            return PART_VISIBLE;

        }
        return ALL_INVISIBLE;
    }
 
Example 9
Project: android-util2   File: ViewUtil.java   Source Code and License Vote up 5 votes
/**
 * is the target view visible in local coordinate.
 *
 * @param view the target view
 * @return true if visible.(visible means the view's all side can see).
 */
public static boolean isVisibleInScreen(View view) {
    if (view == null) {
        throw new NullPointerException();
    }
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    return view.getLocalVisibleRect(new Rect(0, 0, dm.widthPixels, dm.heightPixels));
}
 
Example 10
Project: weex-3d-map   File: AppearanceHelper.java   Source Code and License Vote up 4 votes
public boolean isViewVisible() {
  View view = mAwareChild.getHostView();
  return view != null && view.getLocalVisibleRect(mVisibleRect);

}
 
Example 11
Project: ucar-weex-core   File: AppearanceHelper.java   Source Code and License Vote up 4 votes
public boolean isViewVisible() {
  View view = mAwareChild.getHostView();
  return view != null && view.getLocalVisibleRect(mVisibleRect);

}
 
Example 12
Project: weex-uikit   File: AppearanceHelper.java   Source Code and License Vote up 4 votes
public boolean isViewVisible() {
  View view = mAwareChild.getHostView();
  return view != null && view.getLocalVisibleRect(mVisibleRect);

}