/// <summary>
        /// Called periodically to get the next departure time
        /// </summary>
        private void PerformUpdate()
        {
            // Make sure a non-cached set of TrainTrips is used
            TrainTrips.Reset();
            trainJourneyRetrieval.GetJourneys(TrainTrips.SelectedTrip);

            // The update is now in progress, so report this
            Application.Context.SendBroadcast(new Intent(AppWidget.UpdateInProgress));
        }
Example #2
0
        /// <summary>
        /// Renders the visual contents of a specific widget contents into a RemoteViews object
        /// </summary>
        /// <param name="widgetContext">Widget context.</param>
        /// <param name="widgetId">Widget identifier.</param>
        private RemoteViews RenderWidgetContents(Context context, int widgetId)
        {
            // Initialise the persistent storage
            PersistentStorage.StorageMechanism = new StorageMechanism(context);
            PersistentStorage.UseCache         = false;

            // Create a RemoteView for the widget
            RemoteViews widgetView = new RemoteViews(context.PackageName, Resource.Layout.widget);

            // Extract the current trip details and display them.
            // The trip details and selected trip can be changed independently by the main app so a new set of train trip details need to be read
            TrainTrips.Reset();
            TrainTrip selectedTrip = TrainTrips.SelectedTrip;

            if (selectedTrip != null)
            {
                widgetView.SetTextViewText(Resource.Id.widgetTrip, string.Format("{0}:{1}", selectedTrip.FromCode, selectedTrip.ToCode));
            }

            // Extract the next departure time and display it
            DateTime departureTime = NextDeparture.DepartureTime;

            widgetView.SetTextViewText(Resource.Id.widgetDeparture, departureTime.ToString("HH:mm"));

            // Register pending intents for clicking on the displayed fields
            RegisterClicks(context, widgetView);

            // Show the correct image for the running state of the update service
            if (PersistentStorage.GetBoolItem(UpdateInProgressName, false) == true)
            {
                // An update is actually in progress, so show the progress indicator and hide
                // the service status flags
                widgetView.SetViewVisibility(Resource.Id.layoutProgressBar, Android.Views.ViewStates.Visible);
                widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Gone);
                widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Gone);
            }
            else
            {
                // Hide the progress indicator and show the servide state
                widgetView.SetViewVisibility(Resource.Id.layoutProgressBar, Android.Views.ViewStates.Gone);

                if (PersistentStorage.GetBoolItem(UpdateServiceRunningName, false) == true)
                {
                    widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Gone);
                    widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Visible);
                }
                else
                {
                    widgetView.SetViewVisibility(Resource.Id.imageStart, Android.Views.ViewStates.Visible);
                    widgetView.SetViewVisibility(Resource.Id.imageStop, Android.Views.ViewStates.Gone);
                }
            }

            return(widgetView);
        }
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            // Make sure a non-cached set of TrainTrips is used
            TrainTrips.Reset();

            trainJourneyRetrieval.GetJourneys(TrainTrips.SelectedTrip);

            // The update is now in progress, so report this
            Application.Context.SendBroadcast(new Intent(AppWidget.UpdateInProgress));

            return(StartCommandResult.NotSticky);
        }