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

import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.HumanDistance;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

public class DistanceView extends TextView {
    private Geopoint cacheCoords = null;

    public DistanceView(Context context) {
        super(context);
    }

    public DistanceView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DistanceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setContent(final Geopoint cacheCoordsIn) {
        cacheCoords = cacheCoordsIn;
    }

    public void update(final Geopoint coords) {
        if (cacheCoords == null || coords == null) {
            return;
        }
        setText(HumanDistance.getHumanDistance(coords.distanceTo(cacheCoords)));
    }

    public void setDistance(Float distance) {
        setText("~" + HumanDistance.getHumanDistance(distance));
    }

    public void clear() {
        setText(null);
    }
}