package dk.thoerup.traininfo; import java.io.InvalidClassException; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import dk.thoerup.android.traininfo.common.StationEntry; import dk.thoerup.traininfo.WelcomeScreen.ListType; import dk.thoerup.traininfo.provider.OfflineStationProvider; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.util.StationEntryCsv; public class ShortcutActivity extends Activity { final static int SHOW_DEPARTURES = 1000; final static int SHOW_STATIONS = 2000; StationEntry station; Button okBtn; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // Resolve the intent final Intent intent = getIntent(); final String action = intent.getAction(); // If the intent is a request to create a shortcut, we'll do that and exit if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { setContentView(R.layout.shortcut); OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider(); try { osp.loadStations(this); } catch (InvalidClassException e) { Log.i("TrainInfo", "invalid class - do a new download of stationlist"); } catch (Exception e) { Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); Log.e("TrainInfo", "load error", e); } Button cancelBtn = (Button) findViewById(R.id.shortcut_cancel); cancelBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { ShortcutActivity.this.setResult(Activity.RESULT_CANCELED); ShortcutActivity.this.finish(); } }); okBtn = (Button) findViewById(R.id.shortcut_ok); okBtn.setEnabled(false); okBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { setupShortcut(station); finish(); } }); Button btn = (Button)findViewById(R.id.nearest); btn.setOnClickListener(new StationListener(ListType.ListNearest)); btn = (Button)findViewById(R.id.search); btn.setOnClickListener(new StationListener(ListType.ListSearch)); btn = (Button)findViewById(R.id.favorites); btn.setOnClickListener(new StationListener(ListType.ListFavorites)); } else { //launched by the user clicking on the shortcut String stationStr = intent.getStringExtra("station"); if (stationStr != null) { //haven't reproduced it, but got a stacktrace where stationStr apparently was null StationEntry station = StationEntryCsv.fromCSV(stationStr); Intent launcher = new Intent( this, DepartureList.class ); launcher.putExtra("stationbean", station); startActivityForResult(launcher, SHOW_DEPARTURES); } else { Toast.makeText(this, "Invalid TrainInfo shortcut - please delete and re-create", Toast.LENGTH_LONG).show(); } } } /** * This function creates a shortcut and returns it to the caller. There are actually two * intents that you will send back. * * The first intent serves as a container for the shortcut and is returned to the launcher by * setResult(). This intent must contain three fields: * *