protected override void OnLayout (bool changed, int l, int t, int r, int b)
		{
			base.OnLayout (changed, l, t, r, b);
			if (changed) {
				var drawables = Control.GetCompoundDrawables ();
				if (drawables [0] != null) {
					Rect drawableBounds = new Rect ();
					drawables [0].CopyBounds (drawableBounds);
					int leftOffset = ((Control.Width - Control.PaddingLeft - Control.PaddingRight) - drawableBounds.Width ()) / 2;
					drawableBounds.Offset (leftOffset, 0);
					drawables [0].SetBounds (drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
				}
			}
		}
        private void InitCells() 
        {
            _calendar[,] tmp = new _calendar[6,7];

            for (int i = 0; i < tmp.GetUpperBound(0); i++)
            {
                int[] n = mHelper.GetDigitsForRow(i);
                for(int d=0; d<n.Length; d++)
                {
                    if(mHelper.IsWithinCurrentMonth(i, d))
                        tmp[i,d] = new _calendar(n[d], true);
                    else
                        tmp[i,d] = new _calendar(n[d]);        
                }
            }

            DateTime today = DateTime.Now;
            int thisDay = 0;
            mToday = null;
            if(mHelper.Year == today.Year && mHelper.Month == today.Month)
                thisDay = today.Day;

            // build cells
            Rect Bound = new Rect(CELL_MARGIN_LEFT, CELL_MARGIN_TOP, CELL_WIDTH+CELL_MARGIN_LEFT, CELL_HEIGH+CELL_MARGIN_TOP);

            int bound0 = mCells.GetUpperBound(0);
            int bound1 = mCells.GetUpperBound(1);
            for (int week = 0; week < bound0; week++)
            {
                for (int day = 0; day < bound1; day++)
                {
                        if(tmp[week,day].thisMonth) {
                                if(day==0 || day==6 )
                                        mCells[week,day] = new RedCell(tmp[week,day].day, new Rect(Bound), CELL_TEXT_SIZE);
                                else 
                                        mCells[week,day] = new Cell(tmp[week,day].day, new Rect(Bound), CELL_TEXT_SIZE);
                        } else {
                                mCells[week,day] = new GrayCell(tmp[week,day].day, new Rect(Bound), CELL_TEXT_SIZE);
                        }
                                
                        Bound.Offset(CELL_WIDTH, 0); // move to next column 
                                
                        // get today
                        if(tmp[week,day].day==thisDay && tmp[week,day].thisMonth) {
                                mToday = mCells[week,day];
                                mDecoration.SetBounds(mToday.Bounds.Left, mToday.Bounds.Top, mToday.Bounds.Right, mToday.Bounds.Bottom);
                        }
                }
                Bound.Offset(0, CELL_HEIGH); // move to next row and first column
                Bound.Left = CELL_MARGIN_LEFT;
                Bound.Right = CELL_MARGIN_LEFT+CELL_WIDTH;
            }
        }
示例#3
0
        private void drawPlaces(Canvas canvas, double pixelsPerDegree, double offset) 
        {
            try
            {
                if (OrientationManager.HasLocation && NearbyPlaces != null)
                {
                    lock (NearbyPlaces)
                    {
                        var userLocation = OrientationManager.Location;
                        var latitude1 = userLocation.Latitude;
                        var longitude1 = userLocation.Longitude;

                        _allBounds.Clear();


                        // Loop over the list of nearby places (those within 10 km of the user's current
                        // location), and compute the relative bearing from the user's location to the
                        // place's location. This determines the position on the compass view where the
                        // pin will be drawn.
                        foreach (var place in NearbyPlaces)
                        {
                            var latitude2 = place.Latitiude;
                            var longitude2 = place.Longitude;
                            var bearing = MathUtils.getBearing(latitude1, longitude1, latitude2, longitude2);

                            var name = place.Name;
                            var distanceKm = MathUtils.getDistance(latitude1, longitude1, latitude2, longitude2);
                            var text = this.Context.Resources.GetString(
                                Resource.String.place_text_format, name, _distanceFormat.Format(distanceKm));

                            // Measure the text and offset the text bounds to the location where the text
                            // will finally be drawn.
                            var textBounds = new Rect();
                            _placePaint.GetTextBounds(text, 0, text.Length, textBounds);
                            textBounds.OffsetTo((int)(offset + bearing * pixelsPerDegree
                                    + PLACE_PIN_WIDTH / 2 + PLACE_TEXT_MARGIN), canvas.Height / 2
                                    - (int)PLACE_TEXT_HEIGHT);

                            // Extend the bounds rectangle to include the pin icon and a small margin
                            // to the right of the text, for the overlap calculations below.
                            textBounds.Left -= (int)(PLACE_PIN_WIDTH + PLACE_TEXT_MARGIN);
                            textBounds.Right += (int)PLACE_TEXT_MARGIN;

                            // This loop attempts to find the best vertical position for the string by
                            // starting at the bottom of the display and checking to see if it overlaps
                            // with any other labels that were already drawn. If there is an overlap, we
                            // move up and check again, repeating this process until we find a vertical
                            // position where there is no overlap, or when we reach the limit on
                            // overlapping place names.
                            bool intersects;
                            var numberOfTries = 0;
                            do
                            {
                                intersects = false;
                                numberOfTries++;
                                textBounds.Offset(0, (int)-(PLACE_TEXT_HEIGHT + PLACE_TEXT_LEADING));

                                foreach (var existing in _allBounds)
                                {
                                    if (Rect.Intersects(existing, textBounds))
                                    {
                                        intersects = true;
                                        break;
                                    }
                                }
                            } while (intersects && numberOfTries <= MAX_OVERLAPPING_PLACE_NAMES);

                            // Only draw the string if it would not go high enough to overlap the compass
                            // directions. This means some places may not be drawn, even if they're nearby.
                            if (numberOfTries <= MAX_OVERLAPPING_PLACE_NAMES)
                            {
                                _allBounds.Add(textBounds);

                                canvas.DrawBitmap(_placeBitmap, (float)(offset + bearing * pixelsPerDegree - PLACE_PIN_WIDTH / 2), textBounds.Top + 2, _paint);
                                canvas.DrawText(
                                    text,
                                    (float)(offset + bearing * pixelsPerDegree + PLACE_PIN_WIDTH / 2 + PLACE_TEXT_MARGIN),
                                    (float)(textBounds.Top + PLACE_TEXT_HEIGHT),
                                    _placePaint);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("Exception", e.Message);
            }
        }
 private static Rect getChildViewRect(View parentView, View childView)
 {
     Rect childRect = new Rect(childView.Left, childView.Top, childView.Right, childView.Bottom);
     if (!parentView.Equals(childView))
     {
         View workingChildView = childView;
         ViewGroup parent;
         while (!(parent = (ViewGroup)workingChildView.Parent).Equals(parentView))
         {
             childRect.Offset(parent.Left, parent.Top);
             workingChildView = parent;
         }
     }
     return childRect;
 }
示例#5
0
        /// <summary>
        ///   The event handler for the thumbnails. Called when they are clicked, it display
        ///   the full sized image, animating the transition from thumbnail to full sized image.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void ZoomImageFromThumb(object sender, EventArgs eventArgs)
        {
            View thumbView = (View)sender;
            ImageView expandedImageView = GetExpandedImageView(thumbView);

            if (_currentAnimator != null)
            {
                _currentAnimator.Cancel();
            }
            Rect startBounds = new Rect();
            Rect finalBounds = new Rect();
            Point globalOffset = new Point();

            // The start bounds are the global visible rectangle of the thumbnail
            thumbView.GetGlobalVisibleRect(startBounds);

            // The final bounds are the global visible rectangle of the container view. Also
            // set the container view's offset as the origin for the bounds, since that's
            // the origin for the positioning animation properties (X, Y).
            FindViewById(Resource.Id.container).GetGlobalVisibleRect(finalBounds, globalOffset);
            startBounds.Offset(-globalOffset.X, -globalOffset.Y);
            finalBounds.Offset(-globalOffset.X, -globalOffset.Y);

            float startScale = CalculateStartScale(startBounds, finalBounds);

            // Construct and run the parallel animation of the four translation and scale properties
            // (X, Y, SCALE_X, and SCALE_Y).
            AnimatorSet expandSet = BuildExpandingAnimatorSet(expandedImageView, startBounds, finalBounds, startScale);
            expandSet.Start();
            _currentAnimator = expandSet;

            // Upon clicking the zoomed image, it should zoom back down to the original bounds
            // and show the thumbnail instead of the expanded image.
            expandedImageView.Click += (o, args) =>{
                if (_currentAnimator != null)
                {
                    _currentAnimator.Cancel();
                }

                AnimatorSet shrinkSet = BuildShrinkingAnimatorSet(expandedImageView, thumbView, startBounds, startScale);
                shrinkSet.Start();
                _currentAnimator = shrinkSet;
            };
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if (Control.GetCompoundDrawables() != null && BaseElement.CenterImage)
            {
                var text            = Control.Text;
                int iconTextSpacing = 0;

                if (!string.IsNullOrWhiteSpace(text))
                {
                    TextPaint textPaint = Control.Paint;
                    textPaint.GetTextBounds(text, 0, text.Length, textBounds);
                    iconTextSpacing = 20;
                }
                else
                {
                    textBounds.SetEmpty();
                }

                int width = Control.Width - (Control.PaddingLeft + Control.PaddingRight);

                Drawable[] drawables = Control.GetCompoundDrawables();

                if (drawables[0] != null)
                {
                    drawables[0].CopyBounds(drawableBounds);

                    int leftOffset =
                        (width - (textBounds.Width() + drawableBounds.Width())) / 2 - Control.CompoundDrawablePadding - iconTextSpacing;

                    if (drawableBounds.Left == 0 && drawableBounds.Left != leftOffset)
                    {
                        drawableBounds.Offset(leftOffset, 0);
                        drawables[0].SetBounds(drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
                    }
                }

                if (drawables[2] != null)
                {
                    drawables[2].CopyBounds(drawableBounds);

                    int rightOffset =
                        ((textBounds.Width() + drawableBounds.Width()) - width) / 2 + Control.CompoundDrawablePadding + iconTextSpacing;

                    if (drawableBounds.Left == 0 && drawableBounds.Right != rightOffset)
                    {
                        drawableBounds.Offset(rightOffset, 0);
                        drawables[2].SetBounds(drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
                    }
                }
            }


            //if (Control.GetCompoundDrawables() != null)
            //{
            //    if (BaseElement.CenterImage)
            //    {
            //        var imageRight = Control.GetCompoundDrawables()[2];
            //        if (imageRight != null)
            //        {
            //            var drawableBounds = new Android.Graphics.Rect();
            //            imageRight.CopyBounds(drawableBounds);
            //            SetImagePadding(drawableBounds.Width());
            //        }

            //        var imageLeft = Control.GetCompoundDrawables()[0];
            //        if (imageLeft != null)
            //        {
            //            var drawableBounds = new Android.Graphics.Rect();
            //            imageLeft.CopyBounds(drawableBounds);
            //            SetImagePadding(drawableBounds.Width());
            //        }
            //    }
            //}
        }