Ejemplo n.º 1
0
		public HubwayMapFragment (Context context)
		{
			MapsInitializer.Initialize (context);
			this.pinFactory = new PinFactory (context);
			this.favManager = FavoriteManager.Obtain (context);
			HasOptionsMenu = true;
		}
Ejemplo n.º 2
0
		public InfoWindowAdapter (Context context)
		{
			this.context = context;
			this.favManager = new FavoriteManager (context);
			bikeDrawable = SvgUtils.GetDrawableFromSvgRes (context.Resources, Resource.Raw.bike);
			lockDrawable = SvgUtils.GetDrawableFromSvgRes (context.Resources, Resource.Raw.ic_lock);
			starOnDrawable = SvgUtils.GetDrawableFromSvgRes (context.Resources, Resource.Raw.star_on);
			starOffDrawable = SvgUtils.GetDrawableFromSvgRes (context.Resources, Resource.Raw.star_off);
		}
Ejemplo n.º 3
0
		public override void OnActivityCreated (Bundle savedInstanceState)
		{
			base.OnActivityCreated (savedInstanceState);
			this.favManager = FavoriteManager.Obtain (Activity);
			ListAdapter = this.adapter = new FavoriteAdapter (Activity);

			if (refreshRequested) {
				refreshRequested = false;
				RefreshData ();
			}
		}
Ejemplo n.º 4
0
 public static FavoriteManager Obtain(Context context)
 {
     return(instance ?? (instance = new FavoriteManager(context)));
 }
Ejemplo n.º 5
0
 public FavoriteFragment(Context context, Action <long> stationShower)
 {
     this.stationShower = stationShower;
     this.favManager    = FavoriteManager.Obtain(context);
     ListAdapter        = this.adapter = new FavoriteAdapter(context);
 }
Ejemplo n.º 6
0
		public override void OnActivityCreated (Bundle savedInstanceState)
		{
			base.OnActivityCreated (savedInstanceState);

			var context = Activity;
			this.pinFactory = new PinFactory (context);
			this.favManager = FavoriteManager.Obtain (context);
		}
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
		public FavoriteFragment (Context context, Action<long> stationShower)
		{
			this.stationShower = stationShower;
			this.favManager = FavoriteManager.Obtain (context);
			ListAdapter = this.adapter = new FavoriteAdapter (context);
		}
Ejemplo n.º 9
0
		public static FavoriteManager Obtain (Context context)
		{
			return instance ?? (instance = new FavoriteManager (context));
		}