private ToggleButton CreateDeviceSelectionItem(Device moj)
        {
            ToggleButton button = new ToggleButton (this);
            if (devicesToShow.Contains (moj))
                button.Checked = true;
            else
                button.Checked = false;

            button.SetBackgroundResource (Resource.Drawable.android_blue_button);
            button.Text = string.Format ("{0}", moj.Name);
            button.Tag = moj.Id;
            button.Click += OnDeviceSelected;
            return button;
        }
예제 #2
0
 public void RemoveFromSubscriptionList(EventType eventType, Device device)
 {
     switch (eventType) {
     case EventType.TowStart:
         if (_devicesForTowEvent.Find (x => x.Id == device.Id && x.Name == device.Name) != null)
             _devicesForTowEvent.RemoveAll (x => x.Id == device.Id && x.Name == device.Name);
         break;
     default:
         break;
     }
 }
예제 #3
0
 public bool GetSubscriptionStatus(EventType eventType, Device device)
 {
     switch (eventType) {
     case EventType.TowStart:
         return _devicesForTowEvent.Find (x => x.Id == device.Id && x.Name == device.Name) != null;
     default:
         return false;
     }
 }
예제 #4
0
 private Button CreateDeviceSelectionItem(Device moj)
 {
     Button button = new Button (this);
     button.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.android_button));
     button.SetMaxHeight (25);
     button.Text = string.Format (moj.Name);
     button.Tag = moj.Id;
     button.Click += OnDeviceSelected;
     return button;
 }
예제 #5
0
        private Marker AddDeviceMarkerToMap(Device dev)
        {
            var loc = new LatLng (dev.LastLocation.Lat, dev.LastLocation.Lng);
            MarkerOptions marker = new MarkerOptions ();
            marker.InvokeIcon (BitmapDescriptorFactory.DefaultMarker (BitmapDescriptorFactory.HueGreen));
            marker.SetPosition (loc);
            String location;
            location = GetAddress (loc.Latitude, loc.Longitude);
            if (location == null)
                location = loc.Latitude.ToString() + ", " + loc.Longitude.ToString();
            marker.SetSnippet (location);
            marker.SetTitle (dev.Name);

            MyLogger.Information (this.LocalClassName, string.Format ("Device Marker Added: {0} at {1}", dev.Name, loc.ToString ()));
            return AddMarkerToMap (marker);
        }
예제 #6
0
 private void OnDeviceSubscriptionToggleClicked(Device dev, EventType eventType, bool isChecked)
 {
     MyLogger.Information (this.LocalClassName, string.Format ("User Preference: {0} for {1} Set to {2}", eventType, dev, isChecked));
     if (isChecked)
         CurrentUserPreference.AddToSubscriptionList (EventType.TowStart, dev);
     else
         CurrentUserPreference.RemoveFromSubscriptionList (EventType.TowStart, dev);
     OnSubscriptionChanged (dev, eventType, isChecked);
     SaveUserPreferences ();
 }
예제 #7
0
		protected bool SubscribeForEvent (Device mojioDevice, EventType eventToSubscribe)
		{
			HttpStatusCode statusCode;
			string msg;
			bool succeed = true;
			Subscription subscription = SubscribeForEvent (RegistrationId, out statusCode, out msg, mojioDevice, eventToSubscribe);
			Subscriptions.Add (subscription);
			if (subscription != null)
				MyLogger.Information (this.LocalClassName, string.Format ("Event Subscription: {0} - {1}.", "Successful", msg));	                    
			if (IsAlreadySubscribed (statusCode))
				MyLogger.Information (this.LocalClassName, string.Format ("Event Subscription: {0} Event already subscribed.", eventToSubscribe.ToString ()));	
			if (subscription == null && !IsAlreadySubscribed (statusCode)) {
				succeed = false;         
				MyLogger.Error (this.LocalClassName, string.Format ("Event Subscription: {0} - {1}.", "Fail", msg));
			}
				                    
			
			return succeed;
		}
예제 #8
0
		//TODO [GROUP 32] I know this is bad implementation. For now, given a device, it checks the user preference to see
		//which events need to be subscribed for the device. Should improve the implementation.
		protected void RegisterEventForNotice (Device dev, EventType eventType, bool toSubscribe)
		{
			if (string.IsNullOrEmpty (RegistrationId))
				RegistrationId = PushClient.GetRegistrationId (this.ApplicationContext);
			var trials = 3; 
			var device = UserDevices.First (x => x.Id == dev.Id);
			if (device == null) {
				MyLogger.Error (this.LocalClassName, string.Format ("Device {0} not found. Subscription canceled.", dev.Id));
				return;
			}
			do {
				if (!toSubscribe) {
					if (UnsubscribeForEvent (device, eventType))
						return;	
				} else {
					if (SubscribeForEvent (device, eventType))
						return;
				}
				trials--;
			} while (trials > 0);
			MyLogger.Error (this.LocalClassName, string.Format ("{0} Subscription/Unsubscription failed.", dev));
		}
예제 #9
0
		protected bool UnsubscribeForEvent (Device device, EventType eventType)
		{
			Subscription subscription = Subscriptions.FirstOrDefault (x => x.EntityId == device.Id);
			if (subscription == null)
				return true;
			bool succeed = Client.Delete (subscription);
			MyLogger.Information (this.LocalClassName, string.Format ("Unsubscription: {0} for event type {1} - {2}", device.Id, eventType, succeed ? "Successful" : "Failed"));
			return succeed;
		}
예제 #10
0
		private Subscription SubscribeForEvent (string registrationId, out HttpStatusCode httpStatusCode, out string msg, Device mojioDevice, EventType eventToSubscribe)
		{
			return Client.SubscribeGcm (registrationId, new Subscription () {
				Event = eventToSubscribe,
				EntityId = mojioDevice.Id,
				EntityType = SubscriptionType.Mojio,
			}, out httpStatusCode, out msg);
		}