예제 #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var mapView = base.OnCreateView(inflater, container, savedInstanceState);

            try
            {
                // tags: GoogleMapCompass (id 4)
                // GoogleMapMyLocationButton
                var       compassView = mapView.FindViewWithTag("GoogleMapCompass");
                ViewGroup parent      = (ViewGroup)compassView.Parent;

                RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams)compassView.LayoutParameters;
                // position on top right
                rlp.AddRule(LayoutRules.AlignParentEnd);
                rlp.RemoveRule(LayoutRules.AlignParentStart);
                rlp.RightMargin = (int)LayoutHelper.ConvertDpToPixel(20);
                rlp.TopMargin   = (int)LayoutHelper.ConvertDpToPixel(155);

                compassView.RequestLayout();
                // listen to click on compass to stop compass mode
                compassView.SetOnClickListener(new CompassClickListener());

                //ViewGroup parent = (ViewGroup)mapView.FindViewWithTag("GoogleMapMyLocationButton").Parent;
                //for (int i = 0, n = parent.ChildCount; i < n; i++)
                //{
                //    View view = parent.GetChildAt(i);
                //    System.Diagnostics.Debug.WriteLine(i);
                //    System.Diagnostics.Debug.WriteLine(view.Tag);
                //    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams)view.LayoutParameters;
                //    // position on top right
                //    rlp.AddRule(LayoutRules.AlignParentLeft, 0);
                //    rlp.AddRule(LayoutRules.AlignParentTop,0);
                //    rlp.AddRule(LayoutRules.AlignParentRight);
                //    rlp.AddRule(LayoutRules.AlignParentBottom);
                //    rlp.RightMargin = rlp.LeftMargin;
                //    rlp.TopMargin = 25;
                //    view.RequestLayout();
                //}
            }
            catch
            {
                // ignore
            }

            // enable a way to detect when the user is actually moving the map to unstick to the current user location for instance
            touchView = new TouchableWrapper(CrossCurrentActivity.Current.Activity);
            touchView.AddView(mapView);
            return(touchView);
        }
예제 #2
0
        /// <summary>
        /// Helper method to provide the corresponding Icon for a station
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public BitmapDescriptor CreateStationIcon(Station station)
        {
            Bitmap bitmap       = null;
            var    value        = _settingsService.Settings.IsBikeMode ? station.AvailableBikes : station.AvailableBikeStands;
            var    printedValue = value.HasValue ? value.Value.ToString() : string.Empty;

            if (!station.Loaded)
            {
                printedValue = string.Empty;
                bitmap       = _iconGreyLowAlpha;
                bitmap       = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.Status == false)
            {
                printedValue = "!";
                bitmap       = _iconGrey;
                bitmap       = bitmap.Copy(bitmap.GetConfig(), true);
            }
            else if (station.ImageAvailable != null || station.ImageDocks != null)
            {
                if (_metrics == null)
                {
                    _metrics = new DisplayMetrics();
                    (CrossCurrentActivity.Current.Activity as MainActivity).WindowManager.DefaultDisplay.GetMetrics(_metrics);
                }

                bitmap = _iconGrey;
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                try
                {
                    var data       = (byte[])(_settingsService.Settings.IsBikeMode ? station.ImageAvailable : station.ImageDocks);
                    var gifDecoder = new GifDecoder();
                    gifDecoder.read(data);
                    if (gifDecoder.getFrameCount() != 0)
                    {
                        gifDecoder.advance();
                        var bmp    = gifDecoder.getNextFrame();
                        var canvas = new Canvas(bitmap);

                        int   width       = bmp.Width;
                        int   height      = bmp.Height;
                        float scaleWidth  = _metrics.ScaledDensity;
                        float scaleHeight = _metrics.ScaledDensity;
                        // create a matrix for the scaling manipulation
                        Matrix matrix = new Matrix();
                        // resize the bitmap
                        matrix.PostScale(scaleWidth, scaleHeight);

                        // recreate the new Bitmap
                        var resizedBitmap = Bitmap.CreateBitmap(bmp, 0, 0, width, height, matrix, true);

                        int xPos = canvas.Width / 2 - resizedBitmap.Width / 2;
                        int yPos = canvas.Height / 2 - resizedBitmap.Height;
                        canvas.DrawBitmap(resizedBitmap, xPos, yPos, null);
                    }
                }
                catch (System.Exception e)
                {
                }
            }
            else
            {
                if (value == 0)
                {
                    bitmap = _iconRed;
                }
                else if (value < 5)
                {
                    bitmap = _iconOrange;
                }
                else if (value >= 5)
                {
                    bitmap = _iconGreen;
                }
                else
                {
                    printedValue = "?";
                    bitmap       = _iconGrey;
                }
            }

            if (printedValue != string.Empty)
            {
                bitmap = bitmap.Copy(bitmap.GetConfig(), true);
                Canvas canvas = new Canvas(bitmap);
                int    xPos   = (canvas.Width / 2);
                int    yPos   = (int)((canvas.Height / 2) - ((_textPaint.Descent() + _textPaint.Ascent()) / 2));
                canvas.DrawText(printedValue, xPos + 1, yPos - LayoutHelper.ConvertDpToPixel(6), _textPaint);
            }

            var icon = BitmapDescriptorFactory.FromBitmap(bitmap);

            bitmap.Recycle();
            return(icon);
        }