Move the satellite mode menu option to MapFragment.

This commit is contained in:
Jimmy Shih
2012-05-08 16:44:07 -07:00
parent 68487329d1
commit 4686194541
4 changed files with 68 additions and 49 deletions
@@ -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) {