diff options
Diffstat (limited to 'main/src/cgeo/geocaching/maps')
4 files changed, 97 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/maps/AbstractMap.java b/main/src/cgeo/geocaching/maps/AbstractMap.java index d341823..aff9c75 100644 --- a/main/src/cgeo/geocaching/maps/AbstractMap.java +++ b/main/src/cgeo/geocaching/maps/AbstractMap.java @@ -5,10 +5,12 @@ import cgeo.geocaching.maps.interfaces.MapActivityImpl; import android.app.Activity; import android.content.res.Resources; +import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.Window; /** * Base class for the map activity. Delegates base class calls to the @@ -31,7 +33,11 @@ public abstract class AbstractMap { } public void onCreate(Bundle savedInstanceState) { + mapActivity.superOnCreate(savedInstanceState); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { + mapActivity.getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + } } public void onResume() { diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index b5d0b0e..004081f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -50,6 +50,7 @@ import rx.schedulers.Schedulers; import rx.subscriptions.CompositeSubscription; import rx.subscriptions.Subscriptions; +import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -60,6 +61,7 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.location.Location; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -69,9 +71,11 @@ import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.ViewGroup.LayoutParams; +import android.widget.CheckBox; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ImageView.ScaleType; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; @@ -183,7 +187,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private int detailProgress = 0; private long detailProgressTime = 0L; // views - private ImageSwitcher myLocSwitch = null; + private CheckBox myLocSwitch = null; /** Controls the map behaviour */ private MapMode mapMode = null; @@ -239,7 +243,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto title.append('[').append(lastSearchResult.getUrl()).append(']'); } - ActivityMixin.setTitle(activity, title.toString()); + setTitle(title.toString()); break; case INVALIDATE_MAP: mapView.repaintRequired(null); @@ -250,6 +254,24 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } }; + + private void setTitle(String title) { + /* Compatibily for the old Action Bar, only used by the maps activity at the moment */ + final TextView titleview = (TextView) activity.findViewById(R.id.actionbar_title); + if (titleview != null) { + titleview.setText(title); + + } + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)) { + setTitleHoneyComb(title); + } + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + private void setTitleHoneyComb(String title) { + activity.getActionBar().setTitle(title); + } + /** Updates the progress. */ final private Handler showProgressHandler = new Handler() { @@ -261,15 +283,32 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto if (what == HIDE_PROGRESS) { if (--counter == 0) { - ActivityMixin.showProgress(activity, false); + showProgress(false); } } else if (what == SHOW_PROGRESS) { - ActivityMixin.showProgress(activity, true); + showProgress(true); counter++; } } + + private void showProgress(boolean show) { + final ProgressBar progress = (ProgressBar) activity.findViewById(R.id.actionbar_progress); + if (progress != null) { + if (show) { + progress.setVisibility(View.VISIBLE); + } else { + progress.setVisibility(View.GONE); + + } + } + if (Build.VERSION.SDK_INT >= 11) { + activity.setProgressBarIndeterminateVisibility(show); + } + } }; + + final private class LoadDetailsHandler extends CancellableHandler { @Override @@ -360,6 +399,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -417,10 +457,16 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.keepScreenOn(activity, true); + // set layout - ActivityMixin.setTheme(activity); + //ActivityMixin.setTheme(activity); + // TODO: set a proper theme + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { + activity.setTheme(android.R.style.Theme_Holo); + activity.getActionBar().setDisplayHomeAsUpEnabled(true); + } activity.setContentView(mapProvider.getMapLayoutId()); - ActivityMixin.setTitle(activity, res.getString(R.string.map_map)); + setTitle(res.getString(R.string.map_map)); // initialize map mapView = (MapViewImpl) activity.findViewById(mapProvider.getMapViewId()); @@ -461,14 +507,11 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto centerMap(geocodeIntent, searchIntent, coordsIntent, mapStateIntent); } - // prepare my location button - myLocSwitch = (ImageSwitcher) activity.findViewById(R.id.my_position); - myLocSwitch.setFactory(this); - myLocSwitch.setInAnimation(activity, android.R.anim.fade_in); - myLocSwitch.setOutAnimation(activity, android.R.anim.fade_out); - myLocSwitch.setOnClickListener(new MyLocationListener()); - switchMyLocationButton(); + CheckBox locSwitch = (CheckBox) activity.findViewById(R.id.my_position); + if (locSwitch!=null) { + initMyLocationSwitchButton(locSwitch); + } prepareFilterBar(); if (!app.isLiveMapHintShownInThisSession() && !Settings.getHideLiveMapHint() && Settings.getLiveMapHintShowCount() <= 3) { @@ -476,6 +519,16 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } + private void initMyLocationSwitchButton(CheckBox locSwitch) { + myLocSwitch = locSwitch; + /* TODO: Switch back to ImageSwitcher for animations? + myLocSwitch.setFactory(this); + myLocSwitch.setInAnimation(activity, android.R.anim.fade_in); + myLocSwitch.setOutAnimation(activity, android.R.anim.fade_out); */ + myLocSwitch.setOnClickListener(new MyLocationListener()); + switchMyLocationButton(); + } + /** * Set the zoom of the map. The zoom is restricted to a certain minimum in case of live map. * @@ -531,6 +584,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto super.onPause(); } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public boolean onCreateOptionsMenu(Menu menu) { // menu inflation happens in Google/Mapsforge specific classes @@ -540,6 +594,19 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto final SubMenu subMenuStrategy = menu.findItem(R.id.submenu_strategy).getSubMenu(); subMenuStrategy.setHeaderTitle(res.getString(R.string.map_strategy_title)); + + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { + /* if we have an Actionbar find the my position toggle */ + MenuItem item = menu.findItem(R.id.menu_toggle_mypos); + myLocSwitch = new CheckBox(activity); + myLocSwitch.setButtonDrawable(R.drawable.ic_menu_myposition); + item.setActionView(myLocSwitch); + initMyLocationSwitchButton(myLocSwitch); + } else { + // Already on the fake Actionbar + menu.removeItem(R.id.menu_toggle_mypos); + } return true; } @@ -616,6 +683,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto public boolean onOptionsItemSelected(MenuItem item) { final int id = item.getItemId(); switch (id) { + case android.R.id.home: + ActivityMixin.navigateToMain(activity); + return true; case R.id.menu_trail_mode: Settings.setMapTrail(!Settings.isMapTrail()); mapView.repaintRequired(overlayPositionAndScale); @@ -1460,11 +1530,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto // switch My Location button image private void switchMyLocationButton() { + myLocSwitch.setChecked(followMyLocation); if (followMyLocation) { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_on); myLocationInMiddle(app.currentGeo()); - } else { - myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off); } } @@ -1493,7 +1561,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto // close activity and open homescreen @Override public void goHome(View view) { - ActivityMixin.goHome(activity); + ActivityMixin.navigateToMain(activity); } @Override diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapActivity.java b/main/src/cgeo/geocaching/maps/google/GoogleMapActivity.java index a98241f..8a1bad6 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleMapActivity.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleMapActivity.java @@ -1,5 +1,6 @@ package cgeo.geocaching.maps.google; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.activity.FilteredActivity; import cgeo.geocaching.maps.AbstractMap; import cgeo.geocaching.maps.CGeoMap; @@ -97,6 +98,11 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override + public void goHome(View view) { + ActivityMixin.navigateToMain(this); + } + + @Override public void superOnResume() { super.onResume(); } @@ -116,12 +122,6 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F return super.onPrepareOptionsMenu(menu); } - // close activity and open homescreen - @Override - public void goHome(View view) { - mapBase.goHome(view); - } - @Override public void showFilterMenu(View view) { // do nothing, the filter bar only shows the global filter diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java index e7deebd..08309f4 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java @@ -34,5 +34,4 @@ public interface MapActivityImpl { boolean superOnOptionsItemSelected(MenuItem item); public abstract void goHome(View view); - } |
