@Override
  public boolean onTouch(View view, MotionEvent motionEvent) {

    float xDelta = Math.abs(motionEvent.getRawX() - showcaseX);
    float yDelta = Math.abs(motionEvent.getRawY() - showcaseY);
    double distanceFromFocus = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2));

    if (mOptions.hideOnClickOutside && distanceFromFocus > showcaseRadius) {
      this.hide();
      return true;
    }

    return mOptions.block && distanceFromFocus > showcaseRadius;
  }
    public byte[] getTileImageData(int x, int y, int zoom) {
      mStream.reset();

      Matrix matrix = new Matrix(mBaseMatrix);
      float scale = (float) (Math.pow(2, zoom) * mScale);
      matrix.postScale(scale, scale);
      matrix.postTranslate(-x * mDimension, -y * mDimension);

      mBitmap.eraseColor(Color.TRANSPARENT);
      Canvas c = new Canvas(mBitmap);
      c.setMatrix(matrix);

      // NOTE: Picture is not thread-safe.
      synchronized (mSvgPicture) {
        mSvgPicture.draw(c);
      }

      BufferedOutputStream stream = new BufferedOutputStream(mStream);
      mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
      try {
        stream.close();
      } catch (IOException e) {
        Log.e(TAG, "Error while closing tile byte stream.");
        e.printStackTrace();
      }
      return mStream.toByteArray();
    }
Exemple #3
0
  @Override
  public void onDraw(Canvas canvas) {
    int margeLeft, margeRight, margeTop, margeBot, line, calcLine, part;
    if (canvas.getWidth() > canvas.getHeight()) {
      ref = (int) (canvas.getHeight() * 0.85);
      margin = (int) (canvas.getHeight() * 0.15);
    } else {
      ref = (int) (canvas.getWidth() * 0.85);
      margin = (int) (canvas.getWidth() * 0.15);
    }
    part = ref / NB_SQUARE_PAR_LINE;
    line = -1;
    int size = (int) Math.pow(NB_SQUARE_PAR_LINE, 2);
    for (int i = 0; i < size; i++) {
      ISquare square = chessboard.get(i);
      calcLine = (i - i % NB_SQUARE_PAR_LINE) / NB_SQUARE_PAR_LINE;
      margeTop = calcLine * part + margin / 2;
      if (calcLine != line) {
        line = calcLine;
        margeLeft = margin / 2;
      } else {
        margeLeft = margin / 2 + part * (i % NB_SQUARE_PAR_LINE);
      }
      margeBot = margeTop + part;
      margeRight = margeLeft + part;

      if ((line + i) % 2 == 1) {
        paintSquare.setColor(Color.parseColor("#a7823d"));
      } else {
        paintSquare.setColor(Color.parseColor("#e6e6ff"));
      }
      Rect rect = new Rect(margeLeft, margeTop, margeRight, margeBot);

      canvas.drawRect(rect, paintSquare);

      int status = square.getStatus();
      if (status != ISquare.STATUS_DEFAULT) {
        int border_margin = (int) (part * 0.08);
        int inner_margin;
        switch (status) {
          case (ISquare.STATUS_SELECTED):
            paintStatus.setColor(Color.parseColor("#0034E1")); // "#FFA200"));
            paintStatus.setStyle(Paint.Style.STROKE);
            paintStatus.setStrokeWidth(border_margin);
            inner_margin = border_margin / 2;
            rectF.set(
                margeLeft + inner_margin,
                margeTop + inner_margin,
                margeRight - inner_margin,
                margeBot - inner_margin);
            canvas.drawRect(rectF, paintStatus);
            break;
          case (ISquare.STATUS_TARGETABLE):
            paintStatus.setColor(Color.parseColor("#D23939"));
            paintStatus.setStyle(Paint.Style.FILL);
            paintStatus.setStrokeWidth(0);
            inner_margin = (int) (border_margin / 1.5);
            rectF.set(
                margeLeft + inner_margin,
                margeTop + inner_margin,
                margeRight - inner_margin,
                margeBot - inner_margin);
            canvas.drawRect(rectF, paintStatus);
            break;
          case (ISquare.STATUS_MOVE):
            paintStatus.setColor(Color.parseColor("#3899D1"));
            paintStatus.setStyle(Paint.Style.FILL);
            paintStatus.setStrokeWidth(0);
            inner_margin = (int) (border_margin / 1.5);
            rectF.set(
                margeLeft + inner_margin,
                margeTop + inner_margin,
                margeRight - inner_margin,
                margeBot - inner_margin);
            canvas.drawRect(rectF, paintStatus);
            break;
        }
      }

      if (!square.isEmpty()) {
        IPiece piece = square.getPiece();

        int marginDrawable = (int) (part * 0.2);

        RelativeLayout myLayout = (RelativeLayout) this.getParent();

        int width = (margeRight - marginDrawable) - (margeLeft + marginDrawable);
        int height = (margeBot - marginDrawable) - (margeTop + marginDrawable);
        int left = margeLeft + marginDrawable;
        int top = margeTop + marginDrawable;

        piece.setImage(getContext(), myLayout, width, height, left, top);
      }
    }
  }