aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/CoordinatesFormatSwitcher.java
blob: db299a292a1f64bc2b474aed072941cb94f17861 (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
package cgeo.geocaching.ui;

import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.GeopointFormatter;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * view click listener to automatically switch different coordinate formats
 *
 */
public class CoordinatesFormatSwitcher implements OnClickListener {

    private static final GeopointFormatter.Format[] availableFormats = new GeopointFormatter.Format[] {
            GeopointFormatter.Format.LAT_LON_DECMINUTE,
            GeopointFormatter.Format.LAT_LON_DECSECOND,
            GeopointFormatter.Format.LAT_LON_DECDEGREE
    };

    private int position = 0;

    private final Geopoint coordinates;

    public CoordinatesFormatSwitcher(final Geopoint coordinates) {
        this.coordinates = coordinates;
    }

    @Override
    public void onClick(final View view) {
        assert view instanceof TextView;
        position = (position + 1) % availableFormats.length;
        final TextView textView = (TextView) view;
        // rotate coordinate formats on click
        textView.setText(coordinates.format(availableFormats[position]));
    }

}