From 419cb3529dd8f59790ee9a6aa869b7afe3c21f0c Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 17 Feb 2012 16:29:46 +0000 Subject: Improved toasts, changed the way the map works, one tap gets you a toast with info, two taps gets you the activity, and a long press changes the favourites state. --- src/net/cbaines/suma/BuildingNumOverlay.java | 35 ++++++++++++++---- src/net/cbaines/suma/BusActivity.java | 3 ++ src/net/cbaines/suma/BusSpecificStopView.java | 21 ++++++++--- src/net/cbaines/suma/BusStopActivity.java | 3 ++ src/net/cbaines/suma/BusStopOverlay.java | 42 +++++++++++++++++++--- .../suma/SouthamptonUniversityMapActivity.java | 3 ++ src/net/cbaines/suma/StopView.java | 20 ++++++++--- src/net/cbaines/suma/TimetableAdapter.java | 4 +-- 8 files changed, 110 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index 4bd5f3a..baa92b5 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; - import org.osmdroid.views.MapView; import org.osmdroid.views.MapView.Projection; import org.osmdroid.views.overlay.Overlay; @@ -62,13 +61,13 @@ public class BuildingNumOverlay extends Overlay { private static final String TAG = "BuildingNumOverlay"; - private final Context context; + private final SouthamptonUniversityMapActivity context; private Dao buildingDao; private float userScale = 1f; - public BuildingNumOverlay(Context context, List buildings) throws SQLException { + public BuildingNumOverlay(SouthamptonUniversityMapActivity context, List buildings) throws SQLException { super(context); this.context = context; @@ -192,12 +191,23 @@ public class BuildingNumOverlay extends Overlay { } else { Log.i(TAG, "building Pressed " + building.id); - Toast.makeText(context, building.name + " (" + building.id + ")", Toast.LENGTH_SHORT).show(); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(building.name + " (" + building.id + ")"); + } + context.activityToast.show(); + return true; } } + public boolean onDoubleTap(final MotionEvent e, final MapView mapView) { + return false; + } + @Override public boolean onLongPress(final MotionEvent event, final MapView mapView) { if (!this.isEnabled()) @@ -214,9 +224,22 @@ public class BuildingNumOverlay extends Overlay { if (building.favourite) { building.favourite = false; - Toast.makeText(context, building.id + " removed from favourites", Toast.LENGTH_SHORT).show(); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, building.id + " removed from favourites", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(building.id + " removed from favourites"); + } + context.activityToast.show(); + } else { - Toast.makeText(context, building.id + " made a favourite", Toast.LENGTH_SHORT).show(); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, building.id + " made a favourite", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(building.id + " made a favourite"); + } + context.activityToast.show(); building.favourite = true; } diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 25f373a..4b59117 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -21,6 +21,7 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; @@ -38,6 +39,8 @@ public class BusActivity extends OrmLiteBaseActivity implements private TextView busContentMessage; private LinearLayout busActivityContentLayout; + Toast activityToast; + /** * The bus this activity is focused on */ diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index cad7524..fc14fcb 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -46,11 +46,11 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener private final TextView location; private final TextView time; private String onClickMessage = ""; - private final Context context; + private final BusActivity context; private Stop stop; - public BusSpecificStopView(Context context, Stop stop) { + public BusSpecificStopView(BusActivity context, Stop stop) { super(context); this.context = context; @@ -147,8 +147,13 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener } public void onClick(View v) { - Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT).show(); - + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); + } else { + context.activityToast.setText(onClickMessage); + context.activityToast.setDuration(Toast.LENGTH_SHORT); + } + context.activityToast.show(); } @Override @@ -165,7 +170,13 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener i.putExtra("poiPoint", stop.busStop.point.toDoubleString()); ((Activity) context).startActivityForResult(i, 0); } else { - Toast.makeText(context, "Arival prediction not avalible for timetabled buses", Toast.LENGTH_SHORT).show(); + 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(); } } catch (SQLException e) { diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 9910ad3..1c325ec 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -52,6 +52,7 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; @@ -100,6 +101,8 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme private HashSet routes = new HashSet(); + Toast activityToast; + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bustimes); diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 59212ef..f912d19 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -60,7 +60,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { private static final String TAG = "BusStopOverlay"; - private final Context context; + private final SouthamptonUniversityMapActivity context; private Dao busStopDao; @@ -68,7 +68,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { private boolean[] routes = new boolean[5]; - public BusStopOverlay(Context context, List busStops) throws SQLException { + public BusStopOverlay(SouthamptonUniversityMapActivity context, List busStops) throws SQLException { super(context); this.context = context; @@ -196,6 +196,28 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { BusStop busStop = getSelectedItem(event, mapView); + if (busStop == null) { + Log.i(TAG, "No busStop pressed"); + return false; + } else { + Log.i(TAG, "busStop Pressed " + busStop.id); + + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(busStop.description + " (" + busStop.id + ")"); + } + context.activityToast.show(); + + return true; + } + } + + public boolean onDoubleTap(final MotionEvent event, final MapView mapView) { + + BusStop busStop = getSelectedItem(event, mapView); + if (busStop == null) { Log.i(TAG, "No busStop pressed"); @@ -226,9 +248,21 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { if (busStop.favourite) { busStop.favourite = false; - Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT).show(); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(busStop.id + " removed from favourites"); + } + context.activityToast.show(); } else { - Toast.makeText(context, busStop.id + " made a favourite", Toast.LENGTH_SHORT).show(); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, busStop.id + " made a favourite", Toast.LENGTH_SHORT); + } else { + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(busStop.id + " made a favourite"); + } + context.activityToast.show(); busStop.favourite = true; } diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java index 26996a0..1412e3b 100644 --- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java +++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java @@ -69,6 +69,7 @@ import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.TextView; +import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; @@ -142,6 +143,8 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity