コード例 #1
0
ファイル: LocationView.java プロジェクト: rocketbob/avare
  private void startClosestAirportTask(double x, double y) {
    // We won't be doing the airport long press under certain circumstances
    if (mDraw) {

      return;
    }

    if (null != mClosestTask) {
      mClosestTask.cancel(true);
    }
    mLongTouchDestination = null;
    mClosestTask = new ClosestAirportTask();

    double lon2, lat2;
    if (mPref.isTrackUp()) {
      double c_x = mOrigin.getOffsetX(mGpsParams.getLongitude());
      double c_y = mOrigin.getOffsetY(mGpsParams.getLatitude());
      double thetab = mGpsParams.getBearing();

      double p[];
      p = Helper.rotateCoord(c_x, c_y, thetab, x, y);
      lon2 = mOrigin.getLongitudeOf(p[0]);
      lat2 = mOrigin.getLatitudeOf(p[1]);
    } else {
      lon2 = mOrigin.getLongitudeOf(x);
      lat2 = mOrigin.getLatitudeOf(y);
    }
    mClosestTask.execute(lon2, lat2);
  }
コード例 #2
0
ファイル: LocationView.java プロジェクト: rocketbob/avare
  /* (non-Javadoc)
   * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent)
   */
  @Override
  public boolean onTouch(View view, MotionEvent e) {
    boolean bPassToGestureDetector = true;

    if (e.getAction() == MotionEvent.ACTION_UP) {

      /** Rubberbanding */
      rubberBand(e.getX(), e.getY(), true);

      /*
       * Drag stops for rubber band
       */
      mDragPlanPoint = -1;

      /*
       * Do not draw point. Only when long press and down.
       */
      mPointProjection = null;

      /*
       * Now that we have moved passed the macro level, re-query for new tiles.
       * Do not query repeatedly hence check for mFactor = 1
       */
      if (mMacro != mScale.getMacroFactor()) {
        loadTiles();
      }
    } else if (e.getAction() == MotionEvent.ACTION_DOWN) {

      if (mService != null) {
        /*
         * Find if this is close to a plan point. Do rubber banding if true
         * This is where rubberbanding starts
         */
        if (mService.getPlan() != null && mDragPlanPoint < 0 && mPref.allowRubberBanding()) {
          double lon = mOrigin.getLongitudeOf(e.getX());
          double lat = mOrigin.getLatitudeOf(e.getY());
          mDragPlanPoint = mService.getPlan().findClosePointId(lon, lat, mScale.getScaleFactor());
          mDragStartedX = e.getX();
          mDragStartedY = e.getY();
        }
      }

      mGestureCallBack.gestureCallBack(GestureInterface.TOUCH, (LongTouchDestination) null);

      // Remember this point so we can make sure we move far enough before losing the long press
      mDoCallbackWhenDone = false;
      mDownFocusPoint = getFocusPoint(e);
      startClosestAirportTask(e.getX(), e.getY());
    } else if (e.getAction() == MotionEvent.ACTION_MOVE) {
      if (mDownFocusPoint != null) {

        Point fp = getFocusPoint(e);
        final int deltaX = fp.x - mDownFocusPoint.x;
        final int deltaY = fp.y - mDownFocusPoint.y;
        int distanceSquare = (deltaX * deltaX) + (deltaY * deltaY);
        bPassToGestureDetector = distanceSquare > mTouchSlopSquare;
      }
      // Rubberbanding, intermediate
      rubberBand(e.getX(), e.getY(), false);
    }

    if (bPassToGestureDetector) {
      // Once we break out of the square or stop the long press, keep sending
      if (e.getAction() == MotionEvent.ACTION_MOVE || e.getAction() == MotionEvent.ACTION_UP) {
        mDownFocusPoint = null;
        mPointProjection = null;
        if (mClosestTask != null) {
          mClosestTask.cancel(true);
        }
      }
      mGestureDetector.onTouchEvent(e);
    }
    return mMultiTouchC.onTouchEvent(e, mScale.getMaxScale(), mScale.getMinScale(), mMacro);
  }