forked from upstream-mirrors/OpenTracks
Addressed review suggestions.
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
android:showAsAction="ifRoom"
|
||||
android:visible="false"/>
|
||||
|
||||
<item android:id="@+id/menu_layers"
|
||||
<item android:id="@+id/menu_satellite_mode"
|
||||
android:icon="@android:drawable/ic_menu_mapmode"
|
||||
android:title="@string/menu_map_view_satellite_mode"
|
||||
android:showAsAction="ifRoom"
|
||||
|
||||
@@ -85,6 +85,12 @@ public class MapActivity extends com.google.android.maps.MapActivity
|
||||
*/
|
||||
private boolean keepMyLocationVisible;
|
||||
|
||||
/**
|
||||
* True if we've already zoomed into the current location.
|
||||
* Only relevant when {@link #keepMyLocationVisible} is true.
|
||||
*/
|
||||
private boolean myLocationWasZoomedIn;
|
||||
|
||||
/**
|
||||
* The current pointer location.
|
||||
* This is kept to quickly center on it when the user requests.
|
||||
@@ -260,9 +266,7 @@ public class MapActivity extends com.google.android.maps.MapActivity
|
||||
public void showMyLocation() {
|
||||
dataHub.forceUpdateLocation();
|
||||
keepMyLocationVisible = true;
|
||||
if (mapView.getZoomLevel() < 18) {
|
||||
mapView.getController().setZoom(18);
|
||||
}
|
||||
myLocationWasZoomedIn = false;
|
||||
if (currentLocation != null) {
|
||||
showCurrentLocation();
|
||||
}
|
||||
@@ -284,6 +288,11 @@ public class MapActivity extends com.google.android.maps.MapActivity
|
||||
GeoPoint geoPoint = LocationUtils.getGeoPoint(currentLocation);
|
||||
MapController controller = mapView.getController();
|
||||
controller.animateTo(geoPoint);
|
||||
if (!myLocationWasZoomedIn && mapView.getZoomLevel() < 18) {
|
||||
// Only zoom in the first time we show the location.
|
||||
myLocationWasZoomedIn = true;
|
||||
controller.setZoom(18);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,27 @@ class MenuManager {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the menu with its initial options.
|
||||
*
|
||||
* @param menu the menu to fill
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
activity.getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the menu for display.
|
||||
*
|
||||
* @param menu the menu to update for display
|
||||
* @param hasRecorded whether any track has been recorded
|
||||
* @param isRecording whether we're recording a track now
|
||||
* @param hasSelectedTrack whether there's a track currently selected for display
|
||||
* @param isSatelliteMode whether the map is currently in satellite mode
|
||||
* @param currentTabTag the tag for the currently-displayed tab
|
||||
*/
|
||||
public void onPrepareOptionsMenu(Menu menu, boolean hasRecorded,
|
||||
boolean isRecording, boolean hasSelectedTrack,
|
||||
boolean isSatelliteMode, String currentTabTag) {
|
||||
@@ -61,13 +77,19 @@ class MenuManager {
|
||||
boolean isMapTab = MAP_TAB_TAG.equals(currentTabTag);
|
||||
menu.findItem(R.id.menu_my_location)
|
||||
.setVisible(isMapTab);
|
||||
menu.findItem(R.id.menu_layers)
|
||||
menu.findItem(R.id.menu_satellite_mode)
|
||||
.setVisible(isMapTab)
|
||||
.setTitle(isSatelliteMode
|
||||
? R.string.menu_map_view_map_mode
|
||||
: R.string.menu_map_view_satellite_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an option from the menu is selected.
|
||||
*
|
||||
* @param item the selected item
|
||||
* @return true if the action was handled, false otherwise
|
||||
*/
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_record_track: {
|
||||
@@ -109,7 +131,7 @@ class MenuManager {
|
||||
activity.showMyLocation();
|
||||
return true;
|
||||
}
|
||||
case R.id.menu_layers: {
|
||||
case R.id.menu_satellite_mode: {
|
||||
activity.toggleSatelliteView();
|
||||
return true;
|
||||
}
|
||||
@@ -118,6 +140,9 @@ class MenuManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an activity with the given class.
|
||||
*/
|
||||
private boolean startActivity(Class<? extends Activity> activityClass) {
|
||||
activity.startActivity(new Intent(activity, activityClass));
|
||||
return true;
|
||||
|
||||
@@ -494,6 +494,9 @@ public class MyTracks extends TabActivity implements OnTouchListener {
|
||||
return dataHub.getSelectedTrackId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the chart tab to show its settings.
|
||||
*/
|
||||
public void showChartSettings() {
|
||||
ChartActivity chart = getChartTab();
|
||||
if (chart != null) {
|
||||
@@ -501,13 +504,19 @@ public class MyTracks extends TabActivity implements OnTouchListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the map tab to show the map in satellite mode.
|
||||
*/
|
||||
public void toggleSatelliteView() {
|
||||
MapActivity mapTab = getMapTab();
|
||||
if (mapTab != null) {
|
||||
mapTab.setSatelliteView(!getMapTab().isSatelliteView());
|
||||
mapTab.setSatelliteView(!mapTab.isSatelliteView());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the map tab to jump to the current location.
|
||||
*/
|
||||
public void showMyLocation() {
|
||||
MapActivity mapTab = getMapTab();
|
||||
if (mapTab != null) {
|
||||
@@ -515,10 +524,16 @@ public class MyTracks extends TabActivity implements OnTouchListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map tab instance if available, or null otherwise.
|
||||
*/
|
||||
private MapActivity getMapTab() {
|
||||
return (MapActivity) getLocalActivityManager().getActivity(MAP_TAB_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the chart tab instance if available, or null otherwise.
|
||||
*/
|
||||
private ChartActivity getChartTab() {
|
||||
return (ChartActivity) getLocalActivityManager().getActivity(CHART_TAB_TAG);
|
||||
}
|
||||
|
||||
@@ -83,16 +83,6 @@ public interface ApiLevelAdapter {
|
||||
*/
|
||||
void applyPreferenceChanges(SharedPreferences.Editor editor);
|
||||
|
||||
/**
|
||||
* Shows the action bar, if the current system supports it.
|
||||
* If it's not supported, the title bar will be kept hidden.
|
||||
*
|
||||
* Due to changes in API level 11.
|
||||
*
|
||||
* @param activity the current activity
|
||||
*/
|
||||
void showActionBar(Activity activity);
|
||||
|
||||
/**
|
||||
* Enables strict mode where supported, only if this is a development build.
|
||||
*
|
||||
@@ -121,4 +111,14 @@ public interface ApiLevelAdapter {
|
||||
* Due to changes in API level 9.
|
||||
*/
|
||||
HttpTransport getHttpTransport();
|
||||
|
||||
/**
|
||||
* Shows the action bar, if the current system supports it.
|
||||
* If it's not supported, the title bar will be kept hidden.
|
||||
*
|
||||
* Due to changes in API level 11.
|
||||
*
|
||||
* @param activity the current activity
|
||||
*/
|
||||
void showActionBar(Activity activity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user