aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/WaypointPopupFragment.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-04-20 21:38:19 +0200
committerArne Schwabe <arne@rfc2549.org>2014-05-17 13:08:14 +0200
commitbe26c1845210a1c8824677ed6e2d093073ea5c84 (patch)
tree81d02773f4fd9edc5d05b44c770be89994a9c207 /main/src/cgeo/geocaching/WaypointPopupFragment.java
parent496878826d638367c129b02e66f992202e0d36c9 (diff)
downloadcgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.zip
cgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.tar.gz
cgeo-be26c1845210a1c8824677ed6e2d093073ea5c84.tar.bz2
Implement ActionBar using AppCompat in cgeo
This a first version of an ActionBar implementation with following properties: - The application should be usuable (there still might be bugs left from the conversation to Action) - Provides a more modern feeling on all devices - gets rid of the "dots of shame" on Android 3.0+ devices - The Maps classes MUST inherit from Activity instead of ActionBarActivity. There these classes use the old ActionBar on Android 2.3 devices and the real ActionBar on 3.0+ - This can be fixed when cgeo is ported to Google Maps API v2.0 API which usesFragment - The Dialog classes (CachePopup and WaypointPopup) have been converted to DialogFragments - The AppCombat themes provide no Theme.Dialog theme - this will later ease using these Fragment in other Activities - Use an almost empty activity which just shows the DialogFragment - Use the 'old' ActionBar but which overflow menu button to fit into Holo Design Style - Using a real ActionBar for Dialogs is not really support by Android and trying to force the frame into showing an Actionbar on a dialog leeds to strange bugs/effects - Most of the icon are still the Android 2.3 Menu Icon. These need to be replaced with Holo Style Icons - for most menu icon the ifRoom and/or withText attributes should be reviewed and set - The ActionBar of the main Activity is transparent. This is more or less by accident but looks good - Review Up Action of activities. Is going back to Main Activity always the semantically right thing to do? - Shortpress/Longpress on the Actionbars Compass Icon for primary/secondary Navigation clashes the normal ActionBar behaviour of long pressing to show the text of the action This commit contains many fixes and suggestions from rsudev
Diffstat (limited to 'main/src/cgeo/geocaching/WaypointPopupFragment.java')
-rw-r--r--main/src/cgeo/geocaching/WaypointPopupFragment.java147
1 files changed, 147 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/WaypointPopupFragment.java b/main/src/cgeo/geocaching/WaypointPopupFragment.java
new file mode 100644
index 0000000..14daada
--- /dev/null
+++ b/main/src/cgeo/geocaching/WaypointPopupFragment.java
@@ -0,0 +1,147 @@
+package cgeo.geocaching;
+
+import butterknife.ButterKnife;
+import butterknife.InjectView;
+
+import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.Units;
+import cgeo.geocaching.sensors.IGeoData;
+import cgeo.geocaching.ui.CacheDetailsCreator;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class WaypointPopupFragment extends AbstractDialogFragment {
+ @InjectView(R.id.actionbar_title) protected TextView actionBarTitle;
+ @InjectView(R.id.waypoint_details_list) protected LinearLayout waypointDetailsLayout;
+ @InjectView(R.id.edit) protected Button buttonEdit;
+ @InjectView(R.id.details_list) protected LinearLayout cacheDetailsLayout;
+
+ private int waypointId = 0;
+ private Waypoint waypoint = null;
+ private TextView waypointDistance = null;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View v = inflater.inflate(R.layout.waypoint_popup, container, false);
+ initCustomActionBar(v);
+ ButterKnife.inject(this,v);
+
+ return v;
+ }
+
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ waypointId = getArguments().getInt(WAYPOINT_ARG);
+ }
+
+ @Override
+ public void onUpdateGeoData(IGeoData geo) {
+ if (geo.getCoords() != null && waypoint != null && waypoint.getCoords() != null) {
+ waypointDistance.setText(Units.getDistanceFromKilometers(geo.getCoords().distanceTo(waypoint.getCoords())));
+ waypointDistance.bringToFront();
+ }
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+
+ waypoint = DataStore.loadWaypoint(waypointId);
+ try {
+ if (StringUtils.isNotBlank(waypoint.getName())) {
+ setTitle(waypoint.getName());
+ } else {
+ setTitle(waypoint.getGeocode());
+ }
+
+
+ actionBarTitle.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);
+
+ //getSupportActionBar().setIcon(getResources().getDrawable(waypoint.getWaypointType().markerId));
+
+ details = new CacheDetailsCreator(getActivity(), waypointDetailsLayout);
+
+ //Waypoint geocode
+ details.add(R.string.cache_geocode, waypoint.getPrefix() + waypoint.getGeocode().substring(2));
+ details.addDistance(waypoint, waypointDistance);
+ waypointDistance = details.getValueView();
+ details.add(R.string.waypoint_note, waypoint.getNote());
+
+ buttonEdit.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ EditWaypointActivity.startActivityEditWaypoint(getActivity(), cache, waypoint.getId());
+ getActivity().finish();
+ }
+ });
+
+ details = new CacheDetailsCreator(getActivity(), cacheDetailsLayout);
+ details.add(R.string.cache_name, cache.getName());
+
+ addCacheDetails();
+
+ } catch (Exception e) {
+ Log.e("WaypointPopup.init", e);
+ }
+ }
+
+ @Override
+ public void navigateTo() {
+ NavigationAppFactory.startDefaultNavigationApplication(1, getActivity(), waypoint);
+ }
+
+ /**
+ * Tries to navigate to the {@link Geocache} of this activity.
+ */
+ @Override
+ public void startDefaultNavigation2() {
+ if (waypoint == null || waypoint.getCoords() == null) {
+ showToast(res.getString(R.string.cache_coordinates_no));
+ return;
+ }
+ NavigationAppFactory.startDefaultNavigationApplication(2, getActivity(), waypoint);
+ getActivity().finish();
+ }
+
+
+
+ @Override
+ public void showNavigationMenu() {
+ NavigationAppFactory.showNavigationMenu(getActivity(), null, waypoint, null);
+ }
+
+ @Override
+ protected Geopoint getCoordinates() {
+ if (waypoint == null) {
+ return null;
+ }
+ return waypoint.getCoords();
+ }
+
+ public static DialogFragment newInstance(String geocode, int waypointId) {
+
+ Bundle args = new Bundle();
+ args.putInt(WAYPOINT_ARG, waypointId);
+ args.putString(GEOCODE_ARG, geocode);
+
+ DialogFragment f = new WaypointPopupFragment();
+ f.setArguments(args);
+ f.setStyle(DialogFragment.STYLE_NO_TITLE,0);
+
+ return f;
+ }
+}