Esempio n. 1
0
        public void QuakeDataSourceNewQuake(Quake quake)
        {
            var quakeIntent = new Intent(NewQuakeDetectedAction);

            quakeIntent.PutExtra("quake", quake.toJson());

            SendOrderedBroadcast(quakeIntent, null);
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(savedInstanceState);

            try
            {
                Log.Info(TAG, "Hello world");

                Intent serviceToStart = new Intent(this, typeof(QuakeService));

                StartService(serviceToStart);

                //quakeServiceIntent = new Intent("uk.co.fixsolutions.QuakeService");
                quakeServiceIntent = new Intent(this, typeof(QuakeService));

                quakeReceiver = new QuakeReceiver(this);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);

                lv            = FindViewById <ListView>(Resource.Id.listView1);
                listAdapter   = new AndroidQuakeAdapter(this);
                lv.Adapter    = listAdapter;
                lv.ItemClick += (sender, e) => {
                    int    pos = e.Position;
                    string msg = "item=" + pos;
                    Android.Widget.Toast.MakeText(this, msg, Android.Widget.ToastLength.Short).Show();

                    Quake quake = getQuakeDataSource().getQuake(pos);

                    //var url = "geo:" + quake.Coordinates.Latitude + "," + quake.Coordinates.Longitude + "?z=10";
                    //var geoUri = Android.Net.Uri.Parse (url);
                    //var mapIntent = new Intent (Intent.ActionView, geoUri);
                    //StartActivity (mapIntent);

                    var intent = new Intent(this, typeof(QuakeDetailActivity));
                    intent.PutExtra("quake", quake.toJson());

                    StartActivity(intent);
                };
            }
            catch (Exception e)
            {
                Log.Error(TAG, "Error: " + e.ToString());
            }
        }
Esempio n. 3
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action.Equals(QuakeService.NewQuakeDetectedAction))
            {
                var   json  = intent.GetStringExtra("quake");
                Quake quake = new Quake(json);

                var nMgr         = (NotificationManager)context.GetSystemService(Context.NotificationService);
                var detailIntent = new Intent(context, typeof(QuakeDetailActivity));
                detailIntent.PutExtra("quake", quake.toJson());
                var pendingIntent = PendingIntent.GetActivity(context, 0, detailIntent, 0);

                Android.App.Notification.Builder builder = new Notification.Builder(context);

                builder.SetContentTitle("New Earthquake");
                builder.SetContentText(quake.ToString());
                builder.SetContentIntent(pendingIntent);
                builder.SetSmallIcon(Resource.Drawable.Icon);
                builder.SetAutoCancel(true);                    // This means it will cancel when user clicks on it.

                var notification = builder.Build();
                nMgr.Notify(0, notification);
            }
        }