aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/WaypointPopup.java
blob: 1d18987568c0a206c6f6a32399dca1d1351c63d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cgeo.geocaching;

import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.geopoint.Geopoint;
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;

public class WaypointPopup extends AbstractPopupActivity {
    private int waypointId = 0;
    private Waypoint waypoint = null;

    public WaypointPopup() {
        super("c:geo-waypoint-info", R.layout.waypoint_popup);
    }

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // get parameters
        final Bundle extras = getIntent().getExtras();
        if (extras != null) {
            waypointId = extras.getInt(Intents.EXTRA_WAYPOINT_ID);
        }
    }

    @Override
    protected void init() {
        super.init();
        waypoint = cgData.loadWaypoint(waypointId);
        try {
            if (StringUtils.isNotBlank(waypoint.getName())) {
                setTitle(waypoint.getName());
            } else {
                setTitle(waypoint.getGeocode());
            }

            // actionbar icon
            ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(waypoint.getWaypointType().markerId), null, null, null);

            //Start filling waypoint details
            details = new CacheDetailsCreator(this, (LinearLayout) findViewById(R.id.waypoint_details_list));

            //Waypoint geocode
            details.add(R.string.cache_geocode, waypoint.getPrefix() + waypoint.getGeocode().substring(2));

            // Edit Button
            final Button buttonEdit = (Button) findViewById(R.id.edit);
            buttonEdit.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    EditWaypointActivity.startActivityEditWaypoint(WaypointPopup.this, waypoint.getId());
                    finish();
                }
            });

            //Start filling cache details
            details = new CacheDetailsCreator(this, (LinearLayout) findViewById(R.id.details_list));
            details.add(R.string.cache_name, cache.getName());

            addCacheDetails();

        } catch (Exception e) {
            Log.e("cgeopopup.init", e);
        }
    }

    @Override
    protected void navigateTo() {
        NavigationAppFactory.startDefaultNavigationApplication(1, this, waypoint);
    }

    /**
     * Tries to navigate to the {@link cgCache} 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) {
        final Intent popupIntent = new Intent(context, WaypointPopup.class);
        popupIntent.putExtra(Intents.EXTRA_WAYPOINT_ID, waypointId);
        popupIntent.putExtra(Intents.EXTRA_GEOCODE, geocode);
        context.startActivity(popupIntent);
    }

    @Override
    protected void showNavigationMenu() {
        NavigationAppFactory.showNavigationMenu(this, null, waypoint, null);
    }

    @Override
    protected Geopoint getCoordinates() {
        if (waypoint == null) {
            return null;
        }
        return waypoint.getCoords();
    }
}