Scrolling within a widget

Former Member
Former Member
I'm mainly a web developer with a PHP background, but I wanted to create a widget which accessed my weather station. I do like the stock weather widget on the fenix 5 and wanted to replicate some of its features, but I'm having a couple problems.

Querying my weather station and displaying the results has been a breeze, but now I'd like to do two more things that the stock weather widget does:

1) Click the Select button to display a new screen showing the daily forecast. Also, clicking the Back button should bring you back to the current conditions screen where we started.

2) When on the daily forecast screen, I'd like to use the Up/Down buttons to scroll through the daily forecast screens.

It looks like this is all possible given the stock weather widget, but I'm at a loss on how to reproduce the same results.

Thanks for any assistance!
  • The input to the main view in a widget is limited, where up/down move to different widgets, and back takes you back to the watchface. So what you do is create a second view when the start button is pushed. in the delegate for that view you can handle up/down/back.
  • Former Member
    Former Member over 6 years ago
    Ahhh. OK, that makes sense. Thanks for the tip!
  • Former Member
    Former Member over 6 years ago
    I'm halfway there. I was able to create a new view which then allowed me to access the Up/Down buttons. Is there a way to enable the scroll up or scroll down animation within a view just like the weather widget does when going between Hourly and Daily forecasts? Here's a video showing that scroll feature:

    https://youtu.be/O_VWjlx6Bt4?t=648
  • I just checked on a 645m too then watched the video.

    I think you can be as animated when changing screens, but it's driven off the up/down and maybe with another view and Ui.SLIDE_UP and Ui.SlDE_DOWN when you're pushing the view.
  • I'm curious about your data source for info from your station. Does the weather station send to a weather website and the widget pulls it from there so the data can be pulled from different stations or is it just your station?

    I've been using weather underground for a few years, but in May, they stopped using API keys.
  • Former Member
    Former Member over 6 years ago
    It's strange that when I push a new view using a slide transition that I don't see the actual transition. The view immediately appears without an animation.


    Ui.pushView(forecast_view, new WeatherViewDelegate(view), Ui.SLIDE_LEFT);

    I'll fool around some more and see if I can get it working.

    For Weather Underground, I use an API key that I generated about 7 years ago. Most of the data I grab directly from my weather station and format it for use on other devices, but for the forecast, I use WU.
  • Former Member
    Former Member over 6 years ago
    You know, perhaps it's the simulator that is fooling me. I have only tested on the simulator since I do not have my watch yet. Maybe the processing speed on the simulator speeds up the slide transitions to the point that you can't detect the animation?
  • Yes, things can look a bit different in the sim. (it's not a full emulator). That could be the case here, but there are other things to. Like when you do a makeWebRequest(), it will be much faster in the sim than on a device, and a biggie is colors. Due to the way the displays work, what looks great in the sim, maybe no so much on a device. I find red on black really hard to see on a real device for example.

    If you don't have a Garmin CIQ device, a note about widgets. They have a timeout on the real watch. They are meant for a "quick view" of things. Based on the device, that timeout can be from around 30 seconds to a couple minutes. After the widget is started, it will revert to the watchface when the timeout occurs (unless there's user interaction).
  • Former Member
    Former Member over 6 years ago
    Good to know on all points. Thanks for the info!

    So let's say I go to the widget for the first time at 7am and then check back at 11am. On that second check, is the displayed weather data from 7am until the 11am web request is made?
  • By default, you run the widget at 7am, get the data, and display it. Run again at 11am, the same.

    Couple of options then.

    When you get the data at 7am, save it in Application.Storage, and at 11am, you can display the 7am data while requesting the 11am data, which in turn you save to Application.Storage. You may want to detect "stale" data, like if the widget is only run once a day, there's no point in showing yesterday's data

    Use a background process, where the data is requested on a regular basis, even if the widget itself isn't running - say once an hour. Then the widget does little more than caching the data it sees and displays it. The trick here involves the amount of data, as a background process has a limited size and can only run at most for 30 seconds at a time. But this is how weather data is displayed on CIQ watchfaces - a background process. You could just request the current conditions in the background, and the widget could request the forecast data when it runs - display the current conditions while requesting the forecast. See the programmer's guide and this thread for info on background processes.