Example #1
0
 public void addPathAndClear() {
   Path path = new Path();
   int size = mPoints.size();
   FileUtil.printToFile("\n<<<<<<添加一个热区>>>>>", "hotarea.txt");
   for (int i = 0; i < size; i++) {
     Point p = mPoints.get(i);
     if (i == 0) {
       path.moveTo(p.x, p.y);
       FileUtil.printToFile(
           "p.moveTo(getGujia_width("
               + df.format((float) p.x / (float) mWidth)
               + "f), getGujia_height("
               + df.format((float) p.y / (float) mHeight)
               + "f));",
           "hotarea.txt");
     } else {
       path.lineTo(p.x, p.y);
       FileUtil.printToFile(
           "p.lineTo(getGujia_width("
               + df.format((float) p.x / (float) mWidth)
               + "f), getGujia_height("
               + df.format((float) p.y / (float) mHeight)
               + "f));",
           "hotarea.txt");
     }
   }
   path.close();
   m_paths.add(path);
   Region region = new Region();
   region.setPath(path, new Region(0, 0, mWidth, mHeight));
   m_regions.add(region);
   startAddPoint();
 }
  @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(point.x, point.y) && event.getAction() == MotionEvent.ACTION_DOWN) {
        indexSelected = count;
      } else if (event.getAction() == MotionEvent.ACTION_UP) {
        if (r.contains(point.x, 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 #3
0
 public void a(Path path) {
   d = path;
   path = new RectF();
   d.computeBounds(path, true);
   e = new Region();
   e.setPath(
       d,
       new Region(
           (int) ((RectF) (path)).left,
           (int) ((RectF) (path)).top,
           (int) ((RectF) (path)).right,
           (int) ((RectF) (path)).bottom));
 }