private TextInfoControl createAltitudeControl() { final TextInfoControl altitudeControl = new TextInfoControl(map, 0, paintText, paintSubText) { private int cachedAlt = 0; @Override public boolean updateInfo() { // draw speed if (showAltitude && map.getLastKnownLocation() != null && map.getLastKnownLocation().hasAltitude()) { if (cachedAlt != (int) map.getLastKnownLocation().getAltitude()) { cachedAlt = (int) map.getLastKnownLocation().getAltitude(); String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map); int ls = ds.lastIndexOf(' '); if (ls == -1) { setText(ds, null); } else { setText(ds.substring(0, ls), ds.substring(ls + 1)); } return true; } } else if (cachedAlt != 0) { cachedAlt = 0; setText(null, null); return true; } return false; } }; altitudeControl.setText(null, null); altitudeControl.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_altitude)); return altitudeControl; }
private TextInfoControl createSpeedControl() { final TextInfoControl speedControl = new TextInfoControl(map, 3, paintText, paintSubText) { private float cachedSpeed = 0; @Override public boolean updateInfo() { // draw speed if (map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()) { // .3 mps == 1.08 kph float minDelta = .3f; // Update more often at walk/run speeds, since we give higher resolution // and use .02 instead of .03 to account for rounding effects. if (cachedSpeed < 6) minDelta = .015f; if (Math.abs(map.getLastKnownLocation().getSpeed() - cachedSpeed) > minDelta) { cachedSpeed = map.getLastKnownLocation().getSpeed(); String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map); int ls = ds.lastIndexOf(' '); if (ls == -1) { setText(ds, null); } else { setText(ds.substring(0, ls), ds.substring(ls + 1)); } return true; } } else if (cachedSpeed != 0) { cachedSpeed = 0; setText(null, null); return true; } return false; } }; speedControl.setImageDrawable(view.getResources().getDrawable(R.drawable.info_speed)); speedControl.setText(null, null); return speedControl; }
private TextInfoControl createDistanceControl() { TextInfoControl distanceControl = new TextInfoControl(map, 0, paintText, paintSubText) { private float[] calculations = new float[1]; private int cachedMeters = 0; @Override public boolean updateInfo() { if (map.getPointToNavigate() != null) { int d = 0; if (map.getRoutingHelper().isRouterEnabled()) { d = map.getRoutingHelper().getLeftDistance(); } if (d == 0) { Location.distanceBetween( view.getLatitude(), view.getLongitude(), map.getPointToNavigate().getLatitude(), map.getPointToNavigate().getLongitude(), calculations); d = (int) calculations[0]; } if (distChanged(cachedMeters, d)) { cachedMeters = d; if (cachedMeters <= 20) { cachedMeters = 0; setText(null, null); } else { String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, map); int ls = ds.lastIndexOf(' '); if (ls == -1) { setText(ds, null); } else { setText(ds.substring(0, ls), ds.substring(ls + 1)); } } return true; } } else if (cachedMeters != 0) { cachedMeters = 0; setText(null, null); return true; } return false; } }; distanceControl.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); LatLon pointToNavigate = view.getSettings().getPointToNavigate(); if (pointToNavigate != null) { float fZoom = view.getFloatZoom() < 15 ? 15 : view.getFloatZoom(); thread.startMoving( pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); } } }); distanceControl.setText(null, null); distanceControl.setImageDrawable(view.getResources().getDrawable(R.drawable.info_target)); return distanceControl; }
private TextInfoControl createTimeControl() { final Drawable time = view.getResources().getDrawable(R.drawable.info_time); final Drawable timeToGo = view.getResources().getDrawable(R.drawable.info_time_to_go); showArrivalTime = view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.get(); final TextInfoControl leftTimeControl = new TextInfoControl(map, 0, paintText, paintSubText) { private long cachedLeftTime = 0; @Override public boolean updateInfo() { int time = 0; if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) { boolean followingMode = routeLayer.getHelper().isFollowingMode(); time = routeLayer.getHelper().getLeftTime(); if (time != 0) { if (followingMode && showArrivalTime) { long toFindTime = time * 1000 + System.currentTimeMillis(); if (Math.abs(toFindTime - cachedLeftTime) > 30000) { cachedLeftTime = toFindTime; if (DateFormat.is24HourFormat(map)) { setText( DateFormat.format("k:mm", toFindTime).toString(), null); // $NON-NLS-1$ } else { setText( DateFormat.format("h:mm", toFindTime).toString(), DateFormat.format("aa", toFindTime).toString()); // $NON-NLS-1$ } return true; } } else { if (Math.abs(time - cachedLeftTime) > 30) { cachedLeftTime = time; int hours = time / (60 * 60); int minutes = (time / 60) % 60; setText(String.format("%d:%02d", hours, minutes), null); // $NON-NLS-1$ return true; } } } } if (time == 0 && cachedLeftTime != 0) { cachedLeftTime = 0; setText(null, null); return true; } return false; }; }; leftTimeControl.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { showArrivalTime = !showArrivalTime; leftTimeControl.setImageDrawable(showArrivalTime ? time : timeToGo); view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime); view.refreshMap(); } }); leftTimeControl.setText(null, null); leftTimeControl.setImageDrawable(showArrivalTime ? time : timeToGo); return leftTimeControl; }