Exemple #1
0
        async Task <Asset> CreateWearAssetFrom(Station station)
        {
            var cacheDir = CacheDir.AbsolutePath;
            var file     = Path.Combine(cacheDir, "StationBackgrounds", station.Id.ToString());

            byte[] content = null;
            var    url     = GoogleApis.MakeStreetViewUrl(station.Location, 640, 400);

            try {
                if (!File.Exists(file))
                {
                    if (client == null)
                    {
                        client = new HttpClient();
                    }
                    content = await client.GetByteArrayAsync(url);

                    Directory.CreateDirectory(Path.GetDirectoryName(file));
                    File.WriteAllBytes(file, content);
                }
                else
                {
                    content = File.ReadAllBytes(file);
                }
            } catch (Exception e) {
                e.Data ["URL"] = url;
                Android.Util.Log.Error("StreetViewBackground", e.ToString());
                AnalyticsHelper.LogException("StreetViewBackground", e);
            }

            return(content == null ? null : Asset.CreateFromBytes(content));
        }
Exemple #2
0
 public static GoogleApis Obtain(Context context)
 {
     if (instance == null)
     {
         instance = new GoogleApis(context);
     }
     return(instance);
 }
Exemple #3
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);
        }
Exemple #4
0
		public static GoogleApis Obtain (Context context)
		{
			if (instance == null)
				instance = new GoogleApis (context);
			return instance;
		}