Example usage for android.view View getTop

List of usage examples for android.view View getTop

Introduction

In this page you can find the example usage for android.view View getTop.

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 * // ww  w. j  a  v  a2 s.c om
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for
 *            scrollability (true), or just its children (false).
 * @param dx Delta scrolled in pixels
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance
        // first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, (isLayoutRtlSupport() ? dx : -dx));
}

From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java

@Override
public void draw(Canvas c) {
    super.draw(c);

    final View shadowView = getChildCount() > 1 ? getChildAt(1) : null;
    if (shadowView == null || mShadowDrawable == null) {
        // No need to draw a shadow if we don't have one.
        return;/*from   ww  w . j ava  2s  .c om*/
    }

    final int shadowWidth = mShadowDrawable.getIntrinsicWidth();
    final int right = shadowView.getLeft();
    final int top = shadowView.getTop();
    final int bottom = shadowView.getBottom();
    final int left = right - shadowWidth;
    mShadowDrawable.setBounds(left, top, right, bottom);
    mShadowDrawable.draw(c);
}

From source file:com.amaze.filemanager.fragments.Main.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    int index;//from   w ww. j  a v  a 2 s.c o m
    View vi;
    if (listView != null) {
        if (IS_LIST) {

            index = (mLayoutManager).findFirstVisibleItemPosition();
            vi = listView.getChildAt(0);
        } else {
            index = (mLayoutManagerGrid).findFirstVisibleItemPosition();
            vi = listView.getChildAt(0);
        }
        int top = (vi == null) ? 0 : vi.getTop();
        outState.putInt("index", index);
        outState.putInt("top", top);
        outState.putBoolean("IS_LIST", IS_LIST);
        outState.putParcelableArrayList("list", LIST_ELEMENTS);
        outState.putString("CURRENT_PATH", CURRENT_PATH);
        outState.putBoolean("selection", selection);
        outState.putInt("openMode", openMode);
        outState.putInt("folder_count", folder_count);
        outState.putInt("file_count", file_count);
        if (selection) {
            outState.putIntegerArrayList("position", adapter.getCheckedItemPositions());
        }
        outState.putBoolean("results", results);
        outState.putParcelable("adapter", adapter);
        if (openMode == 1) {
            outState.putString("SmbPath", smbPath);
        }
    }
}

From source file:com.dycody.android.idealnote.ListFragment.java

private void refreshListScrollPosition() {
    if (list != null) {
        listViewPosition = list.getFirstVisiblePosition();
        View v = list.getChildAt(0);
        listViewPositionOffset = (v == null) ? (int) getResources().getDimension(R.dimen.vertical_margin)
                : v.getTop();
    }//from   w  w w. j  a  v  a  2  s.co  m
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

public void computeScroll() {
    View vi = listView.getChildAt(0);
    int top = (vi == null) ? 0 : vi.getTop();
    int index;//from w  w w.  j  a  va 2s  . c  om
    if (IS_LIST)
        index = mLayoutManager.findFirstVisibleItemPosition();
    else
        index = mLayoutManagerGrid.findFirstVisibleItemPosition();
    Bundle b = new Bundle();
    b.putInt("index", index);
    b.putInt("top", top);
    scrolls.put(CURRENT_PATH, b);
}

From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v      View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true), or just its children
 *               (false).//ww  w .  j  a v  a  2 s .  c o  m
 * @param dx     Delta scrolled in pixels
 * @param x      X coordinate of the active touch point
 * @param y      Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.  
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.  
            // This will not work for transformed views in Honeycomb+  
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

private boolean inChild(int x, int y) {
    if (getChildCount() > 0) {
        final int scrollY = getScrollY();
        final View child = getChildAt(0);
        return !(y < child.getTop() - scrollY || y >= child.getBottom() - scrollY || x < child.getLeft()
                || x >= child.getRight());
    }//from   w  ww .j a  v  a  2s  .c  o m
    return false;
}

From source file:com.digreamon.android.widget.SlidingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    if (Build.VERSION.SDK_INT >= 11) { // HC
        return super.drawChild(canvas, child, drawingTime);
    }// w ww .j  a  v  a 2  s.c  o m

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.dimWhenOffset && mSlideOffset > 0) {
        if (!child.isDrawingCacheEnabled()) {
            child.setDrawingCacheEnabled(true);
        }
        final Bitmap cache = child.getDrawingCache();
        canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
        return false;
    } else {
        if (child.isDrawingCacheEnabled()) {
            child.setDrawingCacheEnabled(false);
        }
        return super.drawChild(canvas, child, drawingTime);
    }
}

From source file:Main.java

private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer,
        final int targtetHeight) {

    setHeight(view, 0);//from  w  ww. j  av a2 s .c  o  m
    view.setVisibility(View.VISIBLE);
    final Animation animation = new Animation() {

        private final Rect rect = new Rect();
        private final Rect parentVisibleRect = new Rect();

        ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;

        private final Runnable checkViewRunnable = new Runnable() {
            @Override
            public void run() {
                checkForViewInsideVisibleArea();
            }
        };

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            setHeight(view, neededHeight);

            final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();

            if (globalLayoutListener == null) {
                globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {

                        if (globalLayoutListener == null) {
                            removeGlobalLayoutListener(viewTreeObserver, this);
                        }

                        checkForViewInsideVisibleArea();
                    }
                };

                viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener);
            }

            if (globalLayoutListener != null && interpolatedTime == 1) {
                runInUIThread(checkViewRunnable);
                globalLayoutListener = null;
            }

            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }

        private void checkForViewInsideVisibleArea() {

            if (rootContainer.indexOfChild(parentView) == -1) {
                return;
            }

            parentVisibleRect.left = 0;
            parentVisibleRect.top = 0;
            parentVisibleRect.right = parentView.getWidth();
            parentVisibleRect.bottom = parentView.getHeight();

            rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect);

            if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) {

                rect.left = parentView.getLeft();
                rect.top = parentView.getTop();
                rect.right = parentView.getRight();
                rect.bottom = parentView.getBottom();

                parentView.requestRectangleOnScreen(rect, true);
            }
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    view.startAnimation(animation);
}

From source file:com.abewy.android.apps.klyph.messenger.widget.SlidingPaneLayout.java

void updateObscuredViewsVisibility(View panel) {
    final int leftBound = getPaddingLeft();
    final int rightBound = getWidth() - getPaddingRight();
    final int topBound = getPaddingTop();
    final int bottomBound = getHeight() - getPaddingBottom();
    final int left;
    final int right;
    final int top;
    final int bottom;
    if (panel != null && hasOpaqueBackground(panel)) {
        left = panel.getLeft();//from w  w w  . ja va 2 s  .c  o m
        right = panel.getRight();
        top = panel.getTop();
        bottom = panel.getBottom();
    } else {
        left = right = top = bottom = 0;
    }

    for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
        final View child = getChildAt(i);

        if (child == panel) {
            // There are still more children above the panel but they won't be affected.
            break;
        }

        final int clampedChildLeft = Math.max(leftBound, child.getLeft());
        final int clampedChildTop = Math.max(topBound, child.getTop());
        final int clampedChildRight = Math.min(rightBound, child.getRight());
        final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
        final int vis;
        if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right
                && clampedChildBottom <= bottom) {
            vis = INVISIBLE;
        } else {
            vis = VISIBLE;
        }
        child.setVisibility(vis);
    }
}