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
89
90
|
package org.navitproject.navit;
import java.util.ArrayList;
import java.util.List;
import org.navitproject.navit.NavitAddressSearchActivity.NavitAddress;
import android.app.Application;
import android.content.SharedPreferences;
import android.util.Log;
import org.acra.*;
import org.acra.annotation.*;
//@ReportsCrashes(formKey = "dGlrNVRIOVVKYjB0UGVoLUZPanlzWFE6MQ")
@ReportsCrashes(mailTo = "android@navit-project.org",
mode = ReportingInteractionMode.TOAST,
resToastText = R.string.app_name)
public class NavitAppConfig extends Application {
private static final int MAX_LAST_ADDRESSES = 10;
private static final String TAG = "Navit";
private List<NavitAddress> mLastAddresses = null;
private int mLastAddressField;
private SharedPreferences mSettings;
@Override
public void onCreate() {
// call ACRA.init(this) as reflection, because old ant may forgot to include it
try {
Class<?> acraClass = Class.forName("org.acra.ACRA");
Class<?> partypes[] = new Class[1];
partypes[0] = Application.class;
java.lang.reflect.Method initMethod = acraClass.getMethod("init", partypes);
Object arglist[] = new Object[1];
arglist[0] = this;
initMethod.invoke(null, arglist);
} catch (Exception e1) {
Log.e(TAG, "Could not init ACRA crash reporter");
}
mSettings = getSharedPreferences(Navit.NAVIT_PREFS, MODE_PRIVATE);
super.onCreate();
}
public List<NavitAddress> getLastAddresses() {
if (mLastAddresses == null) {
mLastAddresses = new ArrayList<NavitAddress>();
int mLastAddressField = mSettings.getInt("LastAddress", -1);
if (mLastAddressField >= 0) {
int index = mLastAddressField;
do {
String addr_str = mSettings.getString("LastAddress_" + String.valueOf(index), "");
if (addr_str.length() > 0) {
mLastAddresses.add(new NavitAddress(
1,
mSettings.getFloat("LastAddress_Lat_" + String.valueOf(index), 0),
mSettings.getFloat("LastAddress_Lon_" + String.valueOf(index), 0),
addr_str));
}
if (--index < 0) index = MAX_LAST_ADDRESSES - 1;
} while (index != mLastAddressField);
}
}
return mLastAddresses;
}
public void addLastAddress(NavitAddress newAddress) {
getLastAddresses();
mLastAddresses.add(newAddress);
if (mLastAddresses.size() > MAX_LAST_ADDRESSES) mLastAddresses.remove(0);
mLastAddressField++;
if (mLastAddressField >= MAX_LAST_ADDRESSES) mLastAddressField = 0;
SharedPreferences.Editor editSettings = mSettings.edit();
editSettings.putInt("LastAddress", mLastAddressField);
editSettings.putString("LastAddress_" + String.valueOf(mLastAddressField), newAddress.addr);
editSettings.putFloat("LastAddress_Lat_" + String.valueOf(mLastAddressField), newAddress.lat);
editSettings.putFloat("LastAddress_Lon_" + String.valueOf(mLastAddressField), newAddress.lon);
editSettings.commit();
}
}
|