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:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

/**
 * Close the specified drawer view by animating it into view.
 *
 * @param drawerView Drawer view to close
 *///w w  w .  j av  a 2 s. c om
public void closeDrawer(View drawerView) {
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }

    if (mFirstLayout) {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 0.f;
        lp.knownOpen = false;
    } else {
        if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) {
            mLeftDragger.smoothSlideViewTo(drawerView, -drawerView.getWidth(), drawerView.getTop());
        } else {
            mRightDragger.smoothSlideViewTo(drawerView, getWidth(), drawerView.getTop());
        }
    }
    invalidate();
}

From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int width = getWidth();
    final boolean drawingContent = isContentView(child);
    int clipTop = 0, clipBottom = getHeight();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getWidth() < width) {
                continue;
            }//w ww . j av  a 2  s .  c o  m

            if (checkDrawerViewGravity(v, Gravity.TOP)) {
                final int vbottom = v.getBottom();
                if (vbottom > clipTop)
                    clipTop = vbottom;
            } else {
                final int vtop = v.getTop();
                if (vtop < clipBottom)
                    clipBottom = vtop;
            }
        }
        canvas.clipRect(0, clipTop, getWidth(), clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);

        canvas.drawRect(0, clipTop, getWidth(), clipBottom, mScrimPaint);
    } else if (mShadowTop != null && checkDrawerViewGravity(child, Gravity.TOP)) {
        final int shadowHeight = mShadowTop.getIntrinsicHeight();
        final int childBottom = child.getBottom();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight);
        mShadowTop.setAlpha((int) (0xff * alpha));
        mShadowTop.draw(canvas);
    } else if (mShadowBottom != null && checkDrawerViewGravity(child, Gravity.BOTTOM)) {
        final int shadowHeight = mShadowBottom.getIntrinsicHeight();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowBottom.setAlpha((int) (0xff * alpha));
        mShadowBottom.draw(canvas);
    }
    return result;
}

From source file:com.coco.draggablegridviewpager.DraggableGridViewPager.java

private void animateGap(int target) {
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        if (i == mLastDragged) {
            continue;
        }//from   w  w w  .  j  ava 2 s  . co  m

        int newPos = i;
        if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
            newPos--;
        } else if (target < mLastDragged && i >= target && i < mLastDragged) {
            newPos++;
        }

        int oldPos = i;
        if (newPositions.get(i) != -1) {
            oldPos = newPositions.get(i);
        }

        if (oldPos == newPos) {
            continue;
        }

        // animate
        DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
        final Rect oldRect = getRectByPosition(oldPos);
        final Rect newRect = getRectByPosition(newPos);
        oldRect.offset(-v.getLeft(), -v.getTop());
        newRect.offset(-v.getLeft(), -v.getTop());

        TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top,
                newRect.top);
        translate.setDuration(ANIMATION_DURATION);
        translate.setFillEnabled(true);
        translate.setFillAfter(true);
        v.clearAnimation();
        v.startAnimation(translate);

        newPositions.set(i, newPos);
    }
}

From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java

/**
 * Open the specified drawer view by animating it into view.
 *
 * @param drawerView Drawer view to open
 *//*from w  ww.j  av  a2  s .c  o  m*/
public void openDrawer(View drawerView) {
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }

    if (mFirstLayout) {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        lp.knownOpen = true;
    } else {
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop());
        } else {
            mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(),
                    drawerView.getTop());
        }
    }
    invalidate();
}

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

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

    int index;//  ww  w . j ava 2 s  . co 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.putParcelableArrayList("list", LIST_ELEMENTS);
        outState.putString("CURRENT_PATH", CURRENT_PATH);
        outState.putBoolean("selection", selection);
        outState.putInt("openMode", openMode.ordinal());
        outState.putInt("folder_count", folder_count);
        outState.putInt("file_count", file_count);

        if (selection) {
            outState.putIntegerArrayList("position", adapter.getCheckedItemsIndex());
        }

        outState.putBoolean("results", results);

        if (openMode == OpenMode.SMB) {
            outState.putString("SmbPath", smbPath);
        }
    }
}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java

@Override
public void draw(Canvas c) {
    super.draw(c);
    final boolean isLayoutRtl = isLayoutRtlSupport();
    Drawable shadowDrawable;/*from ww  w  . ja  v  a  2  s. c  om*/
    if (isLayoutRtl) {
        shadowDrawable = mShadowDrawableRight;
    } else {
        shadowDrawable = mShadowDrawableLeft;
    }

    final View shadowView = getChildCount() > 1 ? getChildAt(1) : null;
    if (shadowView == null || shadowDrawable == null) {
        // No need to draw a shadow if we don't have one.
        return;
    }

    final int top = shadowView.getTop();
    final int bottom = shadowView.getBottom();

    final int shadowWidth = shadowDrawable.getIntrinsicWidth();
    final int left;
    final int right;
    if (isLayoutRtlSupport()) {
        left = shadowView.getRight();
        right = left + shadowWidth;
    } else {
        right = shadowView.getLeft();
        left = right - shadowWidth;
    }

    shadowDrawable.setBounds(left, top, right, bottom);
    shadowDrawable.draw(c);
}

From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Log.i(TAG, "drawChild()");
    final int width = getWidth();
    final boolean drawingContent = isContentView(child);
    int clipTop = 0;
    int clipBottom = getHeight();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getWidth() < width) {
                Log.i(TAG, "drawChild() -- 0");
                continue;
            }/* ww w  .  j  a v a 2s. c o  m*/
            if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                final int vbottom = v.getBottom();
                if (vbottom > clipTop)
                    clipTop = vbottom;
            } else {
                final int vtop = v.getTop();
                if (vtop < clipBottom) {
                    clipBottom = vtop;
                }
            }
        }
        canvas.clipRect(0, clipTop, getWidth(), clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        Log.i(TAG, "drawChild() -- drawingContent");
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);
        canvas.drawRect(0, clipTop, getWidth(), clipBottom, mScrimPaint);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        Log.i(TAG, "drawChild() -- Gravity.BOTTOM");
        final int shadowHeight = mShadowBottom.getIntrinsicWidth();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowBottom.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowBottom.setAlpha((int) (0xff * alpha));
        mShadowBottom.draw(canvas);
    }
    return result;
}

From source file:com.android.hcframe.DraggableGridViewPager.java

private void animateGap(int target) {
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        if (i == mLastDragged) {
            continue;
        }/*from  w ww.  j a  va  2  s.  c  o m*/

        int newPos = i;
        if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
            newPos--;
        } else if (target < mLastDragged && i >= target && i < mLastDragged) {
            newPos++;
        }

        int oldPos = i;
        if (newPositions.get(i) != -1) {
            oldPos = newPositions.get(i);
        }

        if (oldPos == newPos) {
            continue;
        }

        // animate
        HcLog.D("animateGap from=" + oldPos + ", to=" + newPos);
        final Rect oldRect = getRectByPosition(oldPos);
        final Rect newRect = getRectByPosition(newPos);
        oldRect.offset(-v.getLeft(), -v.getTop());
        newRect.offset(-v.getLeft(), -v.getTop());

        TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top,
                newRect.top);
        translate.setDuration(ANIMATION_DURATION);
        translate.setFillEnabled(true);
        translate.setFillAfter(true);
        v.clearAnimation();
        v.startAnimation(translate);

        newPositions.set(i, newPos);
    }
}

From source file:com.chenglong.muscle.ui.LazyViewPager.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).
 * @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.
 *//*  ww w  .ja v a  2s . c o m*/
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.aidy.bottomdrawerlayout.DrawerLayout.java

/**
 * Open the specified drawer view by animating it into view.
 * /*  www.  j ava2s.  c  o m*/
 * @param drawerView
 *            Drawer view to open
 */
public void openDrawer(View drawerView) {
    Log.i(TAG, "openDrawer() --view");
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }

    if (mFirstLayout) {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        lp.knownOpen = true;
    } else {
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
            mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop());
        } else {
            mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(),
                    drawerView.getTop());
        }
    }
    invalidate();
}