2 |
|
|
3 |
|
|
4 |
|
|
5 |
import java.util.ArrayList; |
import java.io.InvalidClassException; |
6 |
|
|
7 |
import android.app.Activity; |
import android.app.Activity; |
8 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
9 |
import android.content.Intent; |
import android.content.Intent; |
10 |
import android.content.SharedPreferences; |
import android.content.SharedPreferences; |
11 |
import android.content.SharedPreferences.Editor; |
import android.content.SharedPreferences.Editor; |
|
import android.location.Location; |
|
12 |
import android.net.Uri; |
import android.net.Uri; |
13 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
14 |
import android.os.Bundle; |
import android.os.Bundle; |
24 |
|
|
25 |
import com.nullwire.trace.ExceptionHandler; |
import com.nullwire.trace.ExceptionHandler; |
26 |
|
|
|
import dk.thoerup.android.traininfo.common.StationEntry; |
|
27 |
import dk.thoerup.androidutils.CheckUpdates; |
import dk.thoerup.androidutils.CheckUpdates; |
28 |
import dk.thoerup.traininfo.provider.OfflineStationProvider; |
import dk.thoerup.traininfo.provider.OfflineStationProvider; |
29 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
30 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
31 |
import dk.thoerup.traininfo.stationmap.GeoPair; |
|
|
import dk.thoerup.traininfo.stationmap.StationMapView; |
|
|
import dk.thoerup.traininfo.util.MessageBox; |
|
32 |
|
|
33 |
public class WelcomeScreen extends Activity{ |
public class WelcomeScreen extends Activity{ |
34 |
|
|
47 |
|
|
48 |
SharedPreferences prefs; |
SharedPreferences prefs; |
49 |
|
|
50 |
|
StationLoader stationLoader; |
51 |
|
|
52 |
@Override |
@Override |
53 |
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
54 |
|
|
90 |
|
|
91 |
if (sp instanceof OfflineStationProvider ) { |
if (sp instanceof OfflineStationProvider ) { |
92 |
OfflineStationProvider osp = (OfflineStationProvider) sp; |
OfflineStationProvider osp = (OfflineStationProvider) sp; |
93 |
try { |
long last = prefs.getLong(stationsreload, 0); |
94 |
|
long now = System.currentTimeMillis(); |
95 |
long last = prefs.getLong(stationsreload, 0); |
Log.i("TrainInfo", "Last Load: " + last); |
96 |
long now = System.currentTimeMillis(); |
|
97 |
|
if ( (now-last) > (14*24*60*60*1000) ) { |
98 |
Log.i("TrainInfo", "Last Load: " + last); |
stationLoader = new StationLoader(osp); |
99 |
|
stationLoader.execute( (Void)null); |
100 |
if ( (now-last) > (14*24*60*60*1000) ) { |
} else { |
101 |
new StationLoader(osp).execute( (Void)null); |
|
102 |
} else { |
boolean didLoad = false; |
103 |
|
|
104 |
boolean didLoad = osp.loadStations(this); |
try { |
105 |
|
didLoad = osp.loadStations(this); |
106 |
if (didLoad == false) { |
} |
107 |
new StationLoader(osp).execute( (Void)null); |
catch (InvalidClassException e) { |
108 |
} |
Log.i("TrainInfo", "invalid class - do a new download of stationlist"); |
109 |
|
} |
110 |
|
catch (Exception e) { |
111 |
|
Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); |
112 |
|
Log.e("TrainInfo", "load error", e); |
113 |
} |
} |
114 |
|
|
115 |
} catch (Exception e) { |
if (didLoad == false) { |
116 |
Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); |
stationLoader = new StationLoader(osp); |
117 |
|
stationLoader.execute( (Void)null); |
118 |
|
} |
119 |
} |
} |
120 |
|
|
121 |
} |
} |
122 |
} |
} |
123 |
|
|
126 |
@Override |
@Override |
127 |
protected void onDestroy() { |
protected void onDestroy() { |
128 |
super.onDestroy(); |
super.onDestroy(); |
129 |
|
if (stationLoader != null) { |
130 |
|
stationLoader.cancel(false); |
131 |
|
} |
132 |
|
|
133 |
ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup |
ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup |
134 |
} |
} |
135 |
|
|
212 |
boolean succeeded; |
boolean succeeded; |
213 |
ProgressDialog dlg; |
ProgressDialog dlg; |
214 |
OfflineStationProvider osp; |
OfflineStationProvider osp; |
215 |
|
String exMsg; |
216 |
|
|
217 |
public StationLoader(OfflineStationProvider osp) { |
public StationLoader(OfflineStationProvider osp) { |
218 |
this.osp = osp; |
this.osp = osp; |
225 |
succeeded = true; |
succeeded = true; |
226 |
} catch (Exception e) { |
} catch (Exception e) { |
227 |
succeeded = false; |
succeeded = false; |
228 |
Toast.makeText(WelcomeScreen.this, "Error " + e.getMessage(), Toast.LENGTH_LONG).show(); |
exMsg = e.getMessage(); |
229 |
} |
} |
230 |
return null; |
return null; |
231 |
} |
} |
232 |
|
|
233 |
|
|
234 |
@Override |
@Override |
235 |
protected void onPreExecute() { |
protected void onPreExecute() { |
236 |
super.onPreExecute(); |
super.onPreExecute(); |
237 |
|
|
238 |
dlg = new ProgressDialog(WelcomeScreen.this); |
dlg = new ProgressDialog(WelcomeScreen.this); |
239 |
dlg.setMessage( "Downloading stations list" );//TODO: translate |
dlg.setMessage( getText(R.string.welcome_downloadingstations) ); |
240 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
241 |
dlg.show(); |
dlg.show(); |
242 |
} |
} |
252 |
Editor edit = prefs.edit(); |
Editor edit = prefs.edit(); |
253 |
edit.putLong(stationsreload, System.currentTimeMillis() ); |
edit.putLong(stationsreload, System.currentTimeMillis() ); |
254 |
edit.commit(); |
edit.commit(); |
255 |
|
} else { |
256 |
|
Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show(); |
257 |
} |
} |
258 |
} |
} |
259 |
} |
} |