wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
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
using System;
using UIKit;
 
namespace Shared
{
    //AVFoundation CoreGraphics UIKit CoreMedia AudioToolbox VideoToolbox GLKit OpenAL MobileCoreServices SystemConfiguration CoreTelephony AVFoundation WebKit
    /// <summary>
    /// UI处理类
    /// </summary>
    public static class Application
    {
        //public static double PhoneType
        //{
        //    get
        //    {
        //        var type = UIDevice.CurrentDevice.SystemVersion.Split(new string[] { "." }, StringSplitOptions.None)[0];
        //        var d = 1.0d;
        //        double.TryParse(type, out d);
        //        return d;
        //    }
        //}
 
        public enum GpsUseMode
        {
            Always,
            WhenInUse
        }
        public static bool IsGpsEnable = true;
        public static GpsUseMode CurrentGpsUseMode = GpsUseMode.WhenInUse;
 
        
        public static bool IsMusicEnable = true;
 
        //2019-08-14 修改
        public static double PhoneType
        {
            get
            {
                var device = Xamarin.Essentials.DeviceInfo.Model;
                if (device == null)
                {
                    return 1.0;
                }
                var type = device.Replace("iPhone", "").Split(',')[0];
 
                double d = 1.0;
                double.TryParse(type, out d);
                return d;
            }
        }
 
        //public static String PhoneTypeModel
        //{
        //    get
        //    {
        //        var device = UIDevice.CurrentDevice.Model;// .SystemVersion.Split(new string[] { "." }, StringSplitOptions.None)[0];
 
        //        return device;
        //    }
        //}
 
 
        /// <summary>
        /// 获取实际的高度
        /// </summary>
        /// <returns>The real height.</returns>
        /// <param name="height">Height.</param>
        public static int GetRealHeight(int height)
        {
            return (int)(height / HeightScale);
        }
 
        /// <summary>
        /// 默认的字体大小
        /// </summary>
        public static int FontSize = 18;
        public static bool IsUsePingFang = false;
 
        /// <summary>
        /// 获取实际的宽度
        /// </summary>
        /// <returns>The real width.</returns>
        /// <param name="width">Width.</param>
        public static int GetRealWidth(int width)
        {
            return (int)(width / WidthScale);
        }
        /// <summary>
        /// 隐藏软键盘
        /// </summary>
        public static void HideSoftInput()
        {
            if (Shared.EditText.Instance != null)
            {
                Shared.EditText.Instance.Foucs = false;
            }
        }
 
        /// <summary>
        /// 当前设备类型
        /// </summary>
        public static readonly Device DeviceType = Device.Ios;
 
        /// <summary>
        /// 获取最小比例的实际值
        /// </summary>
        /// <returns>The minimum real.</returns>
        /// <param name="widthOrHeight">Width or height.</param>
        public static int GetMinReal(int widthOrHeight)
        {
            return (int)(widthOrHeight / MinScale);
        }
 
        /// <summary>
        /// 获取平均实际值
        /// </summary>
        /// <returns>The minimum real average.</returns>
        /// <param name="widthOrHeight">Width or height.</param>
        public static int GetMinRealAverage(int widthOrHeight)
        {
            return (int)(widthOrHeight / AverageScale);
        }
 
        /// <summary>
        /// 主线程执行指定事件
        /// </summary>
        /// <param name="action">Action.</param>
        public static void RunOnMainThread(Action action)
        {
            if (System.Threading.Thread.CurrentThread.ManagedThreadId == mainThreadId)
            {
                action();
            }
            else
            {
                RootFrameLayout.InvokeOnMainThread(action);
            }
        }
 
        public static bool IsWifi {
            get {
                return MyReachability.InternetConnectionStatus() == MyNetworkStatus.ReachableViaWiFiNetwork;
            }
        }
 
        /// <summary>
        /// 当前设备的宽度
        /// </summary>
        public static int CurrentWidth;
        /// <summary>
        /// 当前设备的高度
        /// </summary>
        public static int CurrentHeight;
 
 
        /// <summary>
        /// 宽度比例
        /// </summary>
        /// <value>The width scale.</value>
        public static float WidthScale
        {
            get
            {
                return DesignWidth * 1.0f / CurrentWidth;
            }
        }
 
        /// <summary>
        /// 高度比例
        /// </summary>
        /// <value>The height scale.</value>
        public static float HeightScale
        {
            get
            {
                //return Application.CurrentHeight / bigsize;
                return DesignHeight * 1.0f / CurrentHeight;
            }
        }
 
        /// <summary>
        /// 最小比例
        /// </summary>
        /// <value>The minimum scale.</value>
        public static float MinScale
        {
            get
            {
                return WidthScale < HeightScale ? WidthScale : HeightScale;
            }
        }
 
        /// <summary>
        /// 平均比例
        /// </summary>
        /// <value>The average scale.</value>
        public static float AverageScale
        {
            get
            {
                return (WidthScale + HeightScale)/2;
            }
        }
 
 
        /// <summary>
        ///  设计宽度 
        /// </summary>
        public static int DesignWidth=1920;
        /// <summary>
        /// 设计高度
        /// </summary>
        public static int DesignHeight=1136;
 
 
//        CoreGraphics.CGRect screenRect = [[UIScreen mainScreen] bounds];
//CoreGraphics.CGSize screenSize = screenRect.size;
 
 
        /// <summary>
        /// 当前主页
        /// </summary>
        /// <value>The main page.</value>
        public static Shared.FrameLayout MainPage
        {
            get;
            private set;
        }
 
        static int mainThreadId;
        static UIView rootFrameLayout;
        /// <summary>
        /// 根容器视图
        /// </summary>
        /// <value>The root frame layout.</value>
        public static UIView RootFrameLayout
        {
            get
            {
                return rootFrameLayout;
            }
            set
            {
                mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
                rootFrameLayout = value;
                CurrentWidth = (int)value.Frame.Width;
                Shared.HDLUtils.WriteLine ("3========" + CurrentWidth);
                CurrentHeight = (int)value.Frame.Height;
 
                MainPage = new FrameLayout(value) { Width = (int)value.Frame.Width, Height = (int)value.Frame.Height, Parent = new RootView() { Width = (int)value.Frame.Width, Height = (int)value.Frame.Height } };
                MainPage.Refresh();
            }
        }
 
        /// <summary>
        /// 数据文件根目录
        /// </summary>
        /// <value>The root path.</value>
        public static  string RootPath=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)+"/";    
 
        /// <summary>
        ///  图片的根目录
        /// </summary>
        /// <value>The root path image.</value>
        public static string  RootPathImage
        {
            get
            {
                return RootPath + "Phone/";
            }
        }
            
        /// <summary>
        /// 是否是pad
        /// </summary>
        public static bool IsPad {
            get {
                return false;
                //return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad;
            }
        }
 
 
        /// <summary>
        /// 皮肤,null时表示用默认的
        /// </summary>
        public static string Skin;
        /// <summary>
        /// GPS位置变化事件
        /// </summary>
        public static Action<double, double> LocationAction;
 
 
        //获取当前屏幕显示的viewcontroller
        public static UIViewController currentVC
        {
            get
            {
                var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                var currentVC = getCurrentVCFrom(rootViewController);
                return currentVC;
            }
        }
 
        static UIViewController getCurrentVCFrom(UIViewController rootVC)
        {
            UIViewController currentVC;
            if (rootVC.PresentedViewController != null)
            {
                // 视图是被presented出来的
                rootVC = rootVC.PresentedViewController;
            }
            if (rootVC.GetType() == typeof(UITabBarController))
            {
                // 根视图为UITabBarController
                currentVC = getCurrentVCFrom((rootVC as UITabBarController).SelectedViewController);
            }
            else if (rootVC.GetType() == typeof(UINavigationController))
            {
                // 根视图为UINavigationController
                currentVC = getCurrentVCFrom((rootVC as UINavigationController).VisibleViewController);
            }
            else
            {
                // 根视图为非导航类
                currentVC = rootVC;
            }
            return currentVC;
        }
    }
}