/// <summary> /// This method is called when the BroadcastReceiver has received an Intent /// </summary> /// <param name="context">The Context in which the receiver is running.</param> /// <param name="intent">The Intent being received.</param> public override void OnReceive(Context context, Intent intent) { base.OnReceive(context, intent); // Check if the click is from the details text being clicked if (DetailsClick == intent.Action) { // Open the main QuTi activity context.StartActivity(new Intent(context, typeof(MainActivity))); } // If a new trip has been selected then update all widgets to display it else if (intent.Action == TripUpdated) { UpdateAllWidgets(context); } // If this is an update service state change then action it else if ((intent.Action == StartClick) || (intent.Action == StopClick)) { // Initialise the persistent storage PersistentStorage.StorageMechanism = new StorageMechanism(context); PersistentStorage.UseCache = false; // Store the state of the update service PersistentStorage.SetBoolItem(UpdateServiceRunningName, (intent.Action == StartClick)); // Start or stop the service if (intent.Action == StartClick) { context.StartService(new Intent(context, typeof(UpdateService))); } else { context.StopService(new Intent(context, typeof(UpdateService))); } // Display the updated state UpdateAllWidgets(context); } // If this is a departure time change then update all the widgets else if ((intent.Action == NextDepartureSuspectChange) || (intent.Action == NextDepartureTimeChange)) { UpdateAllWidgets(context); } // If the device has just unlocked then update the widget else if (intent.Action == Intent.ActionUserPresent) { UpdateAllWidgets(context); } else if ((intent.Action == UpdateInProgress) || (intent.Action == UpdateFinished)) { // Store the state of the update operation PersistentStorage.SetBoolItem(UpdateInProgressName, (intent.Action == UpdateInProgress)); UpdateAllWidgets(context); } }
/// <summary> /// Called when the first widget is displayed. /// </summary> /// <param name="context"></param> public override void OnEnabled(Context context) { // Initialise the persistent storage PersistentStorage.StorageMechanism = new StorageMechanism(context); PersistentStorage.UseCache = false; // Initialise the update service state to not running PersistentStorage.SetBoolItem(UpdateServiceRunningName, false); // Register for when the device wakes up and the keylock is off // Cannot register for this in the manifest // Also cannot use the provided context, must use the application context?? context.ApplicationContext.RegisterReceiver(this, new IntentFilter(Intent.ActionUserPresent)); base.OnEnabled(context); }