diff options
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | gen/net/cbaines/suma/R.java | 185 | ||||
-rw-r--r-- | res/anim/updated_stop_view.xml | 12 | ||||
-rw-r--r-- | res/layout/view_child_row.xml | 2 | ||||
-rw-r--r-- | res/layout/view_group_row.xml | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/Bus.java | 22 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java (renamed from src/net/cbaines/suma/BusTimeActivity.java) | 167 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopOverlay.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/DatabaseHelper.java | 1 | ||||
-rw-r--r-- | src/net/cbaines/suma/FindActivity.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/SouthamptonUniversityMapActivity.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/Stop.java | 46 | ||||
-rw-r--r-- | src/net/cbaines/suma/Timetable.java | 27 | ||||
-rw-r--r-- | src/net/cbaines/suma/TimetableAdapter.java | 31 |
14 files changed, 340 insertions, 163 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3c874ba..b0747f0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -27,7 +27,7 @@ </activity> <activity android:name="FindActivity" > </activity> - <activity android:name="BusTimeActivity" > + <activity android:name=".BusStopActivity" > </activity> <activity android:name="AboutActivity" > </activity> diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index cf96e75..2535953 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -8,11 +8,14 @@ package net.cbaines.suma; public final class R { + public static final class anim { + public static final int updated_stop_view=0x7f040000; + } public static final class array { - public static final int buildingTypes=0x7f070001; - public static final int preferencesHeadings=0x7f070003; - public static final int uniLinkBusRoutes=0x7f070000; - public static final int utilityOverlays=0x7f070002; + public static final int buildingTypes=0x7f080001; + public static final int preferencesHeadings=0x7f080003; + public static final int uniLinkBusRoutes=0x7f080000; + public static final int utilityOverlays=0x7f080002; } public static final class attr { } @@ -28,46 +31,46 @@ public final class R { public static final int u9_back=0x7f020008; } public static final class id { - public static final int busStopID=0x7f09000c; - public static final int busStopLoadBar=0x7f09000f; - public static final int busStopMessage=0x7f09000e; - public static final int busStopName=0x7f090004; - public static final int busStopTimes=0x7f090010; - public static final int busStopU1=0x7f090006; - public static final int busStopU1N=0x7f090007; - public static final int busStopU2=0x7f090008; - public static final int busStopU6=0x7f090009; - public static final int busStopU9=0x7f09000a; - public static final int busTimeContentLayout=0x7f09000d; - public static final int check1=0x7f090020; - public static final int childname=0x7f09001f; - public static final int donateBitcoinAddress=0x7f090017; - public static final int donateButton=0x7f090003; - public static final int donateDialogErrorMessage=0x7f090016; - public static final int donateDialogMessage=0x7f090013; - public static final int donateDialogMessageLayout=0x7f090015; - public static final int donateDialogProgress=0x7f090014; - public static final int favouriteCheckBox=0x7f09000b; - public static final int favouriteDialogMessage=0x7f090018; - public static final int favouriteListItems=0x7f090019; - public static final int findContentLayout=0x7f09001b; - public static final int findListItems=0x7f09001d; - public static final int findLoadBar=0x7f09001c; - public static final int helpExpandableListView=0x7f090002; - public static final int layout_root=0x7f090011; - public static final int linearLayout1=0x7f090005; - public static final int linearLayout2=0x7f090012; - public static final int mapview=0x7f09001e; - public static final int menu_about=0x7f090026; - public static final int menu_favourites=0x7f090027; - public static final int menu_find=0x7f090022; - public static final int menu_find_my_location=0x7f090024; - public static final int menu_preferences=0x7f090023; - public static final int menu_view=0x7f090025; - public static final int searchBar=0x7f09001a; - public static final int textView1=0x7f090000; - public static final int textView2=0x7f090001; - public static final int view_list=0x7f090021; + public static final int busStopID=0x7f0a000c; + public static final int busStopLoadBar=0x7f0a000f; + public static final int busStopMessage=0x7f0a000e; + public static final int busStopName=0x7f0a0004; + public static final int busStopTimes=0x7f0a0010; + public static final int busStopU1=0x7f0a0006; + public static final int busStopU1N=0x7f0a0007; + public static final int busStopU2=0x7f0a0008; + public static final int busStopU6=0x7f0a0009; + public static final int busStopU9=0x7f0a000a; + public static final int busTimeContentLayout=0x7f0a000d; + public static final int check1=0x7f0a0020; + public static final int childname=0x7f0a001f; + public static final int donateBitcoinAddress=0x7f0a0017; + public static final int donateButton=0x7f0a0003; + public static final int donateDialogErrorMessage=0x7f0a0016; + public static final int donateDialogMessage=0x7f0a0013; + public static final int donateDialogMessageLayout=0x7f0a0015; + public static final int donateDialogProgress=0x7f0a0014; + public static final int favouriteCheckBox=0x7f0a000b; + public static final int favouriteDialogMessage=0x7f0a0018; + public static final int favouriteListItems=0x7f0a0019; + public static final int findContentLayout=0x7f0a001b; + public static final int findListItems=0x7f0a001d; + public static final int findLoadBar=0x7f0a001c; + public static final int helpExpandableListView=0x7f0a0002; + public static final int layout_root=0x7f0a0011; + public static final int linearLayout1=0x7f0a0005; + public static final int linearLayout2=0x7f0a0012; + public static final int mapview=0x7f0a001e; + public static final int menu_about=0x7f0a0026; + public static final int menu_favourites=0x7f0a0027; + public static final int menu_find=0x7f0a0022; + public static final int menu_find_my_location=0x7f0a0024; + public static final int menu_preferences=0x7f0a0023; + public static final int menu_view=0x7f0a0025; + public static final int searchBar=0x7f0a001a; + public static final int textView1=0x7f0a0000; + public static final int textView2=0x7f0a0001; + public static final int view_list=0x7f0a0021; } public static final class layout { public static final int about_dialog=0x7f030000; @@ -81,60 +84,60 @@ public final class R { public static final int view_group_row=0x7f030008; } public static final class menu { - public static final int map_menu=0x7f080000; + public static final int map_menu=0x7f090000; } public static final class raw { - public static final int u1=0x7f050000; - public static final int u1e=0x7f050001; - public static final int u1n=0x7f050002; - public static final int u2=0x7f050003; - public static final int u6=0x7f050004; - public static final int u9=0x7f050005; + public static final int u1=0x7f060000; + public static final int u1e=0x7f060001; + public static final int u1n=0x7f060002; + public static final int u2=0x7f060003; + public static final int u6=0x7f060004; + public static final int u9=0x7f060005; } public static final class string { - public static final int U1=0x7f060009; - public static final int U1N=0x7f06000a; - public static final int U2=0x7f06000b; - public static final int U6=0x7f06000c; - public static final int U9=0x7f06000d; - public static final int about_help_message=0x7f060015; - public static final int about_menu_instruction_text=0x7f060023; - public static final int app_name=0x7f060004; - public static final int bitcoin_error_message=0x7f06001a; - public static final int building_non_residential=0x7f060007; - public static final int building_residential=0x7f060006; - public static final int bustimes_favourite_checkbox_label=0x7f060024; - public static final int credits_help_message=0x7f060018; - public static final int donate_button=0x7f060019; - public static final int donate_dialog_error_title=0x7f060026; - public static final int donate_dialog_message=0x7f060025; - public static final int favourites_dialog_message=0x7f06001c; - public static final int favourites_help_message=0x7f060016; - public static final int find_help_message=0x7f060011; - public static final int findmylocation_help_message=0x7f060013; - public static final int legal_message=0x7f060005; - public static final int licence_help_message=0x7f060017; + public static final int U1=0x7f070009; + public static final int U1N=0x7f07000a; + public static final int U2=0x7f07000b; + public static final int U6=0x7f07000c; + public static final int U9=0x7f07000d; + public static final int about_help_message=0x7f070015; + public static final int about_menu_instruction_text=0x7f070023; + public static final int app_name=0x7f070004; + public static final int bitcoin_error_message=0x7f07001a; + public static final int building_non_residential=0x7f070007; + public static final int building_residential=0x7f070006; + public static final int bustimes_favourite_checkbox_label=0x7f070024; + public static final int credits_help_message=0x7f070018; + public static final int donate_button=0x7f070019; + public static final int donate_dialog_error_title=0x7f070026; + public static final int donate_dialog_message=0x7f070025; + public static final int favourites_dialog_message=0x7f07001c; + public static final int favourites_help_message=0x7f070016; + public static final int find_help_message=0x7f070011; + public static final int findmylocation_help_message=0x7f070013; + public static final int legal_message=0x7f070005; + public static final int licence_help_message=0x7f070017; /** Preferences Messages */ - public static final int map_help_message=0x7f060010; - public static final int menu_about=0x7f06000e; - public static final int menu_favourites=0x7f06000f; - public static final int menu_find=0x7f060000; - public static final int menu_find_my_location=0x7f060003; - public static final int menu_preferences=0x7f060001; - public static final int menu_view=0x7f060002; - public static final int pref_bus_stop=0x7f060008; - public static final int preferences=0x7f06001b; - public static final int preferences_catagory_bus_times=0x7f060020; - public static final int preferences_catagory_positioning=0x7f06001d; - public static final int preferences_gps_disabled=0x7f06001f; - public static final int preferences_gps_enabled=0x7f06001e; - public static final int preferences_help_message=0x7f060012; - public static final int preferences_live_bus_times_disabled=0x7f060022; - public static final int preferences_live_bus_times_enabled=0x7f060021; - public static final int view_help_message=0x7f060014; + public static final int map_help_message=0x7f070010; + public static final int menu_about=0x7f07000e; + public static final int menu_favourites=0x7f07000f; + public static final int menu_find=0x7f070000; + public static final int menu_find_my_location=0x7f070003; + public static final int menu_preferences=0x7f070001; + public static final int menu_view=0x7f070002; + public static final int pref_bus_stop=0x7f070008; + public static final int preferences=0x7f07001b; + public static final int preferences_catagory_bus_times=0x7f070020; + public static final int preferences_catagory_positioning=0x7f07001d; + public static final int preferences_gps_disabled=0x7f07001f; + public static final int preferences_gps_enabled=0x7f07001e; + public static final int preferences_help_message=0x7f070012; + public static final int preferences_live_bus_times_disabled=0x7f070022; + public static final int preferences_live_bus_times_enabled=0x7f070021; + public static final int view_help_message=0x7f070014; } public static final class xml { - public static final int preferences=0x7f040000; + public static final int preferences=0x7f050000; } } diff --git a/res/anim/updated_stop_view.xml b/res/anim/updated_stop_view.xml new file mode 100644 index 0000000..eab6853 --- /dev/null +++ b/res/anim/updated_stop_view.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<set xmlns:android="http://schemas.android.com/apk/res/android" + android:interpolator="@android:anim/accelerate_interpolator" + android:shareInterpolator="true" > + + <alpha + xmlns:android="http://schemas.android.com/apk/res/android" + android:duration="1000" + android:fromAlpha="0.0" + android:toAlpha="1" /> + +</set>
\ No newline at end of file diff --git a/res/layout/view_child_row.xml b/res/layout/view_child_row.xml index d1ac7f3..081a600 100644 --- a/res/layout/view_child_row.xml +++ b/res/layout/view_child_row.xml @@ -11,7 +11,7 @@ android:layout_height="wrap_content" android:focusable="false" android:paddingLeft="50dp" - android:textSize="25dp" /> + android:textSize="17dp" /> <CheckBox android:id="@+id/check1" diff --git a/res/layout/view_group_row.xml b/res/layout/view_group_row.xml index 7b5989a..cdfc740 100644 --- a/res/layout/view_group_row.xml +++ b/res/layout/view_group_row.xml @@ -11,6 +11,6 @@ android:paddingBottom="5dp" android:paddingLeft="50dp" android:paddingTop="5dp" - android:textSize="28dp" /> + android:textSize="18dp" /> </LinearLayout>
\ No newline at end of file diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java index c73d6d7..ff71df4 100644 --- a/src/net/cbaines/suma/Bus.java +++ b/src/net/cbaines/suma/Bus.java @@ -54,4 +54,26 @@ public class Bus { return String.valueOf(id); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Bus other = (Bus) obj; + if (id != other.id) + return false; + return true; + } + } diff --git a/src/net/cbaines/suma/BusTimeActivity.java b/src/net/cbaines/suma/BusStopActivity.java index be8b14a..1495258 100644 --- a/src/net/cbaines/suma/BusTimeActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -21,8 +21,11 @@ package net.cbaines.suma; import java.sql.SQLException; +import android.content.Context; import android.content.SharedPreferences; +import android.os.AsyncTask; import android.os.Bundle; +import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; import android.view.Gravity; @@ -40,7 +43,7 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class BusTimeActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Runnable, OnCheckedChangeListener { +public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener { final static String TAG = "BusTimeActivity"; @@ -54,22 +57,29 @@ public class BusTimeActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme private ProgressBar progBar; private LinearLayout busTimeContentLayout; - private TimetableAdapter adapter; + protected Timetable timetable; - private String busStopID; + protected String busStopID; private String busStopName; private Dao<BusStop, String> busStopDao; private BusStop busStop; - private Thread timetableThread; + private GetTimetableTask timetableTask; + + private Context instance; + + private Handler mHandler; + private Runnable refreshData; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bustimes); - DatabaseHelper helper = getHelper(); + final DatabaseHelper helper = getHelper(); + + instance = this; busStopID = getIntent().getExtras().getString("busStopID"); busStopName = getIntent().getExtras().getString("busStopName"); @@ -153,12 +163,37 @@ public class BusTimeActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme busName.setText(busStopName); busID.setText(busStopID); + } + + public void onResume() { + super.onResume(); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPrefs.getBoolean("liveBusTimesEnabled", false)) { - timetableThread = new Thread(this); - timetableThread.start(); + Log.i(TAG, "Live Times enabled"); + timetable = (Timetable) getLastNonConfigurationInstance(); + + refreshData = new Runnable() { + @Override + public void run() { + timetableTask = new GetTimetableTask(); + timetableTask.execute(busStopID); + mHandler.postDelayed(refreshData, 20000); + } + }; + + mHandler = new Handler(); + + if (timetable == null) { + Log.i(TAG, "No Previous timetable"); + mHandler.post(refreshData); + } else { + Log.i(TAG, "Displaying previous timetable"); + displayTimetable(timetable); + } + } else { + Log.i(TAG, "Live Times Disabled"); progBar.setVisibility(View.GONE); busStopMessage.setText("Live bus times disabled"); busStopMessage.setVisibility(View.VISIBLE); @@ -166,12 +201,17 @@ public class BusTimeActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } - public void finish() { - Log.i(TAG, "Stopping BusTimeActivity thread"); - if (timetableThread != null) { // Could happen if live bus times are disabled - timetableThread.interrupt(); + public void onPause() { + if (mHandler != null) { // BusTimes are enabled + mHandler.removeCallbacks(refreshData); + timetableTask.cancel(true); + Log.i(TAG, "Stoping refreshing timetable data"); } + super.onPause(); + } + + public void finish() { if (dataChanged) { getIntent().putExtra("busStopChanged", busStopID); } @@ -181,67 +221,66 @@ public class BusTimeActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme super.finish(); } - public void run() { - while (true) { - try { - Timetable timetable = DataManager.getTimetable(this, busStopID, true); - - Log.i(TAG, "Got timetable for " + busStopID); - if (timetable == null) { - Log.i(TAG, "Its null"); - busTimeList.post(new Runnable() { - public void run() { - progBar.setVisibility(View.GONE); - busStopMessage.setText("Error fetching bus times"); - busStopMessage.setVisibility(View.VISIBLE); - } - }); - } else { - Log.i(TAG, "It contains " + timetable.size() + " stops"); - - if (timetable.size() == 0) { - busTimeList.post(new Runnable() { - public void run() { - progBar.setVisibility(View.GONE); - busStopMessage.setText("No Busses"); - busStopMessage.setVisibility(View.VISIBLE); - } - }); - } else { - - adapter = new TimetableAdapter(this, timetable); + public void onCheckedChanged(CompoundButton arg0, boolean arg1) { + busStop.favourite = arg1; + try { + busStopDao.update(busStop); + dataChanged = true; + } catch (SQLException e) { + e.printStackTrace(); + } + } - busTimeList.post(new Runnable() { - public void run() { - progBar.setVisibility(View.GONE); - busStopMessage.setVisibility(View.GONE); - busTimeList.setAdapter(adapter); - busTimeContentLayout.setGravity(Gravity.TOP); - } - }); - } - } + @Override + public Object onRetainNonConfigurationInstance() { + return timetable; + } - } catch (SQLException e1) { - e1.printStackTrace(); + private class GetTimetableTask extends AsyncTask<String, Integer, Timetable> { + protected Timetable doInBackground(String... activity) { + Timetable newTimetable = null; + try { + newTimetable = DataManager.getTimetable(instance, busStopID, true); + } catch (SQLException e) { + e.printStackTrace(); } + return newTimetable; + } - try { - Thread.sleep(20000); - } catch (InterruptedException e) { - Log.i(TAG, "Bus stop activity thread stoped"); - break; + protected void onPostExecute(Timetable newTimetable) { + Log.i(TAG, "Got timetable for " + busStopID); + if (newTimetable == null) { + Log.i(TAG, "Its null"); + + progBar.setVisibility(View.GONE); + busStopMessage.setText("Error fetching bus times"); + busStopMessage.setVisibility(View.VISIBLE); + } else { + timetable = newTimetable; + displayTimetable(timetable); } } } - public void onCheckedChanged(CompoundButton arg0, boolean arg1) { - busStop.favourite = arg1; - try { - busStopDao.update(busStop); - dataChanged = true; - } catch (SQLException e) { - e.printStackTrace(); + private void displayTimetable(Timetable timetable) { + Log.i(TAG, "It contains " + timetable.size() + " stops"); + + if (timetable.size() == 0) { + progBar.setVisibility(View.GONE); + busStopMessage.setText("No Busses"); + busStopMessage.setVisibility(View.VISIBLE); + } else { + progBar.setVisibility(View.GONE); + busStopMessage.setVisibility(View.GONE); + TimetableAdapter adapter; + if ((adapter = (TimetableAdapter) busTimeList.getAdapter()) != null) { + adapter.updateTimetable(timetable); + } else { + adapter = new TimetableAdapter(this, timetable); + busTimeList.setAdapter(adapter); + } + busTimeContentLayout.setGravity(Gravity.TOP); } } + } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 1b6a384..83b10c1 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -201,7 +201,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { } else { Log.i(TAG, "Pressed " + busStop.id); - Intent i = new Intent(context, BusTimeActivity.class); + Intent i = new Intent(context, BusStopActivity.class); i.putExtra("busStopID", busStop.id); i.putExtra("busStopName", busStop.description); ((Activity) context).startActivityForResult(i, 0); diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java index 7ccc08d..925b15f 100644 --- a/src/net/cbaines/suma/DatabaseHelper.java +++ b/src/net/cbaines/suma/DatabaseHelper.java @@ -28,7 +28,6 @@ import java.sql.SQLException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteException; import android.util.Log; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java index dbbff49..68db3c5 100644 --- a/src/net/cbaines/suma/FindActivity.java +++ b/src/net/cbaines/suma/FindActivity.java @@ -332,7 +332,7 @@ public class FindActivity extends OrmLiteBaseActivity<DatabaseHelper> implements BusStop busStop = (BusStop) poi; - Intent i = new Intent(FindActivity.this, BusTimeActivity.class); + Intent i = new Intent(FindActivity.this, BusStopActivity.class); i.putExtra("busStopID", busStop.id); i.putExtra("busStopName", busStop.description); startActivityForResult(i, 0); diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java index b6fcc7b..5b134c6 100644 --- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java +++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java @@ -951,7 +951,7 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa Log.i(TAG, "Pressed " + busStop.id); - Intent i = new Intent(this, BusTimeActivity.class); + Intent i = new Intent(this, BusStopActivity.class); i.putExtra("busStopID", busStop.id); i.putExtra("busStopName", busStop.description); startActivityForResult(i, 0); diff --git a/src/net/cbaines/suma/Stop.java b/src/net/cbaines/suma/Stop.java index 6e6bd39..2fa8d33 100644 --- a/src/net/cbaines/suma/Stop.java +++ b/src/net/cbaines/suma/Stop.java @@ -75,4 +75,50 @@ public class Stop { return (String) DateUtils.getRelativeTimeSpanString(arivalTime.getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS); } } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((arivalTime == null) ? 0 : arivalTime.hashCode()); + result = prime * result + ((bus == null) ? 0 : bus.hashCode()); + result = prime * result + ((busStop == null) ? 0 : busStop.hashCode()); + result = prime * result + id; + return result; + } + + @Override + public String toString() { + return "Stop [id=" + id + ", bus=" + bus + ", busStop=" + busStop + ", arivalTime=" + arivalTime + "]"; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Stop other = (Stop) obj; + if (arivalTime == null) { + if (other.arivalTime != null) + return false; + } else if (!arivalTime.equals(other.arivalTime)) + return false; + if (bus == null) { + if (other.bus != null) + return false; + } else if (!bus.equals(other.bus)) + return false; + if (busStop == null) { + if (other.busStop != null) + return false; + } else if (!busStop.equals(other.busStop)) + return false; + if (id != other.id) + return false; + return true; + } + } diff --git a/src/net/cbaines/suma/Timetable.java b/src/net/cbaines/suma/Timetable.java index 466bdfe..758c95f 100644 --- a/src/net/cbaines/suma/Timetable.java +++ b/src/net/cbaines/suma/Timetable.java @@ -28,4 +28,31 @@ public class Timetable extends ArrayList<Stop> { */ private static final long serialVersionUID = -9021303378059511643L; + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Stop stop : this) { + sb.append(stop + "\n"); + } + return sb.toString(); + } + + public boolean contains(Stop otherStop, boolean toTheMinute) { + if (toTheMinute) { + for (Stop stop : this) { + if (otherStop.bus != null && stop.bus != null && otherStop.bus.equals(stop.bus)) { + if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { + return true; + } + } else if (otherStop.busStop.equals(stop.busStop)) { + if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { + return true; + } + } + } + return false; + } else { + return this.contains(otherStop); + } + } + } diff --git a/src/net/cbaines/suma/TimetableAdapter.java b/src/net/cbaines/suma/TimetableAdapter.java index 8326856..19ca5a5 100644 --- a/src/net/cbaines/suma/TimetableAdapter.java +++ b/src/net/cbaines/suma/TimetableAdapter.java @@ -20,18 +20,26 @@ package net.cbaines.suma; import android.content.Context; +import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.widget.BaseAdapter; public class TimetableAdapter extends BaseAdapter { private final Context context; - private final Timetable timetable; + private Timetable timetable; + private final Animation a; + private boolean[] changed; + + private static final String TAG = "TimetableAdapter"; public TimetableAdapter(Context context, Timetable timetable) { this.context = context; this.timetable = timetable; + this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); } public View getView(int position, View convertView, ViewGroup parent) { @@ -43,6 +51,10 @@ public class TimetableAdapter extends BaseAdapter { stopView.setStop(timetable.get(position)); } + if (changed == null || changed[position]) { + stopView.startAnimation(a); + } + return stopView; } @@ -57,4 +69,21 @@ public class TimetableAdapter extends BaseAdapter { public long getItemId(int position) { return position; } + + public void updateTimetable(Timetable newTimetable) { + Log.v(TAG, "Old timetable " + timetable); + Log.v(TAG, "Adaptor loading new timetable"); + changed = new boolean[newTimetable.size()]; + for (int i = 0; i < newTimetable.size(); i++) { + if (!timetable.contains(newTimetable.get(i), true)) { + changed[i] = true; + Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i)); + } else { + Log.i(TAG, "Old timetable contains: " + newTimetable.get(i)); + changed[i] = false; + } + } + timetable = newTimetable; + this.notifyDataSetChanged(); + } } |