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

import org.apache.commons.lang3.StringUtils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

public class cgImage implements Parcelable {
    private final String url;
    private final String title;
    private final String description;

    public cgImage(final String url, final String title, final String description) {
        this.url = url;
        this.title = title;
        this.description = description;
    }

    public cgImage(final String url, final String title) {
        this(url, title, null);
    }

    public cgImage(final Parcel in) {
        url = in.readString();
        title = in.readString();
        description = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(url);
        dest.writeString(title);
        dest.writeString(description);
    }

    public static final Parcelable.Creator<cgImage> CREATOR = new Parcelable.Creator<cgImage>() {
        @Override
        public cgImage createFromParcel(Parcel in) {
            return new cgImage(in);
        }

        @Override
        public cgImage[] newArray(int size) {
            return new cgImage[size];
        }
    };

    public String getUrl() {
        return url;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    public void openInBrowser(final Context fromActivity) {
        if (StringUtils.isBlank(url)) {
            return;
        }
        final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        fromActivity.startActivity(browserIntent);
    }

    @Override
    public String toString() {
        if (null != title) {
            return title;
        }

        if (url != null) {
            return url;
        }

        return "???";
    }
}