private boolean commonOnTap(GeoPoint tappedGeoPoint) { List<Uri> tappedUri = new Vector<Uri>(); Point tappedPoint = new Point(); mProjection.toPixels(tappedGeoPoint, tappedPoint); for (MediaVO media : mMediaPath) { if (media.x < tappedPoint.x && tappedPoint.x < media.x + media.w && media.y < tappedPoint.y && tappedPoint.y < media.y + media.h) { // Log.d( TAG, String.format( "Tapped at a (x,y) (%d,%d)", tappedPoint.x, tappedPoint.y ) ); tappedUri.add(media.uri); } } if (tappedUri.size() > 0) { return handleMediaTapList(tappedUri); } else { if (mTrackColoringMethod == DRAW_DOTS) { DotVO tapped = null; synchronized (mDotPath) // Switch the fresh path with the old Path object { int w = 25; for (DotVO dot : mDotPath) { // Log.d( TAG, "Compare ("+dot.x+","+dot.y+") with tap // ("+tappedPoint.x+","+tappedPoint.y+")" ); if (dot.x - w < tappedPoint.x && tappedPoint.x < dot.x + w && dot.y - w < tappedPoint.y && tappedPoint.y < dot.y + w) { if (tapped == null) { tapped = dot; } else { tapped = dot.distanceTo(tappedPoint) < tapped.distanceTo(tappedPoint) ? dot : tapped; } } } } if (tapped != null) { DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(mLoggerMap.getApplicationContext()); String timetxt = timeFormat.format(new Date(tapped.time)); UnitsI18n units = new UnitsI18n(mLoggerMap, null); double speed = units.conversionFromMetersPerSecond(tapped.speed); String speedtxt = String.format("%.1f %s", speed, units.getSpeedUnit()); String text = mLoggerMap.getString(R.string.time_and_speed, timetxt, speedtxt); Toast toast = Toast.makeText(mLoggerMap, text, Toast.LENGTH_SHORT); toast.show(); } } return false; } }
/** * @param canvas * @param mapView * @param shadow * @see SegmentOverlay#draw(Canvas, MapView, boolean) */ private void calculateDots() { mPathCalculation.reset(); mDotPathCalculation.clear(); mCalculatedPoints = 0; if (mWaypointsCursor == null) { mWaypointsCursor = this.mResolver.query( this.mWaypointsUri, new String[] { Waypoints.LATITUDE, Waypoints.LONGITUDE, Waypoints.SPEED, Waypoints.TIME, Waypoints.ACCURACY }, null, null, null); } if (mRequeryFlag) { mWaypointsCursor.requery(); mRequeryFlag = false; } if (mProjection != null && mWaypointsCursor.moveToFirst()) { GeoPoint geoPoint; mStartPoint = extractGeoPoint(); mPrevGeoPoint = mStartPoint; do { geoPoint = extractGeoPoint(); setScreenPoint(geoPoint); float distance = (float) distanceInPoints(this.mPrevDrawnScreenPoint, this.mScreenPoint); if (distance > MINIMUM_PX_DISTANCE) { DotVO dotVO = new DotVO(); dotVO.x = this.mScreenPoint.x; dotVO.y = this.mScreenPoint.y; dotVO.speed = mWaypointsCursor.getLong(2); dotVO.time = mWaypointsCursor.getLong(3); dotVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4)); mDotPathCalculation.add(dotVO); this.mPrevDrawnScreenPoint.x = this.mScreenPoint.x; this.mPrevDrawnScreenPoint.y = this.mScreenPoint.y; } } while (moveToNextWayPoint()); this.mEndPoint = extractGeoPoint(); DotVO pointVO = new DotVO(); pointVO.x = this.mScreenPoint.x; pointVO.y = this.mScreenPoint.y; pointVO.speed = mWaypointsCursor.getLong(2); pointVO.time = mWaypointsCursor.getLong(3); pointVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4)); mDotPathCalculation.add(pointVO); } }