@@ -58,9 +58,9 @@ public class RealTimeFragment extends Fragment {
5858 public static MapView map ;
5959 public static Activity activity ;
6060 Button button ;
61- Button nextButton ;
61+ public static Button nextButton ;
6262 public static TextView textView ;
63- Button previousButton ;
63+ public static Button previousButton ;
6464 EditText editText ;
6565 public static CheckBox checkBox ;
6666 public BusBackgroundThread backgroundThread = new BusBackgroundThread ();
@@ -94,9 +94,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
9494 checkBox = v .findViewById (R .id .checkBox );
9595 editText .setInputType (InputType .TYPE_CLASS_NUMBER );
9696
97-
9897 map .getZoomController ().setVisibility (CustomZoomButtonsController .Visibility .NEVER );
99- map .setTileSource (TileSourceFactory . OpenTopo );
98+ map .setTileSource (SettingsFragment . getCurrentTileProvider () );
10099
101100 map .setMultiTouchControls (true );
102101 map .getController ().setCenter (new GeoPoint (38.73329737648646d , -9.14096412687648d ));
@@ -181,7 +180,7 @@ public void run() {
181180 @ Override
182181 public void run () {
183182 updateMarkers (pathList , map );
184- updateBuses ( busList , map , getActivity () );
183+ updateBusesUI ( );
185184 updateTextView ();
186185 updateDirectionIndex ();
187186 Log .println (Log .DEBUG , "BUS DEBUG" , "GUI UPDATED" );
@@ -214,6 +213,7 @@ public void onClick(View view) {
214213 currentSelectedBus ++;
215214 updateTextView ();
216215 updateDirectionIndex ();
216+ updateBusesUI ();
217217 updateMarkers (currentCarreira .getDirectionList ().get (currentDirectionIndex ).getPathList (), map );
218218 Log .println (Log .DEBUG , "Button" , "Current Bus: " + currentSelectedBus );
219219 getActivity ().runOnUiThread (new Runnable () {
@@ -222,7 +222,9 @@ public void onClick(View view) {
222222 public void run () {
223223 //textView.setText((currentSelectedBus + 1) + "/" + busList.size() + "\n" + busList.get(currentSelectedBus).getStatus());
224224 GeoPoint point = markerBusList .get (currentSelectedBus ).getPosition ();
225- map .getController ().animateTo (point , 16.5 , 2500L );
225+ if (checkBox .isChecked ()){
226+ map .getController ().animateTo (point , 16.5 , 2500L );
227+ }
226228 map .invalidate ();
227229 }
228230 });
@@ -242,13 +244,16 @@ public void onClick(View view) {
242244 currentSelectedBus --;
243245 updateTextView ();
244246 updateDirectionIndex ();
247+ updateBusesUI ();
245248 updateMarkers (currentCarreira .getDirectionList ().get (currentDirectionIndex ).getPathList (), map );
246249 Log .println (Log .DEBUG , "Button" , "Current Bus: " + currentSelectedBus );
247250 getActivity ().runOnUiThread (new Runnable () {
248251 @ Override
249252 public void run () {
250253 GeoPoint point = markerBusList .get (currentSelectedBus ).getPosition ();
251- map .getController ().animateTo (point , 16.5 , 2500L );
254+ if (checkBox .isChecked ()){
255+ map .getController ().animateTo (point , 16.5 , 2500L );
256+ }
252257 map .invalidate ();
253258 }
254259 });
@@ -307,6 +312,7 @@ private void updateMarkers(List<Path> pathList, MapView map){
307312 int resultBlue = Integer .valueOf (hexCode .substring (4 , 6 ), 16 );
308313 line .setColor (Color .rgb (resultRed , resultGreen , resultBlue ));
309314 line .setWidth (7.5f );
315+ line .setInfoWindow (null );
310316 map .getOverlays ().add (line );
311317 markerList .forEach (marker -> map .getOverlays ().add (marker ));
312318 }else {
@@ -322,11 +328,17 @@ public static void updateBuses(List<Bus> busList, MapView map, Activity activity
322328 map .getOverlays ().remove (marker );
323329 }
324330 markerBusList .clear ();
331+ int index = 0 ;
325332 for (Bus bus : busList ){
326333 double [] coordinates = bus .getCoordinates ();
327334 GeoPoint point = new GeoPoint (coordinates [0 ], coordinates [1 ]);
328335 Marker marker = new Marker (map );
329- Drawable d = ResourcesCompat .getDrawable (activity .getResources (), R .drawable .cm_bus_regular , null );
336+ Drawable d ;
337+ if (index !=currentSelectedBus ){
338+ d = ResourcesCompat .getDrawable (activity .getResources (), R .drawable .cm_bus , null );
339+ }else {
340+ d = ResourcesCompat .getDrawable (activity .getResources (), R .drawable .cm_bus_regular , null );
341+ }
330342 RotateDrawable d1 = new RotateDrawable ();
331343 d1 .setDrawable (d );
332344 d1 .setFromDegrees (0f );
@@ -338,47 +350,23 @@ public static void updateBuses(List<Bus> busList, MapView map, Activity activity
338350 marker .setAnchor (Marker .ANCHOR_CENTER , Marker .ANCHOR_CENTER );
339351 String descrption = "Vehicle Id: " + bus .getVehicleId () + "\n Speed: " + bus .getSpeed () + "\n Pattern Id: " + bus .getPattern_id ();
340352 MarkerInfoWindow miw = new CustomMarkerInfoWindow (org .osmdroid .library .R .layout .bonuspack_bubble , map , "Bus " + bus .getId (), descrption );
341- marker .setInfoWindow ( miw );
353+ marker .setOnMarkerClickListener ( new BusClickListener ( miw ) );
342354 map .getOverlays ().add (marker );
355+ index ++;
343356 }
344357 }
345358
346359 public static void updateBusesUI (){
347360 activity .runOnUiThread (new Runnable () {
348361 @ Override
349362 public void run () {
350- updateBuses (busList , map , activity );
363+ synchronized (busList ){
364+ updateBuses (busList , map , activity );
365+ }
351366 }
352367 });
353368 }
354369
355-
356- private static Drawable getRotateDrawable (Bitmap b , float angle , Activity activity ) {
357- final BitmapDrawable drawable = new BitmapDrawable (activity .getApplicationContext ().getResources (), b ) {
358- @ Override
359- public void draw (final Canvas canvas ) {
360- canvas .save ();
361- canvas .rotate (angle , b .getWidth () / 2f , b .getHeight () / 2f );
362- super .draw (canvas );
363- canvas .restore ();
364- }
365- };
366- return drawable ;
367- }
368-
369- private static Drawable getRotateDrawable2 (final Drawable d , final float angle ) {
370- final Drawable [] arD = { d };
371- return new LayerDrawable (arD ) {
372- @ Override
373- public void draw (final Canvas canvas ) {
374- canvas .save ();
375- canvas .rotate (angle , d .getBounds ().width () / 2 , d .getBounds ().height () / 2 );
376- super .draw (canvas );
377- canvas .restore ();
378- }
379- };
380- }
381-
382370 public void showBackgroundThreadDialog (){
383371 getActivity ().runOnUiThread (new Runnable () {
384372 @ Override
@@ -395,4 +383,29 @@ public static void updateTextView(){
395383 public MapView getMap () {
396384 return map ;
397385 }
386+
387+ static class BusClickListener implements Marker .OnMarkerClickListener {
388+ MarkerInfoWindow miw ;
389+ public BusClickListener (MarkerInfoWindow miw ){
390+ this .miw =miw ;
391+ }
392+ @ Override
393+ public boolean onMarkerClick (Marker marker , MapView mapView ) {
394+ int index = 0 ;
395+ marker .closeInfoWindow ();
396+ for (Marker busMarker : markerBusList ) {
397+ if (busMarker .equals (marker )){
398+ if (currentSelectedBus != index ){
399+ currentSelectedBus = index + 1 ;
400+ previousButton .performClick ();
401+ }
402+ break ;
403+ }
404+ index ++;
405+ }
406+ marker .setInfoWindow (miw );
407+ marker .showInfoWindow ();
408+ return false ;
409+ }
410+ }
398411}
0 commit comments