Example #1
0
  /**
   * * Draw the horizontal and vertical distance tape
   *
   * @param canvas what to draw upon
   * @param scale object for zoom determinations
   * @param pixPerUnit how many pixels per mile/km/nm
   * @param homeX horizontal position of current location on display
   * @param homeY vertical position of current location on display
   * @param top the usable top of the display
   * @param width of the display
   * @param height of the display
   */
  @SuppressLint("DefaultLocale")
  public void draw(
      Canvas canvas,
      Scale scale,
      float pixPerUnit,
      int homeX,
      int homeY,
      int top,
      int width,
      int height) {

    // Set color and transparency for the shadow
    mPaint.setColor(Color.BLACK); // shadow color is black
    mPaint.setAlpha(0x7F); // Make it see-thru

    // the vertical shadow down the left of the display
    mPaint.setStrokeWidth(mBgndWidth); // Line width
    canvas.drawLine(mBgndWidth / 2, top, mBgndWidth / 2, height, mPaint);

    // the horizontal shadow along the top of the display under the display rows
    mPaint.setStrokeWidth(mBgndHeight);
    canvas.drawLine(mBgndWidth - 1, top + mBgndHeight / 2, width, top + mBgndHeight / 2, mPaint);

    // The interval values for the scale indicator
    double step = scale.getStep();

    // text is white in color
    mPaint.setColor(Color.WHITE);

    // the horizontal values use posX and posY
    int posX = homeX - (mTextWidth / 2);
    int posY = top + mBotmMargin;

    // Display the tape values for 20 distances
    for (int idx = 0; idx < 21; idx++) {

      // The current range. Make its label. Calc its display offset
      double inc = idx * step;
      String strLabel = String.format(inc < 10 ? "%1.1f" : "%.0f", inc);
      float offset = (float) step * idx * pixPerUnit;

      // vertical tape on the left side. Show if on the screen
      if (inRangeY(homeY - offset, posY, height))
        canvas.drawText(strLabel, mLeftMargin, homeY - offset, mPaint);
      if (inRangeY(homeY + offset, posY, height))
        canvas.drawText(strLabel, mLeftMargin, homeY + offset, mPaint);

      // Horizontal tape on the top edge. Show if on the screen
      if (inRangeX(posX - offset, mBgndWidth, width))
        canvas.drawText(strLabel, posX - offset, posY, mPaint);
      if (inRangeX(posX + offset, mBgndWidth, width))
        canvas.drawText(strLabel, posX + offset, posY, mPaint);
    }

    return;
  }
Example #2
0
 /** Center to the location */
 public void center() {
   /*
    * On double tap, move to center
    */
   mPan = new Pan();
   if (mService != null) {
     mPan.setMove(0, (float) ((getHeight() * .25) / mScale.getScaleFactor()));
     mService.setPan(mPan);
     mService.getTiles().forceReload();
   }
   loadTiles();
   updateCoordinates();
   postInvalidate();
 }
Example #3
0
  /* (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;
  }
Example #4
0
 /* (non-Javadoc)
  * @see com.ds.avare.MultiTouchController.MultiTouchObjectCanvas#getPositionAndScale(java.lang.Object, com.ds.avare.MultiTouchController.PositionAndScale)
  */
 public void getPositionAndScale(Object obj, PositionAndScale objPosAndScaleOut) {
   objPosAndScaleOut.set(
       mPan.getMoveX(), mPan.getMoveY(), true, mScale.getScaleFactorRaw(), false, 0, 0, false, 0);
 }
Example #5
0
  /* (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);
  }
Example #6
0
 public void zoomIn20Pct() {
   mScale.setScaleFactor((float) (mScale.getScaleFactor() * 1.2));
   invalidate();
 }
Example #7
0
 public void zoomOut20Pct() {
   mScale.setScaleFactor((float) (mScale.getScaleFactor() * .8));
   invalidate();
 }
Example #8
0
 public void zoomOut() {
   mScale.zoomOut();
 }