Ejemplo n.º 1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;

            if (view == null)
            {
                var inflater = context.GetSystemService(Context.LayoutInflaterService).JavaCast <LayoutInflater> ();
                view = inflater.Inflate(Resource.Layout.DrawerAroundItem, parent, false);
            }

            var star              = view.FindViewById <ImageView> (Resource.Id.aroundStar);
            var stationName       = view.FindViewById <TextView> (Resource.Id.aroundStation1);
            var stationNameSecond = view.FindViewById <TextView> (Resource.Id.aroundStation2);
            var bikes             = view.FindViewById <TextView> (Resource.Id.aroundBikes);
            var racks             = view.FindViewById <TextView> (Resource.Id.aroundRacks);

            var station = stations [position];

            star.SetImageDrawable(starDrawable);
            star.Visibility = favorites.Contains(station.Id) ? ViewStates.Visible : ViewStates.Invisible;
            string secondPart;

            stationName.Text       = Hubway.CutStationName(station.Name, out secondPart);
            stationNameSecond.Text = secondPart;
            bikes.Text             = station.BikeCount.ToString();
            racks.Text             = station.EmptySlotCount.ToString();

            return(view);
        }
Ejemplo n.º 2
0
        public void OnNext(Station[] value)
        {
            var locPerm = ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation);

            if (locPerm != (int)Permission.Granted)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new[] { Android.Manifest.Permission.AccessFineLocation },
                                                  LocationPermissionRequest);
                return;
            }
            var location = GetCurrentUserLocationAsync().Result;

            if (location == null)
            {
                return;
            }
            var stations = Hubway.GetStationsAround(value,
                                                    new GeoPoint {
                Lat = location.Latitude, Lon = location.Longitude
            },
                                                    minDistance: 1,
                                                    maxItems: 4);

            RunOnUiThread(() => aroundAdapter.SetStations(stations));
        }
Ejemplo n.º 3
0
        public void OnNext(Station[] value)
        {
            if (client == null || !client.IsConnected)
            {
                return;
            }
            var locPerm = ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation);

            if (locPerm != (int)Permission.Granted)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new[] { Android.Manifest.Permission.AccessFineLocation },
                                                  LocationPermissionRequest);
                return;
            }
            var location = LocationServices.FusedLocationApi.GetLastLocation(client);

            if (location == null)
            {
                return;
            }
            var stations = Hubway.GetStationsAround(value,
                                                    new GeoPoint {
                Lat = location.Latitude, Lon = location.Longitude
            },
                                                    minDistance: 1,
                                                    maxItems: 4);

            RunOnUiThread(() => aroundAdapter.SetStations(stations));
        }
Ejemplo n.º 4
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                var r = rentals [position];

                if (r == null)
                {
                    var header = convertView as TextView;
                    if (header == null)
                    {
                        header = MakeHeaderView();
                    }
                    header.Text = rentals [position + 1].Value.DepartureTime.Date.ToLongDateString();
                    return(header);
                }
                else
                {
                    var view = convertView as RentalView;
                    if (view == null)
                    {
                        view = new RentalView(context);
                        view.FindViewById <ImageView> (Resource.Id.bikeImageView)
                        .SetImageDrawable(bikeSeparatorDrawable);
                    }
                    var stationFromText = view.FindViewById <TextView> (Resource.Id.rentalFromStation);
                    var stationToText   = view.FindViewById <TextView> (Resource.Id.rentalToStation);
                    var priceText       = view.FindViewById <TextView> (Resource.Id.rentalPrice);
                    var chronometer     = view.FindViewById <ChronometerView> (Resource.Id.rentalTime);
                    var timePrimary     = view.FindViewById <TextView> (Resource.Id.rentalTimePrimary);
                    var timeSecondary   = view.FindViewById <TextView> (Resource.Id.rentalTimeSecondary);

                    var rental = r.Value;
                    stationFromText.Text = Hubway.CutStationName(rental.FromStationName);
                    stationToText.Text   = Hubway.CutStationName(rental.ToStationName);
                    if (rental.Duration > TimeSpan.FromHours(1))
                    {
                        timePrimary.Text   = rental.Duration.Hours.ToString("D2") + " hrs";
                        timeSecondary.Text = rental.Duration.Minutes.ToString("D2") + " min";
                    }
                    else
                    {
                        timePrimary.Text   = rental.Duration.Minutes.ToString("D2") + " min";
                        timeSecondary.Text = rental.Duration.Seconds.ToString("D2") + " sec";
                    }
                    var color = basePriceColor;
                    if (rental.Price > 0)
                    {
                        color = InterpolateColor(Math.Min(MaxPriceForEnd, rental.Price) / MaxPriceForEnd,
                                                 startPriceColor,
                                                 endPriceColor);
                    }
                    priceText.SetTextColor(color);
                    priceText.Text   = rental.Price.ToString("F2");
                    chronometer.Time = rental.Duration;

                    return(view);
                }
            }
Ejemplo n.º 5
0
		public void OnNext (Station[] value)
		{
			if (client == null || !client.IsConnected)
				return;
			var location = LocationServices.FusedLocationApi.GetLastLocation (client);
			if (location == null)
				return;
			var stations = Hubway.GetStationsAround (value,
				                                     new GeoPoint { Lat = location.Latitude, Lon = location.Longitude },
				                                     minDistance: 1,
				                                     maxItems: 4);
			RunOnUiThread (() => aroundAdapter.SetStations (stations));
		}
Ejemplo n.º 6
0
        async void HandleMessage(IMessageEvent message)
        {
            try {
                Android.Util.Log.Info("WearIntegration", "Received Message");
                var client = new GoogleApiClientBuilder(this)
                             .AddApi(WearableClass.Api)
                             .AddApi(LocationServices.Api)
                             .Build();

                var result = client.BlockingConnect(30, Java.Util.Concurrent.TimeUnit.Seconds);
                if (!result.IsSuccess)
                {
                    return;
                }

                try {
                    var lastLocation = LocationServices.FusedLocationApi.GetLastLocation(client);
                    if (lastLocation == null)
                    {
                        return;
                    }

                    var stations = Hubway.Instance.LastStations;
                    if (stations == null)
                    {
                        stations = await Hubway.Instance.GetStations();
                    }

                    var currentPoint = new GeoPoint {
                        Lat = lastLocation.Latitude,
                        Lon = lastLocation.Longitude
                    };
                    var nearestStations = Hubway.GetStationsAround(stations, currentPoint);

                    using (var stream = new System.IO.MemoryStream()) {
                        GeoUtils.DumpLocation(currentPoint, stream);
                        StationUtils.DumpStations(nearestStations, stream);
                        var bytes = stream.ToArray();
                        WearableClass.MessageApi.SendMessage(client,
                                                             message.SourceNodeId,
                                                             SearchStationPath + "/Answer",
                                                             bytes).Await();
                    }
                } finally {
                    client.Disconnect();
                }
            } catch (Exception e) {
                Android.Util.Log.Error("WearIntegration", e.ToString());
            }
        }
Ejemplo n.º 7
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view    = EnsureView(convertView);
            var version = Interlocked.Increment(ref view.VersionNumber);

            var mapView           = view.FindViewById <ImageView> (Resource.Id.StationMap);
            var stationName       = view.FindViewById <TextView> (Resource.Id.MainStationName);
            var secondStationName = view.FindViewById <TextView> (Resource.Id.SecondStationName);
            var bikeNumber        = view.FindViewById <TextView> (Resource.Id.BikeNumber);
            var slotNumber        = view.FindViewById <TextView> (Resource.Id.SlotNumber);
            var bikeImage         = view.FindViewById <ImageView> (Resource.Id.bikeImageView);

            if (bikePicture == null)
            {
                bikePicture = XamSvg.SvgFactory.GetDrawable(context.Resources, Resource.Raw.bike);
            }
            bikeImage.SetImageDrawable(bikePicture);
            if (mapPlaceholder == null)
            {
                mapPlaceholder = XamSvg.SvgFactory.GetDrawable(context.Resources, Resource.Raw.map_placeholder);
            }
            mapView.SetImageDrawable(mapPlaceholder);

            var station = stations [position];

            view.Station = station;

            string secondPart;

            stationName.Text       = Hubway.CutStationName(station.Name, out secondPart);
            secondStationName.Text = secondPart;
            bikeNumber.Text        = station.BikeCount.ToString();
            slotNumber.Text        = station.Capacity.ToString();

            var    api    = GoogleApis.Obtain(context);
            string mapUrl = GoogleApis.MakeMapUrl(station.Location);
            Bitmap mapBmp = null;

            if (api.MapCache.TryGet(mapUrl, out mapBmp))
            {
                mapView.SetImageDrawable(new RoundCornerDrawable(mapBmp));
            }
            else
            {
                api.LoadMap(station.Location, view, mapView, version);
            }

            return(view);
        }
Ejemplo n.º 8
0
        public void OpenStationWithMarker(Marker marker)
        {
            var name       = pane.FindViewById <TextView> (Resource.Id.InfoViewName);
            var name2      = pane.FindViewById <TextView> (Resource.Id.InfoViewSecondName);
            var bikes      = pane.FindViewById <TextView> (Resource.Id.InfoViewBikeNumber);
            var slots      = pane.FindViewById <TextView> (Resource.Id.InfoViewSlotNumber);
            var starButton = pane.FindViewById <ImageButton> (Resource.Id.StarButton);

            var    splitTitle = marker.Title.Split('|');
            string displayNameSecond;
            var    displayName = Hubway.CutStationName(splitTitle [1], out displayNameSecond);

            name.Text  = displayName;
            name2.Text = displayNameSecond;

            currentShownID     = int.Parse(splitTitle [0]);
            currentShownMarker = marker;

            var isLocked = string.IsNullOrEmpty(marker.Snippet);

            pane.FindViewById(Resource.Id.stationStats).Visibility = isLocked ? ViewStates.Gone : ViewStates.Visible;
            pane.FindViewById(Resource.Id.stationLock).Visibility  = isLocked ? ViewStates.Visible : ViewStates.Gone;
            if (!isLocked)
            {
                var splitNumbers = marker.Snippet.Split('|');
                bikes.Text = splitNumbers [0];
                slots.Text = splitNumbers [1];
            }

            var  favs      = favManager.LastFavorites ?? favManager.GetFavoriteStationIds();
            bool activated = favs.Contains(currentShownID);

            starButton.SetImageDrawable(activated ? starOnDrawable : starOffDrawable);

            var streetView = streetViewFragment.StreetViewPanorama;

            streetView.SetPosition(marker.Position);

            LoadStationHistory(currentShownID);

            pane.SetState(InfoPane.State.Opened);
        }
Ejemplo n.º 9
0
        async void HandleMessage(IMessageEvent message)
        {
            try {
                Android.Util.Log.Info("WearIntegration", "Received Message");
                var client = new GoogleApiClientBuilder(this)
                             .AddApi(LocationServices.API)
                             .AddApi(WearableClass.API)
                             .Build();

                var result = client.BlockingConnect(30, Java.Util.Concurrent.TimeUnit.Seconds);
                if (!result.IsSuccess)
                {
                    return;
                }

                var path = message.Path;

                try {
                    var stations = Hubway.Instance.LastStations;
                    if (stations == null)
                    {
                        stations = await Hubway.Instance.GetStations();
                    }

                    if (path.StartsWith(SearchStationPath))
                    {
                        var lastLocation = LocationServices.FusedLocationApi.GetLastLocation(client);
                        if (lastLocation == null)
                        {
                            return;
                        }

                        var currentPoint = new GeoPoint {
                            Lat = lastLocation.Latitude,
                            Lon = lastLocation.Longitude
                        };
                        var nearestStations = Hubway.GetStationsAround(stations, currentPoint, maxItems: 6, minDistance: double.MaxValue);
                        var favManager      = FavoriteManager.Obtain(this);
                        var favorites       = await favManager.GetFavoriteStationIdsAsync();

                        var request = PutDataMapRequest.Create(SearchStationPath + "/Answer");
                        var map     = request.DataMap;

                        var stationMap = new List <DataMap> ();
                        foreach (var station in nearestStations)
                        {
                            var itemMap = new DataMap();

                            itemMap.PutInt("Id", station.Id);

                            var asset = await CreateWearAssetFrom(station);

                            itemMap.PutAsset("Background", asset);

                            string secondary;
                            string primary = StationUtils.CutStationName(station.Name, out secondary);
                            itemMap.PutString("Primary", primary);
                            itemMap.PutString("Secondary", secondary);

                            var distance = GeoUtils.Distance(currentPoint, station.Location);
                            itemMap.PutDouble("Distance", distance);
                            itemMap.PutDouble("Lat", station.Location.Lat);
                            itemMap.PutDouble("Lon", station.Location.Lon);

                            itemMap.PutInt("Bikes", station.BikeCount);
                            itemMap.PutInt("Racks", station.EmptySlotCount);

                            itemMap.PutBoolean("IsFavorite", favorites.Contains(station.Id));

                            stationMap.Add(itemMap);
                        }
                        map.PutDataMapArrayList("Stations", stationMap);
                        map.PutLong("UpdatedAt", DateTime.UtcNow.Ticks);

                        await WearableClass.DataApi.PutDataItem(client, request.AsPutDataRequest());
                    }
                    else
                    {
                        var uri   = new Uri("wear://watch" + path);
                        var query = uri.GetComponents(UriComponents.Query, UriFormat.Unescaped);
                        var parts = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped).Split('/');

                        var action = parts[parts.Length - 2];
                        var id     = int.Parse(parts.Last());

                        if (action == FavoriteAction)
                        {
                            var favorites = FavoriteManager.Obtain(this);
                            handler.Post(() => {
                                if (query == "add")
                                {
                                    favorites.AddToFavorite(id);
                                }
                                else
                                {
                                    favorites.RemoveFromFavorite(id);
                                }
                            });
                        }
                    }
                } finally {
                    client.Disconnect();
                }
            } catch (Exception e) {
                Android.Util.Log.Error("WearIntegration", e.ToString());
                AnalyticsHelper.LogException("WearIntegration", e);
            }
        }