using System;
|
using Android;
|
using Android.Content;
|
using Android.Net;
|
using Android.OS;
|
//using CN.Jpush.Android.Api;
|
//using CN.Jpush.Android.Service;
|
using Java.Lang;
|
using Java.Util;
|
using Java.Util.Zip;
|
using Shared;
|
using Shared.SimpleControl;
|
using SmartHome;
|
|
|
namespace SharedMethod
|
{
|
public static class SharedMethod
|
{
|
//public static UIApplication sharedApp;
|
public static void ChangeSkin ()
|
{
|
//if (UserConfig.Instance.SkinCode == 0) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.LightContent;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//} else if (UserConfig.Instance.SkinCode == 1) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.Default;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//}
|
}
|
|
public static PageLayout CurPageLayout = null;
|
}
|
|
}
|
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 ();
|
|
|
Language.CurrentLanguage = "Chinese";
|
Locale locale1 = Locale.Default;
|
var localeList = Resources.Configuration.Locale;
|
Console.WriteLine ("当前语言:" + localeList.Language);
|
if (localeList.Language == "zh") {
|
Language.CurrentLanguage = "Chinese";
|
|
|
} else {
|
Language.CurrentLanguage = "English";
|
}
|
}
|
|
/// <summary>
|
/// 所有初始化全部在这个方法实现
|
/// </summary>
|
void initAll ()
|
{
|
//BaseActivity.TopMargin = -30;
|
//BaseActivity.IsEnnableGPS = false;
|
//BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
//BaseActivity.KeepScreenON = false;
|
|
|
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;
|
}
|
}
|
//if(BaseActivity.VerifyDateTime == DateTime.MaxValue) { } else
|
try {
|
var lastView = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 1);
|
Console.WriteLine ("lastView " + lastView);
|
if (MainPage.Loading.CurStatus) {
|
return;
|
}
|
if (lastView != null && lastView.Tag.ToString () == "Dialog") {
|
if (SharedMethod.SharedMethod.CurPageLayout == null) {
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
return;
|
} else {
|
Console.WriteLine ("Remove Dialog!!!!");
|
var lastView2 = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 2);
|
lastView.RemoveFromParent ();
|
lastView2.RemoveFromParent ();
|
Console.WriteLine ("Remove Dialog End!!!!");
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
return;
|
}
|
}
|
} catch (System.Exception ezx) {
|
Console.WriteLine (ezx.Message);
|
}
|
if (SharedMethod.SharedMethod.CurPageLayout != null) {
|
if (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount > 1) {
|
Console.WriteLine ("Remove PageLayout Children!!!!");
|
SharedMethod.SharedMethod.CurPageLayout.GetChildren (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount - 1).RemoveFromParent ();
|
Console.WriteLine ("Remove PageLayout Children End!!!!");
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
} else {
|
Console.WriteLine ("BaseActivity.VerifyDateTime = DateTime.MaxValue");
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
}
|
}
|
};
|
|
Shared.Application.FontSize = 16;
|
BaseActivity.IsHideVirualButtons = false;
|
init ();
|
BaseActivity.OnCreateActoin += (activity, application) => {
|
BaseActivity.NetworkStateChanged += (int obj) => {
|
Console.WriteLine ("NetworkStateChanged " + obj);
|
};
|
};
|
BaseActivity.RefreshUIAction += (activity) => {
|
MainPage.Show ();
|
checkSomeInfo ();
|
};
|
BaseActivity.OnResumeAction += (activity) => {
|
if (MainPage.Showed) {
|
checkSomeInfo ();
|
Shared.Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
};
|
BaseActivity.OnDestroyAction += (activity) => {
|
BusSocket.Stop ();
|
};
|
|
//HDLUtils.SetAuthoritiesName ("com.hdl.crabtree.fileProvider");
|
|
}
|
public static bool IsShowTip = true;
|
void init ()
|
{
|
Shared.Application.Skin = "Phone2";
|
SkinStyle.Current.ChangeColor ();
|
////设置极光调试模式,为false时只打印警告信息
|
//JPushInterface.SetDebugMode (false);
|
//JPushInterface.Init (this);//保存手机名称到本地文件
|
//获取经纬度
|
//Shared.Application.LocationAction = (arg1, arg2) => {
|
// Shared.Application.LocationAction = null;
|
// Shared.Application.StopGPSLocationService ();
|
// System.Threading.Tasks.Task.Run (() => {
|
// while (true) {
|
// try {
|
// Shared.SimpleControl.CommonPage.AirQuality = new service.hdlcontrol.com_WebServiceAirQuality.WebServiceAirQuality ().GetAirQuality (arg2.ToString (), arg1.ToString ());
|
// if (Shared.SimpleControl.CommonPage.AirQuality != null)
|
// break;
|
// } catch { }
|
// }
|
// Shared.Application.RunOnMainThread (() => {
|
// if (CommonPage.RefreshAir != null)
|
// CommonPage.RefreshAir ();
|
// });
|
// });
|
//};
|
}
|
void checkSomeInfo ()
|
{
|
//JPushInterface.ClearAllNotifications (this);
|
|
IsShowTip = true;
|
int internetStatus = 0;
|
internetStatus = NetworkUtils.CheckConnectedMode ();
|
Console.WriteLine ("internetStatus:" + internetStatus);
|
|
}
|
|
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;
|
}
|
|
}
|
}
|