Пример #1
0
        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            var count = status == BikeActionStatus.Stop ? station.BikeCount : station.EmptySlotCount;
            var ratio = ((float)count) / station.Capacity;
            var color = InterpolateColor(Color.Rgb(0xff, 0x44, 0x44),
                                         Color.Rgb(0x99, 0xcc, 0x00),
                                         ratio);
            var bg = new RoundRectDrawable(color, TypedValue.ApplyDimension(ComplexUnitType.Dip, 2, view.Resources.DisplayMetrics));

            var countText = view.FindViewById <TextView> (Resource.Id.count);

            countText.Text = count.ToString();
            countText.SetBackgroundDrawable(bg);

            string secondary;
            var    primary = StationUtils.CutStationName(station.Name, out secondary);

            view.FindViewById <TextView> (Resource.Id.stationPrimary).Text   = primary;
            view.FindViewById <TextView> (Resource.Id.stationSecondary).Text = secondary;

            var distance     = GeoUtils.Distance(currentLocation, station.Location);
            var distanceText = view.FindViewById <TextView> (Resource.Id.distance);

            if (distance < 1)
            {
                distanceText.Text = (distance * 1000).ToString("N0") + " meters";
            }
            else
            {
                distanceText.Text = distance.ToString("N1") + " km";
            }
        }
Пример #2
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 = StationUtils.CutStationName(rental.FromStationName);
                    stationToText.Text   = StationUtils.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);
                }
            }