using System;
|
using Android;
|
using Android.Content;
|
using Android.Net;
|
using Android.OS;
|
using Java.Util;
|
using Shared;
|
using Shared.SimpleControl;
|
using SmartHome;
|
|
namespace com.hdl.on
|
{
|
/// <summary>
|
/// 设定为默认启动的Application
|
/// </summary>
|
[Android.App.Application]
|
public class Application : Android.App.Application
|
{
|
static void reStartApp (Android.App.Application application)
|
{
|
var intent = new Intent (application, typeof (BaseActivity));
|
intent.AddFlags (ActivityFlags.NewTask);
|
application.StartActivity (intent);
|
Android.OS.Process.KillProcess (Android.OS.Process.MyPid ());
|
}
|
|
public Application (IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base (handle, ownerShip) { }
|
public override void OnCreate ()
|
{
|
if (Shared.Application.Activity != null) {
|
reStartApp (this);
|
return;
|
}
|
|
Shared.Application.IsGpsEnable = false;
|
|
base.OnCreate ();
|
|
initAll ();
|
}
|
/// <summary>
|
/// 所有初始化全部在这个方法实现
|
/// </summary>
|
void initAll ()
|
{
|
#if wallon
|
BaseActivity.TopMargin = -30;
|
BaseActivity.IsEnnableGPS = false;
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
BaseActivity.KeepScreenON = false;
|
#endif
|
Locale locale1 = Locale.Default;
|
var localeList = Resources.Configuration.Locale;
|
//if(localeList.Language == "zh") {
|
//Language.CurrentLanguage = "Chinese";
|
//}
|
|
|
|
string [] permissions = new string [] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.RecordAudio,
|
Manifest.Permission.Camera, Manifest.Permission.ProcessOutgoingCalls, Manifest.Permission.GetAccounts};
|
|
var version = Build.VERSION.SdkInt + "";
|
Console.WriteLine ("Build.VERSION.SdkInt : " + version);
|
|
BaseActivity.BackKeyAction = () => {
|
if (Shared.SimpleControl.MainPage.Loading != null) {
|
Console.WriteLine (MainPage.Loading.CurStatus);
|
if (Shared.SimpleControl.MainPage.Loading.CurStatus) {
|
//Shared.SimpleControl.MainPage.Loading.Hide ();
|
return;
|
}
|
}
|
try {
|
var lastView = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 1);
|
if (lastView != null && lastView.Tag.ToString () == "Dialog") {
|
if (SharedMethod.SharedMethod.CurPageLayout == null) {
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
return;
|
} else {
|
var lastView2 = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 2);
|
lastView.RemoveFromParent ();
|
lastView2.RemoveFromParent ();
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
return;
|
}
|
}
|
} catch (System.Exception ezx) {
|
Console.WriteLine (ezx.Message);
|
}
|
if (SharedMethod.SharedMethod.CurPageLayout != null) {
|
if (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount > 1) {
|
SharedMethod.SharedMethod.CurPageLayout.GetChildren (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount - 1).RemoveFromParent ();
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
} else {
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
}
|
}
|
};
|
BaseActivity.IsHideVirualButtons = true;
|
ZXing.Mobile.MobileBarcodeScanner.Initialize (this);
|
init ();
|
BaseActivity.OnCreateActoin += (activity, application) => {
|
Microsoft.AppCenter.AppCenter.Start ("7e0ba985-ae3b-4299-9483-b10f4041f8b2", typeof (Microsoft.AppCenter.Analytics.Analytics), typeof (Microsoft.AppCenter.Crashes.Crashes));
|
if (!string.IsNullOrEmpty (UserConfig.Instance.SetLanguage)) {
|
Language.CurrentLanguage = UserConfig.Instance.SetLanguage;
|
}
|
|
};
|
BaseActivity.RefreshUIAction += (activity) => {
|
MainPage.Show ();
|
checkSomeInfo ();
|
};
|
BaseActivity.OnResumeAction += (activity) => {
|
checkSomeInfo ();
|
WiFiSet.refreshView?.Invoke ();
|
};
|
BaseActivity.OnDestroyAction += (activity) => {
|
Console.WriteLine ("OnDestroyAction");
|
BusSocket.Stop ();
|
};
|
|
HDLUtils.SetAuthoritiesName ("com.hdl.SmartCenter.fileProvider");
|
}
|
public static bool IsShowTip = true;
|
void init ()
|
{
|
UserConfig.Instance.phoneName = Android.OS.Build.Manufacturer;
|
|
//获取经纬度
|
}
|
void checkSomeInfo ()
|
{
|
try {
|
IsShowTip = true;
|
var status = isNetworkAvailable (this);
|
int internetStatus = 0;
|
if (!status) {
|
internetStatus = 0;
|
}
|
|
var isWifi = isWifiConnected (this);
|
if (isWifi) {
|
internetStatus = 2;
|
} else {
|
|
internetStatus = 1;
|
}
|
UserConfig.Instance.internetStatus = internetStatus;
|
} catch (Exception ex) {
|
Console.WriteLine ($"android check some info erorr : {ex.Message}");
|
}
|
}
|
|
bool isNetworkAvailable (Context context)
|
{
|
var cm = (ConnectivityManager)context.GetSystemService (ConnectivityService);
|
if (cm == null || cm.ActiveNetworkInfo == null) {
|
return false;
|
} else {
|
return cm.ActiveNetworkInfo.IsAvailable;
|
}
|
}
|
|
bool isWifiConnected (Context context)
|
{
|
if (context != null) {
|
var mConnectivityManager = (ConnectivityManager)context.GetSystemService
|
(ConnectivityService);
|
var mWiFiNetworkInfo = mConnectivityManager.GetNetworkInfo (ConnectivityType.Wifi);
|
if (mWiFiNetworkInfo != null) {
|
return mWiFiNetworkInfo.IsAvailable;
|
}
|
}
|
return false;
|
}
|
}
|
}
|