blob: 3bc7f7112f803eb03926b7c73bbd50658ba5499f (
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
|
package cgeo.geocaching.apps;
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.utils.ProcessUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import android.content.Intent;
public abstract class AbstractApp implements App {
@Nullable private final String packageName;
@Nullable private final String intent;
@NonNull
private final String name;
/**
* a unique id, defined in res/values/ids.xml
*/
private final int id;
protected AbstractApp(@NonNull final String name, final int id, @Nullable final String intent,
@Nullable final String packageName) {
this.name = name;
this.id = id;
this.intent = intent;
this.packageName = packageName;
}
protected AbstractApp(@NonNull final String name, final int id, @Nullable final String intent) {
this(name, id, intent, null);
}
@Override
public boolean isInstalled() {
if (StringUtils.isNotEmpty(packageName) && ProcessUtils.isLaunchable(packageName)) {
return true;
}
if (intent == null) {
return false;
}
assert intent != null; // eclipse issue
return ProcessUtils.isIntentAvailable(intent);
}
@Nullable
protected Intent getLaunchIntent() {
return ProcessUtils.getLaunchIntent(packageName);
}
@Override
public boolean isUsableAsDefaultNavigationApp() {
return true;
}
@Override
@NonNull
public String getName() {
return name;
}
@Override
public int getId() {
return id;
}
protected static String getString(final int ressourceId) {
return CgeoApplication.getInstance().getString(ressourceId);
}
@Override
public boolean isEnabled(final Geocache cache) {
return cache != null;
}
}
|