xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
using System;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 做成一个头像控件,可以切换头像
    /// </summary>
    public class ProfilePhotoControl:ButtonCommon
    {
        /// <summary>
        /// 做成一个头像控件,可以切换头像
        /// </summary>
        /// <param name="isCanEditor">不允许编辑头像</param>
        public ProfilePhotoControl(bool isCanEditor = false)
        {
            int iconSize = Application.GetRealHeight(180);
            this.Width = iconSize;
            this.Height = iconSize;
            this.Radius = (uint)iconSize / 2;
 
            if (isCanEditor == true)
            {
                this.MouseUpEventHandler += (sender, e) =>
                {
                    //显示用户图标选择菜单
                    this.ShowUserIconSelectMenu();
                };
            }
        }
 
        /// <summary>
        /// 显示用户图标选择菜单
        /// </summary>
        private void ShowUserIconSelectMenu()
        {
            //Dialog dialog = new Dialog();
            //FrameLayout frameLayout = new FrameLayout();
            //frameLayout.MouseUpEventHandler += (sender, e) =>
            //{
            //    dialog.Close();
            //};
            //dialog.AddChidren(frameLayout);
 
            ////设定控件的高度
            //int height = Application.GetRealHeight(100);
            ////设定控件左右与界面的间距
            //int space = Application.GetRealHeight(30);
            ////设定控件的宽度
            //int width = frameLayout.Width - space * 2;
 
            ////取消
            //Button btnCancel = UserCenterControls.MakeViewButton(width, height);
            ////btnCancel.TextID = R.MyInternationalizationString.Cancel;
            //btnCancel.Gravity = Gravity.BottomCenter;
            //btnCancel.TextColor = UserCenterColor.Current.Red;
            //btnCancel.BorderWidth = 2;
            //btnCancel.BackgroundColor = UserCenterColor.Current.White;
            //btnCancel.BorderColor = UserCenterColor.Current.Gray;
            //btnCancel.Radius = 5;
            //btnCancel.MouseUpEventHandler += (sender, e) =>
            //{
            //    dialog.Close();
            //};
            //frameLayout.AddChidren(btnCancel);
 
            ////相册
            //Button btnAlbum = UserCenterControls.MakeViewButton(width, height);
            //btnAlbum.Text = "从相册中选择";
            //btnAlbum.Gravity = Gravity.CenterHorizontal;
            //btnAlbum.TextColor = UserCenterColor.Current.SelectTextColor;
            //btnAlbum.BorderWidth = 2;
            //btnAlbum.BorderColor = UserCenterColor.Current.Gray;
            //btnAlbum.BackgroundColor = UserCenterColor.Current.White;
            //btnAlbum.Radius = 5;
            //btnAlbum.Y = btnCancel.Bottom - height * 2 - Application.GetRealHeight(10);
            //btnAlbum.MouseUpEventHandler += (sender, e) =>
            //{
            //    Camera.SelectPicture(this.EditorPictrue, "MyIconPic.png");
 
            //    dialog.Close();
            //};
            //frameLayout.AddChidren(btnAlbum);
 
            ////拍照
            //Button btnCamera = UserCenterControls.MakeViewButton(width, height);
            //btnCamera.Text = "拍照";
            //btnCamera.Gravity = Gravity.CenterHorizontal;
            //btnCamera.TextColor = UserCenterColor.Current.SelectTextColor;
            //btnCamera.BorderWidth = 2;
            //btnCamera.BorderColor = UserCenterColor.Current.Gray;
            //btnCamera.BackgroundColor = UserCenterColor.Current.White;
            //btnCamera.Y = btnAlbum.Bottom - height * 2 + 2;
            //btnCamera.Radius = 5;
            //btnCamera.MouseUpEventHandler += (sender, e) =>
            //{
            //    Camera.TakePicture((filename) =>
            //    { }
            //                        , "Picture");
 
            //    dialog.Close();
            //};
            //frameLayout.AddChidren(btnCamera);
 
            //dialog.Show();
        }
 
        /// <summary>
        /// 图片编辑
        /// </summary>
        /// <param name="fileName">File name.</param>
        private void EditorPictrue(string fileName)
        {
            //Dialog dialog = new Dialog();
            //FrameLayout frameLayout = new FrameLayout();
            //frameLayout.MouseUpEventHandler += (sender, e) =>
            //{
            //    if (e.X <= 50)
            //    {
            //        dialog.Close();
            //    }
            //};
            //dialog.AddChidren(frameLayout);
 
            //ClipView clipView = new ClipView();
            //clipView.Height = Application.GetRealHeight(600);
            //clipView.Gravity = Gravity.CenterVertical;
 
            //Bitmap bitmap = BitmapFactory.DecodeFile(fileName);
            //clipView.imageView.SetAdjustViewBounds(true);
            //clipView.imageView.SetScaleType(Android.Widget.ImageView.ScaleType.CenterCrop);
            //clipView.imageView.SetImageBitmap(bitmap);
            //frameLayout.AddChidren(clipView);
 
            //CircleView circleView = new CircleView();
            //circleView.Height = Application.GetRealHeight(600);
            //circleView.Gravity = Gravity.CenterVertical;
            //frameLayout.AddChidren(circleView);
 
            //dialog.Show();
 
            //ScaleGestureListener listener = new ScaleGestureListener(Application.Activity);
            //listener.init(clipView.imageView);
        }
 
        ///// <summary>
        ///// Circle view.
        ///// </summary>
        //public class CircleView : Shared.View
        //{
        //    public Android.Widget.ImageView imageView
        //    {
        //        get { return base.AndroidView as Android.Widget.ImageView; }
        //        set { base.AndroidView = value; }
        //    }
 
        //    /// <summary>
        //    /// Initializes a new instance of the <see cref="T:Shared.Phone.Device.UserInformation.CircleView"/> class.
        //    /// </summary>
        //    public CircleView()
        //    {
        //        ImageViewEx view = new ImageViewEx(Application.Activity);
        //        this.imageView = view;
        //    }
        //}
 
        ///// <summary>
        ///// Android image view ex.
        ///// </summary>
        //public class ImageViewEx : Android.Widget.ImageView
        //{
        //    /// <summary>
        //    /// Initializes a new instance of the <see cref="T:Shared.Phone.Device.UserInformation.AndroidImageViewEx"/> class.
        //    /// </summary>
        //    /// <param name="context">Context.</param>
        //    public ImageViewEx(Android.Content.Context context) : base(context)
        //    {
        //    }
 
        //    /// <summary>
        //    /// Ons the draw.
        //    /// </summary>
        //    /// <param name="canvas">Canvas.</param>
        //    protected override void OnDraw(Canvas canvas)
        //    {
        //        base.OnDraw(canvas);
 
        //        drawMask(canvas);
        //    }
 
        //    /// <summary>
        //    /// 绘制蒙版
        //    /// </summary>
        //    /// <param name="canvas">Canvas.</param>
        //    private void drawMask(Canvas canvas)
        //    {
        //        //画背景颜色
        //        Bitmap bitmap = Bitmap.CreateBitmap(this.Width, this.Height, Bitmap.Config.Argb8888);
        //        Canvas c1 = new Canvas(bitmap);
        //        c1.DrawARGB(150, 0, 0, 0);
        //        Paint strokePaint = new Paint();
        //        strokePaint.AntiAlias = true;
        //        strokePaint.Color = Android.Graphics.Color.White;
        //        strokePaint.SetStyle(Paint.Style.Stroke);
        //        c1.DrawCircle(this.Width / 2, this.Height / 2, this.Height / 2, strokePaint);
 
        //        //画圆
        //        Bitmap circleBitmap = Bitmap.CreateBitmap(this.Width, this.Height, Bitmap.Config.Argb8888);
        //        Canvas c2 = new Canvas(circleBitmap);
        //        Paint circlePaint = new Paint();
        //        circlePaint.SetStyle(Paint.Style.Fill);
        //        circlePaint.Color = Android.Graphics.Color.Red;
        //        circlePaint.AntiAlias = true;
        //        c2.DrawCircle(this.Width / 2, this.Height / 2, this.Height / 2, circlePaint);
        //        //两个图层合成
        //        Paint paint = new Paint();
        //        paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.DstOut));
        //        c1.DrawBitmap(circleBitmap, 0, 0, paint);
        //        paint.SetXfermode(null);
 
        //        canvas.DrawBitmap(bitmap, 0, 0, null);
        //    }
        //}
 
 
        ///// <summary>
        ///// Clip view.
        ///// </summary>
        //public class ClipView : Shared.View
        //{
        //    public Android.Widget.ImageView imageView
        //    {
        //        get { return base.AndroidView as Android.Widget.ImageView; }
        //        set { base.AndroidView = value; }
        //    }
 
        //    /// <summary>
        //    /// Initializes a new instance of the <see cref="T:Shared.Phone.Device.UserInformation.CircleView"/> class.
        //    /// </summary>
        //    public ClipView()
        //    {
        //        ImageViewEx2 view = new ImageViewEx2(Application.Activity);
        //        this.imageView = view;
        //    }
        //}
 
        ///// <summary>
        ///// Image view ex2.
        ///// </summary>
        //public class ImageViewEx2 : Android.Widget.ImageView
        //{
        //    /// <summary>
        //    /// Initializes a new instance of the <see cref="T:Shared.Phone.Device.UserInformation.AndroidImageViewEx"/> class.
        //    /// </summary>
        //    /// <param name="context">Context.</param>
        //    public ImageViewEx2(Android.Content.Context context) : base(context)
        //    {
        //    }
 
        //    /// <summary>
        //    /// Ons the touch event.
        //    /// </summary>
        //    /// <returns><c>true</c>, if touch event was oned, <c>false</c> otherwise.</returns>
        //    /// <param name="e">E.</param>
        //    public override bool OnTouchEvent(MotionEvent e)
        //    {
        //        this.AdjustMotionEvent(e);
        //        return base.OnTouchEvent(e);
        //    }
 
 
 
        //    PointF startPoint = new PointF();
        //    //当前状态
        //    private int mMode = Mode.NONE;
 
        //    /// <summary>
        //    /// 状态
        //    /// </summary>
        //    private class Mode
        //    {
        //        //初始状态
        //        public const int NONE = 0;
        //        //托动
        //        public const int DRAG = 1;
        //        //缩放
        //        public const int ZOOM = 2;
        //    }
 
        //    private void AdjustMotionEvent(MotionEvent e)
        //    {
        //        if (e.Action == MotionEventActions.Down)
        //        {
        //            mMode = Mode.DRAG;
        //            startPoint.Set(e.GetX(), e.GetY());
        //        }
        //        else if (e.Action == MotionEventActions.Up)
        //        {
        //            mMode = Mode.NONE;
        //        }
        //        else if (e.Action == MotionEventActions.Move)
        //        {
        //            if (mMode == Mode.DRAG && e.PointerCount == 1)
        //            {
        //                float x = e.GetX();
        //                float y = e.GetY();
        //                float dx = e.GetX() - startPoint.X;
        //                float dy = e.GetY() - startPoint.Y;
 
        //                this.SetX(this.GetX() + dx);
        //                this.SetY(this.GetY() + dy);
        //                //刷新起点坐标
        //                startPoint.Set(x, y);
        //            }   
        //        }
        //    }
        //}
 
        ///// <summary>
        ///// ScaleGestureListener
        ///// </summary>
        //public class ScaleGestureListener :Android.Widget.FrameLayout, 
        //ScaleGestureDetector.IOnScaleGestureListener
        //{
        //    //最大缩放比例
        //    private float MAX_SCALE = 4.0f;
        //    //最小缩放比例
        //    private float MIN_SCALE = 1.0f;
        //    //matrix array
        //    private float[] MATRIX_ARR = new float[9];
 
        //    /// <summary>
        //    /// 状态
        //    /// </summary>
        //    private class Mode
        //    {
        //        // 初始状态
        //        public const int NONE = 0;
        //        //托动
        //        public const int DRAG = 1;
        //        //缩放
        //        public const int ZOOM = 2;
        //    }
 
        //    //当前状态
        //    private int mMode = Mode.NONE;
        //    //缩放手势
        //    private Android.Views.ScaleGestureDetector mScaleDetector;
        //    //矩阵
        //    private Matrix mMatrix = new Matrix();
        //    //托动时手指按下的点
        //    private PointF mPrevPointF = new PointF();
 
        //    //第一次
        //    private bool firstTime = true;
 
        //    Android.Widget.ImageView imageView = null;
 
        //    /// <summary>
        //    /// ScaleGestureListener
        //    /// </summary>
        //    public ScaleGestureListener(Android.Content.Context context) : base(context)
        //    {
        //    }
 
        //    /// <summary>
        //    /// 初始化
        //    /// </summary>
        //    public void init(Android.Widget.ImageView i_View)
        //    {
        //        imageView = i_View;
        //        mScaleDetector = new ScaleGestureDetector(imageView.Context, this);
 
        //        initPosAndScale();
        //    }
 
        //    /// <summary>
        //    /// 初始化缩放比例
        //    /// </summary>
        //    private void initPosAndScale()
        //    {
        //        if (firstTime)
        //        {
        //            Android.Graphics.Drawables.Drawable drawable = imageView.Drawable;
        //            int width = imageView.Width;
        //            int height = imageView.Height;
        //            //初始化
        //            int dw = drawable.IntrinsicWidth;
        //            int dh = drawable.IntrinsicHeight;
 
        //            float scaleX = 1.0f;
        //            float scaleY = 1.0f;
        //            //是否已经做过缩放处理
        //            bool isScaled = false;
        //            if (width < getDiameter())
        //            {
        //                scaleX = getDiameter() * 1.0f / width;
        //                isScaled = true;
        //            }
        //            if (height < getDiameter())
        //            {
        //                scaleY = getDiameter() * 1.0f / height;
        //                isScaled = true;
        //            }
        //            float scale = Math.Max(scaleX, scaleY);
        //            if (isScaled)
        //            {
        //                MIN_SCALE = scale;
        //            }
        //            else
        //            {
        //                MIN_SCALE = Math.Max((getDiameter() * 1.0f) / dw, getDiameter() * 1.0f / dh) + 0.01f;
        //            }
        //            mMatrix.PostScale(scale, scale, imageView.Width / 2, imageView.Height / 2);
        //            mMatrix.PostTranslate((width - dw) / 2, (height - dh) / 2);
        //            imageView.ImageMatrix = mMatrix;
        //            firstTime = false;
        //        }
        //    }
 
        //    /// <summary>
        //    /// Ons the touch event.
        //    /// </summary>
        //    /// <returns><c>true</c>, if touch event was oned, <c>false</c> otherwise.</returns>
        //    /// <param name="e">E.</param>
        //    private bool OnTouchEvent2(MotionEvent e)
        //    {
        //        if (imageView.Drawable == null)
        //        {
        //            return false;
        //        }
 
        //        mScaleDetector.OnTouchEvent(e);
 
        //        switch (e.Action)
        //        {
        //            case MotionEventActions.Down:
        //                {
        //                    mMode = Mode.DRAG;
        //                    mPrevPointF.Set(e.GetX(), e.GetY());
        //                    break;
        //                }
        //            case MotionEventActions.Up:
        //                {
        //                    mMode = Mode.NONE;
        //                    break;
        //                }
        //            case MotionEventActions.Move:
        //                {
        //                    if (mMode == Mode.DRAG && e.PointerCount == 1)
        //                    {
        //                        float x = e.GetX();
        //                        float y = e.GetY();
        //                        float dx = e.GetX() - mPrevPointF.X;
        //                        float dy = e.GetY() - mPrevPointF.Y;
        //                        RectF rectF = getMatrixRectF();
        //                        // 如果宽度小于屏幕宽度,则禁止左右移动
        //                        if (rectF.Width() <= getDiameter())
        //                        {
        //                            dx = 0;
        //                        }
        //                        // 如果高度小雨屏幕高度,则禁止上下移动
        //                        if (rectF.Height() <= getDiameter())
        //                        {
        //                            dy = 0;
        //                        }
        //                        mMatrix.PostTranslate(dx, dy);
        //                        checkTrans();
        //                        //边界判断
        //                        imageView.ImageMatrix = mMatrix;
        //                        mPrevPointF.Set(x, y);
        //                    }
        //                    break;
        //                }
        //        }
        //        return true;
        //    }
 
        //    /// <summary>
        //    /// Ons the scale.
        //    /// </summary>
        //    /// <returns><c>true</c>, if scale was oned, <c>false</c> otherwise.</returns>
        //    /// <param name="detector">Detector.</param>
        //    public bool OnScale(ScaleGestureDetector detector)
        //    {
        //        float scale = getScale();
        //        float scaleFactor = detector.ScaleFactor;
        //        if ((scale >= MIN_SCALE && scaleFactor > 1.0f) ||
        //                (scale <= MAX_SCALE && scaleFactor < 1.0f))
        //        {
        //            if (scale * scaleFactor <= MIN_SCALE)
        //            {
        //                scaleFactor = MIN_SCALE / scale;
        //            }
        //            else if (scale * scaleFactor >= MAX_SCALE)
        //            {
        //                scaleFactor = MAX_SCALE / scale;
        //            }
        //            mMatrix.PostScale(scaleFactor, scaleFactor, detector.FocusX, detector.FocusY);
        //            checkTrans();
        //            imageView.ImageMatrix = mMatrix;
        //        }
 
        //        return true;
        //    }
 
        //    /// <summary>
        //    /// Ons the scale begin.
        //    /// </summary>
        //    /// <returns><c>true</c>, if scale begin was oned, <c>false</c> otherwise.</returns>
        //    /// <param name="detector">Detector.</param>
        //    public bool OnScaleBegin(ScaleGestureDetector detector)
        //    {
        //        mMode = Mode.ZOOM;
        //        return true;
        //    }
 
        //    /// <summary>
        //    /// Ons the scale end.
        //    /// </summary>
        //    /// <param name="detector">Detector.</param>
        //    public void OnScaleEnd(ScaleGestureDetector detector)
        //    {
        //        mMode = Mode.NONE;
        //    }
 
        //    /// <summary>
        //    /// 移动边界检查
        //    /// </summary>
        //    private void checkTrans()
        //    {
        //        RectF rect = getMatrixRectF();
        //        float deltaX = 0;
        //        float deltaY = 0;
 
        //        int width = imageView.Width;
        //        int height = imageView.Height;
 
        //        int horizontalPadding = (width - getDiameter()) / 2;
        //        int verticalPadding = (height - getDiameter()) / 2;
 
        //        // 如果宽或高大于屏幕,则控制范围 ; 这里的0.001是因为精度丢失会产生问题
        //        if (rect.Width() + 0.01 >= getDiameter())
        //        {
        //            if (rect.Left > horizontalPadding)
        //            {
        //                deltaX = -rect.Left + horizontalPadding;
        //            }
        //            if (rect.Right < width - horizontalPadding)
        //            {
        //                deltaX = width - horizontalPadding - rect.Right;
        //            }
        //        }
        //        if (rect.Height() + 0.01 >= getDiameter())
        //        {
        //            if (rect.Top > verticalPadding)
        //            {
        //                deltaY = -rect.Top + verticalPadding;
        //            }
        //            if (rect.Bottom < height - verticalPadding)
        //            {
        //                deltaY = height - verticalPadding - rect.Bottom;
        //            }
        //        }
        //        mMatrix.PostTranslate(deltaX, deltaY);
        //    }
 
 
        //    /// <summary>
        //    /// 得到直径
        //    /// </summary>
        //    /// <returns>The diameter.</returns>
        //    public int getDiameter()
        //    {
        //        return imageView.Height;
        //    }
 
        //    /// <summary>
        //    /// 获得缩放值
        //    /// </summary>
        //    /// <returns>The scale.</returns>
        //    private float getScale()
        //    {
        //        return getMatrixValue(Matrix.MscaleX);
        //    }
 
        //    /// <summary>
        //    /// Gets the matrix value.
        //    /// </summary>
        //    /// <returns>The matrix value.</returns>
        //    /// <param name="index">Index.</param>
        //    private float getMatrixValue(int index)
        //    {
        //        mMatrix.GetValues(MATRIX_ARR);
        //        return MATRIX_ARR[index];
        //    }
 
        //    /// <summary>
        //    /// 获得Matrix的RectF
        //    /// </summary>
        //    /// <returns>The matrix rect f.</returns>
        //    private RectF getMatrixRectF()
        //    {
        //        Matrix matrix = mMatrix;
        //        RectF rect = new RectF();
        //        if (null != imageView.Drawable)
        //        {
        //            rect.Set(0, 0, imageView.Drawable.IntrinsicWidth, imageView.Drawable.IntrinsicHeight);
        //            matrix.MapRect(rect);
        //        }
        //        return rect;
        //    }
        //}
    }
}