From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/GateWay.Droid/ZXing/ZXingOverlayView.cs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 118 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/GateWay.Droid/ZXing/ZXingOverlayView.cs b/ZigbeeApp/GateWay.Droid/ZXing/ZXingOverlayView.cs new file mode 100755 index 0000000..8f456b4 --- /dev/null +++ b/ZigbeeApp/GateWay.Droid/ZXing/ZXingOverlayView.cs @@ -0,0 +1,118 @@ +锘縰sing System; +using Android.Content; +using Android.Graphics; +using Android.Util; +using Android.Views; +using Android.Widget; + +namespace GateWay.Droid +{ + public class ZXingOverlayView: View + { + float screenRate; + float lineWidth; + float textSize; + float left; + float width; + float height; + float top; + Paint paint; + public ZXingOverlayView(Context context) : base(context) + { + InitData(context); + } + + public ZXingOverlayView(Context context, IAttributeSet attrs) : base(context, attrs) + { + InitData(context); + } + + public override void Draw(Canvas canvas) + { + left = canvas.Width * 0.125f; + width = canvas.Width * 0.75f; + height = canvas.Width * 0.75f; + top = (canvas.Height - height) / 2; + + paint = new Paint { AntiAlias = true, }; + paint.SetStyle(Paint.Style.FillAndStroke); + + AddScreenFillRect(canvas); + AddCenterClearRect(canvas); + AddWhiteCanvas(canvas); + AddCornerLineWithCanvas(canvas); + //AddTextWithCanvas(canvas); + } + + private void InitData(Context context) + { + screenRate = 15 * context.Resources.DisplayMetrics.Density; + lineWidth = 2 * context.Resources.DisplayMetrics.Density; + textSize = 16 * context.Resources.DisplayMetrics.Density; + + + } + + //娣诲姞灞忓箷鍗婇�忔槑濉厖鑹� + private void AddScreenFillRect(Canvas canvas) + { + paint.Color = Color.Black; + paint.Alpha = 128; + + canvas.DrawRect(0, 0, canvas.Width, top, paint); + canvas.DrawRect(0, top, left, top + width, paint); + canvas.DrawRect(width + left, top, canvas.Width, top + width, paint); + canvas.DrawRect(0, top + width, canvas.Width, canvas.Height, paint); + } + //娣诲姞涓績鍏ㄩ�忔槑濉厖鑹� + private void AddCenterClearRect(Canvas canvas) + { + paint.Color = Color.Transparent; + + canvas.DrawRect(left, top, left + width, top + width, paint); + } + //娣诲姞鐧借壊鏂规 + private void AddWhiteCanvas(Canvas canvas) + { + paint.Color = Color.Rgb(255, 255, 255); + + canvas.DrawRect(left, top, left + width, top + 2, paint); + canvas.DrawRect(left, top, left + 2, top + height, paint); + canvas.DrawRect(left + width, top, left + width + 2, top + height, paint); + canvas.DrawRect(left, top + height, left + width, top + height + 2, paint); + } + //娣诲姞鍥涗釜瑙掔殑钃濊壊 + private void AddCornerLineWithCanvas(Canvas canvas) + { + paint.Color = Color.Rgb(22, 118, 188); + + canvas.DrawRect(left, top, left + screenRate, top + lineWidth, paint); + canvas.DrawRect(left, top, left + lineWidth, top + screenRate, paint); + canvas.DrawRect(left + width - screenRate, top, left + width, top + lineWidth, paint); + canvas.DrawRect(left + width, top, left + width + lineWidth, top + screenRate, paint); + canvas.DrawRect(left, top + width, left + screenRate, top + width + lineWidth, paint); + canvas.DrawRect(left, top + width - screenRate, left + lineWidth, top + width, paint); + canvas.DrawRect(left + width - screenRate, top + width, left + width + lineWidth, top + width + lineWidth, paint); + canvas.DrawRect(left + width, top + width - screenRate, left + width + lineWidth, top + width + lineWidth, paint); + } + //娣诲姞鏂囧瓧鎻愰啋 + private void AddTextWithCanvas(Canvas canvas) + { + paint.Color = Color.Rgb(255, 255, 255); + paint.SetTypeface(Typeface.DefaultBold); + paint.TextSize = textSize; + string text = "BottomText"; + + float textWidth = paint.MeasureText(text); + + canvas.DrawText(text, (canvas.Width - textWidth) / 2, top + width + textSize, paint); + + + //canvas.DrawText("杩斿洖", 50, 100, paint); + + } + + + + } +} -- Gitblit v1.8.0