void SetImagePadding(int drawableWidth)
        {
            var button = this.Control as Android.Widget.Button;

            Android.Graphics.Rect bounds = new Android.Graphics.Rect();
            Paint p = button.Paint;

            float textWidth = 0;

            if (!string.IsNullOrWhiteSpace(Element.Text))
            {
                p.GetTextBounds(Element.Text, 0, Element.Text.Length, bounds);
                textWidth = p.MeasureText(Element.Text);
            }

            var paddingRight = BaseUIHelper.ConvertDPToPixels(BaseElement.Padding.Right);

            var left = Control.MeasuredWidth - ((Control.MeasuredWidth + textWidth + drawableWidth) / 2 + paddingRight);

            if (textWidth > 0)
            {
                left /= 2;
            }

            if (BaseElement.Padding.Top > 0 || BaseElement.Padding.Bottom > 0)
            {
                Control.SetPadding((int)left, (int)BaseElement.Padding.Top, (int)left, (int)BaseElement.Padding.Bottom);
            }
            else
            {
                Control.SetPadding((int)left, Control.PaddingTop, (int)left, Control.PaddingBottom);
            }
        }
        public Bitmap GetBitmapMarker(Context mContext, int resourceId, string text)
        {
            Resources resources = mContext.Resources;
            float scale = resources.DisplayMetrics.Density;
            Bitmap bitmap = BitmapFactory.DecodeResource(resources, resourceId);

            Bitmap.Config bitmapConfig = bitmap.GetConfig();

            // set default bitmap config if none
            if (bitmapConfig == null)
                bitmapConfig = Bitmap.Config.Argb8888;

            bitmap = bitmap.Copy(bitmapConfig, true);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint(PaintFlags.AntiAlias);
            paint.Color = global::Android.Graphics.Color.Black;
            paint.TextSize = ((int)(14 * scale));
            paint.SetShadowLayer(1f, 0f, 1f, global::Android.Graphics.Color.White);

            // draw text to the Canvas center
            Rect bounds = new Rect();
            paint.GetTextBounds(text, 0, text.Length, bounds);
            int x = (bitmap.Width - bounds.Width()) / 2;
            int y = (bitmap.Height + bounds.Height()) / 2 - 20;

            canvas.DrawText(text, x, y, paint);

            return bitmap;
        }
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     outRect.Left = left;
     outRect.Top = top;
     outRect.Right = right;
     outRect.Bottom = bottom;
 }
Example #4
0
 protected override void OnFocusChanged(bool gainFocus, Android.Views.FocusSearchDirection direction, Rect previouslyFocusedRect)
 {
     if (gainFocus)
     {
         base.OnFocusChanged(true, direction, previouslyFocusedRect);
     }
 }
Example #5
0
		//http://egoco.de/post/19077604048/calculating-the-height-of-text-in-android
		//http://stackoverflow.com/questions/16082359/how-to-auto-adjust-text-size-on-a-multi-line-textview-according-to-the-view-max
		public SizeF MeasureString(string text, int maxWidth = 2147483647)
		{
			TextPaint paint = AndroidBrush.CreateTextPaint();
			paint.TextSize = SizeInPoints;
			paint.SetTypeface(InnerFont);

			int lineCount = 0;

			int index = 0;
			int length = text.Length;

			float[] measuredWidths = new float[]{ 0 };
			float measuredWidth = 1f;
			while(index < length - 1) 
			{
				index += paint.BreakText(text, index, length, true, maxWidth, measuredWidths);
				lineCount++;
				if (measuredWidth < measuredWidths[0]) measuredWidth = measuredWidths[0];
			}

			Rect bounds = new Rect();
			paint.GetTextBounds("Py", 0, 2, bounds);
			float height = (float)System.Math.Floor((double)lineCount * bounds.Height());

			return new SizeF (measuredWidth, height);
		}
        /// <summary>
        ///   This method will determine the scaling ratio for the image view.
        /// </summary>
        /// <param name="startBounds">The visible rectangle of the thumbnail.</param>
        /// <param name="finalBounds">The visible rectangle of the expanded image view.</param>
        /// <returns></returns>
        private static float CalculateStartScale(Rect startBounds, Rect finalBounds)
        {
            float startScale;
            // First figure out width-to-height ratio of each rectangle.
            float finalBoundsRatio = finalBounds.Width() / (float)finalBounds.Height();
            float startBoundsRatio = startBounds.Width() / (float)startBounds.Height();

            if (finalBoundsRatio > startBoundsRatio)
            {
                // Extend start bounds horizontally
                startScale = (float)startBounds.Height() / finalBounds.Height();
                float startWidth = startScale * finalBounds.Width();
                float deltaWidth = (startWidth - startBounds.Width()) / 2;
                startBounds.Left -= (int)deltaWidth;
                startBounds.Right += (int)deltaWidth;
            }
            else
            {
                // Extend start bounds vertically
                startScale = (float)startBounds.Width() / finalBounds.Width();
                float startHeight = startScale * finalBounds.Height();
                float deltaHeight = (startHeight - startBounds.Height()) / 2;
                startBounds.Top -= (int)deltaHeight;
                startBounds.Bottom += (int)deltaHeight;
            }
            return startScale;
        }
Example #7
0
        public override void Draw(Canvas canvas)
        {
            var box   = Element as RoundBoxView;
            var rect  = new Rect();
            var color = box.BorderColor != Color.White ? box.BorderColor.ToAndroid() : box.BackgroundColor.ToAndroid();
            var paint = new Paint
            {
                Color     = color,
                AntiAlias = true
            };

            GetDrawingRect(rect);
            var radius = (float)(rect.Width() / 14 * 8);  // ... / box width * box corner radius

            canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);

            if (box.BorderThickness <= 0)
            {
                return;
            }

            var diameter = rect.Width() - box.BorderThickness;
            var rect1    = new Rect(box.BorderThickness, box.BorderThickness, diameter, diameter);
            var paint1   = new Paint
            {
                Color     = box.BackgroundColor.ToAndroid(),
                AntiAlias = true
            };

            canvas.DrawRoundRect(new RectF(rect1), radius, radius, paint1);
        }
        public void Run()
        {
            Rect dstRect = new Rect();
            long startTime = Java.Lang.System.NanoTime();
            while (running)
            {
                if (!holder.GetSurface().IsValid())
                    continue;


                float deltaTime = (Java.Lang.System.NanoTime() - startTime) / 10000000.000f;
                startTime = Java.Lang.System.NanoTime();

                if (deltaTime > 3.15)
                {
                    deltaTime = (float)3.15;
                }


                game.getCurrentScreen().update(deltaTime);
                game.getCurrentScreen().paint(deltaTime);



                Canvas canvas = holder.LockCanvas();
                canvas.GetClipBounds(dstRect);
                canvas.DrawBitmap(framebuffer, null, dstRect, null);
                holder.UnlockCanvasAndPost(canvas);


            }
        }
        void AdjustHorizontalScroll(int index, ScrollToPosition scrollToPosition)
        {
            _pendingScrollAdjustment = null;

            var viewRect = GetViewRect(index);

            if (viewRect == null)
            {
                return;
            }

            var offset = 0;

            var rvRect = new ARect();

            _recyclerView.GetGlobalVisibleRect(rvRect);

            if (scrollToPosition == ScrollToPosition.Center)
            {
                offset = viewRect.CenterX() - rvRect.CenterX();
            }
            else if (scrollToPosition == ScrollToPosition.End)
            {
                offset = viewRect.Right - rvRect.Right;
            }

            _recyclerView.ScrollBy(offset, 0);
        }
Example #10
0
		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
Example #11
0
        private void MeasureLayout(PopupWindow sender)
        {
            // We can obtain the size of keyboard by comparing the layout of two popup windows
            // where one (AdjustResize) resizes to keyboard and one(AdjustNothing) that doesn't:
            // [size] realMetrics			: screen
            // [rect] adjustNothingFrame	: screen - (top: status_bar) - (bottom: nav_bar)
            // [rect] adjustResizeFrame		: screen - (top: status_bar) - (bottom: keyboard + nav_bar)
            var realMetrics        = Get <DisplayMetrics>(_activity.WindowManager.DefaultDisplay.GetRealMetrics);
            var adjustNothingFrame = Get <Rect>(_adjustNothingLayoutProvider.ContentView.GetWindowVisibleDisplayFrame);
            var adjustResizeFrame  = Get <Rect>(_adjustResizeLayoutProvider.ContentView.GetWindowVisibleDisplayFrame);

            StatusBarRect     = new Rect(0, 0, realMetrics.WidthPixels, adjustNothingFrame.Top);
            KeyboardRect      = new Rect(0, adjustResizeFrame.Bottom, realMetrics.WidthPixels, adjustNothingFrame.Bottom);
            NavigationBarRect = new Rect(0, adjustNothingFrame.Bottom, realMetrics.WidthPixels, realMetrics.HeightPixels);

            LayoutChanged?.Invoke(StatusBarRect, KeyboardRect, NavigationBarRect);

            T Get <T>(Action <T> getter) where T : new()
            {
                var result = new T();

                getter(result);

                return(result);
            }
        }
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (parent.GetChildLayoutPosition(view) != 0)
     {
         outRect.Top = space;
     }
 }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw (canvas);

            var r = new Rect ();
            this.GetLocalVisibleRect (r);

            var half = r.Width() / 2;
            var height = r.Height();

            var percentage = (this.Limit - Math.Abs(this.CurrentValue)) / this.Limit;


            var paint = new Paint()
            {
                Color = this.CurrentValue < 0 ? this.negativeColor : this.positiveColor,
                StrokeWidth = 5
            };

            paint.SetStyle(Paint.Style.Fill);

            if (this.CurrentValue < 0)
            {
                var start = (float)percentage * half;
                var size = half - start;
                canvas.DrawRect (new Rect ((int)start, 0, (int)(start + size), height), paint);
            }
            else
            {
                canvas.DrawRect (new Rect((int)half, 0, (int)(half + percentage * half), height), paint);
            }
        }
        static Bitmap GetCroppedBitmap (Bitmap bmp, int radius)
        {
            Bitmap sbmp;
            if (bmp.Width != radius || bmp.Height != radius)
                sbmp = Bitmap.CreateScaledBitmap (bmp, radius, radius, false);
            else
                sbmp = bmp;
            var output = Bitmap.CreateBitmap (sbmp.Width,
                             sbmp.Height, Bitmap.Config.Argb8888);
            var canvas = new Canvas (output);

            var paint = new Paint ();
            var rect = new Rect (0, 0, sbmp.Width, sbmp.Height);

            paint.AntiAlias = true;
            paint.FilterBitmap = true;
            paint.Dither = true;
            canvas.DrawARGB (0, 0, 0, 0);
            paint.Color = Color.ParseColor ("#BAB399");
            canvas.DrawCircle (sbmp.Width / 2 + 0.7f, sbmp.Height / 2 + 0.7f,
                sbmp.Width / 2 + 0.1f, paint);
            paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
            canvas.DrawBitmap (sbmp, rect, rect, paint);

            return output;
        }
        static View GetFrontmostChildAt(ViewGroup viewGroup, int x, int y)
        {
            var locArray = new int[2];

            for (int i = viewGroup.ChildCount - 1; i >= 0; i--)
            {
                var child = viewGroup.GetChildAt(i);

                child.GetLocationOnScreen(locArray);
                var frame = new AG.Rect(
                    locArray [0],
                    locArray [1],
                    locArray [0] + child.Width,
                    locArray [1] + child.Height);

                if (!frame.Contains(x, y))
                {
                    continue;
                }

                var childGroup = child as ViewGroup;
                if (childGroup != null)
                {
                    var grandChild = GetFrontmostChildAt(childGroup, x, y);
                    if (grandChild != null)
                    {
                        return(grandChild);
                    }
                }
                return(child);
            }

            return(null);
        }
        void AdjustVerticalScroll(int index, ScrollToPosition scrollToPosition)
        {
            _pendingScrollAdjustment = null;

            var viewRect = GetViewRect(index);

            if (viewRect == null)
            {
                return;
            }

            var offset = 0;

            var rvRect = new ARect();

            _recyclerView.GetGlobalVisibleRect(rvRect);

            if (scrollToPosition == ScrollToPosition.Center)
            {
                offset = viewRect.CenterY() - rvRect.CenterY();
            }
            else if (scrollToPosition == ScrollToPosition.End)
            {
                offset = viewRect.Bottom - rvRect.Bottom;
            }

            _recyclerView.ScrollBy(0, offset);
        }
Example #17
0
        public override void Draw(Canvas canvas)
        {
            RoundedBoxView rbv = (RoundedBoxView)this.Element;

            Rect rc = new Rect();

            GetDrawingRect(rc);

            Rect interior = rc;

            interior.Inset((int)rbv.BorderThickness, (int)rbv.BorderThickness);

            Paint p = new Paint()
            {
                Color     = rbv.BackgroundColor.ToAndroid(),
                AntiAlias = true,
            };

            var radius = (float)(rc.Width() / rbv.Width * rbv.CornerRadius);

            //canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);
            canvas.DrawRoundRect(new RectF(interior), radius, radius, p);

            // Draw border
            if (rbv.BorderThickness > 0)
            {
                p.Color       = rbv.BorderColor.ToAndroid();
                p.StrokeWidth = (float)rbv.BorderThickness;
                p.SetStyle(Paint.Style.Stroke);

                //canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);
                canvas.DrawRoundRect(new RectF(rc), radius, radius, p);
            }
        }
		public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
			Bitmap finalBitmap;
			if (bitmap.Width != radius || bitmap.Height!= radius)
				finalBitmap = Bitmap.CreateScaledBitmap(bitmap, radius, radius,
					false);
			else
				finalBitmap = bitmap;
			Bitmap output = Bitmap.CreateBitmap(finalBitmap.Width,
				finalBitmap.Height, Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas(output);

			 Paint paint = new Paint();
			Rect rect = new Rect(0, 0, finalBitmap.Width,
				finalBitmap.Height);

			paint.AntiAlias=true;
			paint.FilterBitmap=true;
			paint.Dither=true;
			canvas.DrawARGB(0, 0, 0, 0);
			paint.Color=Color.ParseColor("#BAB399");
			canvas.DrawCircle(finalBitmap.Width / 2 + 0.7f,
				finalBitmap.Height / 2 + 0.7f,
				finalBitmap.Width / 2 + 0.1f, paint);
			paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
			canvas.DrawBitmap(finalBitmap, rect, rect, paint);

			return output;
		}	
Example #19
0
        Bitmap CreateRoundImage(Bitmap image)
        {
            var clipArea = Bitmap.CreateBitmap(image.Width, image.Height, Bitmap.Config.Argb8888);
            var canvas   = new Canvas(clipArea);
            var paint    = new Paint(PaintFlags.AntiAlias);

            canvas.DrawARGB(0, 0, 0, 0);
            canvas.DrawRoundRect(new RectF(0, 0, image.Width, image.Height), _iconRadius, _iconRadius, paint);


            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));

            var rect = new Android.Graphics.Rect(0, 0, image.Width, image.Height);

            canvas.DrawBitmap(image, rect, rect, paint);

            image.Recycle();
            image.Dispose();
            image = null;
            canvas.Dispose();
            canvas = null;
            paint.Dispose();
            paint = null;
            rect.Dispose();
            rect = null;

            return(clipArea);
        }
Example #20
0
        public WrapperView(Context context)
            : base(context)
        {
            _viewBounds = new Android.Graphics.Rect();

            SetClipChildren(false);
            SetWillNotDraw(true);
        }
Example #21
0
 public BitmapDrawable(Resources resources, int id, double left, double top, double right, double bottom)
 {
     mBitmap = BitmapFactory.DecodeResource(resources, id, new BitmapFactory.Options {
         InDither = false,
         InPreferredConfig = Bitmap.Config.Argb8888
     });
     mBounds = new Rect((int)left, (int)top, (int)right, (int)bottom);
 }
Example #22
0
        public void PushClip(Rectangle clip)
        {
            Rect oldClip = new Rect();

            this.canvas.GetClipBounds(oldClip);
            clipStack.Push(new RectF(oldClip));
            this.canvas.ClipRect((RectF)clip, Region.Op.Intersect);
        }
 public override void GetItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     if (orientation == VerticalList) {
         outRect.Set (0, 0, 0, divider.IntrinsicHeight);
     } else {
         outRect.Set (0, 0, divider.IntrinsicWidth, 0);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CanvasRenderContext" /> class.
 /// </summary>
 /// <param name="scale">The scale.</param>
 public CanvasRenderContext(double scale)
 {
     this.paint = new Paint();
     this.path = new Path();
     this.bounds = new Rect();
     this.pts = new List<float>();
     this.Scale = scale;
 }
		protected override void OnBoundsChange (Rect bounds)
		{
			base.OnBoundsChange (bounds);
			if (oval == null)
				return;
			
			oval.Set (0, 0, bounds.Width (), bounds.Height ());
		}
		// we need this constructor for LayoutInflater
		public LinedEditText (Context context, IAttributeSet attrs)
			: base (context, attrs)
		{
			rect = new Rect ();
			paint = new Paint ();
			paint.SetStyle (Android.Graphics.Paint.Style.Stroke);
			paint.Color = Color.LightGray;
		}
		/// <summary>
		/// Determines whether the specified point is hit.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="point">The point.</param>
		/// <returns><c>true</c> if the specified point is hit; otherwise, <c>false</c>.</returns>
		public static bool IsHit(this Android.Views.View view, PointF point)
        {
            var r = new Rect();
            view.GetHitRect(r);

            var touch = new Rect((int)point.X, (int)point.Y, (int)point.X, (int)point.Y);

            return r.Intersect(touch);
        }
Example #28
0
        public Collider(int leftOffset, int rightOffset, int topOffset, int bottomOffset)
        {
            this.leftOffset = leftOffset;
            this.rightOffset = rightOffset;
            this.topOffset = topOffset;
            this.bottomOffset = bottomOffset;

            Boundary = new Rect (0, 0, 0, 0);
        }
		protected override bool SetFrame (int l, int t, int r, int b)
		{
			bool changed = base.SetFrame(l, t, r, b);
	        mBounds = new Rect(0, 0, r - l, b - t);
	        mBoundsF = new RectF(mBounds);
	        mBorderDrawable.Bounds = mBounds;
	        mMaskDrawable.Bounds = mBounds;
	        return changed;
		}
Example #30
0
			public SvgPath (Path path, Paint paint)
			{
				this.path = path;
				this.paint = paint;
				measure = new PathMeasure (path, false);
				length = measure.Length;
				region.SetPath (path, maxClip);
				bounds = region.Bounds;
			}
Example #31
0
        public Projectile(int x, int y)
        {
            _x = x + xOFFSET;
            _y = y + yOFFSET;
            _speedX = 7;
            _visible = true;

            boundary = new Rect ();
        }
Example #32
0
        public Projectile(int startX, int startY)
        {
            x = startX;
            y = startY;
            speedX = 7;
            visible = true;

            r = new Rect(0, 0, 0, 0);
        }
Example #33
0
		private int computeUsableHeight()
		{
			Rect r = new Rect();
			mChildOfContent.GetWindowVisibleDisplayFrame(r);
			if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
			{
				return (r.Bottom - r.Top);
			}
			return r.Bottom;
		}
Example #34
0
		protected override void OnBoundsChange (Rect bounds)
		{
			var width = bounds.Width ();
			var height = bounds.Height ();
			if (width <= 0 || height <= 0)
                		return;

            		if (Picture != null && (currentBitmap == null || currentBitmap.Height != height || currentBitmap.Width != width))
                		currentBitmap = SvgFactory.MakeBitmapFromPicture(Picture, width, height);
		}
 public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
 {
     base.GetItemOffsets(outRect, view, parent, state);
     if (this.GetOrientation(parent) == LinearLayoutManager.Vertical) 
     {
         outRect.Set(0, 0, 0, this.divider.IntrinsicHeight);
     } else {
         outRect.Set(0, 0, this.divider.IntrinsicWidth, 0);
     }
 }
Example #36
0
        public Size Measure(FormattedText formattedText)
        {
            var paint = new Paint();
            var rect  = new Rect();

            paint.GetTextBounds(formattedText.Text, 0, formattedText.Text.Length, rect);


            return(new Size(rect.Width(), rect.Height()));
        }
Example #37
0
        public override void GetItemOffsets(ARect outRect, AView view, RecyclerView parent, RecyclerView.State state)
        {
            base.GetItemOffsets(outRect, view, parent, state);

            if (_adjustedVerticalSpacing == -1)
            {
                _adjustedVerticalSpacing = parent.Context.ToPixels(_verticalSpacing);
            }

            if (_adjustedHorizontalSpacing == -1)
            {
                _adjustedHorizontalSpacing = parent.Context.ToPixels(_horizontalSpacing);
            }

            var itemViewType = parent.GetChildViewHolder(view).ItemViewType;

            if (itemViewType == ItemViewType.Header)
            {
                outRect.Bottom = (int)_adjustedVerticalSpacing;
                return;
            }

            if (itemViewType == ItemViewType.Footer)
            {
                return;
            }

            var spanIndex = 0;

            if (view.LayoutParameters is GridLayoutManager.LayoutParams gridLayoutParameters)
            {
                spanIndex = gridLayoutParameters.SpanIndex;
            }

            if (_orientation == ItemsLayoutOrientation.Vertical)
            {
                outRect.Left = spanIndex == 0 ? 0 : (int)_adjustedHorizontalSpacing;

                if (parent.GetChildAdapterPosition(view) != parent.GetAdapter().ItemCount - 1)
                {
                    outRect.Bottom = (int)_adjustedVerticalSpacing;
                }
            }

            if (_orientation == ItemsLayoutOrientation.Horizontal)
            {
                outRect.Top = spanIndex == 0 ? 0 : (int)_adjustedVerticalSpacing;

                if (parent.GetChildAdapterPosition(view) != parent.GetAdapter().ItemCount - 1)
                {
                    outRect.Right = (int)_adjustedHorizontalSpacing;
                }
            }
        }
			public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
			{
				base.GetItemOffsets(outRect, view, parent, state);

				var layoutManager = (StaggeredGridLayoutManager)parent.GetLayoutManager();
				int position = parent.GetChildAdapterPosition(view);
				if (position < layoutManager.SpanCount)
				{
					outRect.Top = headerView.heightHeader;
				}
			}
Example #39
0
        public override void GetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
        {
            var holder = parent.GetChildViewHolder(view) as ViewHolder;

            if (!CellIsVisible(holder?.RowInfo.Cell))
            {
                return;
            }

            outRect.Set(0, _drawable.IntrinsicHeight, 0, 0);
        }
Example #40
0
            public override void GetOutline(Android.Views.View view, Outline outline)
            {
                float  scale        = view.Resources.DisplayMetrics.Density;
                double width        = (double)element.GetValue(VisualElement.WidthProperty) * scale;
                double height       = (double)element.GetValue(VisualElement.HeightProperty) * scale;
                float  minDimension = (float)Math.Min(height, width);
                float  radius       = minDimension / 2f;
                var    rect         = new Android.Graphics.Rect(0, 0, (int)width, (int)height);

                outline.SetRoundRect(rect, radius);
            }
        protected override void OnBoundsChange(Rect bounds)
        {
            base.OnBoundsChange(bounds);

            var height = Bounds.Height();
            var width = Bounds.Width();

            _numRectanglesHorizontal = (int)Math.Ceiling((double) (width / _rectangleSize));
            _numRectanglesVertical = (int)Math.Ceiling((double) (height / _rectangleSize));

            GeneratePatternBitmap();
        }
		Rect GetFramingRect(Canvas canvas)
		{
			int width = canvas.Width * 15 / 16;

			int height = canvas.Height * 4/ 10;

			int leftOffset = (canvas.Width - width) / 2;
			int topOffset = (canvas.Height - height) / 2;
			var framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);

			return framingRect;
		}
Example #43
0
        public Tile(int x, int y, TileType type, Background bg, Robot robot)
        {
            this._x = x * 40;
            this._y = y * 40;
            this._bg = bg;
            this.robot = robot;

            boundary = new Rect ();

            this.Type = type;
            findPicture ();
        }
Example #44
0
 public override void Draw(Canvas canvas)
 {
     Rect bounds = Bounds;
     int height = bounds.Height();
     paint.TextSize = height;
     Rect textBounds = new Rect();
     string textValue = icon.Character.ToString();
     paint.GetTextBounds(textValue, 0, 1, textBounds);
     int textHeight = textBounds.Height();
     float textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom;
     canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, paint);
 }
        /// <summary>
        /// get the height of the the string
        /// </summary>
        /// <param name="text">the string to measure</param>
        /// <param name="fontSize">the font size of the displayed string</param>
        /// <returns>the height of the measured string</returns>
        public static double TextHeightNative(string text, float fontSize)
        {
            Graphics.Rect bounds   = new Graphics.Rect();
            TextView      textView = new TextView(Native.Application.Context)
            {
                TextSize = fontSize
            };

            textView.Paint.GetTextBounds(text.ToCharArray(), 0, text.Length, bounds);
            var height = bounds.Height();

            return(height / Resources.System.DisplayMetrics.ScaledDensity);
        }
Example #46
0
        protected override void OnBoundsChange(Android.Graphics.Rect bounds)
        {
            base.OnBoundsChange(bounds);

            if (this.element.Width >= 0 && this.element.Height >= 0 && (this.element.Width != this.lastWidth || this.element.Height != this.lastHeight))
            {
                this.lastWidth  = this.element.Width;
                this.lastHeight = this.element.Height;
                this.drawingBrush.SetSize(this.element.Width, this.element.Height);
                this.UpdateSize(element.Width, element.Height);
                this.UpdateShape(this.drawingBrush.Geometry.ToAPath(this.view.Context));
            }
        }
Example #47
0
        private void MeasureLayout(PopupWindow sender)
        {
#pragma warning disable 618
            // We can obtain the size of keyboard by comparing the layout of two popup windows
            // where one (AdjustResize) resizes to keyboard and one(AdjustNothing) that doesn't:
            // [size] realMetrics			: screen
            // [size] metrics				: screen - dead zones
            // [rect] displayRect			: screen - (bottom: nav_bar)
            // [rect] adjustNothingFrame	: screen - (top: status_bar) - (bottom: nav_bar)
            // [rect] adjustResizeFrame		: screen - (top: status_bar) - (bottom: keyboard + nav_bar)
            var realMetrics        = Get <DisplayMetrics>(_activity.WindowManager.DefaultDisplay.GetRealMetrics);
            var metrics            = Get <DisplayMetrics>(_activity.WindowManager.DefaultDisplay.GetMetrics);
            var displayRect        = Get <Rect>(_activity.WindowManager.DefaultDisplay.GetRectSize);
            var adjustNothingFrame = Get <Rect>(_adjustNothingLayoutProvider.ContentView.GetWindowVisibleDisplayFrame);
            var adjustResizeFrame  = Get <Rect>(_adjustResizeLayoutProvider.ContentView.GetWindowVisibleDisplayFrame);
#pragma warning restore 618

            var orientation = DisplayInformation.GetForCurrentView().CurrentOrientation;

            StatusBarRect = new Rect(0, 0, realMetrics.WidthPixels, adjustNothingFrame.Top);
            KeyboardRect  = new Rect(0, adjustResizeFrame.Bottom, realMetrics.WidthPixels, adjustNothingFrame.Bottom);

            switch (orientation)
            {
            case DisplayOrientations.Landscape:
                NavigationBarRect = new Rect(0, 0, metrics.WidthPixels - displayRect.Width(), metrics.HeightPixels);
                break;

            case DisplayOrientations.LandscapeFlipped:
                NavigationBarRect = new Rect(adjustNothingFrame.Width(), 0, metrics.WidthPixels - displayRect.Width(), metrics.HeightPixels);
                break;

            // Miss portrait flipped
            case DisplayOrientations.Portrait:
            default:
                NavigationBarRect = new Rect(0, adjustNothingFrame.Bottom, realMetrics.WidthPixels, realMetrics.HeightPixels);
                break;
            }

            LayoutChanged?.Invoke(StatusBarRect, KeyboardRect, NavigationBarRect);

            T Get <T>(Action <T> getter) where T : new()
            {
                var result = new T();

                getter(result);

                return(result);
            }
        }
        public Size Measure(FormattedText formattedText)
        {
            var paint = new Paint();
            var rect  = new Rect();

            paint.TextSize = formattedText.FontSize;
            paint.GetTextBounds(formattedText.Text, 0, formattedText.Text.Length, rect);

            var descent = paint.Descent();

            var height = rect.Height();
            var width  = rect.Width();

            return(new Size(width, height + descent));
        }
Example #49
0
        public SizeF MeasureString(Font font, string text)
        {
            if (string.IsNullOrEmpty(text))            // needed to avoid exception
            {
                return(SizeF.Empty);
            }
            var paint = GetTextPaint(font);

            // See http://stackoverflow.com/questions/7549182/android-paint-measuretext-vs-gettextbounds
            var bounds = new ag.Rect();

            paint.GetTextBounds(text, 0, text.Length, bounds);

            // TODO: see the above article; the width may be truncated to the nearest integer.
            return(new SizeF(bounds.Width(), bounds.Height()));
        }
        ARect GetViewRect(int index)
        {
            var holder = _recyclerView.FindViewHolderForAdapterPosition(index);
            var view   = holder?.ItemView;

            if (view == null)
            {
                return(null);
            }

            var viewRect = new ARect();

            view.GetGlobalVisibleRect(viewRect);

            return(viewRect);
        }
        private Android.Graphics.Rect GetScaledRect(int sourceHeight, int sourceWidth)
        {
            int height = 0;
            int width  = 0;
            int top    = 0;
            int left   = 0;

            height = sourceHeight;
            width  = sourceWidth;
            height = this.MakeSquare(height, ref width);
            left   = (int)((sourceWidth - width) / 2);
            top    = (int)((sourceHeight - height) / 2);

            var rect = new Android.Graphics.Rect(left, top, width + left, height + top);

            return(rect);
        }
Example #52
0
        internal void DrawText(string text, Paint p, Typeface font, float size, Rectangle rect, ReoGridHorAlign halign, ReoGridVerAlign valign)
        {
            p.SetTypeface(font);
            p.TextSize = size;

            var measuredRect = new Rect();

            p.GetTextBounds(text, 0, text.Length, measuredRect);

            float x = rect.Left, y = rect.Top;

            switch (halign)
            {
            case ReoGridHorAlign.General:
            case ReoGridHorAlign.Left:
                x = rect.Left;
                break;

            case ReoGridHorAlign.Center:
                x = rect.Left + (rect.Width - measuredRect.Width()) / 2;
                break;

            case ReoGridHorAlign.Right:
                x = rect.Right - measuredRect.Width();
                break;
            }

            switch (valign)
            {
            case ReoGridVerAlign.Top:
                y = rect.Top + measuredRect.Height();
                break;

            case ReoGridVerAlign.Middle:
                y = rect.Bottom - (rect.Height - measuredRect.Height()) / 2;
                break;

            case ReoGridVerAlign.General:
            case ReoGridVerAlign.Bottom:
                y = rect.Bottom;
                break;
            }

            this.canvas.DrawText(text, x, y, p);
        }
Example #53
0
        public Bitmap CreateRoundImage(Bitmap image)
        {
            using ( image )
            {
                using var clipArea = Bitmap.CreateBitmap(image.Width, image.Height, Bitmap.Config.Argb8888 ?? throw new NullReferenceException(nameof(Bitmap.Config.Argb8888)));
                using var canvas   = new Canvas(clipArea ?? throw new NullReferenceException(nameof(clipArea)));
                using var paint    = new Paint(PaintFlags.AntiAlias);
                canvas.DrawARGB(0, 0, 0, 0);
                canvas.DrawRoundRect(new RectF(0, 0, image.Width, image.Height), _IconRadius, _IconRadius, paint);

                paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));

                using var rect = new Android.Graphics.Rect(0, 0, image.Width, image.Height);
                canvas.DrawBitmap(image, rect, rect, paint);

                return(clipArea);
            }
        }
Example #54
0
        protected override void OnDraw(Canvas canvas)
        {
            var frame = Element as CustomizedFrame;

            var my1stPaint      = new Android.Graphics.Paint();
            var my2ndPaint      = new Android.Graphics.Paint();
            var backgroundPaint = new Android.Graphics.Paint();

            my1stPaint.AntiAlias = true;
            my1stPaint.SetStyle(Paint.Style.Stroke);
            my1stPaint.StrokeWidth = frame.BorderWidth + 2;
            my1stPaint.Color       = frame.BorderColor.ToAndroid();

            my2ndPaint.AntiAlias = true;
            my2ndPaint.SetStyle(Paint.Style.Stroke);
            my2ndPaint.StrokeWidth = frame.BorderWidth;
            my2ndPaint.Color       = frame.BackgroundColor.ToAndroid();

            backgroundPaint.SetStyle(Paint.Style.Stroke);
            backgroundPaint.StrokeWidth = 4;
            backgroundPaint.Color       = frame.BackgroundColor.ToAndroid();

            Android.Graphics.Rect oldBounds = new Android.Graphics.Rect();
            canvas.GetClipBounds(oldBounds);

            RectF oldOutlineBounds = new RectF();

            oldOutlineBounds.Set(oldBounds);

            RectF myOutlineBounds = new RectF();

            myOutlineBounds.Set(oldBounds);
            myOutlineBounds.Top    += (int)my2ndPaint.StrokeWidth + 3;
            myOutlineBounds.Bottom -= (int)my2ndPaint.StrokeWidth + 3;
            myOutlineBounds.Left   += (int)my2ndPaint.StrokeWidth + 3;
            myOutlineBounds.Right  -= (int)my2ndPaint.StrokeWidth + 3;

            canvas.DrawRoundRect(oldOutlineBounds, 10, 10, backgroundPaint); //to "hide" old outline
            canvas.DrawRoundRect(myOutlineBounds, frame.CornerRadius, frame.CornerRadius, my1stPaint);
            canvas.DrawRoundRect(myOutlineBounds, frame.CornerRadius, frame.CornerRadius, my2ndPaint);

            base.OnDraw(canvas);
        }
Example #55
0
        /// <summary>
        /// Transforms ImageBrush's bitmap based on target bounds and shape, Stretch mode, and RelativeTransform, and draws it to the supplied canvas.
        /// </summary>
        /// <param name="destinationCanvas">The canvas to draw the final image on</param>
        /// <param name="drawRect">The destination bounds</param>
        /// <param name="maskingPath">An optional path to clip the bitmap by (eg an ellipse)</param>
        internal void DrawBackground(Canvas destinationCanvas, Windows.Foundation.Rect drawRect, Path maskingPath = null)
        {
            var bitmap = ImageSource?.ImageData;

            if (bitmap == null)
            {
                return;
            }

            //Create a temporary bitmap
            var output = GetTransformedBitmap(drawRect, maskingPath);

            var paint = new Paint();

            //Draw the output bitmap to the screen
            var rect = new Android.Graphics.Rect(0, 0, (int)drawRect.Width, (int)drawRect.Height);

            destinationCanvas.DrawBitmap(output, rect, rect, paint);
        }
        public override void GetItemOffsets(ARect outRect, AView view, RecyclerView parent, RecyclerView.State state)
        {
            base.GetItemOffsets(outRect, view, parent, state);

            if (Math.Abs(_adjustedVerticalSpacing - (-1)) < double.Epsilon)
            {
                _adjustedVerticalSpacing = parent.Context.ToPixels(_verticalSpacing);
            }

            if (Math.Abs(_adjustedHorizontalSpacing - (-1)) < double.Epsilon)
            {
                _adjustedHorizontalSpacing = parent.Context.ToPixels(_horizontalSpacing);
            }

            int position  = parent.GetChildAdapterPosition(view);
            int itemCount = parent.GetAdapter().ItemCount;

            if (position == RecyclerView.NoPosition || itemCount == 0)
            {
                return;
            }

            if (_orientation == ItemsLayoutOrientation.Vertical)
            {
                var verticalInsets       = parent.Context.ToPixels(_carouselView.PeekAreaInsets.Bottom + _carouselView.PeekAreaInsets.Top) / 2;
                var finalVerticalSpacing = (int)(_adjustedVerticalSpacing - (_verticalSpacing * 2));

                outRect.Left   = position == 0 ? 0 : (int)_adjustedHorizontalSpacing;
                outRect.Bottom = (position == (itemCount - 1) && verticalInsets > 0) ? ((int)Math.Ceiling(verticalInsets / 2) + finalVerticalSpacing) : finalVerticalSpacing;
                outRect.Top    = (position == 0 && verticalInsets > 0) ? ((int)Math.Ceiling(verticalInsets / 2) + finalVerticalSpacing) : finalVerticalSpacing;
            }

            if (_orientation == ItemsLayoutOrientation.Horizontal)
            {
                var horizontalInsets       = parent.Context.ToPixels(_carouselView.PeekAreaInsets.Left + _carouselView.PeekAreaInsets.Right) / 2;
                var finalHorizontalSpacing = (int)(_adjustedHorizontalSpacing - (_horizontalSpacing * 2));

                outRect.Top   = position == 0 ? 0 : (int)_adjustedVerticalSpacing;
                outRect.Right = (position == (itemCount - 1) && horizontalInsets > 0) ? ((int)Math.Ceiling(horizontalInsets / 2) + finalHorizontalSpacing) : finalHorizontalSpacing;
                outRect.Left  = (position == 0 && horizontalInsets > 0) ? ((int)Math.Ceiling(horizontalInsets / 2) + finalHorizontalSpacing) : finalHorizontalSpacing;
            }
        }
Example #57
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int SaveCount = canvas.Save();

            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);

            //Draw background
            canvas.DrawColor(new Color(mCurrentBackgroundColor));
            //Draw reveal circle
            if (mRevealCircleRadius > 0)
            {
                mPaint.Color = new Color(mCurrentBackgroundColor == mBackgroundColor ? mBackgroundDeepColor : mBackgroundColor);
                canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), mRevealCircleRadius, mPaint);
            }

            //Draw mother oval
            mPaint.Color = new Color(mCurrentOvalColor);

            int motherSaveCount = canvas.Save();

            canvas.Rotate(mRotateDegrees, mMotherPosition[0], mMotherPosition[1]);
            canvas.DrawPath(CreateMotherPath(), mPaint);
            canvas.DrawPath(CreateLinkPath(), mPaint);
            canvas.RestoreToCount(motherSaveCount);

            int childSaveCount = canvas.Save();

            canvas.Rotate(mRotateDegrees, mChildPosition[0], mChildPosition[1]);
            canvas.DrawPath(CreateChildPath(), mPaint);
            canvas.RestoreToCount(childSaveCount);
            canvas.RestoreToCount(SaveCount);

            //    canvas.DrawPath(mMotherMovePath, mPaint);
            //    canvas.DrawPath(mChildMovePath, mPaint);
            //    canvas.DrawLine(mMotherPosition[0], mMotherPosition[1], mChildPosition[0], mChildPosition[1], mPaint);
        }
Example #58
0
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);
            if (Window.Current == null)
            {
                // Do not calc keyboard height before window init, because we need to know pixel scale.
                return;
            }
            var r = new Android.Graphics.Rect();

            this.GetWindowVisibleDisplayFrame(r);
            var totalHeight   = bottom - top;
            var visibleHeight = r.Bottom - r.Top;

            if (visibleHeight == totalHeight)
            {
                androidSoftKeyboard.Height = 0;
            }
            else
            {
                androidSoftKeyboard.Height = totalHeight - visibleHeight;
            }
        }
Example #59
0
        public static Bitmap getCroppedBitmap(Bitmap bmp, int radius)
        {
            Bitmap sbmp;

            if (bmp.Width != radius || bmp.Height != radius)
            {
                sbmp = Bitmap.CreateScaledBitmap(bmp, radius, radius, false);
            }
            else
            {
                sbmp = bmp;
            }

            Bitmap output = Bitmap.CreateBitmap(sbmp.Width, sbmp.Height, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(output);
            Paint  paint  = new Paint();

            paint.AntiAlias    = true;
            paint.FilterBitmap = true;
            paint.Dither       = true;
            canvas.DrawARGB(0, 0, 0, 0);
            paint.Color = Android.Graphics.Color.ParseColor("#000000");

            canvas.DrawCircle(sbmp.Width / 2 + 0.0f, sbmp.Height / 2 + 0.0f, sbmp.Width / 2 + 0.0f, paint);
            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
            try
            {
                Android.Graphics.Rect rect = new Android.Graphics.Rect(0, 0, sbmp.Width, sbmp.Height);
                //Rect rectDest = new Rect(0, 0, sbmp.Width, sbmp.Height);
                canvas.DrawBitmap(sbmp, rect, rect, paint);
            }
            catch (System.Exception)
            {
            }
            return(output);
        }
        protected override void OnFocusChanged(bool gainFocus, Views.FocusSearchDirection direction, Graphics.Rect previouslyFocusedRect)
        {
            base.OnFocusChanged(gainFocus, direction, previouslyFocusedRect);

            if (gainFocus)
            {
                OnTextFieldClicked();
            }
            else
            {
                _dialog.Hide();
                ((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedProperty, false);
                Control.ClearFocus();
                _dialog.CancelEvent -= OnCancelButtonClicked;
                _dialog              = null;
            }
        }