aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/StopView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/StopView.java')
-rw-r--r--src/net/cbaines/suma/StopView.java81
1 files changed, 28 insertions, 53 deletions
diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java
index f942137..afe8664 100644
--- a/src/net/cbaines/suma/StopView.java
+++ b/src/net/cbaines/suma/StopView.java
@@ -22,8 +22,8 @@ package net.cbaines.suma;
import java.sql.SQLException;
import java.text.DateFormat;
-import android.app.Activity;
import android.content.Intent;
+import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
@@ -36,8 +36,7 @@ import android.widget.Toast;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
-public class StopView extends LinearLayout implements OnClickListener,
- OnLongClickListener {
+public class StopView extends LinearLayout implements OnClickListener, OnLongClickListener {
// private final ImageView icon;
@@ -66,10 +65,8 @@ public class StopView extends LinearLayout implements OnClickListener,
setStop(stop);
- addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.WRAP_CONTENT));
- addView(time, new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.WRAP_CONTENT));
+ addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
public void setStop(Stop stop) {
@@ -81,8 +78,7 @@ public class StopView extends LinearLayout implements OnClickListener,
name.setText(stop.bus.getName());
time.setText(stop.getTimeToArival());
- DatabaseHelper helper = OpenHelperManager.getHelper(context,
- DatabaseHelper.class);
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
try {
Dao<Bus, Integer> busDao = helper.getBusDao();
@@ -91,31 +87,19 @@ public class StopView extends LinearLayout implements OnClickListener,
if (stop.bus.id != null) {
if (stop.live) {
- onClickMessage = "Bus "
- + stop.bus.toString()
- + " at "
- + DateFormat.getTimeInstance(DateFormat.SHORT)
- .format(stop.arivalTime);
+ onClickMessage = "Bus " + stop.bus.toString() + " at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
} else {
- onClickMessage = "Timetabled bus "
- + stop.bus.toString()
- + " at "
- + DateFormat.getTimeInstance(DateFormat.SHORT)
- .format(stop.arivalTime);
+ onClickMessage = "Timetabled bus " + stop.bus.toString() + " at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
}
} else {
if (stop.live) {
- onClickMessage = "Unidentified bus ("
- + stop.bus.getName()
- + ") at "
- + DateFormat.getTimeInstance(DateFormat.SHORT)
- .format(stop.arivalTime);
+ onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
} else {
- onClickMessage = "Timetabled bus ("
- + stop.bus.getName()
- + ") at "
- + DateFormat.getTimeInstance(DateFormat.SHORT)
- .format(stop.arivalTime);
+ onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at "
+ + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
}
}
} catch (SQLException e) {
@@ -128,8 +112,7 @@ public class StopView extends LinearLayout implements OnClickListener,
public void onClick(View v) {
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, onClickMessage,
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT);
} else {
context.activityToast.setText(onClickMessage);
context.activityToast.setDuration(Toast.LENGTH_SHORT);
@@ -139,8 +122,7 @@ public class StopView extends LinearLayout implements OnClickListener,
}
public boolean onLongClick(View v) {
- DatabaseHelper helper = OpenHelperManager.getHelper(context,
- DatabaseHelper.class);
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
try {
Dao<Bus, Integer> busDao = helper.getBusDao();
@@ -149,38 +131,31 @@ public class StopView extends LinearLayout implements OnClickListener,
busDao.refresh(stop.bus);
busRouteDao.refresh(stop.bus.route);
- Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link "
- + stop.bus.route.uniLink + " Bus ID " + stop.bus.id);
+ Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID "
+ + stop.bus.id);
if (stop.bus.id != null && stop.bus.route.uniLink) {
- Intent i = new Intent(context, BusActivity.class);
- i.putExtra("busID", stop.bus.id);
- i.putExtra("busStopID", stop.busStop.id);
- ((Activity) context).startActivityForResult(i, 0);
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id);
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ busStopIntent.putExtra("busStopID", stop.busStop.id);
+ context.startActivity(busStopIntent);
} else {
if (!stop.bus.route.uniLink) {
if (context.activityToast == null) {
- context.activityToast = Toast
- .makeText(
- context,
- "Bus schedules only avalible for Uni-Link buses",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context,
+ "Bus schedules only avalible for Uni-Link buses", Toast.LENGTH_SHORT);
} else {
- context.activityToast
- .setText("Bus schedules only avalible for Uni-Link buses");
+ context.activityToast.setText("Bus schedules only avalible for Uni-Link buses");
context.activityToast.setDuration(Toast.LENGTH_SHORT);
}
context.activityToast.show();
} else {
if (context.activityToast == null) {
- context.activityToast = Toast
- .makeText(
- context,
- "Bus schedules not avalible for unidentified buses",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context,
+ "Bus schedules not avalible for unidentified buses", Toast.LENGTH_SHORT);
} else {
- context.activityToast
- .setText("Bus schedules not avalible for unidentified buses");
+ context.activityToast.setText("Bus schedules not avalible for unidentified buses");
context.activityToast.setDuration(Toast.LENGTH_SHORT);
}
context.activityToast.show();