當前位置: 首頁>>代碼示例>>Java>>正文


Java Rect.contains方法代碼示例

本文整理匯總了Java中android.graphics.Rect.contains方法的典型用法代碼示例。如果您正苦於以下問題:Java Rect.contains方法的具體用法?Java Rect.contains怎麽用?Java Rect.contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Rect的用法示例。


在下文中一共展示了Rect.contains方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findClickableViewInChild

import android.graphics.Rect; //導入方法依賴的package包/類
private boolean findClickableViewInChild(View view, int x, int y) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            final Rect rect = new Rect();
            child.getHitRect(rect);

            final boolean contains = rect.contains(x, y);
            if (contains) {
                return findClickableViewInChild(child, x - rect.left, y - rect.top);
            }
        }
    } else if (view != childView) {
        return (view.isEnabled() && (view.isClickable() || view.isLongClickable() || view.isFocusableInTouchMode()));
    }

    return view.isFocusableInTouchMode();
}
 
開發者ID:yangchong211,項目名稱:YCUtils,代碼行數:20,代碼來源:MaterialRippleLayout.java

示例2: dispatchTouchEvent

import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if ( v instanceof EditText) {
            Rect outRect = new Rect();
            v.getGlobalVisibleRect(outRect);
            if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
                v.clearFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
    }
    return super.dispatchTouchEvent( event );
}
 
開發者ID:Pritom14,項目名稱:Password-Storage,代碼行數:17,代碼來源:RegistrationActivity.java

示例3: findAccessibilityNodeInfosByBounds

import android.graphics.Rect; //導入方法依賴的package包/類
private void findAccessibilityNodeInfosByBounds(UiObject root, List<UiObject> list) {
    if (root == null)
        return;
    Rect rect = new Rect();
    root.getBoundsInScreen(rect);
    if (rect.equals(mBoundsInScreen)) {
        list.add(root);
    }
    int oldSize = list.size();
    for (int i = 0; i < root.getChildCount(); i++) {
        UiObject child = root.child(i);
        if (child == null)
            continue;
        findAccessibilityNodeInfosByBounds(child, list);
    }
    if (oldSize == list.size() && rect.contains(mBoundsInScreen)) {
        list.add(root);
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:20,代碼來源:FilterAction.java

示例4: myPointToPosition

import android.graphics.Rect; //導入方法依賴的package包/類
private int myPointToPosition(int x, int y) {

        if (y < 0) {
            // when dragging off the top of the screen, calculate position
            // by going back from a visible item
            int pos = myPointToPosition(x, y + mItemHeightNormal);
            if (pos > 0) {
                return pos - 1;
            }
        }

        Rect frame = mTempRect;
        final int count = getChildCount();
        for (int i = count - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            child.getHitRect(frame);
            if (frame.contains(x, y)) {
                return getFirstVisiblePosition() + i;
            }
        }
        return INVALID_POSITION;
    }
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:23,代碼來源:TouchInterceptor.java

示例5: onRequestChildRectangleOnScreen

import android.graphics.Rect; //導入方法依賴的package包/類
@Override
    public boolean onRequestChildRectangleOnScreen(CoordinatorLayout parent, View child,
            Rect rectangle, boolean immediate) {
  final AppBarLayout header = findFirstDependency(parent.getDependencies(child));
  if (header != null) {
    // Offset the rect by the child's left/top
    rectangle.offset(child.getLeft(), child.getTop());

    final Rect parentRect = mTempRect1;
    parentRect.set(0, 0, parent.getWidth(), parent.getHeight());

    if (!parentRect.contains(rectangle)) {
      // If the rectangle can not be fully seen the visible bounds, collapse
      // the AppBarLayout
      header.setExpanded(false, !immediate);
      return true;
    }
  }
  return false;
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:21,代碼來源:AppBarLayout.java

示例6: findDropTarget

import android.graphics.Rect; //導入方法依賴的package包/類
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    final Rect r = mRectTemp;

    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i=count-1; i>=0; i--) {
        DropTarget target = dropTargets.get(i);
        if (!target.isDropEnabled())
            continue;

        target.getHitRectRelativeToDragLayer(r);

        mDragObject.x = x;
        mDragObject.y = y;
        if (r.contains(x, y)) {

            dropCoordinates[0] = x;
            dropCoordinates[1] = y;
            mLauncher.getDragLayer().mapCoordInSelfToDescendent((View) target, dropCoordinates);

            return target;
        }
    }
    return null;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:26,代碼來源:DragController.java

示例7: findChild

import android.graphics.Rect; //導入方法依賴的package包/類
private TagView findChild(int x, int y)
{
    final int cCount = getChildCount();
    for (int i = 0; i < cCount; i++)
    {
        TagView v = (TagView) getChildAt(i);
        if (v.getVisibility() == View.GONE) continue;
        Rect outRect = new Rect();
        v.getHitRect(outRect);
        if (outRect.contains(x, y))
        {
            return v;
        }
    }
    return null;
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:17,代碼來源:TagFlowLayout.java

示例8: closeKeyboardWhenRequired

import android.graphics.Rect; //導入方法依賴的package包/類
/**
 * Closes the keyboard when required, if the motion event does not point to a text field
 *
 * @param activity the activity
 * @param event    the event
 */
public static void closeKeyboardWhenRequired(Activity activity, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        View v = activity.getCurrentFocus();
        if (v instanceof EditText) {
            Rect outRect = new Rect();
            v.getGlobalVisibleRect(outRect);
            if (!outRect.contains((int) event.getRawX(), (int) event.getRawY())) {
                v.clearFocus();
                InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
        }
    }
}
 
開發者ID:worldiety,項目名稱:homunculus,代碼行數:23,代碼來源:Widget.java

示例9: touchIsCloseToSelection

import android.graphics.Rect; //導入方法依賴的package包/類
private boolean touchIsCloseToSelection(int x, int y, int start, int end) {

            final int distanceAwayDp = 40; // dp
            int distanceAwayPx = (int) (distanceAwayDp * getResources().getDisplayMetrics().density);

            // test if near selection start
            Rect selectionStart = getCursorRect(start);
            Rect nearbyStart = new Rect(
                    selectionStart.left - distanceAwayPx,
                    selectionStart.top - distanceAwayPx,
                    selectionStart.right + distanceAwayPx,
                    selectionStart.bottom + distanceAwayPx);
            if (nearbyStart.contains(x, y)) return true;

            if (end == start) return false;

            // test if near selection end
            Rect selectionEnd = getCursorRect(end);
            Rect nearbyEnd = new Rect(
                    selectionEnd.left - distanceAwayPx,
                    selectionEnd.top - distanceAwayPx,
                    selectionEnd.right + distanceAwayPx,
                    selectionEnd.bottom + distanceAwayPx);
            if (nearbyEnd.contains(x, y)) return true;
            return false;
        }
 
開發者ID:suragch,項目名稱:mongol-library,代碼行數:27,代碼來源:MongolEditText.java

示例10: findChild

import android.graphics.Rect; //導入方法依賴的package包/類
private TagView findChild(int x, int y) {
    int cCount = getChildCount();
    for (int i = 0; i < cCount; i++) {
        TagView v = (TagView) getChildAt(i);
        if (v.getVisibility() != 8) {
            Rect outRect = new Rect();
            v.getHitRect(outRect);
            if (outRect.contains(x, y)) {
                return v;
            }
        }
    }
    return null;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:15,代碼來源:TagFlowLayout.java

示例11: isPointInChildBounds

import android.graphics.Rect; //導入方法依賴的package包/類
/**
   * Check if a given point in the CoordinatorLayout's coordinates are within the view bounds
   * of the given direct child view.
 *
 * @param child child view to test
 * @param x X coordinate to test, in the CoordinatorLayout's coordinate system
 * @param y Y coordinate to test, in the CoordinatorLayout's coordinate system
 * @return true if the point is within the child view's bounds, false otherwise
 */
public boolean isPointInChildBounds(View child, int x, int y) {
  final Rect r = acquireTempRect();
  getDescendantRect(child, r);
  try {
    return r.contains(x, y);
  } finally {
    releaseTempRect(r);
  }
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:19,代碼來源:CoordinatorLayout.java

示例12: findChildByPoint

import android.graphics.Rect; //導入方法依賴的package包/類
private View findChildByPoint(int x, int y) {
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        Rect rect = new Rect();
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            return child;
        }
    }
    return null;
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:13,代碼來源:BigBangLayout.java

示例13: findHeaderPositionUnder

import android.graphics.Rect; //導入方法依賴的package包/類
/**
 * Gets the position of the header under the specified (x, y) coordinates.
 *
 * @param x x-coordinate
 * @param y y-coordinate
 * @return position of header, or -1 if not found
 */
public int findHeaderPositionUnder(int x, int y) {
    for (int i = 0; i < mHeaderRects.size(); i++) {
        Rect rect = mHeaderRects.get(mHeaderRects.keyAt(i));
        if (rect.contains(x, y)) {
            return mHeaderRects.keyAt(i);
        }
    }
    return -1;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:StickyRecyclerHeadersDecoration.java

示例14: onTouchEvent

import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    updateSourcePartial();

    // The logic below is mostly copied from the parent class, since we
    // can't update private mBounds variable.

    // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;
    // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98

    final Rect sourcePartial = mSourcePartial;
    final View target = mTarget;

    int x = (int)event.getX();
    int y = (int)event.getY();

    boolean sendToDelegate = false;
    boolean hit = true;
    boolean handled = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (sourcePartial.contains(x, y)) {
            mDelegateTargeted = true;
            sendToDelegate = true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_MOVE:
        sendToDelegate = mDelegateTargeted;
        if (sendToDelegate) {
            if (!sourcePartial.contains(x, y)) {
                hit = false;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        sendToDelegate = mDelegateTargeted;
        mDelegateTargeted = false;
        break;
    }

    if (sendToDelegate) {
        if (hit) {
            event.setLocation(target.getWidth() / 2, target.getHeight() / 2);
        } else {
            event.setLocation(-1, -1);
        }
        handled = target.dispatchTouchEvent(event);
    }
    return handled;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:53,代碼來源:FractionalTouchDelegate.java

示例15: isOnTouchRect

import android.graphics.Rect; //導入方法依賴的package包/類
private boolean isOnTouchRect(View view, MotionEvent event) {
    int rawX = (int) event.getRawX();
    int rawY = (int) event.getRawY();
    int[] xy = new int[2];
    view.getLocationOnScreen(xy);
    Rect rect = new Rect();
    rect.set(xy[0], xy[1], xy[0] + view.getWidth(), xy[1] + view.getHeight());
    return rect.contains(rawX, rawY);
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:10,代碼來源:TouchEventHandler.java


注:本文中的android.graphics.Rect.contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。