1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
3 |
|
import java.io.InvalidClassException; |
4 |
|
|
5 |
import android.app.Activity; |
import android.app.Activity; |
6 |
import android.content.Intent; |
import android.content.Intent; |
7 |
import android.os.Bundle; |
import android.os.Bundle; |
8 |
import android.os.Parcelable; |
import android.os.Parcelable; |
9 |
|
import android.util.Log; |
10 |
import android.view.View; |
import android.view.View; |
11 |
import android.view.View.OnClickListener; |
import android.view.View.OnClickListener; |
12 |
import android.widget.Button; |
import android.widget.Button; |
13 |
import android.widget.TextView; |
import android.widget.TextView; |
14 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
import android.widget.Toast; |
15 |
|
import dk.thoerup.android.traininfo.common.StationEntry; |
16 |
import dk.thoerup.traininfo.WelcomeScreen.ListType; |
import dk.thoerup.traininfo.WelcomeScreen.ListType; |
17 |
|
import dk.thoerup.traininfo.provider.OfflineStationProvider; |
18 |
|
import dk.thoerup.traininfo.provider.ProviderFactory; |
19 |
|
import dk.thoerup.traininfo.util.StationEntryCsv; |
20 |
|
|
21 |
public class ShortcutActivity extends Activity { |
public class ShortcutActivity extends Activity { |
22 |
|
|
41 |
if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { |
if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { |
42 |
setContentView(R.layout.shortcut); |
setContentView(R.layout.shortcut); |
43 |
|
|
44 |
|
OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider(); |
45 |
|
|
46 |
|
try { |
47 |
|
osp.loadStations(this); |
48 |
|
} |
49 |
|
catch (InvalidClassException e) { |
50 |
|
Log.i("TrainInfo", "invalid class - do a new download of stationlist"); |
51 |
|
} |
52 |
|
catch (Exception e) { |
53 |
|
Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); |
54 |
|
Log.e("TrainInfo", "load error", e); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
Button cancelBtn = (Button) findViewById(R.id.shortcut_cancel); |
Button cancelBtn = (Button) findViewById(R.id.shortcut_cancel); |
59 |
cancelBtn.setOnClickListener( new OnClickListener() { |
cancelBtn.setOnClickListener( new OnClickListener() { |
60 |
|
|
85 |
} else { |
} else { |
86 |
//launched by the user clicking on the shortcut |
//launched by the user clicking on the shortcut |
87 |
String stationStr = intent.getStringExtra("station"); |
String stationStr = intent.getStringExtra("station"); |
88 |
StationEntry station = StationEntry.fromCSV(stationStr); |
|
89 |
|
if (stationStr != null) { //haven't reproduced it, but got a stacktrace where stationStr apparently was null |
90 |
|
StationEntry station = StationEntryCsv.fromCSV(stationStr); |
91 |
|
|
92 |
Intent launcher = new Intent( this, DepartureList.class ); |
Intent launcher = new Intent( this, DepartureList.class ); |
93 |
launcher.putExtra("stationbean", station); |
launcher.putExtra("stationbean", station); |
94 |
startActivityForResult(launcher, SHOW_DEPARTURES); |
startActivityForResult(launcher, SHOW_DEPARTURES); |
95 |
|
} else { |
96 |
|
Toast.makeText(this, "Invalid TrainInfo shortcut - please delete and re-create", Toast.LENGTH_LONG).show(); |
97 |
|
} |
98 |
} |
} |
99 |
} |
} |
100 |
|
|
129 |
// First, set up the shortcut intent. |
// First, set up the shortcut intent. |
130 |
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); |
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); |
131 |
shortcutIntent.setClassName(this, this.getClass().getName()); |
shortcutIntent.setClassName(this, this.getClass().getName()); |
132 |
shortcutIntent.putExtra("station", station.toCSV() ); |
shortcutIntent.putExtra("station", StationEntryCsv.toCSV(station) ); |
133 |
|
|
134 |
|
|
135 |
// Then, set up the container intent (the response to the caller) |
// Then, set up the container intent (the response to the caller) |