aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/WaypointPopup.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/WaypointPopup.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/WaypointPopup.java')
-rw-r--r--main/src/cgeo/geocaching/WaypointPopup.java136
1 files changed, 31 insertions, 105 deletions
diff --git a/main/src/cgeo/geocaching/WaypointPopup.java b/main/src/cgeo/geocaching/WaypointPopup.java
index 916ad4c..f1ffc1d 100644
--- a/main/src/cgeo/geocaching/WaypointPopup.java
+++ b/main/src/cgeo/geocaching/WaypointPopup.java
@@ -1,115 +1,35 @@
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.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.TextView;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.view.Window;
-public class WaypointPopup extends AbstractPopupActivity {
- @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;
+import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.activity.ActivityMixin;
+public class WaypointPopup extends AbstractActivity {
private int waypointId = 0;
- private Waypoint waypoint = null;
- private TextView waypointDistance = null;
-
- public WaypointPopup() {
- super(R.layout.waypoint_popup);
- }
+ private String geocode;
@Override
- public void onCreate(final Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ButterKnife.inject(this);
- // get parameters
- final Bundle extras = getIntent().getExtras();
- if (extras != null) {
- waypointId = extras.getInt(Intents.EXTRA_WAYPOINT_ID);
- }
- }
-
- @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);
-
- details = new CacheDetailsCreator(this, waypointDetailsLayout);
+ supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
- //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());
+ this.setTheme(ActivityMixin.getDialogTheme());
- buttonEdit.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- EditWaypointActivity.startActivityEditWaypoint(WaypointPopup.this, cache, waypoint.getId());
- finish();
- }
- });
-
- details = new CacheDetailsCreator(this, cacheDetailsLayout);
- details.add(R.string.cache_name, cache.getName());
-
- addCacheDetails();
-
- } catch (Exception e) {
- Log.e("WaypointPopup.init", e);
+ final Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ waypointId = extras.getInt(Intents.EXTRA_WAYPOINT_ID);
+ geocode = extras.getString(Intents.EXTRA_GEOCODE);
}
- }
-
- @Override
- public void navigateTo() {
- NavigationAppFactory.startDefaultNavigationApplication(1, this, waypoint);
- }
+ showDialog();
- /**
- * Tries to navigate to the {@link Geocache} of this activity.
- */
- @Override
- protected void startDefaultNavigation2() {
- if (waypoint == null || waypoint.getCoords() == null) {
- showToast(res.getString(R.string.cache_coordinates_no));
- return;
- }
- NavigationAppFactory.startDefaultNavigationApplication(2, this, waypoint);
- finish();
}
public static void startActivity(final Context context, final int waypointId, final String geocode) {
@@ -119,16 +39,22 @@ public class WaypointPopup extends AbstractPopupActivity {
context.startActivity(popupIntent);
}
- @Override
- public void showNavigationMenu() {
- NavigationAppFactory.showNavigationMenu(this, null, waypoint, null);
- }
- @Override
- protected Geopoint getCoordinates() {
- if (waypoint == null) {
- return null;
+ void showDialog() {
+ // DialogFragment.show() will take care of adding the fragment
+ // in a transaction. We also want to remove any currently showing
+ // dialog, so make our own transaction and take care of that here.
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
}
- return waypoint.getCoords();
+ ft.addToBackStack(null);
+
+ // Create and show the dialog.
+ DialogFragment newFragment = WaypointPopupFragment.newInstance(geocode, waypointId);
+ newFragment.show(ft, "dialog");
}
+
+
}