Java Code Examples for android.view.ViewGroup#getTop()

The following examples show how to use android.view.ViewGroup#getTop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZSwipeItem.java    From AutoLoadListView with Apache License 2.0 6 votes vote down vote up
public void close(boolean smooth, boolean notify) {
	ViewGroup surface = getSurfaceView();
	int dx, dy;
	if (smooth)
		mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
				getPaddingTop());
	else {
		Rect rect = computeSurfaceLayoutArea(false);
		dx = rect.left - surface.getLeft();
		dy = rect.top - surface.getTop();
		surface.layout(rect.left, rect.top, rect.right, rect.bottom);
		if (notify) {
			dispatchSwipeEvent(rect.left, rect.top, dx, dy);
		} else {
			safeBottomView();
		}
	}
	invalidate();
}
 
Example 2
Source File: ClickShadowView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Aligns the shadow with {@param view}
 * @param viewParent immediate parent of {@param view}. It must be a sibling of this view.
 */
public void alignWithIconView(BubbleTextView view, ViewGroup viewParent) {
    float leftShift = view.getLeft() + viewParent.getLeft() - getLeft();
    float topShift = view.getTop() + viewParent.getTop() - getTop();
    int iconWidth = view.getRight() - view.getLeft();
    int iconHSpace = iconWidth - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft();
    float drawableWidth = view.getIcon().getBounds().width();

    setTranslationX(leftShift
            + viewParent.getTranslationX()
            + view.getCompoundPaddingLeft() * view.getScaleX()
            + (iconHSpace - drawableWidth) * view.getScaleX() / 2  /* drawable gap */
            + iconWidth * (1 - view.getScaleX()) / 2  /* gap due to scale */
            - mShadowPadding  /* extra shadow size */
            );
    setTranslationY(topShift
            + viewParent.getTranslationY()
            + view.getPaddingTop() * view.getScaleY()  /* drawable gap */
            + view.getHeight() * (1 - view.getScaleY()) / 2  /* gap due to scale */
            - mShadowPadding  /* extra shadow size */
            );
}
 
Example 3
Source File: SwipeLayout.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean onDoubleTap(MotionEvent e) {
    if (mDoubleClickListener != null) {
        View target;
        ViewGroup bottom = getBottomView();
        ViewGroup surface = getSurfaceView();
        if (e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
                && e.getY() > bottom.getTop()
                && e.getY() < bottom.getBottom()) {
            target = bottom;
        } else {
            target = surface;
        }
        mDoubleClickListener.onDoubleClick(SwipeLayout.this,
                target == surface);
    }
    return true;
}
 
Example 4
Source File: SwipeLayoutConv.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * close surface
 *
 * @param smooth smoothly or not.
 * @param notify if notify all the listeners.
 */
public void close(boolean smooth, boolean notify) {
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if (smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
                getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if (notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right,
                    rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        } else {
            safeBottomView();
        }
    }
    invalidate();
}
 
Example 5
Source File: PendIntentCompat.java    From container with GNU General Public License v3.0 6 votes vote down vote up
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) {
	int count = viewGroup.getChildCount();
	for (int i = 0; i < count; i++) {
		View v = viewGroup.getChildAt(i);
		if (v instanceof ViewGroup) {
			// linearlayout
			setIntentByViewGroup(remoteViews, (ViewGroup) v, list);
		} else if (v instanceof TextView) {
			// textview
			Rect rect = new Rect();
			v.getHitRect(rect);
			// height修正
			rect.top += viewGroup.getTop();
			rect.bottom += viewGroup.getTop();
			PendingIntent pendingIntent = findIntent(rect, list);
			if (pendingIntent != null) {
				remoteViews.setOnClickPendingIntent(v.getId(), pendingIntent);
			}
		}
	}
}
 
Example 6
Source File: DragSortListView.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {
    final Drawable divider = getDivider();
    final int dividerHeight = getDividerHeight();

    if (divider != null && dividerHeight != 0) {
        final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                - getFirstVisiblePosition());
        if (expItem != null) {
            final int left = getPaddingLeft();
            final int right = getWidth() - getPaddingRight();
            final int top;
            final int bottom;

            final int childHeight = expItem.getChildAt(0).getHeight();

            if (expPosition > mSrcPos) {
                top = expItem.getTop() + childHeight;
                bottom = top + dividerHeight;
            } else {
                bottom = expItem.getBottom() - childHeight;
                top = bottom - dividerHeight;
            }

            // Have to clip to support ColorDrawable on <= Gingerbread
            canvas.save();
            canvas.clipRect(left, top, right, bottom);
            divider.setBounds(left, top, right, bottom);
            divider.draw(canvas);
            canvas.restore();
        }
    }
}
 
Example 7
Source File: DragSortListView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {

        final Drawable divider = getDivider();
        final int dividerHeight = getDividerHeight();
        // Log.d("mobeta", "div="+divider+" divH="+dividerHeight);

        if (divider != null && dividerHeight != 0) {
            final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                    - getFirstVisiblePosition());
            if (expItem != null) {
                final int l = getPaddingLeft();
                final int r = getWidth() - getPaddingRight();
                final int t;
                final int b;

                final int childHeight = expItem.getChildAt(0).getHeight();

                if (expPosition > mSrcPos) {
                    t = expItem.getTop() + childHeight;
                    b = t + dividerHeight;
                } else {
                    b = expItem.getBottom() - childHeight;
                    t = b - dividerHeight;
                }
                // Log.d("mobeta", "l="+l+" t="+t+" r="+r+" b="+b);

                // Have to clip to support ColorDrawable on <= Gingerbread
                canvas.save();
                canvas.clipRect(l, t, r, b);
                divider.setBounds(l, t, r, b);
                divider.draw(canvas);
                canvas.restore();
            }
        }
    }
 
Example 8
Source File: DragSortListView.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {

        final Drawable divider = getDivider();
        final int dividerHeight = getDividerHeight();
        // Log.d("mobeta", "div="+divider+" divH="+dividerHeight);

        if (divider != null && dividerHeight != 0) {
            final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                    - getFirstVisiblePosition());
            if (expItem != null) {
                final int l = getPaddingLeft();
                final int r = getWidth() - getPaddingRight();
                final int t;
                final int b;

                final int childHeight = expItem.getChildAt(0).getHeight();

                if (expPosition > mSrcPos) {
                    t = expItem.getTop() + childHeight;
                    b = t + dividerHeight;
                } else {
                    b = expItem.getBottom() - childHeight;
                    t = b - dividerHeight;
                }
                // Log.d("mobeta", "l="+l+" t="+t+" r="+r+" b="+b);

                // Have to clip to support ColorDrawable on <= Gingerbread
                canvas.save();
                canvas.clipRect(l, t, r, b);
                divider.setBounds(l, t, r, b);
                divider.draw(canvas);
                canvas.restore();
            }
        }
    }
 
Example 9
Source File: FocusAnimator.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 10
Source File: FocusAnimator.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 11
Source File: CalendarGridView.java    From android-times-square with Apache License 2.0 5 votes vote down vote up
@Override protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final ViewGroup row = (ViewGroup) getChildAt(1);
  int top = row.getTop();
  int bottom = getBottom();
  // Left side border.
  final int left = row.getChildAt(0).getLeft() + getLeft();
  canvas.drawLine(left + FLOAT_FUDGE, top, left + FLOAT_FUDGE, bottom, dividerPaint);

  // Each cell's right-side border.
  for (int c = 0; c < 7; c++) {
    float x = left + row.getChildAt(c).getRight() - FLOAT_FUDGE;
    canvas.drawLine(x, top, x, bottom, dividerPaint);
  }
}
 
Example 12
Source File: CalendarGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override protected void dispatchDraw(Canvas canvas) {
  super.dispatchDraw(canvas);
  final ViewGroup row = (ViewGroup) getChildAt(1);
  int top = row.getTop();
  int bottom = getBottom();
  // Left side border.
  final int left = row.getChildAt(0).getLeft() + getLeft();
  canvas.drawLine(left + FLOAT_FUDGE, top, left + FLOAT_FUDGE, bottom, dividerPaint);

  // Each cell's right-side border.
  for (int c = 0; c < 7; c++) {
    float x = left + row.getChildAt(c).getRight() - FLOAT_FUDGE;
    canvas.drawLine(x, top, x, bottom, dividerPaint);
  }
}
 
Example 13
Source File: DragSortListView.java    From android-kernel-tweaker with GNU General Public License v3.0 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {

        final Drawable divider = getDivider();
        final int dividerHeight = getDividerHeight();
        // Log.d("mobeta", "div="+divider+" divH="+dividerHeight);

        if (divider != null && dividerHeight != 0) {
            final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                    - getFirstVisiblePosition());
            if (expItem != null) {
                final int l = getPaddingLeft();
                final int r = getWidth() - getPaddingRight();
                final int t;
                final int b;

                final int childHeight = expItem.getChildAt(0).getHeight();

                if (expPosition > mSrcPos) {
                    t = expItem.getTop() + childHeight;
                    b = t + dividerHeight;
                } else {
                    b = expItem.getBottom() - childHeight;
                    t = b - dividerHeight;
                }
                // Log.d("mobeta", "l="+l+" t="+t+" r="+r+" b="+b);

                // Have to clip to support ColorDrawable on <= Gingerbread
                canvas.save();
                canvas.clipRect(l, t, r, b);
                divider.setBounds(l, t, r, b);
                divider.draw(canvas);
                canvas.restore();
            }
        }
    }
 
Example 14
Source File: DragSortListView.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {

        final Drawable divider = getDivider();
        final int dividerHeight = getDividerHeight();
        // Log.d("mobeta", "div="+divider+" divH="+dividerHeight);

        if (divider != null && dividerHeight != 0) {
            final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                    - getFirstVisiblePosition());
            if (expItem != null) {
                final int l = getPaddingLeft();
                final int r = getWidth() - getPaddingRight();
                final int t;
                final int b;

                final int childHeight = expItem.getChildAt(0).getHeight();

                if (expPosition > mSrcPos) {
                    t = expItem.getTop() + childHeight;
                    b = t + dividerHeight;
                } else {
                    b = expItem.getBottom() - childHeight;
                    t = b - dividerHeight;
                }
                // Log.d("mobeta", "l="+l+" t="+t+" r="+r+" b="+b);

                // Have to clip to support ColorDrawable on <= Gingerbread
                canvas.save();
                canvas.clipRect(l, t, r, b);
                divider.setBounds(l, t, r, b);
                divider.draw(canvas);
                canvas.restore();
            }
        }
    }
 
Example 15
Source File: DragSortListView.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void drawDivider(int expPosition, Canvas canvas) {

        final Drawable divider = getDivider();
        final int dividerHeight = getDividerHeight();
        // Log.d("mobeta", "div="+divider+" divH="+dividerHeight);

        if (divider != null && dividerHeight != 0) {
            final ViewGroup expItem = (ViewGroup) getChildAt(expPosition
                    - getFirstVisiblePosition());
            if (expItem != null) {
                final int l = getPaddingLeft();
                final int r = getWidth() - getPaddingRight();
                final int t;
                final int b;

                final int childHeight = expItem.getChildAt(0).getHeight();

                if (expPosition > mSrcPos) {
                    t = expItem.getTop() + childHeight;
                    b = t + dividerHeight;
                } else {
                    b = expItem.getBottom() - childHeight;
                    t = b - dividerHeight;
                }
                // Log.d("mobeta", "l="+l+" t="+t+" r="+r+" b="+b);

                // Have to clip to support ColorDrawable on <= Gingerbread
                canvas.save();
                canvas.clipRect(l, t, r, b);
                divider.setBounds(l, t, r, b);
                divider.draw(canvas);
                canvas.restore();
            }
        }
    }
 
Example 16
Source File: ClickShadowView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Aligns the shadow with {@param view}
 * @param viewParent immediate parent of {@param view}. It must be a sibling of this view.
 */
public void alignWithIconView(BubbleTextView view, ViewGroup viewParent, View clipAgainstView) {
    float leftShift = view.getLeft() + viewParent.getLeft() - getLeft();
    float topShift = view.getTop() + viewParent.getTop() - getTop();
    int iconWidth = view.getRight() - view.getLeft();
    int iconHeight = view.getBottom() - view.getTop();
    int iconHSpace = iconWidth - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft();
    float drawableWidth = view.getIcon().getBounds().width();

    if (clipAgainstView != null) {
        // Set the bounds to clip against
        int[] coords = new int[] {0, 0};
        Utilities.getDescendantCoordRelativeToAncestor(clipAgainstView, (View) getParent(),
                coords, false);
        int clipLeft = (int) Math.max(0, coords[0] - leftShift - mShadowPadding);
        int clipTop = (int) Math.max(0, coords[1] - topShift - mShadowPadding) ;
        setClipBounds(new Rect(clipLeft, clipTop, clipLeft + iconWidth, clipTop + iconHeight));
    } else {
        // Reset the clip bounds
        setClipBounds(null);
    }

    setTranslationX(leftShift
            + viewParent.getTranslationX()
            + view.getCompoundPaddingLeft() * view.getScaleX()
            + (iconHSpace - drawableWidth) * view.getScaleX() / 2  /* drawable gap */
            + iconWidth * (1 - view.getScaleX()) / 2  /* gap due to scale */
            - mShadowPadding  /* extra shadow size */
            );
    setTranslationY(topShift
            + viewParent.getTranslationY()
            + view.getPaddingTop() * view.getScaleY()  /* drawable gap */
            + view.getHeight() * (1 - view.getScaleY()) / 2  /* gap due to scale */
            - mShadowPadding  /* extra shadow size */
            );
}
 
Example 17
Source File: FocusAnimator.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 18
Source File: DragListView.java    From DongWeather with Apache License 2.0 5 votes vote down vote up
/**
     * 获取触点所在条目的位置
     * 获取选中条目的图片
     * 事件的拦截机制
     *
     * @param ev
     * @return
     */
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//识别动作
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
//获取触点的坐标
                int x = (int) ev.getX();
                int y = (int) ev.getY();
//这样就可以计算我按到哪个条目上了
                mStartPosition = mEndPosition = pointToPosition(x, y);
//判断触点是否在logo的区域
                ViewGroup itemView = (ViewGroup) getChildAt(mStartPosition - getFirstVisiblePosition());
//记录手指在条目中的相对Y坐标
                dragPoint = y - itemView.getTop();
//ListView在屏幕中的Y坐标
                dragOffset = (int) (ev.getRawY() - y);
//拖动的图标
                View dragger = itemView.findViewById(R.id.guide_shape_im); //有修改
//判断触点是否在logo区域
                if (dragger != null && x < dragger.getRight() + 10) {
//定义ListView的滚动条目
//上
                    upScroll = getHeight() / 3;
//下
                    downScroll = getHeight() * 2 / 3;
//获取选中的图片/截图
                    itemView.setDrawingCacheEnabled(true);
//获取截图
                    Bitmap bitMap = itemView.getDrawingCache();
//图片滚动
                    startDrag(bitMap, y);
                }
                break;
        }
//还会传递事件到子View
        return false;
    }
 
Example 19
Source File: TouchInterceptor.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mDragListener != null || mDropListener != null) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                int x = (int) ev.getX();
                int y = (int) ev.getY();
                int itemnum = pointToPosition(x, y);
                if (itemnum == AdapterView.INVALID_POSITION) {
                    break;
                }
                ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
                mDragPoint = y - item.getTop();
                mCoordOffset = ((int) ev.getRawY()) - y;
                View dragger = item.findViewById(R.id.grabber);
                Rect r = mTempRect;
                dragger.getDrawingRect(r);
                if (shouldStartDragging(x, r.width())) {
                    // Fix x position while dragging
                    int[] itemPos = new int[2];
                    item.getLocationOnScreen(itemPos);

                    item.setDrawingCacheEnabled(true);
                    // Create a copy of the drawing cache so that it does
                    // not get recycled
                    // by the framework when the list tries to clean up
                    // memory
                    Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
                    startDragging(bitmap, itemPos[0], y);
                    mDragPos = itemnum;
                    mFirstDragPos = mDragPos;
                    mHeight = getHeight();
                    int touchSlop = mTouchSlop;
                    mUpperBound = Math.min(y - touchSlop, mHeight / 3);
                    mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
                    return false;
                }
                stopDragging();
                break;
        }
    }
    return super.onInterceptTouchEvent(ev);
}
 
Example 20
Source File: DSListView.java    From direct-select-android with MIT License 4 votes vote down vote up
@Override
public void onScroll(AbsListView listView, int firstVisible, int visibleItemCount, int totalItemCount) {
    if (!pickerInitialized || !selectorAnimationsEnabled) return;

    int selectorPosY = cellHeight * cellsBeforeSelector;
    int applyingRangeY = cellHeight;

    for (int i = 0; i < listView.getChildCount(); i++) {

        // Exclude elements that does not need to edit
        if (!(listView.getChildAt(i) instanceof FrameLayout))
            continue;

        ViewGroup itemRoot = (ViewGroup) listView.getChildAt(i);

        float deviation = 2f;
        if (itemRoot.getTop() > selectorPosY + applyingRangeY * deviation || itemRoot.getTop() < selectorPosY - applyingRangeY * deviation)
            continue;

        View cellContent = itemRoot.getChildAt(0);

        // Edit elements regarding to their position from selector
        float dy = Math.abs(itemRoot.getTop() - selectorPosY);
        if (!selectorAnimationCenterPivot) {
            cellContent.setPivotX(0);
            cellContent.setPivotY(cellContent.getHeight() / 2);
        }

        // Scale and "3d effect" for big scale factors on API>=LOLLIPOP
        if (dy <= applyingRangeY) {
            float k1 = 1 - (dy / applyingRangeY);
            float scale = 1 + scaleFactorDelta * k1;
            cellContent.setScaleX(scale);
            cellContent.setScaleY(scale);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                itemRoot.setZ((dy <= applyingRangeY / 2) ? 2 : 1);

        } else {
            cellContent.setScaleX(1f);
            cellContent.setScaleY(1f);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                itemRoot.setZ(0);
        }

    }
}