예제 #1
0
        /**
         * Transfer the required data over to the wearable
         * @param attractions list of attraction data to transfer over
         */
        private void SendDataToWearable(List <Attraction> attractions)
        {
            GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
                                              .AddApi(WearableClass.API)
                                              .Build();

            // It's OK to use blockingConnect() here as we are running in an
            // IntentService that executes work on a separate (background) thread.
            ConnectionResult connectionResult = googleApiClient.BlockingConnect(
                Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.Seconds);

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

            List <DataMap> attractionsData = new List <DataMap>(count);

            for (int i = 0; i < count; i++)
            {
                Attraction attraction = attractions[i];

                Bitmap image          = null;
                Bitmap secondaryImage = null;

                try
                {
                    //TODO:
                    // Fetch and resize attraction image bitmap
                    //image = Glide.with(this)
                    //		.load(attraction.imageUrl)
                    //		.asBitmap()
                    //		.diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    //		.into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    //		.get();

                    //secondaryImage = Glide.with(this)
                    //		.load(attraction.secondaryImageUrl)
                    //		.asBitmap()
                    //		.diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    //		.into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE)
                    //		.get();
                }
                catch (Exception e)
                {
                    Log.Error("UtilityService", "Exception loading bitmap from network");
                }

                if (image != null && secondaryImage != null)
                {
                    DataMap attractionData = new DataMap();

                    string distance = Utils.FormatDistanceBetween(
                        Utils.GetLocation(this), attraction.Location);

                    attractionData.PutString(Constants.EXTRA_TITLE, attraction.Name);
                    attractionData.PutString(Constants.EXTRA_DESCRIPTION, attraction.Description);
                    attractionData.PutDouble(
                        Constants.EXTRA_LOCATION_LAT, attraction.Location.Latitude);
                    attractionData.PutDouble(
                        Constants.EXTRA_LOCATION_LNG, attraction.Location.Longitude);
                    attractionData.PutString(Constants.EXTRA_DISTANCE, distance);
                    attractionData.PutString(Constants.EXTRA_CITY, attraction.City);

                    //TODO:
                    //	attractionData.PutAsset(Constants.EXTRA_IMAGE,
                    //		Utils.CreateAssetFromBitmap(image));
                    //attractionData.PutAsset(Constants.EXTRA_IMAGE_SECONDARY,
                    //		Utils.CreateAssetFromBitmap(secondaryImage));

                    attractionsData.Add(attractionData);
                }
            }

            if (connectionResult.IsSuccess && googleApiClient.IsConnected &&
                attractionsData.Count > 0)
            {
                PutDataMapRequest dataMap = PutDataMapRequest.Create(Constants.ATTRACTION_PATH);
                dataMap.DataMap.PutDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData);
                //TODO:
                //dataMap.DataMap.PutLong(Constants.EXTRA_TIMESTAMP, DateTime.Now.ToFileTime);
                PutDataRequest request = dataMap.AsPutDataRequest();
                request.SetUrgent();

                //TODO: Async/Await
                // Send the data over
                //            var result =
                //					WearableClass.DataApi.PutDataItem(googleApiClient, request));

                //            if (!result.).isSuccess()) {
                //                Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)",
                //                        result.getStatus().getStatusCode()));
                //            }

                //} else {
                //            Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                //                    connectionResult.getErrorCode()));
                //        }
                googleApiClient.Disconnect();
            }
        }
예제 #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            HasOptionsMenu = true;

            var view           = inflater.Inflate(Resource.Layout.fragment_detail, container, false);
            var attractionName = Arguments.GetString(ExtraAttraction);

            Attraction = FindAttraction(attractionName);

            if (Attraction == null)
            {
                Activity.Finish();
                return(null);
            }

            var nameTextView     = view.FindViewById <TextView>(Resource.Id.nameTextView);
            var descTextView     = view.FindViewById <TextView>(Resource.Id.descriptionTextView);
            var distanceTextView = view.FindViewById <TextView>(Resource.Id.distanceTextView);
            var imageView        = view.FindViewById <ImageView>(Resource.Id.imageView);
            var mapFab           = view.FindViewById <FloatingActionButton>(Resource.Id.mapFab);

            var checkInButton = view.FindViewById <Button>(Resource.Id.checkinButton);

            checkInButton.Click += (sender, e) => {
                var detailActivity = (DetailActivity)Activity;
                if (detailActivity.IsFingerPrintReady && detailActivity.InitCipher())
                {
                    var fingerPrintFrag = new FingerprintAuthenticationDialogFragment();
                    fingerPrintFrag.SetCryptoObject(new FingerprintManager.CryptoObject(detailActivity.mCipher));
                    fingerPrintFrag.Show(FragmentManager, "my_frag");
                }
            };

            LatLng location = Utils.GetLocation(Activity);
            //TODO:
            string distance = string.Empty;

            //String distance = Utils.formatDistanceBetween(location, mAttraction.location);
            //if (TextUtils.isEmpty(distance))
            //{
            //	distanceTextView.setVisibility(View.GONE);
            //}

            nameTextView.Text     = attractionName;
            distanceTextView.Text = distance;
            descTextView.Text     = Attraction.LongDescription;

            Koush.UrlImageViewHelper.SetUrlDrawable(imageView, Attraction.ImageUrl.AbsoluteUri);


            //TODO: Glide

            //int imageSize = getResources().getDimensionPixelSize(R.dimen.image_size)
            //   * Constants.IMAGE_ANIM_MULTIPLIER;
            //Glide.with(getActivity())
            //		.load(mAttraction.imageUrl)
            //		.diskCacheStrategy(DiskCacheStrategy.SOURCE)
            //		.placeholder(R.color.lighter_gray)
            //		.override(imageSize, imageSize)
            //             .into(imageView);

            mapFab.Click += (o, e) => {
                var intent = new Intent(Intent.ActionView);
                intent.SetData(Android.Net.Uri.Parse(Constants.MapsIntentUri +
                                                     Android.Net.Uri.Encode(Attraction.Name + ", " + Attraction.City)));
                StartActivity(intent);
            };


            return(view);
        }
예제 #3
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());
        }
예제 #4
0
        int IComparable.CompareTo(object obj)
        {
            Attraction a = (Attraction)obj;

            return(String.Compare(this.Name, a.Name));
        }