aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusSpecificStopView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusSpecificStopView.java')
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
index 06bd267..f0fc273 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -24,6 +24,8 @@ import java.text.DateFormat;
import android.app.Activity;
import android.content.Intent;
+import android.content.res.Resources;
+import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
@@ -49,6 +51,9 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
private Stop stop;
+ private String onClickHelpMessage;
+ private String onClickUnidentifiedMessage;
+
public BusSpecificStopView(BusActivity context, Stop stop) {
super(context);
@@ -63,6 +68,10 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
time.setTextSize(22f);
time.setGravity(Gravity.RIGHT);
+ Resources resources = context.getResources();
+ onClickHelpMessage = resources.getString(R.string.bus_stop_view_on_click_toast_help_message);
+ onClickUnidentifiedMessage = resources.getString(R.string.bus_stop_view_on_click_toast_unidentified_message);
+
setStop(stop);
addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
@@ -76,16 +85,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
this.stop = stop;
- if (stop == null) {
- Log.e(TAG, "stop == null");
- }
- if (stop.busStop == null) {
- Log.e(TAG, "stop.busStop == null");
- }
- if (stop.busStop.description == null) {
- Log.e(TAG, "stop.busStop.description == null");
- }
-
if (stop.busStop.description.length() > 20) {
location.setText(stop.busStop.description.substring(0, 20)); // TODO
} else {
@@ -147,13 +146,19 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
}
public void onClick(View v) {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT);
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+ try {
+ Dao<Bus, Integer> busDao = helper.getBusDao();
+ busDao.refresh(stop.bus);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ if (stop.bus.id != null) {
+ context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT);
} else {
- context.activityToast.setText(onClickMessage);
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.makeToast(onClickMessage, Toast.LENGTH_SHORT);
}
- context.activityToast.show();
}
public boolean onLongClick(View v) { // TODO
@@ -165,19 +170,15 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
busDao.refresh(stop.bus);
if (stop.bus.id != null) {
- // TODO Change to URI
- Intent i = new Intent(context, MapActivity.class);
- i.putExtra("poiPoint", stop.busStop.point.toDoubleString());
- ((Activity) context).startActivityForResult(i, 0);
+ Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(stop.busStop.point.getLatitudeE6()) + ","
+ + Util.E6IntToDouble(stop.busStop.point.getLongitudeE6()) + "?z=18");
+
+ Log.i(TAG, "Starting a activity for " + uri);
+
+ Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
+ ((Activity) context).startActivity(mapIntent);
} else {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, "Arival prediction not avalible for timetabled buses",
- Toast.LENGTH_SHORT);
- } else {
- context.activityToast.setText("Arival prediction not avalible for timetabled buses");
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
- }
- context.activityToast.show();
+ context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT);
}
} catch (SQLException e) {