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;
|
// }
|
//}
|
}
|
}
|