Exemplo n.º 1
0
        static TrackMeApp()
        {
            WebService = new LocationService ();
            WebService.Url = "http://ideary.com:8080/LocationService.asmx";

            var userId = Android.Provider.Settings.Secure.GetString(Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
            var userName = "******";

            LoadConfiguration ();

            try {
                GCMRegistrar.CheckDevice (Application.Context);
                GCMRegistrar.CheckManifest (Application.Context);
                var regId = GCMRegistrar.GetRegistrationId (Application.Context);
                if (regId == "")
                    GCMRegistrar.Register (Application.Context, GCMIntentService.SenderId);
                else
                    Console.WriteLine ("GCM client already registered: " + regId);
            } catch (Exception ex) {
                Console.WriteLine (ex);
            }

            LocalUser = new UserInfo () {
                Name = userName,
                Id = userId,
                RegistrationId = GCMRegistrar.GetRegistrationId (Application.Context)
            };

            Application.Context.RegisterReceiver (new LocalBroadcastReceiver (), new IntentFilter (GCMIntentService.BroadcastAction));

            System.Threading.ThreadPool.QueueUserWorkItem (delegate {
                var trackedShares = WebService.GetTrackedShares (TrackMeApp.LocalUser.Id);
                var shares = WebService.GetActiveShares (TrackMeApp.LocalUser.Id);
                lock (StatusLock) {
                    Targets.Clear ();
                    Targets.AddRange (trackedShares);
                    Shares.Clear ();
                    Shares.AddRange (shares);
                    NotifySharesChanged ();
                    NotifyTrackedSharesChanged ();
                }
            });
        }
Exemplo n.º 2
0
        internal static void ProcessBroadcastIntent(Intent intent)
        {
            LogService.Log ("Processing broadcast intent: " + intent.Extras);

            var not = AppNotification.ReadNotification (intent);

            if (not is TargetChangedNotification) {
                var tn = (TargetChangedNotification) not;
                var t = Targets.FirstOrDefault (tr => tr.Id == tn.ShareId);
                if (t != null) {
                    t.Latitude = tn.Latitude;
                    t.Longitude = tn.Longitude;
                }
                NotifyTrackedSharesChanged ();
            }

            if (not is TrackerAddedNotification) {
                var tn = (TrackerAddedNotification) not;
                try {
                    var t = WebService.GetTrackerInfo (tn.ShareId, tn.TrackerId);
                    if (t != null) {
                        lock (StatusLock) {
                            var sh = Shares.FirstOrDefault (s => s.PrivateId == tn.ShareId);
                            if (sh != null) {
                                var arr = sh.Trackers;
                                if (arr != null) {
                                    Array.Resize (ref arr, arr.Length + 1);
                                } else
                                    arr = new UserInfo[1];
                                arr [arr.Length - 1] = t;
                                sh.Trackers = arr;
                            }
                        }
                    }
                    NotifySharesChanged ();
                } catch (Exception ex) {
                    LogService.LogError (ex);
                }
            }
        }