forked from upstream-mirrors/OpenTracks
Move the satellite mode menu option to MapFragment.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item
|
||||
android:icon="@drawable/menu_satellite_mode"
|
||||
android:id="@+id/map_satellite_mode"
|
||||
android:orderInCategory="6"/>
|
||||
</menu>
|
||||
@@ -18,21 +18,25 @@ limitations under the License.
|
||||
<item
|
||||
android:icon="@drawable/menu_stop_recording"
|
||||
android:id="@+id/track_detail_stop_recording"
|
||||
android:orderInCategory="1"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_stop_recording"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_insert_marker"
|
||||
android:id="@+id/track_detail_insert_marker"
|
||||
android:orderInCategory="2"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_insert_marker"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_play"
|
||||
android:id="@+id/track_detail_play"
|
||||
android:orderInCategory="3"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_play"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_share"
|
||||
android:id="@+id/track_detail_share"
|
||||
android:orderInCategory="4"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_share">
|
||||
<menu>
|
||||
@@ -51,15 +55,19 @@ limitations under the License.
|
||||
<item
|
||||
android:icon="@drawable/menu_markers"
|
||||
android:id="@+id/track_detail_markers"
|
||||
android:orderInCategory="5"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_markers"/>
|
||||
<!-- android:orderInCategory="6" is in map.xml -->
|
||||
<item
|
||||
android:icon="@drawable/menu_send_google"
|
||||
android:id="@+id/track_detail_send_google"
|
||||
android:orderInCategory="7"
|
||||
android:title="@string/menu_send_google"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_save"
|
||||
android:id="@+id/track_detail_save"
|
||||
android:orderInCategory="8"
|
||||
android:title="@string/menu_save">
|
||||
<menu>
|
||||
<item android:id="@+id/track_detail_save_gpx"/>
|
||||
@@ -71,25 +79,26 @@ limitations under the License.
|
||||
<item
|
||||
android:icon="@drawable/menu_edit"
|
||||
android:id="@+id/track_detail_edit"
|
||||
android:orderInCategory="9"
|
||||
android:title="@string/menu_edit"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_delete"
|
||||
android:id="@+id/track_detail_delete"
|
||||
android:orderInCategory="10"
|
||||
android:title="@string/menu_delete"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_satellite_mode"
|
||||
android:id="@+id/track_detail_satellite_mode"
|
||||
android:title="@string/menu_satellite_mode"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_sensor_state"
|
||||
android:id="@+id/track_detail_sensor_state"
|
||||
android:orderInCategory="11"
|
||||
android:title="@string/menu_sensor_state"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_settings"
|
||||
android:id="@+id/track_detail_settings"
|
||||
android:orderInCategory="12"
|
||||
android:title="@string/menu_settings"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_help"
|
||||
android:id="@+id/track_detail_help"
|
||||
android:orderInCategory="13"
|
||||
android:title="@string/menu_help"/>
|
||||
</menu>
|
||||
@@ -227,27 +227,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
String currentTabTag = tabHost.getCurrentTabTag();
|
||||
MenuItem satelliteMode = menu.findItem(R.id.track_detail_satellite_mode)
|
||||
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
|
||||
|
||||
if (satelliteMode.isVisible()) {
|
||||
MapFragment mapFragment = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
||||
/*
|
||||
* The current tag is mapFragment, thus safe to call its methods like
|
||||
* isSatelliteView.
|
||||
*/
|
||||
boolean isSatelliteMode = mapFragment != null ? mapFragment.isSatelliteView() : false;
|
||||
menu.findItem(R.id.track_detail_satellite_mode).setTitle(
|
||||
isSatelliteMode ? R.string.menu_map_mode : R.string.menu_satellite_mode);
|
||||
}
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHomeSelected() {
|
||||
Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
|
||||
@@ -256,7 +235,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
MapFragment mapFragment;
|
||||
Intent intent;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.track_detail_stop_recording:
|
||||
@@ -333,13 +311,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
DeleteOneTrackDialogFragment.newInstance(trackId).show(
|
||||
getSupportFragmentManager(), DeleteOneTrackDialogFragment.DELETE_ONE_TRACK_DIALOG_TAG);
|
||||
return true;
|
||||
case R.id.track_detail_satellite_mode:
|
||||
mapFragment = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
||||
if (mapFragment != null) {
|
||||
mapFragment.setSatelliteView(!mapFragment.isSatelliteView());
|
||||
}
|
||||
return true;
|
||||
case R.id.track_detail_sensor_state:
|
||||
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
@@ -40,6 +40,9 @@ import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -90,6 +93,12 @@ public class MapFragment extends Fragment
|
||||
private ImageButton myLocationImageButton;
|
||||
private TextView messageTextView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -156,6 +165,30 @@ public class MapFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflator) {
|
||||
menuInflator.inflate(R.menu.map, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
int titleId = R.string.menu_satellite_mode;
|
||||
if (mapView != null) {
|
||||
titleId = mapView.isSatellite() ? R.string.menu_map_mode : R.string.menu_satellite_mode;
|
||||
}
|
||||
menu.findItem(R.id.map_satellite_mode).setTitle(titleId);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
if (mapView != null && menuItem.getItemId() == R.id.map_satellite_mode) {
|
||||
mapView.setSatellite(!mapView.isSatellite());
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows my location.
|
||||
*/
|
||||
@@ -209,22 +242,6 @@ public class MapFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if in satellite mode.
|
||||
*/
|
||||
public boolean isSatelliteView() {
|
||||
return mapView.isSatellite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the satellite mode
|
||||
*
|
||||
* @param enabled true for satellite mode, false for map mode
|
||||
*/
|
||||
public void setSatelliteView(boolean enabled) {
|
||||
mapView.setSatellite(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (keepMyLocationVisible && event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
|
||||
Reference in New Issue
Block a user