wxr
2020-06-16 f6fd8acd7c53c44187e70b4709443318a628f4b5
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
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;
        }
        /// <summary>
        /// Refresh this instance.
        /// </summary>
        public override void Refresh ()
        {
            base.Refresh ();
            Hide ();
        }
        /// <summary>
        /// Hide this instance.
        /// </summary>
        public void Hide ()
        {
            (AndroidView as MyLoading).textView.Text = "Loading......";
            AndroidView.Visibility = Android.Views.ViewStates.Gone;
            CurStatus = false;
        }
 
        /// <summary>
        /// Start this instance.
        /// </summary>
        public void Start ()
        {
            (AndroidView as MyLoading).textView.Text = "Loading......";
            AndroidView.BringToFront ();
            AndroidView.Visibility = ViewStates.Visible;
            CurStatus = true;
        }
 
        /// <summary>
        /// Start this instance.
        /// </summary>
        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;
            }
        }
 
 
        /// <summary>
        /// 文字大小
        /// </summary>
        /// <value>The size of the text.</value>
        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;
        /// <summary>
        /// 背景颜色
        /// </summary>
        /// <value>The color of the background.</value>
        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 ());
                }
            }
        }
 
        /// <summary>
        /// 点击事件
        /// </summary>
        /// <returns>The touch event.</returns>
        /// <param name="e">E.</param>
        public override bool OnTouchEvent (Android.Views.MotionEvent e)
        {
            //事件自己处理
            return true;
        }
    }
}