/// <summary> /// Initializes the ion instance. /// </summary> /// <returns>The async.</returns> protected async override Task <bool> OnPreInitAsync() { if (!await base.OnPreInitAsync()) { return(false); } fileManager = new AndroidFileManager(context); var path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ION.database"); database = new IONDatabase(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), path, this); deviceManager = new BaseDeviceManager(this, new AndroidConnectionManager(this)); locationManager = new AndroidLocationManager(this); alarmManager = new BaseAlarmManager(this); dataLogManager = new DataLogManager(this); alarmManager.alertFactory = (IAlarmManager am, IAlarm alarm) => { return(new CompoundAlarmAlert(alarm, new PopupActivityAlert(alarm, context), new ToneAlarmAlert(alarm, this), new VibrateAlarmAlert(alarm, this) )); }; fluidManager = new BaseFluidManager(this); return(true); }
// Overridden from BaseAndroidION protected async override Task <bool> OnPreInitAsync() { if (!await base.OnPreInitAsync()) { return(false); } fileManager = new AndroidFileManager(context); var file = fileManager.CreateTemporaryFile("TEMPORARY_DATABASE.db", EFileAccessResponse.CreateIfMissing); database = new IONDatabase(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), file.fullPath, this); deviceManager = new RemoteDeviceManager(this); locationManager = new AndroidLocationManager(this); alarmManager = new BaseAlarmManager(this); dataLogManager = new DataLogManager(this); alarmManager.alertFactory = (IAlarmManager am, IAlarm alarm) => { return(new CompoundAlarmAlert(alarm, new PopupActivityAlert(alarm, context), new ToneAlarmAlert(alarm, this), new VibrateAlarmAlert(alarm, this))); }; fluidManager = new BaseFluidManager(this); return(true); }
public void Initialize() { m_liveSessionListeners = new HashSet <object>(); IStepTracker stepTracker = null; #if IOS_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing iOS Native"); m_categoryOptions = IOSAudioSessionCategoryOptions.None; if (MixWithOthers) { m_categoryOptions = IOSAudioSessionCategoryOptions.MixWithOthers; } m_currentCategory = DefaultAudioCategory; if (EnableBackgroundAudio) { IOSAudioSession.Instance.SetCategory(m_currentCategory, m_categoryOptions); IOSAudioSession.Instance.RemoteCommandReceived += (sender, args) => { if (args.Command == IOSAudioRemoteCommand.Pause) { SuspendLiveSession(); } }; } if (UseNativeDownloader) { FileDownloader.SetFactory(new IOSFileDownloaderFactory()); } AppDataPath = IOSFileDownloader.AppDataPath; Accelerometer = IOSMotionManager.Instance.GetAccelerometer(); LocationManager = IOSLocationManager.Instance; SystemCompass = new IOSCompass(); if (EnableBeacons) { BeaconManager = IOSBeaconManager.Instance; } if (EnableNotifications) { LocalNotificationManager = new IOSLocalNotificationManager(IOSLocalNotificationTypes.Badge | IOSLocalNotificationTypes.Sound); } } #endif #if ANDROID_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing Android Native"); JavaClass activityClass = new JavaClass("com.unity3d.player.UnityPlayer"); JavaObject mainActivity = activityClass.GetStaticFieldValue <JavaObject>("currentActivity", "android.app.Activity"); AndroidApplicationManager.Instance.Initialize(mainActivity); LocationManager = new AndroidLocationManager(); if (EnableBeacons) { BeaconManager = new AndroidBeaconManager(); } if (EnableNotifications) { LocalNotificationManager = new AndroidLocalNotificationManager(StorageManager.GetFilePath("platform", "androidNotificationManager.json")); } } #endif if (BeaconManager == null && EnableBeacons) { BeaconManager = UnityBeaconManager.Instance; } if (Accelerometer == null) { Accelerometer = gameObject.AddComponent <UnityAccelerometer>(); } if (LocationManager == null) { LocationManager = gameObject.AddComponent <UnityLocationManager>(); } LocationManager.EnableBackgroundUpdates = EnableBackgroundLocation; if (SystemCompass == null) { SystemCompass = gameObject.AddComponent <UnityCompass>(); } if (LocalNotificationManager == null) { LocalNotificationManager = new DummyLocalNotificationManager(); } if (EnableNotifications && EnableBackgroundNotifications) { BackgroundNotifier.Instance.Initialize(); } var nrCompass = new NoiseDampeningCompass(SystemCompass); #if UNITY_ANDROID // Android compass tends to be much more jittery--apply a higher dampening // factor nrCompass.DampeningFactor = 0.25; #endif NoiseReducedCompass = nrCompass; if (Application.isMobilePlatform) { var accTracker = new AccelerometerStepTracker(Accelerometer); stepTracker = accTracker; Accelerometer.Start(); accTracker.Start(); } else { stepTracker = gameObject.AddComponent <DebugStepTracker>(); } Pedometer = new Pedometer(stepTracker); m_logger.Debug("Setting compass type={0}", CompassType); switch (CompassType) { case CompassType.System: Compass = SystemCompass; break; case CompassType.NoiseReduced: Compass = NoiseReducedCompass; break; case CompassType.LocationTracker: LocationTrackerCompass = new Motive.AR.LocationServices.LocationTrackerCompass(); Compass = LocationTrackerCompass; break; case CompassType.Hybrid: default: var hybrid = new HybridCompass(NoiseReducedCompass); LocationTrackerCompass = hybrid.TrackerCompass; Compass = hybrid; break; } AudioChannel = CreateAudioPlayerChannel(); ForegroundAudioChannel = gameObject.AddComponent <UnityAudioPlayerChannel>(); Pedometer.Stepped += (sender, args) => { if (ScriptEngine.Instance.UserInteractionEventManager != null) { ScriptEngine.Instance.UserInteractionEventManager.AddEvent("step"); } }; if (ScreenSleepBehavior == ScreenSleepBehavior.AlwaysOn) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } }