// Defines a callback that sends the drag shadow dimensions and touch
    // point back to the
    // system.
    @Override
    public void onProvideShadowMetrics(Point size, Point touch) {

      // Sets the width of the shadow to half the width of the original
      // View
      width = tile.tileImg.getWidth(); // getView().getWidth() / 2;

      // Sets the height of the shadow to half the height of the original
      // View
      height = tile.tileImg.getHeight(); // getView().getHeight() / 2;

      // The drag shadow is a ColorDrawable. This sets its dimensions to
      // be the same as the
      // Canvas that the system will provide. As a result, the drag shadow
      // will fill the
      // Canvas.
      shadow.setBounds(0, 0, width, height);

      // Sets the size parameter's width and height values. These get back
      // to the system
      // through the size parameter.
      size.set(width, height);

      // Sets the touch point's position to be in the middle of the drag
      // shadow
      touch.set(width / 2, height / 2);
    }
Example #2
0
    private Point cY(int i)
    {
        Point point;
        int j;
        byte byte0;
        byte0 = 24;
        j = 20;
        point = new Point();
        i;
        JVM INSTR tableswitch 0 2: default 44
    //                   0 112
    //                   1 106
    //                   2 122;
           goto _L1 _L2 _L3 _L4
_L1:
        i = 38;
        j = 24;
_L6:
        android.util.DisplayMetrics displaymetrics = getResources().getDisplayMetrics();
        float f = TypedValue.applyDimension(1, i, displaymetrics);
        float f1 = TypedValue.applyDimension(1, j, displaymetrics);
        point.x = (int)((double)f + 0.5D);
        point.y = (int)((double)f1 + 0.5D);
        return point;
_L3:
        i = 32;
        continue; /* Loop/switch isn't completed */
_L2:
        j = 14;
        i = byte0;
        continue; /* Loop/switch isn't completed */
_L4:
        i = 50;
        if (true) goto _L6; else goto _L5
Example #3
0
  // uses the difficulty to decide weather to return a hit spot or a missed
  public Point rollTheDice() {
    Point guessPoint = new Point(-1, -1);
    if ((int) (Math.random() * 100)
        > difficultyLevel) { // if you beat the percentage (so if difficulty is low, this has a
                             // higher chance)
      do {
        guessPoint.x = (int) (Math.random() * 10);
        guessPoint.y = (int) (Math.random() * 10);
      } while (cheater[guessPoint.x][guessPoint.y]
          != 0); // keep going while the spot you find is not zero
    } else {
      do {
        guessPoint.x = (int) (Math.random() * 10);
        guessPoint.y = (int) (Math.random() * 10);
      } while (cheater[guessPoint.x][guessPoint.y]
          < 1); // keep going while the spot you keep finding is 0 or -1
      focusPoint = guessPoint; // save where the first hit spot is
      fillSurroundingSpots();
      hasHit = true;
    }

    cheater[guessPoint.x][guessPoint.y] =
        -1; // set cheater board to -1 to say that we have guessed this spot now.
    lastHit = guessPoint;
    return guessPoint;
  }
Example #4
0
  private ArrayList<Point> createArc() {
    Point creature = new Point((int) target.centerX(), (int) target.centerY());
    Point tower = new Point((int) attacker.centerX(), (int) attacker.centerY());

    int N =
        (int)
            (Math.sqrt(
                    (creature.x - tower.x) * (creature.x - tower.x)
                        + (creature.y - tower.y) * (creature.y - tower.y))
                / 10);

    ArrayList<Point> arc = new ArrayList<Point>();

    arc.add(new Point((int) attacker.centerX(), (int) attacker.centerY()));

    Point vector = new Point(creature.x - tower.x, creature.y - tower.y);
    double nx = vector.y / Math.sqrt(vector.x * vector.x + vector.y * vector.y);
    double ny = -vector.x / Math.sqrt(vector.x * vector.x + vector.y * vector.y);

    Random ran = new Random();

    for (int i = 0; i < N - 1; i++) {
      tower.x += vector.x / N;
      tower.y += vector.y / N;

      int rand = ran.nextInt(20) - 10;

      arc.add(new Point((int) (tower.x + rand * nx), (int) (tower.y + rand * ny)));
    }

    arc.add(new Point((int) target.centerX(), (int) target.centerY()));

    return arc;
  }
 @Override
 public boolean onTouchEvent(MotionEvent e) {
   lastTouch.x = (int) e.getX();
   lastTouch.y = (int) e.getY();
   //		report("onTouchEvent()", "Touch at: " + lastTouch.x + "," + lastTouch.y);
   return true;
 }
  /** Reads, one time, values from the camera that are needed by the app. */
  void initFromCameraParameters(Camera camera) {

    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");
    Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenResolution = new Point(display.getWidth(), display.getHeight());
    Log.d(TAG, "Screen resolution: " + screenResolution);

    // ���һЩ�ֻ��޷�ɨ���BUG����������i9228��i9220.
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;
    // preview size is always something like 480*320, other 320*480
    if (screenResolution.x < screenResolution.y) {
      screenResolutionForCamera.x = screenResolution.y;
      screenResolutionForCamera.y = screenResolution.x;
    }

    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
    // cameraResolution = getCameraResolution(parameters, screenResolution);
    Log.d(TAG, "Camera resolution: " + screenResolution);
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    //        Logger.d(TAG, "onTouchEvent: " + event);
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        isTouched = true;
        this.setLayoutParams(newLp);
        endPoint.x = (int) downX;
        endPoint.y = (int) downY;

        changeViewHeight(
            this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        postInvalidate();

        downX = event.getX() + location[0];
        downY = event.getY() + location[1];
        //                Logger.d(TAG, String.format("downX: %f, downY: %f", downX, downY));

        break;
      case MotionEvent.ACTION_MOVE:
        // 计算直角边和斜边(用于计算绘制两圆之间的填充去)
        triangle.deltaX = event.getX() - downX;
        triangle.deltaY = -1 * (event.getY() - downY); // y轴方向相反,所有需要取反
        double distance =
            Math.sqrt(triangle.deltaX * triangle.deltaX + triangle.deltaY * triangle.deltaY);
        triangle.hypotenuse = distance;
        //                Logger.d(TAG, "triangle: " + triangle);
        refreshCurRadiusByMoveDistance((int) distance);

        endPoint.x = (int) event.getX();
        endPoint.y = (int) event.getY();

        postInvalidate();

        break;
      case MotionEvent.ACTION_UP:
        isTouched = false;
        this.setLayoutParams(originLp);

        if (isArrivedMaxMoved) { // 触发事件
          changeViewHeight(this, originWidth, originHeight);
          postInvalidate();
          if (null != onDraggableFlagViewListener) {
            onDraggableFlagViewListener.onFlagDismiss(this);
          }
          Logger.d(TAG, "触发事件...");
          resetAfterDismiss();
        } else { // 还原
          changeViewHeight(this, originWidth, originHeight);
          startRollBackAnimation(500 /*ms*/);
        }

        downX = Float.MAX_VALUE;
        downY = Float.MAX_VALUE;
        break;
    }

    return true;
  }
Example #8
0
  public final void loop(
      final Canvas pCanvas,
      final String pCacheKey,
      final float pZoomLevel,
      final int pTileSizePx,
      final Rect pViewPort,
      final Rect pClipRect) {
    // Calculate the amount of tiles needed for each side around the center one.
    Projection.pixelXYToTileXY(pViewPort.left, pViewPort.top, mUpperLeft);
    mUpperLeft.offset(-1, -1);

    Projection.pixelXYToTileXY(pViewPort.right, pViewPort.bottom, mLowerRight);
    mLowerRight.offset(1, 1);

    center.set((mUpperLeft.x + mLowerRight.x) / 2, (mUpperLeft.y + mLowerRight.y) / 2);

    final int roundedZoom = (int) Math.floor(pZoomLevel);
    final int mapTileUpperBound = 1 << roundedZoom;
    initializeLoop(pZoomLevel, pTileSizePx);

    int tileX, tileY;

    for (int y = mUpperLeft.y; y <= mLowerRight.y; y++) {
      for (int x = mUpperLeft.x; x <= mLowerRight.x; x++) {
        tileY = GeometryMath.mod(y, mapTileUpperBound);
        tileX = GeometryMath.mod(x, mapTileUpperBound);
        final MapTile tile = new MapTile(pCacheKey, roundedZoom, tileX, tileY);
        handleTile(pCanvas, pCacheKey, pTileSizePx, tile, x, y, pClipRect);
      }
    }
    finalizeLoop();
  }
  @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;
  }
    /**
     * Give the marker a slight bounce effect
     *
     * @param marker marker to animate
     */
    private void animateMarker(final Marker marker) {
      final Handler handler = new Handler();

      final long startTime = SystemClock.uptimeMillis();
      final long duration = 300; // ms

      Projection proj = mMap.getProjection();
      final LatLng markerLatLng = marker.getPosition();
      Point startPoint = proj.toScreenLocation(markerLatLng);
      startPoint.offset(0, -10);
      final LatLng startLatLng = proj.fromScreenLocation(startPoint);

      final Interpolator interpolator = new BounceInterpolator();

      handler.post(
          new Runnable() {
            @Override
            public void run() {
              long elapsed = SystemClock.uptimeMillis() - startTime;
              float t = interpolator.getInterpolation((float) elapsed / duration);
              double lng = t * markerLatLng.longitude + (1 - t) * startLatLng.longitude;
              double lat = t * markerLatLng.latitude + (1 - t) * startLatLng.latitude;
              marker.setPosition(new LatLng(lat, lng));

              if (t < 1.0) {
                // Post again 16ms later (60fps)
                handler.postDelayed(this, 16);
              }
            }
          });
    }
Example #11
0
  public void zoomToLocation(Location location, Float zoom, boolean calloutOffset) {
    if (mGoogleMap == null) return;
    // float density = getResources().getDisplayMetrics().density;
    // float targetZoom = zoom > 0 ? zoom : mGoogleMap.getCameraPosition().zoom;
    // double scale = 256 * Math.pow(2, (targetZoom - 1)) / Math.PI;
    // double latitude = location.getLatitude();
    // double longitude = location.getLongitude();

    mGoogleMap.moveCamera(
        CameraUpdateFactory.newLatLngZoom(mGoogleMap.getCameraPosition().target, zoom));
    LatLng dest;
    if (calloutOffset) {
      Point pt =
          mGoogleMap
              .getProjection()
              .toScreenLocation(new LatLng(location.getLatitude(), location.getLongitude()));
      pt.offset(0, getResources().getDimensionPixelSize(R.dimen.callout_offset));
      dest = mGoogleMap.getProjection().fromScreenLocation(pt);
      /*            double y = Math.log(Math.tan(Math.toRadians(latitude) / 2 + Math.PI / 4));
      y += getResources().getDimensionPixelSize(R.dimen.callout_offset) / scale;
      latitude = Math.toDegrees((Math.atan(Math.exp(y)) - Math.PI / 4) * 2);*/
    } else {
      dest = new LatLng(location.getLatitude(), location.getLongitude());
    }
    if (zoom > 0) {
      mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(dest, zoom));
    } else {
      mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(dest));
    }
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    mWidth = getMeasuredWidth();
    mStrokeWidth = (mStrokeWidth == 0 ? getMeasuredWidth() / 10 : mStrokeWidth);
    mStrokeWidth = mStrokeWidth > getMeasuredWidth() / 5 ? getMeasuredWidth() / 5 : mStrokeWidth;
    mStrokeWidth = (mStrokeWidth < 3) ? 3 : mStrokeWidth;
    mCenterPoint.x = mWidth / 2;
    mCenterPoint.y = getMeasuredHeight() / 2;

    mTickPoints[0].x = Math.round((float) getMeasuredWidth() / 30 * 7);
    mTickPoints[0].y = Math.round((float) getMeasuredHeight() / 30 * 14);
    mTickPoints[1].x = Math.round((float) getMeasuredWidth() / 30 * 13);
    mTickPoints[1].y = Math.round((float) getMeasuredHeight() / 30 * 20);
    mTickPoints[2].x = Math.round((float) getMeasuredWidth() / 30 * 22);
    mTickPoints[2].y = Math.round((float) getMeasuredHeight() / 30 * 10);

    mLeftLineDistance =
        (float)
            Math.sqrt(
                Math.pow(mTickPoints[1].x - mTickPoints[0].x, 2)
                    + Math.pow(mTickPoints[1].y - mTickPoints[0].y, 2));
    mRightLineDistance =
        (float)
            Math.sqrt(
                Math.pow(mTickPoints[2].x - mTickPoints[1].x, 2)
                    + Math.pow(mTickPoints[2].y - mTickPoints[1].y, 2));
    mTickPaint.setStrokeWidth(mStrokeWidth);
  }
 /**
  * Gets the real size of the display without subtracting any window decor or applying any
  * compatibility scale factors.
  *
  * <p>The size is adjusted based on the current rotation of the display.
  *
  * <p>The real size may be smaller than the physical size of the screen when the window manager is
  * emulating a smaller display (using adb shell am display-size).
  *
  * @param outSize Set to the real size of the display.
  */
 public void getRealSize(Point outSize) {
   synchronized (this) {
     updateDisplayInfoLocked();
     outSize.x = mDisplayInfo.logicalWidth;
     outSize.y = mDisplayInfo.logicalHeight;
   }
 }
  private Point getUpperLeftCornerOfCenterMapTileInScreen(
      final int[] centerMapTileCoords, final int tileSizePx, final Point reuse) {
    if (OpenStreetMapViewConstants.DEBUGMODE)
      Log.d("RMAPS-Me", "YandexTrafficOverlay getUpperLeftCornerOfCenterMapTileInScreen is Called");
    final Point out = (reuse != null) ? reuse : new Point();

    final int viewWidth = mMapView.getWidth();
    final int viewWidth_2 = viewWidth / 2;
    final int viewHeight = mMapView.getHeight();
    final int viewHeight_2 = viewHeight / 2;

    /*
     * Calculate the Latitude/Longitude on the left-upper ScreenCoords of the center MapTile. So in the end we can
     * determine which MapTiles we additionally need next to the centerMapTile.
     */
    final BoundingBoxE6 bb =
        Util.getBoundingBoxFromMapTile(
            centerMapTileCoords, mMapView.getZoomLevel(), mRendererInfo.PROJECTION);
    final float[] relativePositionInCenterMapTile =
        bb.getRelativePositionOfGeoPointInBoundingBoxWithLinearInterpolation(
            mMapView.getMapCenterLatitudeE6(), mMapView.getMapCenterLongitudeE6(), null);

    final int centerMapTileScreenLeft =
        viewWidth_2 - (int) (0.5f + (relativePositionInCenterMapTile[1] * tileSizePx));
    final int centerMapTileScreenTop =
        viewHeight_2 - (int) (0.5f + (relativePositionInCenterMapTile[0] * tileSizePx));

    out.set(centerMapTileScreenLeft, centerMapTileScreenTop);
    return out;
  }
Example #15
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int eventAction = event.getAction();
    switch (eventAction) {
      case MotionEvent.ACTION_DOWN:
        if (isTouchInsideRectangle(event.getX(), event.getY())) {
          affectedSide = getAffectedSide(event.getX(), event.getY());
        } else affectedSide = AffectedSide.NONE;

        previous.set((int) event.getX(), (int) event.getY());

        break;
      case MotionEvent.ACTION_MOVE:
        if (DEBUG) {
          Log.i(TAG, affectedSide.toString());
        }

        adjustRectangle(affectedSide, (int) event.getX(), (int) event.getY());

        invalidate();

        previous.set((int) event.getX(), (int) event.getY());

        break;
      case MotionEvent.ACTION_UP:
        affectedSide = AffectedSide.NONE;
        invalidate();
      default:
        previous = new Point();
        break;
    }

    return true;
  }
  /**
   * Use to update location/point state when calculating the line
   *
   * @param geoPoint
   */
  private void setScreenPoint(GeoPoint geoPoint) {
    mScreenPointBackup.x = this.mScreenPoint.x;
    mScreenPointBackup.y = this.mScreenPoint.x;

    this.mProjection.toPixels(geoPoint, this.mScreenPoint);
    mCalculatedPoints++;
  }
  @Override
  public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
    shadowSize.x = shadow.getMinimumWidth();
    shadowSize.y = shadow.getMinimumHeight();

    shadowTouchPoint.x = (int) (shadowSize.x / 2);
    shadowTouchPoint.y = (int) (shadowSize.y / 2);
  }
 /**
  * Gets the size of the display, in pixels.
  *
  * <p>Note that this value should <em>not</em> be used for computing layouts, since a device will
  * typically have screen decoration (such as a status bar) along the edges of the display that
  * reduce the amount of application space available from the size returned here. Layouts should
  * instead use the window size.
  *
  * <p>The size is adjusted based on the current rotation of the display.
  *
  * <p>The size returned by this method does not necessarily represent the actual raw size (native
  * resolution) of the display. The returned size may be adjusted to exclude certain system
  * decoration elements that are always visible. It may also be scaled to provide compatibility
  * with older applications that were originally designed for smaller displays.
  *
  * @param outSize A {@link Point} object to receive the size information.
  */
 public void getSize(Point outSize) {
   synchronized (this) {
     updateDisplayInfoLocked();
     mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
     outSize.x = mTempMetrics.widthPixels;
     outSize.y = mTempMetrics.heightPixels;
   }
 }
Example #19
0
  /**
   * 比较并改变最大尺寸
   *
   * @param point 保存最大尺寸的对象
   * @param width 宽
   * @param height 高
   */
  private void compareDimension(Point point, int width, int height) {
    if (point.x < width) {
      point.x = width;
    }

    if (point.y < height) {
      point.y = height;
    }
  }
Example #20
0
 /*
  * (non-Javadoc)
  *
  * @see
  * android.view.View.DragShadowBuilder#onProvideShadowMetrics(android
  * .graphics.Point, android.graphics.Point)
  */
 @SuppressLint("NewApi")
 @Override
 public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
   shadowSize.x = this.shadowSize;
   shadowSize.y = this.shadowSize;
   shadowTouchPoint.x = this.shadowSize / 2;
   shadowTouchPoint.y = this.shadowSize;
   super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
 }
Example #21
0
 /** Essentially reset the AI */
 public void forget() {
   hasHit = false;
   dirKnown = false;
   focusPoint.x = -1;
   focusPoint.y = -1;
   surroundingSpots.clear();
   xInterval = 0;
   yInterval = 0;
 }
  void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    //    theCamera.setDisplayOrientation(90);//add 这句代码作用是旋转镜头90度,使相机预览方向正确显示

    if (parameters == null) {
      Log.w(
          TAG,
          "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    CameraConfigurationUtils.setFocus(parameters, true, true, safeMode);

    if (!safeMode) {
      CameraConfigurationUtils.setBarcodeSceneMode(parameters);
      CameraConfigurationUtils.setVideoStabilization(parameters);
      CameraConfigurationUtils.setFocusArea(parameters);
      CameraConfigurationUtils.setMetering(parameters);
    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null
        && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
      Log.w(
          TAG,
          "Camera said it supported preview size "
              + bestPreviewSize.x
              + 'x'
              + bestPreviewSize.y
              + ", but after setting it, preview size is "
              + afterSize.width
              + 'x'
              + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
 /**
  * Return the range of display sizes an application can expect to encounter under normal
  * operation, as long as there is no physical change in screen size. This is basically the sizes
  * you will see as the orientation changes, taking into account whatever screen decoration there
  * is in each rotation. For example, the status bar is always at the top of the screen, so it will
  * reduce the height both in landscape and portrait, and the smallest height returned here will be
  * the smaller of the two.
  *
  * <p>This is intended for applications to get an idea of the range of sizes they will encounter
  * while going through device rotations, to provide a stable UI through rotation. The sizes here
  * take into account all standard system decorations that reduce the size actually available to
  * the application: the status bar, navigation bar, system bar, etc. It does <em>not</em> take
  * into account more transient elements like an IME soft keyboard.
  *
  * @param outSmallestSize Filled in with the smallest width and height that the application will
  *     encounter, in pixels (not dp units). The x (width) dimension here directly corresponds to
  *     {@link android.content.res.Configuration#smallestScreenWidthDp
  *     Configuration.smallestScreenWidthDp}, except the value here is in raw screen pixels rather
  *     than dp units. Your application may of course still get smaller space yet if, for example,
  *     a soft keyboard is being displayed.
  * @param outLargestSize Filled in with the largest width and height that the application will
  *     encounter, in pixels (not dp units). Your application may of course still get larger space
  *     than this if, for example, screen decorations like the status bar are being hidden.
  */
 public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
   synchronized (this) {
     updateDisplayInfoLocked();
     outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
     outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
     outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
     outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
   }
 }
Example #24
0
 /**
  * Animated equivalent to {@link MapController#scrollBy(int, int)}. Scroll by a given amount using
  * the default animation, in pixels.
  *
  * <p><strong>Limitations</strong>: This method internally uses {@link
  * MapController#animateTo(com.google.android.maps.GeoPoint)} which doesn't animate anything if
  * the point is really far (in pixels) from the current point. In this case, nothing will be
  * animated at all.
  *
  * @param mapView The {@link MapView} to scroll
  * @param dx The horizontal scroll amount in pixels.
  * @param dy The vertical scroll amount in pixels.
  */
 public static void smoothScrollBy(MapView mapView, int dx, int dy) {
   final Projection projection = mapView.getProjection();
   final Point tmpPoint = TEMP_POINT;
   projection.toPixels(mapView.getMapCenter(), tmpPoint);
   tmpPoint.offset(dx, dy);
   IGeoPoint geoPoint = projection.fromPixels(tmpPoint.x, tmpPoint.y);
   //        mapView.getController().animateTo(geoPoint);
   mapView.getController().setCenter(geoPoint);
 }
 @Override
 public Point toPixels(GeoPoint in, Point out) {
   double[] coords = new double[] {in.getLatitudeE6() / 1E6, in.getLongitudeE6() / 1E6};
   int[] pixels = TileFactory.LatLngToPixel(coords, mView.getZoomLevel());
   Point center = mView.getController().getCenter();
   out.x = pixels[0] - center.x + mView.getWidth() / 2;
   out.y = pixels[1] - center.y + mView.getHeight() / 2;
   return out;
 }
Example #26
0
  @Override
  protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
    if (shadow) {
      return;
    }
    MapView.Projection p = mapView.getProjection();

    int idx = 0;
    int geoTrackSize = geoTracks.size();
    boolean isFirstDraw = false;
    for (GeoTrack geoTrack : geoTracks) {
      idx++;
      // Log.d(TAG, "User selected new date range: MIN=" + (geoTrack.time
      // >= seletedRangeBeginTimeInMs) + "ms, MAX=" + (geoTrack.time <=
      // seletedRangeEndTimeInMs)+ ", geoTrack.time="+geoTrack.time);

      if (!seletedRangeActivated
          || (geoTrack.time >= seletedRangeBeginTimeInMs
              && geoTrack.time <= seletedRangeEndTimeInMs)) {
        GeoPoint geoPoint = geoTrack.asGeoPoint();
        p.toMapPixels(geoPoint, myScreenCoords);
        // Line Path
        boolean isLast = geoTrackSize == idx;
        if (isFirstDraw) {
          canvas.drawLine(
              lastScreenCoords.x, lastScreenCoords.y, myScreenCoords.x, myScreenCoords.y, mPaint);
        }
        // Point
        canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, 4, mGeoPointPaint);
        if (isLast) {
          canvas.drawCircle(
              myScreenCoords.x, myScreenCoords.y, 8, mGeoPointAccuracyCirclePaintBorder);
          canvas.drawCircle(
              myScreenCoords.x, myScreenCoords.y, 12, mGeoPointAccuracyCirclePaintBorder);
        }
        // End Loop
        lastScreenCoords.x = myScreenCoords.x;
        lastScreenCoords.y = myScreenCoords.y;
        isFirstDraw = true;
      }
    }

    // Draw Selected
    if (selectedGeoTrack != null) {
      // Select Point
      GeoTrack lastFix = selectedGeoTrack;
      GeoPoint geoPoint = lastFix.asGeoPoint();
      p.toMapPixels(geoPoint, myScreenCoords);
      // Compute Radius Accuracy
      final float groundResolutionInM =
          lastFix.computeGroundResolutionInMForZoomLevel(mapView.getZoomLevel());
      final float radius = ((float) lastFix.getAccuracy()) / groundResolutionInM;
      canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, radius, mGeoPointAccuracyCirclePaint);
      canvas.drawCircle(
          myScreenCoords.x, myScreenCoords.y, radius, mGeoPointAccuracyCirclePaintBorder);
    }
  }
Example #27
0
 public static Point getDisplaySize(Activity activity) {
   Point point = new Point();
   Display display = activity.getWindowManager().getDefaultDisplay();
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
     display.getRealSize(point);
   } else {
     point.set(display.getWidth(), display.getHeight());
   }
   return point;
 }
Example #28
0
 public void create(
     Scene scene, int left, int top, int positionx, int positionY, TiledTextureRegion region) {
   position.x = positionx;
   position.y = positionY;
   int with = region.getWidth() / 2;
   int height = region.getHeight();
   backgroud =
       new AnimatedSprite(left + positionx * with, top + positionY * height, region.deepCopy());
   scene.attachChild(backgroud);
 }
Example #29
0
 @Override
 public void onProvideShadowMetrics(Point size, Point touch) {
   int width;
   int height;
   width = getView().getWidth() / 2;
   height = getView().getHeight() / 2;
   shadow.setBounds(0, 0, width, height);
   size.set(width, height);
   touch.set(width / 2, height / 2);
 }
  @SuppressWarnings("unused")
  private Point getMarkerStartPoint(Point point) {
    Point pt = new Point();
    // In draw() we used boundCenterBottom(marker); so use this to find start point
    int x = point.x - BaiduItemizedOverlay.MARKER_WIDTH / 2; // this.marker.getIntrinsicWidth()/2;
    int y = point.y - BaiduItemizedOverlay.MARKER_HEIGHT; // this.marker.getIntrinsicHeight();
    pt.set(x, y);

    return pt;
  }