using System;
using Android.Content;
using Android.Runtime;
using Android.Widget;
using Android.Util;
using Android.Views;
using Android.Graphics.Drawables;
namespace Shared
{
public class Loading : View
{
public bool CurStatus = false;
public Loading ()
{
AndroidView = new MyLoading (Application.Activity);
CurStatus = false;
}
///
/// Refresh this instance.
///
public override void Refresh ()
{
base.Refresh ();
Hide ();
}
///
/// Hide this instance.
///
public void Hide ()
{
(AndroidView as MyLoading).textView.Text = "Loading......";
AndroidView.Visibility = Android.Views.ViewStates.Gone;
CurStatus = false;
}
///
/// Start this instance.
///
public void Start ()
{
(AndroidView as MyLoading).textView.Text = "Loading......";
AndroidView.BringToFront ();
AndroidView.Visibility = ViewStates.Visible;
CurStatus = true;
}
///
/// Start this instance.
///
public void Start (string s)
{
(AndroidView as MyLoading).textView.Text = s;
AndroidView.BringToFront ();
AndroidView.Visibility = ViewStates.Visible;
}
public string Text {
get {
return (AndroidView as MyLoading).textView.Text;
}
set {
(AndroidView as MyLoading).textView.Text = value;
}
}
uint mTextColor;
public uint TextColor
{
get
{
return mTextColor;
}
set
{
mTextColor = value;
(AndroidView as MyLoading).textView.SetTextColor (HDLUtils.GetUIColorWithUint(mTextColor));
}
}
public virtual uint LodingBackgroundColor {
get {
return (AndroidView as MyLoading).LodingBackgroundColor;
}
set {
(AndroidView as MyLoading).LodingBackgroundColor = value;
}
}
///
/// 文字大小
///
/// The size of the text.
public float TextSize
{
get
{
return (AndroidView as MyLoading).textView.TextSize;
}
set
{
(AndroidView as MyLoading).textView.SetTextSize(ComplexUnitType.Sp, value);
}
}
}
class MiddleLinearLayout : LinearLayout
{
public MiddleLinearLayout (Context context)
: base (context)
{
}
int mMaxWidth {
get {
var metric = new DisplayMetrics ();
Application.Activity.WindowManager.DefaultDisplay.GetRealMetrics (metric);
return metric.WidthPixels * 3 / 4;
}
}
protected override void OnMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
var widthMode = MeasureSpec.GetMode (widthMeasureSpec);
var widthSize = MeasureSpec.GetSize (widthMeasureSpec);
if (widthMode == MeasureSpecMode.Exactly) {
widthSize = widthSize <= mMaxWidth ? widthSize
: (int)mMaxWidth;
}
if (widthMode == MeasureSpecMode.Unspecified) {
widthSize = widthSize <= mMaxWidth ? widthSize
: (int)mMaxWidth;
}
if (widthMode == MeasureSpecMode.AtMost) {
widthSize = widthSize <= mMaxWidth ? widthSize
: (int)mMaxWidth;
}
var maxWidthMeasureSpec = MeasureSpec.MakeMeasureSpec (widthSize,
widthMode);
base.OnMeasure (maxWidthMeasureSpec, heightMeasureSpec);
}
}
class MyLoading : Android.Widget.LinearLayout
{
ProgressBar Progress;
public Android.Widget.TextView textView;
LinearLayout tempLinearLayout;
public MyLoading (Context context)
: base (context)
{
//Progress = new ProgressBar(context);
//SetBackgroundColor(Android.Graphics.Color.Argb(50, 0x32, 0x32, 0x32));
//SetGravity(GravityFlags.Center);
//tempLinearLayout = new LinearLayout(context) { Orientation = Orientation.Vertical };
//tempLinearLayout.SetGravity(GravityFlags.CenterHorizontal);
//tempLinearLayout.AddView(Progress, new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent));
//textView = new Android.Widget.TextView(context);
//textView.Text = "Please wait....";
//tempLinearLayout.AddView(textView, new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent));
//AddView(tempLinearLayout, new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent));
//tempLinearLayout.SetPadding(20, 20, 20, 20);
Progress = new ProgressBar (context);
SetBackgroundColor (Android.Graphics.Color.Argb (50, 0x32, 0x32, 0x32));
SetGravity (GravityFlags.Center);
tempLinearLayout = new MiddleLinearLayout (context) { Orientation = Orientation.Vertical };
tempLinearLayout.SetGravity (GravityFlags.CenterHorizontal);
//*******ProgressBar***********
var mProgressLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
//mProgressLayoutParams.SetMargins(0, 0, 0, 40);
tempLinearLayout.AddView (Progress, mProgressLayoutParams);
//*******TextView***********
textView = new Android.Widget.TextView (context);
textView.Text = "Loading......";
var mTextViewParams = new LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
mTextViewParams.SetMargins(0, 20, 0, 0);
tempLinearLayout.AddView(textView, mTextViewParams);
//tempLinearLayout.AddView(textView, new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent));
AddView(tempLinearLayout, new Android.Views.ViewGroup.LayoutParams (Android.Views.ViewGroup.LayoutParams.WrapContent, Android.Views.ViewGroup.LayoutParams.WrapContent));
tempLinearLayout.SetPadding (40, 40, 40, 40);
tempLinearLayout.SetMinimumWidth(DensityUtil.Dip2Px(100));
}
uint loadingBackgroundColor;
///
/// 背景颜色
///
/// The color of the background.
public virtual uint LodingBackgroundColor {
get {
return loadingBackgroundColor;
}
set {
loadingBackgroundColor = value;
if (this.GetType () != typeof (ImageView)) {
if (tempLinearLayout.Background == null || tempLinearLayout.Background.GetType () != typeof (GradientDrawable)) {
tempLinearLayout.Background = new Android.Graphics.Drawables.GradientDrawable ();
}
var gradientDrawable = (GradientDrawable)tempLinearLayout.Background;
gradientDrawable.SetCornerRadius (DensityUtil.Dip2Px (6));
byte r, g, b, a;
r = (byte)(loadingBackgroundColor / 256 / 256 % 256);
g = (byte)(loadingBackgroundColor / 256 % 256);
b = (byte)(loadingBackgroundColor % 256);
a = (byte)(loadingBackgroundColor / 256 / 256 / 256 % 256);
gradientDrawable.SetColor (Android.Graphics.Color.Argb (a, r, g, b).ToArgb ());
}
}
}
///
/// 点击事件
///
/// The touch event.
/// E.
public override bool OnTouchEvent (Android.Views.MotionEvent e)
{
//事件自己处理
return true;
}
}
}