using System;
|
using Android.Graphics.Drawables;
|
using Android.Graphics;
|
using Android.Telephony;
|
using Android.Content;
|
|
namespace Shared
|
{
|
/// <summary>
|
/// UI处理类
|
/// </summary>
|
public class Application
|
{
|
/// <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 float FontSize = 12;
|
|
/// <summary>
|
/// 当前设备类型
|
/// </summary>
|
public static readonly Device DeviceType = Device.Android;
|
|
/// <summary>
|
/// 获取实际的宽度
|
/// </summary>
|
/// <returns>The real width.</returns>
|
/// <param name="width">Width.</param>
|
public static int GetRealWidth(int width)
|
{
|
return (int)(width / WidthScale);
|
}
|
|
public static void HideSoftInput()
|
{
|
var imm = (Android.Views.InputMethods.InputMethodManager)Application.Activity.GetSystemService(Context.InputMethodService);
|
if (Shared.EditText.Instance != null)
|
{
|
imm.HideSoftInputFromWindow(Shared.EditText.Instance.AndroidView.WindowToken, 0); //强制隐藏键盘
|
}
|
else
|
{
|
imm.ToggleSoftInput(0, Android.Views.InputMethods.HideSoftInputFlags.NotAlways);
|
}
|
}
|
|
/// <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);
|
}
|
|
public static void RunOnMainThread (Action action)
|
{
|
if (System.Threading.Thread.CurrentThread.ManagedThreadId == mainThreadId) {
|
action ();
|
} else {
|
//System.Threading.Tasks.Task.Run (() => {
|
Activity.RunOnUiThread (action);
|
//});
|
};
|
}
|
|
public static bool IsWifi;
|
|
|
/// <summary>
|
/// 当前设备的宽度
|
/// </summary>
|
public static int CurrentWidth { get; internal set;}
|
|
/// <summary>
|
/// 当前设备的高度
|
/// </summary>
|
public static int CurrentHeight { get; internal set; }
|
|
|
/// <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 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=640;
|
/// <summary>
|
/// 设计高度
|
/// </summary>
|
public static int DesignHeight=1136;
|
|
/// <summary>
|
/// 当前的Activity
|
/// </summary>
|
public static Android.App.Activity Activity { get; internal set;}
|
|
/// <summary>
|
/// 当前主页
|
/// </summary>
|
/// <value>The main page.</value>
|
public static Shared.FrameLayout MainPage
|
{
|
get;
|
private set;
|
}
|
static int mainThreadId;
|
static Android.Widget.FrameLayout rootFrameLayout;
|
/// <summary>
|
/// 根容器视图
|
/// </summary>
|
/// <value>The root frame layout.</value>
|
public static Android.Widget.FrameLayout RootFrameLayout
|
{
|
get
|
{
|
return rootFrameLayout;
|
}
|
set
|
{
|
mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
|
rootFrameLayout = value;
|
rootFrameLayout.LayoutParameters.Width = CurrentWidth;
|
rootFrameLayout.LayoutParameters.Height = CurrentHeight;
|
|
MainPage = new FrameLayout(value) { Width = value.Width, Height = value.Height,BackgroundColor=0xFF000000, Parent = new RootView() { Width = value.Width, Height = value.Height } };
|
MainPage.Refresh();
|
}
|
}
|
|
/// <summary>
|
/// 数据文件根目录
|
/// </summary>
|
/// <value>The root path.</value>
|
public static readonly string RootPath=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)+"/";
|
|
|
/// <summary>
|
/// 是否是pad
|
/// </summary>
|
public static bool IsPad
|
{
|
get {
|
return false;
|
//TelephonyManager telephony = (TelephonyManager)Activity.GetSystemService (Context.TelephonyService);
|
//if (telephony.PhoneType == PhoneType.None) {
|
// return true;
|
//} else {
|
// return false;
|
//}
|
}
|
}
|
|
/// <summary>
|
/// 皮肤,null时表示用默认的
|
/// </summary>
|
public static string Skin;
|
/// <summary>
|
/// GPS位置变化事件
|
/// </summary>
|
public static Action<double, double> LocationAction;
|
|
public static bool IsGpsEnable = true;
|
|
public static bool IsMusicEnable = true;
|
|
/// <summary>
|
/// 开启定位服务
|
/// </summary>
|
public static void StartGPSLocationService()
|
{
|
Activity.StartService(new Intent(Activity, typeof(GPSLocationService)));
|
}
|
/// <summary>
|
/// 关闭定位服务
|
/// </summary>
|
public static void StopGPSLocationService()
|
{
|
Activity.StopService(new Intent(Activity, typeof(GPSLocationService)));
|
}
|
}
|
}
|