Java Code Examples for android.graphics.Region#contains()

The following examples show how to use android.graphics.Region#contains() . 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: LineView.java    From SimplePomodoro-android with MIT License 6 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    Point point = new Point();
    point.x = (int) event.getX();
    point.y = (int) event.getY();
    Region r = new Region();
    int width = backgroundGridWidth/2;
    if(drawDotList != null || !drawDotList.isEmpty()){
        for(Dot dot : drawDotList){
            r.set(dot.x-width,dot.y-width,dot.x+width,dot.y+width);
            if (r.contains(point.x,point.y) && event.getAction() == MotionEvent.ACTION_DOWN){
                selectedDot = dot;
            }else if (event.getAction() == MotionEvent.ACTION_UP){
                if (r.contains(point.x,point.y)){
                    showPopup = true;
                }
            }
        }
    }
    if (event.getAction() == MotionEvent.ACTION_DOWN ||
            event.getAction() == MotionEvent.ACTION_UP){
        postInvalidate();
    }
    return true;
}
 
Example 2
Source File: LineView.java    From AndroidCharts with MIT License 6 votes vote down vote up
private Dot findPointAt(int x, int y) {
    if (drawDotLists.isEmpty()) {
        return null;
    }

    final int width = backgroundGridWidth / 2;
    final Region r = new Region();

    for (ArrayList<Dot> data : drawDotLists) {
        for (Dot dot : data) {
            final int pointX = dot.x;
            final int pointY = (int) dot.y;

            r.set(pointX - width, pointY - width, pointX + width, pointY + width);
            if (r.contains(x, y)) {
                return dot;
            }
        }
    }

    return null;
}
 
Example 3
Source File: BitmapSticker.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void calculateClickType(int x, int y) {
    RectF rectF = new RectF(x - btSize / 2 - 40, y - btSize / 2 - 40, x + btSize / 2 + 40, y + btSize / 2 + 40);
    if (rectF.contains(dstPs[2] - 20, dstPs[3])) {
        clickType = ClickType.DELETE;
    } else if (rectF.contains(dstPs[0], dstPs[1])) {
        clickType = ClickType.MIRROR;
    } else if (rectF.contains(dstPs[4] + 20, dstPs[5])) {
        clickType = ClickType.SCALE;
    } else if (rectF.contains(dstPs[6] - 20, dstPs[7])) {
        clickType = ClickType.IMAGE;
    } else {

        RectF bounds = new RectF();
        path.computeBounds(bounds, true);
        Region region = new Region();
        region.setPath(path, new Region((int)bounds.left, (int)bounds.top,(int)bounds.right, (int)bounds.bottom));

        if (region.contains(x, y)) {
            if (isOut) {
                isOut = false;
            }
            if (!isUsing) {
                isUsing = true;
                listener.onUsing();
                postInvalidate();
            }
            clickType = ClickType.IMAGE;
        } else {
            if (isUsing) {
                isUsing = false;
                postInvalidate();
            }
            if (!isOut) {
                isOut = true;
            }
            clickType = ClickType.OUT;
        }
    }
}
 
Example 4
Source File: BitmapSticker.java    From imsdk-android with MIT License 5 votes vote down vote up
private void calculateClickType(int x, int y) {
    RectF rectF = new RectF(x - btSize / 2 - 40, y - btSize / 2 - 40, x + btSize / 2 + 40, y + btSize / 2 + 40);
    if (rectF.contains(dstPs[2] - 20, dstPs[3])) {
        clickType = ClickType.DELETE;
    } else if (rectF.contains(dstPs[0], dstPs[1])) {
        clickType = ClickType.MIRROR;
    } else if (rectF.contains(dstPs[4] + 20, dstPs[5])) {
        clickType = ClickType.SCALE;
    } else if (rectF.contains(dstPs[6] - 20, dstPs[7])) {
        clickType = ClickType.IMAGE;
    } else {

        RectF bounds = new RectF();
        path.computeBounds(bounds, true);
        Region region = new Region();
        region.setPath(path, new Region((int)bounds.left, (int)bounds.top,(int)bounds.right, (int)bounds.bottom));

        if (region.contains(x, y)) {
            if (isOut) {
                isOut = false;
            }
            if (!isUsing) {
                isUsing = true;
                listener.onUsing();
                postInvalidate();
            }
            clickType = ClickType.IMAGE;
        } else {
            if (isUsing) {
                isUsing = false;
                postInvalidate();
            }
            if (!isOut) {
                isOut = true;
            }
            clickType = ClickType.OUT;
        }
    }
}
 
Example 5
Source File: VectorView.java    From SVG-Android with Apache License 2.0 5 votes vote down vote up
public int findPathIndexByPoint(int x, int y) {
    Region region = new Region();
    for (int i = 0; i < mPaths.length; i++) {
        mPaths[i].computeBounds(RECTF, true);
        region.setPath(mPaths[i], new Region((int)RECTF.left,(int)RECTF.top,(int)RECTF.right,(int)RECTF.bottom));
        if (region.contains(x, y)) {
            return i;
        }
    }
    return INVALID_PATH_INDEX;
}
 
Example 6
Source File: MonthView.java    From Android-LunarView with Apache License 2.0 5 votes vote down vote up
private void handleClickEvent(int x, int y) {
  Region[][] monthRegion = getMonthRegion();
  for (int i = 0; i < monthRegion.length; i++) {
    for (int j = 0; j < DAYS_IN_WEEK; j++) {
      Region region = monthRegion[i][j];
      if (!region.contains(x, y)) {
        continue;
      }

      MonthDay monthDay = month.getMonthDay(i, j);
      if (monthDay == null) {
        return;
      }

      int day = monthDay.getCalendar().get(Calendar.DAY_OF_MONTH);

      if (monthDay.isCheckable()) {
        selectedIndex = i * DAYS_IN_WEEK + j;
        performDayClick();
        invalidate();
      } else {
        if (monthDay.getDayFlag() == MonthDay.PREV_MONTH_DAY) {
          lunarView.showPrevMonth(day);
        } else if (monthDay.getDayFlag() == MonthDay.NEXT_MONTH_DAY) {
          lunarView.showNextMonth(day);
        }
      }
      break;
    }
  }
}
 
Example 7
Source File: BarGraph.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

	Point point = new Point();
	point.x = (int) event.getX();
	point.y = (int) event.getY();

	int count = 0;
	for (Bar bar : points) {
		Region r = new Region();
		r.setPath(bar.getPath(), bar.getRegion());
		if (r.contains((int) point.x, (int) point.y)
				&& event.getAction() == MotionEvent.ACTION_DOWN) {
			indexSelected = count;
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			if (r.contains((int) point.x, (int) point.y)
					&& listener != null) {
				listener.onClick(indexSelected);
			}
			indexSelected = -1;
		}
		count++;
	}

	if (event.getAction() == MotionEvent.ACTION_DOWN
			|| event.getAction() == MotionEvent.ACTION_UP) {
		shouldUpdate = true;
		postInvalidate();
	}

	return true;
}
 
Example 8
Source File: PieGraph.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    Point point = new Point();
    point.x = (int) event.getX();
    point.y = (int) event.getY();
    
    int count = 0;
    for (PieSlice slice : slices){
    	Region r = new Region();
    	r.setPath(slice.getPath(), slice.getRegion());
    	if (r.contains((int)point.x,(int) point.y) && event.getAction() == MotionEvent.ACTION_DOWN){
    		indexSelected = count;
    	} else if (event.getAction() == MotionEvent.ACTION_UP){
    		if (r.contains((int)point.x,(int) point.y) && listener != null){
    			if (indexSelected > -1){
	    			listener.onClick(indexSelected);
    			}
    			indexSelected = -1;
    		}
    		
    	}
	    count++;
    }
    
    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP){
    	postInvalidate();
    }
    
    

    return true;
}
 
Example 9
Source File: PolyOverlayWithIW.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
   * Used to be if {@link Polygon}
   * Important note: this function returns correct results only if the Poly has been drawn before,
   * and if the MapView positioning has not changed.
   * @return true if the Poly contains the event position.
   */
  public boolean contains(final MotionEvent pEvent){
      if (mPath.isEmpty()) {
	return false;
}
      final RectF bounds = new RectF(); //bounds of the Path
      mPath.computeBounds(bounds, true);
      final Region region = new Region();
      //Path has been computed in #draw (we assume that if it can be clicked, it has been drawn before).
      region.setPath(mPath, new Region((int)bounds.left, (int)bounds.top,
              (int) (bounds.right), (int) (bounds.bottom)));
      return region.contains((int)pEvent.getX(), (int)pEvent.getY());
  }
 
Example 10
Source File: TextSticker.java    From EasyPhotos with Apache License 2.0 4 votes vote down vote up
private void calculateClickType(int x, int y) {
        RectF rectF = new RectF(x - btSize / 2 - 40, y - btSize / 2 - 40, x + btSize / 2 + 40, y + btSize / 2 + 40);

        Rect rect = new Rect();


        if (rectF.contains(dstPs[2] - 20, dstPs[3])) {
            clickType = ClickType.DELETE;
        }
//        else if (rectF.contains(dstPs[0], dstPs[1])) {
//            clickType = ClickType.EDITOR;
//        }
        else if (rectF.contains(dstPs[4] + 20, dstPs[5])) {
            clickType = ClickType.SCALE;
        }
//        else if (rectF.contains(dstPs[6] - 20, dstPs[7])) {
//            clickType = ClickType.IMAGE;
//        }
        else {
            RectF bounds = new RectF();
            path.computeBounds(bounds, true);
            Region region = new Region();
            region.setPath(path, new Region((int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom));

            if (region.contains(x, y)) {
                if (isOut) {
                    isOut = false;
                }
                if (!isUsing) {
                    isUsing = true;
                    listener.onUsing();
                    postInvalidate();
                }
                clickType = ClickType.IMAGE;
            } else {
                if (isUsing) {
                    isUsing = false;
                    postInvalidate();
                }
                if (!isOut) {
                    isOut = true;
                }
                clickType = ClickType.OUT;
            }
        }
    }
 
Example 11
Source File: TextSticker.java    From imsdk-android with MIT License 4 votes vote down vote up
private void calculateClickType(int x, int y) {
        RectF rectF = new RectF(x - btSize / 2 - 40, y - btSize / 2 - 40, x + btSize / 2 + 40, y + btSize / 2 + 40);

        Rect rect = new Rect();


        if (rectF.contains(dstPs[2] - 20, dstPs[3])) {
            clickType = ClickType.DELETE;
        }
//        else if (rectF.contains(dstPs[0], dstPs[1])) {
//            clickType = ClickType.EDITOR;
//        }
        else if (rectF.contains(dstPs[4] + 20, dstPs[5])) {
            clickType = ClickType.SCALE;
        }
//        else if (rectF.contains(dstPs[6] - 20, dstPs[7])) {
//            clickType = ClickType.IMAGE;
//        }
        else {
            RectF bounds = new RectF();
            path.computeBounds(bounds, true);
            Region region = new Region();
            region.setPath(path, new Region((int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom));

            if (region.contains(x, y)) {
                if (isOut) {
                    isOut = false;
                }
                if (!isUsing) {
                    isUsing = true;
                    listener.onUsing();
                    postInvalidate();
                }
                clickType = ClickType.IMAGE;
            } else {
                if (isUsing) {
                    isUsing = false;
                    postInvalidate();
                }
                if (!isOut) {
                    isOut = true;
                }
                clickType = ClickType.OUT;
            }
        }
    }
 
Example 12
Source File: LineGraph.java    From Pimp_my_Z1 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    Point point = new Point();
    point.x = (int) event.getX();
    point.y = (int) event.getY();

    int count = 0;
    int lineCount = 0;
    int pointCount = 0;

    Region r = new Region();
    for (Line line : lines) {
        pointCount = 0;
        for (LinePoint p : line.getPoints()) {

            if (p.getPath() != null && p.getRegion() != null) {
                r.setPath(p.getPath(), p.getRegion());
                if (r.contains((int) point.x, (int) point.y) && event.getAction() == MotionEvent.ACTION_DOWN) {
                    indexSelected = count;
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (r.contains((int) point.x, (int) point.y) && listener != null) {
                        listener.onClick(lineCount, pointCount);
                    }
                    indexSelected = -1;
                }
            }

            pointCount++;
            count++;
        }
        lineCount++;

    }

    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP) {
        shouldUpdate = true;
        postInvalidate();
    }


    return true;
}