aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/apps/cache/navi/AndroidWearApp.java
blob: 5abe2fc9e80309d5e08065f8f36a422cb843f779 (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
package cgeo.geocaching.apps.cache.navi;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.Intents;
import cgeo.geocaching.R;
import cgeo.geocaching.Waypoint;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.utils.ProcessUtils;

import android.app.Activity;
import android.content.Intent;

/**
 * For use with any Android Wear geocaching apps which can handle the intent action below.
 */
class AndroidWearApp extends AbstractPointNavigationApp {
    private static final String INTENT_ACTION = "cgeo.geocaching.wear.NAVIGATE_TO";

    public AndroidWearApp() {
        super(getString(R.string.cache_menu_android_wear), R.id.cache_app_android_wear, INTENT_ACTION, null);
    }

    @Override
    public boolean isInstalled() {
        return ProcessUtils.isIntentAvailable(INTENT_ACTION);
    }

    @Override
    public void navigate(final Activity activity, final Geopoint coords) {
        navigate(activity, null, null, coords);
    }

    @Override
    public void navigate(final Activity activity, final Geocache cache) {
        navigate(activity, cache.getName(), cache.getGeocode(), cache.getCoords());
    }

    @Override
    public void navigate(final Activity activity, final Waypoint waypoint) {
        navigate(activity, waypoint.getName(), waypoint.getGeocode(), waypoint.getCoords());
    }

    private static void navigate(final Activity activity, final String destName,
                                 final String destCode, final Geopoint coords) {
        final Intent launchIntent = new Intent(INTENT_ACTION);
        launchIntent.putExtra(Intents.EXTRA_NAME, destName)
                .putExtra(Intents.EXTRA_GEOCODE, destCode)
                .putExtra(Intents.EXTRA_LATITUDE, coords.getLatitude())
                .putExtra(Intents.EXTRA_LONGITUDE, coords.getLongitude());
        activity.startService(launchIntent);
    }
}