void AdjustTextBounds(NMapView mapView)
        {
            //  Determine the screen coordinates of the selected MapLocation
            mapView.MapProjection.ToPixels(MOverlayItem.PointInUtmk, MTempPoint);

            var title = MOverlayItem.Title;

            mTextPaint.GetTextBounds(title, 0, title.Length, MTempRect);

            //  Setup the callout with the appropriate size & location
            MTempRectF.Set(MTempRect);
            MTempRectF.Inset(-CALLOUT_TEXT_PADDING_X, -CALLOUT_TEXT_PADDING_Y);
            mOffsetX = MTempPoint.X - MTempRect.Width() / 2;
            mOffsetY = MTempPoint.Y - MTempRect.Height() - MItemBounds.Height() - CALLOUT_TEXT_PADDING_Y;
            MTempRectF.Offset(mOffsetX, mOffsetY);
        }
Example #2
0
        void AdjustTextBounds(NMapView mapView)
        {
            //  First determine the screen coordinates of the selected MapLocation
            mapView.MapProjection.ToPixels(MOverlayItem.PointInUtmk, MTempPoint);

            int mapViewWidth = mapView.MapController.ViewFrameVisibleWidth;

            if (mTitleTruncated == null || mWidthTitleTruncated != mapViewWidth)
            {
                mWidthTitleTruncated = mapViewWidth;
                float maxWidth = mWidthTitleTruncated - 2 * mMarginX - 2 * mPaddingX;
                if (DEBUG)
                {
                    Log.Info(LOG_TAG, "adjustTextBounds: maxWidth=" + maxWidth + ", mMarginX=" + mMarginX + ", mPaddingX="
                             + mPaddingX);
                }

                if (mDrawableRightButton != null)
                {
                    maxWidth -= mPaddingX + mCalloutRightButtonWidth;
                }

                if (mTailText != null)
                {
                    mTextPaint.GetTextBounds(mTailText, 0, mTailText.Length, MTempRect);
                    mTailTextWidth = MTempRect.Width();

                    maxWidth -= mTailGapX + mTailTextWidth;
                }

                var title = TextUtils.Ellipsize(MOverlayItem.Title, mTextPaint, maxWidth,
                                                TextUtils.TruncateAt.End).ToString();

                mTitleTruncated = title;

                if (DEBUG)
                {
                    Log.Info(LOG_TAG, "adjustTextBounds: mTitleTruncated=" + mTitleTruncated + ", length="
                             + mTitleTruncated.Length);
                }
            }

            mTextPaint.GetTextBounds(mTitleTruncated, 0, mTitleTruncated.Length, MTempRect);

            if (mDrawableRightButton != null)
            {
                MTempRect.Right += (int)(mPaddingX + mCalloutRightButtonWidth);
            }

            if (mTailText != null)
            {
                MTempRect.Right += (int)(mTailGapX + mTailTextWidth);
            }

            if (DEBUG)
            {
                Log.Info(LOG_TAG, "adjustTextBounds: mTempRect.width=" + MTempRect.Width() + ", mTempRect.height="
                         + MTempRect.Height());
            }

            //  Setup the callout with the right size & location
            MTempRectF.Set(MTempRect);
            var dy = (mBackgroundHeight - MTempRect.Height()) / 2;

            MTempRectF.Inset(-mPaddingX, -dy);
            //mTempRectF.inset(-mPaddingX, -mPaddingY);

            // set minimum size
            if (MTempRectF.Width() < mMinimumWidth)
            {
                var dx = (mMinimumWidth - MTempRectF.Width()) / 2;
                MTempRectF.Inset(-dx, 0);
            }

            // set position
            float left = MTempPoint.X - (int)(MTempRectF.Width() * MOverlayItem.AnchorXRatio);
            float top  = MTempPoint.Y - (int)(MItemBounds.Height() * MOverlayItem.AnchorYRatio) - mItemGapY - mTotalHeight;

            MTempRectF.Set(left, top, left + MTempRectF.Width(), top + MTempRectF.Height());
        }
Example #3
0
        protected override void DrawCallout(Canvas canvas, NMapView mapView, bool shadow, long when)
        {
            AdjustTextBounds(mapView);

            StepAnimations(canvas, mapView, when);

            DrawBackground(canvas);

            float left, top;

            // draw title
            mOffsetX  = MTempPoint.X - MTempRect.Width() / 2;
            mOffsetX -= mPaddingOffset;
            mOffsetY  = MTempRectF.Top + mPaddingY + mTextPaint.TextSize + mTitleOffsetY;
            canvas.DrawText(mTitleTruncated, mOffsetX, mOffsetY, mTextPaint);

            // draw right button
            if (mDrawableRightButton != null)
            {
                left = MTempRectF.Right - mPaddingX - mCalloutRightButtonWidth;
                top  = MTempRectF.Top + (mBackgroundHeight - mCalloutRightButtonHeight) / 2;

                // Use background drawables depends on current state
                mRightButtonRect.Left   = (int)(left + 0.5F);
                mRightButtonRect.Top    = (int)(top + 0.5F);
                mRightButtonRect.Right  = (int)(left + mCalloutRightButtonWidth + 0.5F);
                mRightButtonRect.Bottom = (int)(top + mCalloutRightButtonHeight + 0.5F);

                int      itemState = base.GetItemState(0);
                Drawable drawable  = GetDrawable(0, itemState);
                if (drawable != null)
                {
                    drawable.Bounds = mRightButtonRect;
                    drawable.Draw(canvas);
                }

                if (mRightButtonText != null)
                {
                    mTextPaint.GetTextBounds(mRightButtonText, 0, mRightButtonText.Length, MTempRect);

                    left = mRightButtonRect.Left + (mCalloutRightButtonWidth - MTempRect.Width()) / 2;
                    top  = mRightButtonRect.Top + (mCalloutRightButtonHeight - MTempRect.Height()) / 2 + MTempRect.Height() + mTitleOffsetY;
                    canvas.DrawText(mRightButtonText, left, top, mTextPaint);
                }
            }

            // draw tail text
            if (mTailText != null)
            {
                if (mRightButtonRect != null)
                {
                    left = mRightButtonRect.Left;
                }
                else
                {
                    left = MTempRectF.Right;
                }
                left -= mPaddingX + mTailTextWidth;
                top   = mOffsetY;

                canvas.DrawText(mTailText, left, top, mTextPaint);
            }
        }