public void OnItemClick(int position, View view)
 {
     if (!AttractionListFragment.IsItemClicked)
     {
         AttractionListFragment.IsItemClicked = true;
         var heroView = view.FindViewById <ImageView>(Android.Resource.Id.Icon);
         DetailActivity.Launch(
             (Activity)context, attractions[position].Name, heroView);
     }
 }
예제 #2
0
        private void ShowNotification(string cityId, bool microApp)
        {
            var attractions = TouristAttractionsHelper.Attractions[cityId];

            if (microApp)
            {
                //TODO:
                // If micro app we first need to transfer some data over
                //sendDataToWearable(attractions);
            }

            // The first (closest) tourist attraction
            Attraction attraction = attractions[0];

            // Limit attractions to send
            int count = (attractions.Count) > Constants.MAX_ATTRACTIONS ?
                        Constants.MAX_ATTRACTIONS : attractions.Count;

            // Pull down the tourist attraction images from the network and store
            var bitmaps = new Dictionary <string, Bitmap>();

            try
            {
                for (int i = 0; i < count; i++)
                {
                    //TODO:
                    //bitmaps.Put(attractions[i].Name,
                    //		Glide.with(this)
                    //				.load(attractions.get(i).imageUrl)
                    //				.asBitmap()
                    //				.diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    //				.into(Constants.WEAR_IMAGE_SIZE, Constants.WEAR_IMAGE_SIZE)
                    //				.get());

                    var bm = Koush.UrlImageViewHelper.GetCachedBitmap(attractions[i].ImageUrl.AbsoluteUri);
                    bitmaps.Add(attractions[i].Name, bm);
                }
            }
            catch (Exception e)
            {
                Log.Error("UtilityService", "Error fetching image from network: " + e);
            }

            // The intent to trigger when the notification is tapped
            PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0,
                                                                    DetailActivity.GetLaunchIntent(this, attraction.Name),
                                                                    PendingIntentFlags.UpdateCurrent);

            // The intent to trigger when the notification is dismissed, in this case
            // we want to clear remote notifications as well
            PendingIntent deletePendingIntent =
                PendingIntent.GetService(this, 0, GetClearRemoteNotificationsIntent(this), 0);

            // Construct the main notification
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 .SetStyle(new NotificationCompat.BigPictureStyle()
                                                           .BigPicture(bitmaps[attraction.Name])
                                                           .SetBigContentTitle(attraction.Name)
                                                           .SetSummaryText(GetString(Resource.String.nearby_attraction))
                                                           )
                                                 .SetLocalOnly(microApp)
                                                 .SetContentTitle(attraction.Name)
                                                 .SetContentText(GetString(Resource.String.nearby_attraction))
                                                 .SetSmallIcon(Resource.Drawable.ic_stat_maps_pin_drop)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetDeleteIntent(deletePendingIntent)
                                                 .SetColor(Resources.GetColor(Resource.Color.colorPrimary, Theme))
                                                 .SetCategory(Notification.CategoryRecommendation)
                                                 .SetAutoCancel(true);

            if (!microApp)
            {
                // If not a micro app, create some wearable pages for
                // the other nearby tourist attractions.
                List <Notification> pages = new List <Notification>();
                for (int i = 1; i < count; i++)
                {
                    // Calculate the distance from current location to tourist attraction
                    String distance = Utils.FormatDistanceBetween(
                        Utils.GetLocation(this), attractions[i].Location);

                    // Construct the notification and add it as a page
                    pages.Add(new NotificationCompat.Builder(this)
                              .SetContentTitle(attractions[i].Name)
                              .SetContentText(distance)
                              .SetSmallIcon(Resource.Drawable.ic_stat_maps_pin_drop)
                              .Extend(new NotificationCompat.WearableExtender()
                                      .SetBackground(bitmaps[attractions[i].Name])
                                      )
                              .Build());
                }
                builder.Extend(new NotificationCompat.WearableExtender().AddPages(pages));
            }

            // Trigger the notification
            NotificationManagerCompat.From(this).Notify(
                Constants.MOBILE_NOTIFICATION_ID, builder.Build());
        }