From e2dd0451d2e5229e3bf746875b12afde8177e10b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 2 Jun 2016 19:18:56 +0200 Subject: [PATCH] added first version of ConnectIQ app for URA based Bus real-time departures --- connectiq/.gitignore | 2 + connectiq/.project | 17 +++ connectiq/manifest.xml | 16 +++ connectiq/resources/drawables/drawables.xml | 3 + .../resources/drawables/launcher_icon.png | Bin 0 -> 1292 bytes connectiq/resources/strings/strings.xml | 3 + connectiq/source/BusStopApp.mc | 54 +++++++++ connectiq/source/BusStopDelegate.mc | 10 ++ connectiq/source/BusStopView.mc | 105 ++++++++++++++++++ 9 files changed, 210 insertions(+) create mode 100644 connectiq/.gitignore create mode 100644 connectiq/.project create mode 100644 connectiq/manifest.xml create mode 100644 connectiq/resources/drawables/drawables.xml create mode 100644 connectiq/resources/drawables/launcher_icon.png create mode 100644 connectiq/resources/strings/strings.xml create mode 100644 connectiq/source/BusStopApp.mc create mode 100644 connectiq/source/BusStopDelegate.mc create mode 100644 connectiq/source/BusStopView.mc diff --git a/connectiq/.gitignore b/connectiq/.gitignore new file mode 100644 index 0000000..55aa8f5 --- /dev/null +++ b/connectiq/.gitignore @@ -0,0 +1,2 @@ +*.prg +*.debug.xml diff --git a/connectiq/.project b/connectiq/.project new file mode 100644 index 0000000..95e8f8d --- /dev/null +++ b/connectiq/.project @@ -0,0 +1,17 @@ + + + ura-busstops + + + + + + connectiq.builder + + + + + + connectiq.projectNature + + diff --git a/connectiq/manifest.xml b/connectiq/manifest.xml new file mode 100644 index 0000000..646f7b4 --- /dev/null +++ b/connectiq/manifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/connectiq/resources/drawables/drawables.xml b/connectiq/resources/drawables/drawables.xml new file mode 100644 index 0000000..d0de5d6 --- /dev/null +++ b/connectiq/resources/drawables/drawables.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/connectiq/resources/drawables/launcher_icon.png b/connectiq/resources/drawables/launcher_icon.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UEhOpsB~<{xic^& zw=!$JH3kVwvB-P=f{G?#Ii_5?4qP9i3M!ukqp?BNM8j#UpTI0_#Odz^N5wPXq3qSx z#*fH + ASEAG Fahrplan + \ No newline at end of file diff --git a/connectiq/source/BusStopApp.mc b/connectiq/source/BusStopApp.mc new file mode 100644 index 0000000..df3e1cc --- /dev/null +++ b/connectiq/source/BusStopApp.mc @@ -0,0 +1,54 @@ +using Toybox.Application as App; +using Toybox.Position as Position; +using Toybox.Time as Time; + +class BusStopApp extends App.AppBase { + var mView; + var mDelegate; + + function intialize() { + AppBase.initialize(); + } + + //! onStart() is called on application start up + function onStart() { + Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition)); + } + + //! onStop() is called when your application is exiting + function onStop() { + Position.enableLocationEvents(Position.LOCATION_DISABLE, method(:onPosition)); + } + + function fakePosition() { + var pos = new Position.Info(); + + pos.accuracy = 0; + pos.altitude = 0; + pos.heading = 0; + pos.speed = 0; + pos.when = Time.now(); + pos.position = new Position.Location({ + :latitude => 50.7855, + :longitude => 6.0541, + :format => :degrees + }); + + mView.setPosition(pos); + } + + function onPosition(info) { + positionView.setPosition(info); + } + + //! Return the initial view of your application here + function getInitialView() { + mView = new BusStopView(); + mDelegate = new BusStopDelegate(); + + fakePosition(); + + return [ mView, mDelegate ]; + } + +} \ No newline at end of file diff --git a/connectiq/source/BusStopDelegate.mc b/connectiq/source/BusStopDelegate.mc new file mode 100644 index 0000000..6fd792e --- /dev/null +++ b/connectiq/source/BusStopDelegate.mc @@ -0,0 +1,10 @@ +using Toybox.WatchUi as Ui; +using Toybox.Graphics as Gfx; +using Toybox.System as Sys; + +var last_key = null; + +class InputTestDelegate extends Ui.BehaviorDelegate { + + +} \ No newline at end of file diff --git a/connectiq/source/BusStopView.mc b/connectiq/source/BusStopView.mc new file mode 100644 index 0000000..18accd2 --- /dev/null +++ b/connectiq/source/BusStopView.mc @@ -0,0 +1,105 @@ +using Toybox.WatchUi as Ui; +using Toybox.Graphics as Gfx; +using Toybox.System as Sys; +using Toybox.Lang as Lang; +using Toybox.Communications as Comm; +using Toybox.System as Sys; +using Toybox.Time as Time; +using Toybox.Timer as Timer; + +class BusStopView extends Ui.View { + var schedule = null; + var tmr; + + function intialize() { + View.initialize(); + } + + //! Load your resources here + function onLayout(dc) { + } + + //! Called when this View is brought to the foreground. Restore + //! the state of this View and prepare it to be shown. This includes + //! loading resources into memory. + function onShow() { + tmr = new Timer.Timer(); + tmr.start(method(:redraw), 1000, true); + } + + //! Called when this View is removed from the screen. Save the + //! state of this View here. This includes freeing resources from + //! memory. + function onHide() { + tmr.stop(); + } + + //! Update the view + function onUpdate(dc) { + var string; + + // Set background color + dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK ); + dc.clear(); + dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT ); + + if( schedule != null ) { + var ts = new Time.Moment(schedule[1][4] / 1000); + var duration = Time.now().subtract(ts); + var ts_greg = Time.Gregorian.info(ts, Time.FORMAT_MEDIUM); + var dur_greg = Time.Gregorian.info(new Time.Moment(duration.value()), Time.FORMAT_SHORT); + + /* Timezone offset */ + dur_greg.hour -= 2; + + var arr = Lang.format("$1$:$2$:$3$", [ + (ts_greg.hour - 2), + (ts_greg.min).format("%02u"), + (ts_greg.sec).format("%02u") + ]); + + var due = ""; + if (dur_greg.hour > 0) { + due += dur_greg.hour + " h "; + } + if (dur_greg.min > 0) { + due += dur_greg.min + " min "; + } + if (dur_greg.sec > 0) { + due += dur_greg.sec + " sec "; + } + + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2) - 80, Gfx.FONT_LARGE, schedule[1][2], Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2) - 40, Gfx.FONT_SMALL, schedule[1][1], Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2) - 20, Gfx.FONT_SMALL, schedule[1][3], Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2) + 10, Gfx.FONT_SMALL, arr, Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2) + 40, Gfx.FONT_SMALL, due, Gfx.TEXT_JUSTIFY_CENTER ); + } + else { + dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2), Gfx.FONT_SMALL, "No schedule avail", Gfx.TEXT_JUSTIFY_CENTER ); + } + } + + function setPosition(info) { + var url = "http://web.0l.de:8080/"; + var parameters = { "Circle" => info.position.toDegrees()[0] + "," + + info.position.toDegrees()[1] + ",150", + "ReturnList" => "StopPointName,DestinationName,LineName,EstimatedTime" }; + var options = { :method => Comm.HTTP_REQUEST_METHOD_GET }; + + Comm.makeJsonRequest(url, parameters, options, method(:requestCompleted)); + } + + function requestCompleted(responseCode, data) { + Sys.println("Request completed: " + responseCode); + + if (responseCode == 200) { + schedule = data; + redraw(); + } + } + + function redraw() { + WatchUi.requestUpdate(); + } +}