コード例 #1
0
  /**
   * callback method for onTouch events
   *
   * @param pointinfo info about the touch event
   * @return
   *     <p><b>true</b> if the touch event is handled by this event<br>
   *     <b>false</b> if this touch event is not for this element
   *     <p>This is intended, that a subobject can check, if it should handle a click or so, or if
   *     the event should be sent to the underlying object.
   */
  public boolean onTouch(PointInfo pointinfo) {
    boolean handleEvent = false;

    // first ask our subobjects to handle it, otherwise let us handle it

    for (int i = subDrawables.size() - 1; i >= 0 && !handleEvent; i--) {

      MultiTouchDrawable sub = subDrawables.get(i);

      if (sub.containsPoint(pointinfo.getX(), pointinfo.getY())) {
        handleEvent = sub.onTouch(pointinfo);
      }
    }

    // Logger.d("touch action: "+this.getClass().getSimpleName()+" " +
    // pointinfo.getAction()+
    // " 0x"+Integer.toHexString(pointinfo.getAction()));

    // it's hard to find MOTION_UP events, because if the finger does not
    // stay exactly on the correct position,
    // this will change to dragging and we wont't get the drag end as
    // MOTION_UP

    if (!handleEvent
        && pointinfo.isMultiTouch() == false
        && pointinfo.getNumTouchPoints() == 1
        && pointinfo.getAction() == MotionEvent.ACTION_DOWN) {
      handleEvent = this.onSingleTouch(pointinfo);
    }

    return handleEvent;
  }
コード例 #2
0
 /**
  * Get the image that is under the single-touch point, or return null (canceling the drag op) if
  * none
  */
 public Img getDraggableObjectAtPoint(PointInfo pt) {
   float x = pt.getX(), y = pt.getY();
   int n = mImages.size();
   for (int i = n - 1; i >= 0; i--) {
     Img im = mImages.get(i);
     if (im.containsPoint(x, y)) return im;
   }
   return null;
 }
コード例 #3
0
 private void drawMultitouchDebugMarks(Canvas canvas) {
   if (currTouchPoint.isDown()) {
     float[] xs = currTouchPoint.getXs();
     float[] ys = currTouchPoint.getYs();
     float[] pressures = currTouchPoint.getPressures();
     int numPoints = Math.min(currTouchPoint.getNumTouchPoints(), 2);
     for (int i = 0; i < numPoints; i++)
       canvas.drawCircle(xs[i], ys[i], 50 + pressures[i] * 80, mLinePaintTouchPointCircle);
     if (numPoints == 2) canvas.drawLine(xs[0], ys[0], xs[1], ys[1], mLinePaintTouchPointCircle);
   }
 }
コード例 #4
0
  /*----------------------getDraggableObjectAtPoint--------------------------------------------------------------------*/
  public KiwiGLSurfaceView getDraggableObjectAtPoint(PointInfo touchPoint) {

    final float x = touchPoint.getX();
    final float y = touchPoint.getY();
    Log.d(TAG, "getDraggableObjectAtPoint");

    this.queueEvent(
        new Runnable() {
          public void run() {
            MidasNative.handleSingleTouchDown(x, y);
            requestRender();
          }
        });

    return this;
  }
コード例 #5
0
 /** Set the position and scale of the dragged/stretched image. */
 public boolean setPositionAndScale(
     Img img, PositionAndScale newImgPosAndScale, PointInfo touchPoint) {
   currTouchPoint.set(touchPoint);
   boolean ok = img.setPos(newImgPosAndScale);
   if (ok) invalidate();
   return ok;
 }
コード例 #6
0
  public MultiTouchDrawable getDraggableObjectAtPoint(PointInfo pt) {
    float x = pt.getX(), y = pt.getY();
    int n = subDrawables.size();
    for (int i = n - 1; i >= 0; i--) {
      MultiTouchDrawable im = subDrawables.get(i);

      if (im.isDragable() && im.containsPoint(x, y)) {
        return im.getDraggableObjectAtPoint(pt);
      }
    }

    if (this.containsPoint(pt.getX(), pt.getY())) {
      return this;
    }

    return null;
  }
コード例 #7
0
 /**
  * Select an object for dragging. Called whenever an object is found to be under the point
  * (non-null is returned by getDraggableObjectAtPoint()) and a drag operation is starting. Called
  * with null when drag op ends.
  */
 public void selectObject(Img img, PointInfo touchPoint) {
   currTouchPoint.set(touchPoint);
   if (img != null) {
     // Move image to the top of the stack when selected
     mImages.remove(img);
     mImages.add(img);
   } else {
     // Called with img == null when drag stops.
   }
   invalidate();
 }
コード例 #8
0
  /*----------------------setPositionAndScale--------------------------------------------------------------------*/
  public boolean setPositionAndScale(KiwiGLSurfaceView obj, PositionAndScale pos, PointInfo info) {

    Log.d(TAG, "setPositionAndScale");

    if (this.mLastTouchInfo == null) {
      this.mLastTouchInfo = new PointInfo();
      this.mLastTouchInfo.set(info);
      return true;
    }

    this.mCurrentTouchInfo.set(info);

    boolean isMulti = mLastTouchInfo.isMultiTouch();

    float dx = mCurrentTouchInfo.getX() - mLastTouchInfo.getX();
    float dy = mCurrentTouchInfo.getY() - mLastTouchInfo.getY();
    float x1 = mCurrentTouchInfo.getX();
    float y1 = mCurrentTouchInfo.getY();
    float x0 = x1 - dx;
    float y0 = y1 + dy;
    float scale = 1.0f;
    float angle = 0.0f;

    if (isMulti && mLastTouchInfo.getMultiTouchDiameter() != 0.0f) {
      scale = mCurrentTouchInfo.getMultiTouchDiameter() / mLastTouchInfo.getMultiTouchDiameter();
    }

    if (isMulti) {
      angle = mCurrentTouchInfo.getMultiTouchAngle() - mLastTouchInfo.getMultiTouchAngle();
    }

    MyRunnable myrun = new MyRunnable();
    myrun.dx = dx;
    myrun.dy = dy;
    myrun.x0 = x0;
    myrun.y0 = y0;
    myrun.x1 = x1;
    myrun.y1 = y1;
    myrun.scale = scale;
    myrun.angle = angle;
    myrun.isMulti = isMulti;
    this.queueEvent(myrun);

    mLastTouchInfo.set(mCurrentTouchInfo);
    return true;
  }
コード例 #9
0
ファイル: LocationView.java プロジェクト: rocketbob/avare
 /** @param touchPoint */
 private void touchPointChanged(PointInfo touchPoint) {
   mCurrTouchPoint.set(touchPoint);
   invalidate();
 }
コード例 #10
0
ファイル: LocationView.java プロジェクト: rocketbob/avare
  /* (non-Javadoc)
   * @see com.ds.avare.MultiTouchController.MultiTouchObjectCanvas#setPositionAndScale(java.lang.Object, com.ds.avare.MultiTouchController.PositionAndScale, com.ds.avare.MultiTouchController.PointInfo)
   */
  public boolean setPositionAndScale(
      Object obj, PositionAndScale newObjPosAndScale, PointInfo touchPoint) {
    touchPointChanged(touchPoint);
    if (false == mCurrTouchPoint.isMultiTouch()) {

      /*
       * Do not move on drag
       */
      if (mDragPlanPoint >= 0) {
        return true;
      }

      /*
       * Do not move on multitouch
       */
      if (mDraw && mService != null) {
        float x = mCurrTouchPoint.getX() * mScale.getScaleFactor();
        float y = mCurrTouchPoint.getY() * mScale.getScaleFactor();
        /*
         * Threshold the drawing so we do not generate too many points
         */
        if (mPref.isTrackUp()) {
          double thetab = mGpsParams.getBearing();
          double p[] = new double[2];
          double c_x = mOrigin.getOffsetX(mGpsParams.getLongitude());
          double c_y = mOrigin.getOffsetY(mGpsParams.getLatitude());
          p = Helper.rotateCoord(c_x, c_y, thetab, x, y);
          mService.getDraw().addPoint((float) p[0], (float) p[1], mOrigin);
        } else {
          mService.getDraw().addPoint(x, y, mOrigin);
        }
        return true;
      }

      // Pan
      if (mPan.setMove(newObjPosAndScale.getXOff(), newObjPosAndScale.getYOff())) {
        /*
         * Query when we have moved one tile. This will happen in background.
         */
        loadTiles();
      }
    } else {

      // Zooming does not change drag
      mDragPlanPoint = -1;

      /*
       * on double touch find distance and bearing between two points.
       */

      if (mPointProjection == null) {
        double x0 = mCurrTouchPoint.getXs()[0];
        double y0 = mCurrTouchPoint.getYs()[0];
        double x1 = mCurrTouchPoint.getXs()[1];
        double y1 = mCurrTouchPoint.getYs()[1];

        double lon0, lat0, lon1, lat1;
        // convert to origin coord if Trackup
        if (mPref.isTrackUp()) {
          double c_x = mOrigin.getOffsetX(mGpsParams.getLongitude());
          double c_y = mOrigin.getOffsetY(mGpsParams.getLatitude());
          double thetab = mGpsParams.getBearing();
          double p0[], p1[];
          p0 = Helper.rotateCoord(c_x, c_y, thetab, x0, y0);
          p1 = Helper.rotateCoord(c_x, c_y, thetab, x1, y1);
          lon0 = mOrigin.getLongitudeOf(p0[0]);
          lat0 = mOrigin.getLatitudeOf(p0[1]);
          lon1 = mOrigin.getLongitudeOf(p1[0]);
          lat1 = mOrigin.getLatitudeOf(p1[1]);
        } else {
          lon0 = mOrigin.getLongitudeOf(x0);
          lat0 = mOrigin.getLatitudeOf(y0);
          lon1 = mOrigin.getLongitudeOf(x1);
          lat1 = mOrigin.getLatitudeOf(y1);
        }
        mPointProjection = new Projection(lon0, lat0, lon1, lat1);
      }

      /*
       * Clamp scaling.
       */

      mScale.setScaleFactor(newObjPosAndScale.getScale());
    }
    updateCoordinates();
    invalidate();
    return true;
  }