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

The following are Jave code examples for showing how to use getTop() of the android.view.ViewGroup 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: SnakeViewMaker   File: SnakeViewMaker.java   Source Code and License Vote up 6 votes
private void updateTargetViewLocation() {
    mTargetView.getLocationOnScreen(mTargetLocation);
    int statusBarHeight = getStatusBarHeight(mContext);
    int titleBarHeight = 0;
    if (mContext instanceof Activity) {
        // actionbar height
        Activity activity = (Activity) mContext;
        ViewGroup content = (ViewGroup) activity.findViewById(android.R.id.content);
        titleBarHeight = content.getTop();
        // statusBar height compat
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WindowManager.LayoutParams params = activity.getWindow().getAttributes();
            boolean isTranslucentStatus = (params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0;
            boolean isFitSystemWindows = true;
            if (null != content.getChildAt(0))
                isFitSystemWindows = content.getChildAt(0).getFitsSystemWindows();

            if (isTranslucentStatus && !isFitSystemWindows)
                statusBarHeight = 0;
        }
    }
    mContentTopInWindow = titleBarHeight + statusBarHeight;
    int top = mTargetLocation[1] - mContentTopInWindow;
    mTargetLocation[1] = top;
}
 
Example 2
Project: container   File: PendIntentCompat.java   Source Code and License Vote up 6 votes
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 3
Project: LaunchEnr   File: ClickShadowView.java   Source Code and License Vote up 5 votes
/**
 * 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 4
Project: ultrasonic   File: DragSortListView.java   Source Code and License Vote up 5 votes
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 5
Project: NoticeDog   File: DragSortListView.java   Source Code and License Vote up 5 votes
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 6
Project: DateRangePicker   File: CalendarGridView.java   Source Code and License Vote up 5 votes
@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 7
Project: chromium-for-android-56-debug-video   File: FocusAnimator.java   Source Code and License Vote up 5 votes
/** 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 8
Project: DateRangePickerLibrary   File: CalendarGridView.java   Source Code and License Vote up 5 votes
@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 9
Project: FlickLauncher   File: ClickShadowView.java   Source Code and License Vote up 5 votes
/**
 * 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 10
Project: PullToLoad   File: PullToRefreshLayout.java   Source Code and License Vote up 5 votes
void filterViewGroup(MotionEvent ev) {
    int downX = Math.round(ev.getX());
    int downY = Math.round(ev.getY());
    int size = mChildViewGroups.size();
    mInAreaViewGroups.clear();
    for (int i = 0; i < size; i++) {
        ViewGroup child = mChildViewGroups.get(i);
        if (child == null || child.getVisibility() == View.GONE)
            continue;
        if (downX > child.getLeft() && downX < child.getRight() && downY > child.getTop() && downY < child.getBottom())
            mInAreaViewGroups.add(child);
    }
}
 
Example 11
Project: SimpleUILauncher   File: ClickShadowView.java   Source Code and License Vote up 5 votes
/**
 * 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 12
Project: CSipSimple   File: DragnDropListView.java   Source Code and License Vote up 4 votes
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
	
	if ((mDragListener != null || mDropListener != null) 
			&& ev.getAction() == MotionEvent.ACTION_DOWN) {
		int x = (int) ev.getX();
		int y = (int) ev.getY();
		int itemnum = pointToPosition(x, y);
		if (itemnum != AdapterView.INVALID_POSITION) {

			ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
			Log.d("DnD view", "Start dragging at " + (itemnum - getFirstVisiblePosition()) + " for "+ itemnum + " # "+ getFirstVisiblePosition());
			mDragPoint = y - item.getTop();
			mCoordOffset = ((int) ev.getRawY()) - y;
			View dragger = item.findViewById(grabberId);
			if(dragger == null || dragger.getVisibility() == View.GONE) {
			    return super.onInterceptTouchEvent(ev);
			}
			Rect r = mTempRect;
			r.left=dragger.getLeft();
			r.right=dragger.getRight();
			r.top=dragger.getTop();
			r.bottom=dragger.getBottom();   

			if ((r.left<x) && (x<r.right)) {
				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, 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);
				item.setDrawingCacheEnabled(false);
				return false;
			}
			mDragView = null;
		}
	}
	return super.onInterceptTouchEvent(ev);
}
 
Example 13
Project: buildAPKsApps   File: SortableSettingsListView.java   Source Code and License Vote up 4 votes
public Dragger(Context context, Setting setting, ViewGroup item, MotionEvent ev) {
	
	mSetting = setting;
          int y = (int) ev.getY();
	
          mDragPointOffset = y - item.getTop();
          mCoordOffset = ((int)ev.getRawY()) - y;
          mRowHeight = item.getHeight();
	
          // enable cache
          // clear cache, otherwise we are going to have problems in donut ;)
          item.setDrawingCacheEnabled(false);
	item.setDrawingCacheEnabled(true);
	// create bitmap
	Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
	mBitmap = bitmap;

	// create window
          mWindowParams = new WindowManager.LayoutParams();
          
          WindowManager.LayoutParams params = mWindowParams;
          params.gravity = Gravity.TOP;
          params.alpha = 0.65f;
          params.x = 0;
          params.y = y - mDragPointOffset + mCoordOffset;

          params.height = WindowManager.LayoutParams.WRAP_CONTENT;
          params.width = WindowManager.LayoutParams.WRAP_CONTENT;
          params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                  | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                  | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
          params.format = PixelFormat.TRANSLUCENT;
          params.windowAnimations = 0;
          
          ImageView imageView = new ImageView(context);
          int backGroundColor = context.getResources().getColor(android.R.color.black);
          imageView.setBackgroundColor(backGroundColor);
          imageView.setImageBitmap(bitmap);

          // add view
          mWindowManager = (WindowManager) context.getSystemService("window");
          mWindowManager.addView(imageView, params);
          mImageView = imageView;
          
}
 
Example 14
Project: GravityBox   File: TouchInterceptor.java   Source Code and License Vote up 4 votes
@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 15
Project: AndroidOpen   File: RevealActivity.java   Source Code and License Vote up 4 votes
private void animateRevealColor(ViewGroup viewRoot, @ColorRes int color) {
    int cx = (viewRoot.getLeft() + viewRoot.getRight()) / 2;
    int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2;
    animateRevealColorFromCoordinates(viewRoot, color, cx, cy);
}