Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            // GPSセンサの取得
            GeolocationSensor = SensorManager.GetSensorsByTypeId(SensorTypes.LocationGps)[0];
        }
Ejemplo n.º 2
0
        public void OnSensorChanged(SensorEvent e)
        {
            if (e.Sensor.Type == SensorType.MagneticField)
            {
                magnet.Clear();
                magnet.AddRange(e.Values);
            }
            if (e.Sensor.Type == SensorType.Accelerometer)
            {
                gravity.Clear();
                gravity.AddRange(e.Values);
            }

            if (magnet.Count > 0 && gravity.Count > 0)
            {
                float[] R      = new float[9];
                float[] I      = new float[9];
                bool    worked = SensorManager.GetRotationMatrix(R, I, gravity.ToArray(), magnet.ToArray());

                if (worked)
                {
                    float[] orientation = new float[3];
                    SensorManager.GetOrientation(R, orientation);

                    ImageView arrowImageView = FindViewById <ImageView>(Resource.Id.arrowImageView);
                    float     azimuth        = orientation[0] * 180 / (float)Math.PI; //convert to degrees
                    arrowImageView.Rotation = azimuth;
                }
            }
        }
Ejemplo n.º 3
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            if (intent.Action.Equals(Constants.ACTION_START_SERVICE))
            {
                if (_isStarted)
                {
                    Log.Info(TAG, "OnStartCommand: The service is already running.");
                }
                else
                {
                    _sensorManager = (SensorManager)GetSystemService(SensorService);
                    InitializeLocationManager();

                    _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(SensorType.Gravity), SensorDelay.Normal);
                    _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(SensorType.Accelerometer), SensorDelay.Normal);
                    foreach (var locationProvider in _locationProviders)
                    {
                        _locationManager.RequestLocationUpdates(locationProvider, 0, 0, this);
                    }

                    _isStarted = true;
                    // RegisterForegroundService();
                    Log.Info(TAG, "OnStartCommand: The service is starting.");
                }
            }
            else if (intent.Action.Equals(Constants.ACTION_STOP_SERVICE))
            {
                UnregisterSensors();
                Log.Info(TAG, "OnStartCommand: The service is stopping.");
                _isStarted = false;
            }

            return(StartCommandResult.Sticky);
        }
Ejemplo n.º 4
0
        void InitSensor()
        {
            sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager;
            stopwatch     = new Stopwatch();
            stopwatch.Restart();
            isFirstRun           = true;
            sensorIsAccelerating = true; // moving forward, not backward

            if (sensorManager != null)
            {
                sensor = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
                DeviceDebugAndroid.LogToFileStatic("accelerometer sensor requested");

                if (sensor != null)
                {
                    // SensorDelay.Ui   = approx 15 Hz = every 66 milliseconds
                    // SensorDelay.Game = approx 50 Hz = every 20 milliseconds
                    sensorManager.RegisterListener(this, sensor, SensorDelay.Game);
                    status = "sensor init";
                    DeviceDebugAndroid.LogToFileStatic("accelerometer sensor init ok");
                }
                else
                {
                    status = "sensor not enabled";
                    DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensor is null");
                }
            }
            else
            {
                status = "sensor manager not enabled";
                DeviceDebugAndroid.LogToFileStatic("ERROR: accelerometer sensorManager is null");
            }
        }
Ejemplo n.º 5
0
        public override void Initialize(GameContext <AndroidXenkoGameView> gameContext)
        {
            var viewListener = new ViewListener(this);

            Control = gameContext.Control;
            Control.SetOnTouchListener(viewListener);
            Control.SetOnKeyListener(viewListener);
            Control.Resize += GameViewOnResize;

            GameViewOnResize(null, EventArgs.Empty);

            // Get the android sensors
            sensorManager           = (SensorManager)PlatformAndroid.Context.GetSystemService(Context.SensorService);
            androidAccelerometer    = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            androidGyroscope        = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
            androidUserAcceleration = sensorManager.GetDefaultSensor(SensorType.LinearAcceleration);
            androidGravity          = sensorManager.GetDefaultSensor(SensorType.Gravity);
            androidRotationVector   = sensorManager.GetDefaultSensor(SensorType.RotationVector);

            // Determine which sensor is available on the device
            Accelerometer.IsSupported    = androidAccelerometer != null;
            Compass.IsSupported          = androidRotationVector != null;
            Gyroscope.IsSupported        = androidGyroscope != null;
            UserAcceleration.IsSupported = androidUserAcceleration != null;
            Gravity.IsSupported          = androidGravity != null;
            Orientation.IsSupported      = androidRotationVector != null;
        }
Ejemplo n.º 6
0
        protected string ReturnHeading()
        {
            SensorManager sm = _context.GetSystemService(Context.SensorService) as SensorManager;

            Sensor sensor = sm.GetDefaultSensor(SensorType.Orientation);

            if (sensor != null)
            {
                sm.RegisterListener(this, sensor, SensorDelay.Ui);
            }

            // block on the search until the async result return
            string heading;

            lock (_locker)
            {
                while (location == null)
                {
                    Monitor.Pulse(_locker);
                }

                heading  = location;
                location = null;
            }
            return(heading);
        }
Ejemplo n.º 7
0
            public RunningView(Context context) : base(context)
            {
                onzecontext = context;
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.InScaled = false;
                geo          = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.Kaart, opt);

                arrow = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.Arrow, opt);
                arrow = Bitmap.CreateScaledBitmap(arrow, arrow.Width / 4, arrow.Height / 4, false);

                this.Touch += RaakAan;

                LocationManager lm   = (LocationManager)context.GetSystemService(Context.LocationService);
                Criteria        crit = new Criteria();

                crit.Accuracy = Accuracy.Fine;
                string lp = lm.GetBestProvider(crit, true);

                lm.RequestLocationUpdates(lp, 0, 5, this);

                SensorManager sm = (SensorManager)context.GetSystemService(Context.SensorService);

                sm.RegisterListener(this, sm.GetDefaultSensor(SensorType.Orientation), SensorDelay.Ui);

                Schaal   = 1;
                maximaal = new PointF();
                minimaal = new PointF();
            }
Ejemplo n.º 8
0
        protected void CompassCancel()
        {
            SensorManager sm     = _context.GetSystemService(Context.SensorService) as SensorManager;
            Sensor        sensor = sm.GetDefaultSensor(SensorType.Orientation);

            sm.UnregisterListener(this, sensor);
        }
Ejemplo n.º 9
0
        protected override void OnPause()
        {
            base.OnPause();

            _sensorManager = (SensorManager)GetSystemService(Context.SensorService);
            _sensorManager.UnregisterListener(_shakeDetector);
        }
Ejemplo n.º 10
0
        public void OnSensorChanged(SensorEvent e)
        {
            if (e.Sensor.Name == accelerometer && !lastAccelerometerSet)
            {
                CopyValues(e.Values, lastAccelerometer);
                lastAccelerometerSet = true;
            }
            else if (e.Sensor.Name == magnetometer && !lastMagnetometerSet)
            {
                CopyValues(e.Values, lastMagnetometer);
                lastMagnetometerSet = true;
            }

            if (lastAccelerometerSet && lastMagnetometerSet)
            {
                SensorManager.GetRotationMatrix(r, null, lastAccelerometer, lastMagnetometer);
                SensorManager.GetOrientation(r, orientation);
                var azimuthInRadians = orientation[0];
                var azimuthInDegress = (Java.Lang.Math.ToDegrees(azimuthInRadians) + 360.0) % 360.0;

                var data = new CompassData(azimuthInDegress);
                Compass.OnChanged(data);
                lastMagnetometerSet  = false;
                lastAccelerometerSet = false;
            }
        }
Ejemplo n.º 11
0
        public void UpdateUI()
        {
            this.Panel.Children.Clear();
            this.Panel.RowDefinitions.Clear();

            Sensor[] sensors = SensorManager.getAllSensors();
            int      col     = 0;
            int      row     = 0;

            foreach (Sensor s in sensors)
            {
                SensorComposite sComposite = new SensorComposite(s);
                this.Panel.Children.Add(sComposite);
                Grid.SetColumn(sComposite, col);
                Grid.SetRow(sComposite, row);
                col++;
                if (col == Panel.ColumnDefinitions.Count)
                {
                    RowDefinition rDef = new RowDefinition();
                    this.Panel.RowDefinitions.Add(new RowDefinition());
                    this.Panel.Height = (sComposite.Height) * row;
                    row++;
                    col = 0;
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                Methods.App.FullScreenApp(this);

                Window.AddFlags(WindowManagerFlags.KeepScreenOn);

                // Create your application here
                SetContentView(Resource.Layout.TwilioVideoCallActivityLayout);

                SensorManager = (SensorManager)GetSystemService(SensorService);
                Proximity     = SensorManager.GetDefaultSensor(SensorType.Proximity);

                GlobalContext = TabbedMainActivity.GetInstance();
                //Get Value And Set Toolbar
                InitComponent();
                InitTwilioCall();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 13
0
        public void OnSensorChanged(SensorEvent evt)
        {
            if (evt.Sensor.Type == SensorType.Accelerometer)
            {
                mGravity = evt.Values.ToArray();
            }
            if (evt.Sensor.Type == SensorType.MagneticField)
            {
                mGeomagnetic = evt.Values.ToArray();
            }
            if (mGravity != null && mGeomagnetic != null)
            {
                var R       = new float[9];
                var I       = new float[9];
                var success = SensorManager.GetRotationMatrix(R, I, mGravity, mGeomagnetic);
                if (success)
                {
                    var orientation = new float[3];
                    SensorManager.GetOrientation(R, orientation);

                    if (Interlocked.CompareExchange(ref Updating, 1, 0) == 1)
                    {
                        return;
                    }
                    RunOnUiThread(() =>
                    {
                        UpdateElementsOnScreen(orientation[2], orientation[1], orientation[0]);
                        Interlocked.Exchange(ref Updating, 0);
                    });
                }
            }
        }
Ejemplo n.º 14
0
        void AccelerometerCancel()
        {
            SensorManager sm     = _context.GetSystemService(Context.SensorService) as SensorManager;
            Sensor        sensor = sm.GetDefaultSensor(SensorType.Accelerometer);

            sm.UnregisterListener(this);
        }
Ejemplo n.º 15
0
        public void InitializeComponents()
        {
            //Lists.... Para guardar en las listas
            list_Light     = new List <string>();
            list_GPS       = new List <string>();
            list_Pressure  = new List <string>();
            list_Proximity = new List <string>();
            //Sensor of Pressure - Barometer
            thread_Pressure       = new Thread(new ThreadStart(StartThreadPressure));
            sensorManagerPressure = (SensorManager)GetSystemService(SensorService);
            sensor_Pressure       = sensorManagerPressure.GetDefaultSensor(SensorType.Pressure);
            sensorManagerPressure.UnregisterListener(this);
            //Sensor of Light
            thread_Light       = new Thread(new ThreadStart(StartThreadLight));
            sensorManagerLight = (SensorManager)GetSystemService(SensorService);
            sensor_Light       = sensorManagerLight.GetDefaultSensor(SensorType.Light);
            sensorManagerLight.UnregisterListener(this);
            //Sensor of Proximity
            thread_Proximity       = new Thread(new ThreadStart(StartThreadProximity));
            sensorManagerProximity = (SensorManager)GetSystemService(SensorService);
            sensor_Proximity       = sensorManagerProximity.GetDefaultSensor(SensorType.Pressure);
            sensorManagerProximity.UnregisterListener(this);
            //Sensor de GPS
            locationManager = (LocationManager)GetSystemService(LocationService);
            locationManager.RemoveUpdates(this);
            captureGPS          = false;
            value_Interval_Time = 250;
            //Cronometro
            chronometer = new Chronometer();
            crono       = new Thread(new ThreadStart(StartThreadChrono));

            thread_GPS = new Thread(new ThreadStart(StartThreadGPS));
        }
Ejemplo n.º 16
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            ViewModel = new MainViewModel(WorldConfiguration.Android);

            var metrics    = Resources.DisplayMetrics;
            var widthInDp  = ConvertPixelsToDp(metrics.WidthPixels);
            var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);

            ViewModel.UpdateWorld(metrics.WidthPixels, metrics.HeightPixels);

            RootLayout = this.FindViewById <RelativeLayout>(Resource.Id.myMainLayout);

            locationManager = GetSystemService(Context.LocationService) as LocationManager;
            locationManager.RequestLocationUpdates(LocationManager.NetworkProvider, 50, 0, this);

            sensorManager = GetSystemService(Context.SensorService) as SensorManager;
            //orientation= sensorManager?.GetDefaultSensor(SensorType.Orientation);
            //sensorManager.RegisterListener(this,orientation, SensorDelay.Normal);

            accelerometer = sensorManager?.GetDefaultSensor(SensorType.Accelerometer);
            magnetometer  = sensorManager?.GetDefaultSensor(SensorType.MagneticField);
            sensorManager.RegisterListener(this, accelerometer, SensorDelay.Ui);
            sensorManager.RegisterListener(this, magnetometer, SensorDelay.Ui);


            PopulateWorld();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Fetches references to the sensors, through the SensorManager class
        /// </summary>
        private void setUpSensors()
        {
            sensorManager = (SensorManager)GetSystemService(Context.SensorService);

            if (sensorManager.GetSensorList(SensorType.HeartRate).Count > 0)
            {
                heartRatesensor = sensorManager.GetDefaultSensor(SensorType.HeartRate);
            }
            else
            {
                heartRatesensor = null;
            }

            if (sensorManager.GetSensorList(SensorType.HeartBeat).Count > 0)
            {
                heartBeatsensor = sensorManager.GetDefaultSensor(SensorType.HeartBeat);
            }
            else
            {
                heartBeatsensor = null;
            }

            if (sensorManager.GetSensorList(SensorType.StepCounter).Count > 0)
            {
                //stepCounter = sensorManager.GetDefaultSensor(SensorType.StepCounter);
                stepCounter = sensorManager.GetDefaultSensor(SensorType.StepDetector);
            }
            else
            {
                stepCounter = null;
            }
            sensorStatusHandler.updateStatus("Sensors ready");
        }
Ejemplo n.º 18
0
        void Calc(IObserver <CompassReading> ob)
        {
            if (this.lastMag == null || this.lastAccel == null)
            {
                return;
            }

            SensorManager.GetRotationMatrix(this.rMatrix, null, this.lastAccel.Values.ToArray(), this.lastMag.Values.ToArray());
            SensorManager.GetOrientation(this.rMatrix, this.orientation);
            var degrees = (Math.ToDegrees(this.orientation[0]) + 360) % 360;

            var accuracy = this.lastAccel.Accuracy switch
            {
                SensorStatus.AccuracyHigh => CompassAccuracy.High,
                SensorStatus.AccuracyLow => CompassAccuracy.Approximate,
                SensorStatus.Unreliable => CompassAccuracy.Unreliable,
                _ => CompassAccuracy.Unknown
            };

            // TODO: calculate true north
            ob.OnNext(new CompassReading(accuracy, degrees, null));

            // clear for fresh read
            this.lastMag   = null;
            this.lastAccel = null;
        }
    }
Ejemplo n.º 19
0
 public CompassImpl()
 {
     this.syncLock      = new object();
     this.sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService);
     this.readOb        = Observable.Create <CompassReading>(ob =>
     {
         var accelMgr = new ShinySensorManager(this.sensorManager);
         var magMgr   = new ShinySensorManager(this.sensorManager);
         accelMgr.Start(SensorType.Accelerometer, SensorDelay.Fastest, e =>
         {
             lock (this.syncLock)
             {
                 this.lastAccel = e; //.Values.ToArray();
                 this.Calc(ob);
             }
         });
         magMgr.Start(SensorType.MagneticField, SensorDelay.Fastest, e =>
         {
             lock (this.syncLock)
             {
                 this.lastMag = e; //.Values.ToArray();
                 this.Calc(ob);
             }
         });
         return(() =>
         {
             accelMgr.Stop();
             magMgr.Stop();
         });
     })
                          .Publish()
                          .RefCount();
 }
Ejemplo n.º 20
0
        public void StartSensorService()
        {
            _sensorManager = GetSystemService(SensorService) as Android.Hardware.SensorManager;
            var sensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);

            _sensorManager.RegisterListener(this, sensor, Android.Hardware.SensorDelay.Game);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Surface a sensor dialog to request access to the sensor device. A user may
        /// restrict access to specific sensors due to security and privacy concerns they may have,
        /// depending on what data the sensor provides.
        /// </summary>
        /// <param name="sensor">The sensor to which to request access.</param>
        /// <returns>Whether the sensor is now ready.</returns>
        private bool RequestSensorAccess(Sensor sensor)
        {
            SensorState state = SensorState.AccessDenied;

            if (sensor != null)
            {
                // if available, the application should get the handle to the
                // main window for this application.
                IntPtr windowHandle = IntPtr.Zero;

                try
                {
                    // ask the sensor platform to request access from the user from a modal window
                    // if we are able to get the main window for the current application.
                    SensorManager.RequestPermission(windowHandle, true, sensor);
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

                state = sensor.State;
            }

            return(state == SensorState.Ready);
        }
Ejemplo n.º 22
0
        public override void Update()
        {
            base.Update();

            // Update sensors
            // Enable/disable supported sensors and update enabled sensors
            UpdateSensorPair(accelerometerListener, accelerometerSensor,
                             (sensor, listener) => sensor.Acceleration = listener.GetCurrentValuesAsVector());
            UpdateSensorPair(gyroscopeListener, gyroscopeSensor,
                             (sensor, listener) => sensor.RotationRate = -listener.GetCurrentValuesAsVector());
            UpdateSensorPair(linearAccelerationListener, userAccelerationSensor,
                             (sensor, listener) => sensor.Acceleration = listener.GetCurrentValuesAsVector());
            UpdateSensorPair(gravityListener, gravitySensor,
                             (sensor, listener) => sensor.Vector = listener.GetCurrentValuesAsVector());

            // Enabled/Disable/Update Orientation
            if (orientationListener != null)
            {
                bool enable = orientationSensor.IsEnabled || compassSensor.IsEnabled; // Orientation is used for compass as well
                if (enable != orientationListener.Enabled)
                {
                    if (enable)
                    {
                        orientationListener.Enable();
                    }
                    else
                    {
                        orientationListener.Disable();
                    }
                }

                if (enable)
                {
                    // Update orientation
                    base.Update();

                    var orientationValues = orientationListener.GetValues();
                    if (orientationValues == null || orientationValues.Count < 3)
                    {
                        return;
                    }

                    rotationVector[0] = orientationValues[0];
                    rotationVector[1] = orientationValues[1];
                    rotationVector[2] = orientationValues[2];
                    SensorManager.GetQuaternionFromVector(quaternionArray, rotationVector);

                    var quaternion = Quaternion.Identity;
                    quaternion.W = +quaternionArray[0];
                    quaternion.X = -quaternionArray[1];
                    quaternion.Y = +quaternionArray[3];
                    quaternion.Z = +quaternionArray[2];
                    quaternion   = Quaternion.RotationY(MathUtil.Pi) * quaternion; // align the orientation with north.
                    orientationSensor.FromQuaternion(quaternion);

                    // Update compass
                    compassSensor.Heading = -orientationSensor.Yaw;
                }
            }
        }
Ejemplo n.º 23
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            _sensorManager              = (SensorManager)GetSystemService(Context.SensorService);
            _sensorTextView             = FindViewById <TextView>(Resource.Id.accelerometer_text);
            _sensorGyroscopeTextView    = FindViewById <TextView>(Resource.Id.gyroscope_text);
            _sensorMagnetoMeterTextView = FindViewById <TextView>(Resource.Id.magnetometer_text);
            _sensorGeomagneticRotationVectorTextView = FindViewById <TextView>(Resource.Id.geomagneticrotationvector_text);
            Button pauseButton  = FindViewById <Button>(Resource.Id.PauseButton);
            Button resumeButton = FindViewById <Button>(Resource.Id.ResumeButton);
            Button shareButton  = FindViewById <Button>(Resource.Id.Share);

            pauseButton.Click += (object sender, EventArgs e) =>
            {
                this.OnPause();
            };
            resumeButton.Click += (object sender, EventArgs e) =>
            {
                this.OnResume();
            };
            shareButton.Click += (object sender, EventArgs e) =>
            {
                this.Share();
            };
        }
Ejemplo n.º 24
0
 public void SetSensorManager()
 {
     MSensorManager         = (SensorManager)this.GetSystemService(SensorService);
     MAccelerometr          = MSensorManager.GetDefaultSensor(SensorType.RotationVector);
     MMagnetometr           = MSensorManager.GetDefaultSensor(SensorType.MagneticField);
     BeaconsMonitorNotifier = new MonitorNotifier();
 }
Ejemplo n.º 25
0
        public void Start()
        {
            if (_accelerometer != null)
            {
                throw new MvxException("Accelerometer already started");
            }

            var globals = this.GetService <IMvxAndroidGlobals>();

            _sensorManager = (SensorManager)globals.ApplicationContext.GetSystemService(Context.SensorService);
            if (_sensorManager == null)
            {
                throw new MvxException("Failed to find SensorManager");
            }

            _accelerometer = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            if (_accelerometer == null)
            {
                throw new MvxException("Failed to find Accelerometer");
            }

            // It is not necessary to get accelerometer events at a very high
            // rate, by using a slower rate (SENSOR_DELAY_UI), we get an
            // automatic low-pass filter, which "extracts" the gravity component
            // of the acceleration. As an added benefit, we use less power and
            // CPU resources.
            _sensorManager.RegisterListener(this, _accelerometer, SensorDelay.Ui);
        }
Ejemplo n.º 26
0
        protected override void OnResume()
        {
            base.OnResume();

            _sensorManager = (SensorManager)GetSystemService(Context.SensorService);
            _sensorManager.RegisterListener(_shakeDetector, _sensor, SensorDelay.Ui);
        }
Ejemplo n.º 27
0
        private void RegisterSelfAsSensorListener(/* final */ SensorManager pSensorManager, /* final int */ SensorType pType, /* final */ Android.Hardware.SensorDelay pSensorDelay)
        {
            /* final */
            Sensor sensor = pSensorManager.GetSensorList(pType)[0];

            pSensorManager.RegisterListener(this, sensor, pSensorDelay /*.getDelay()*/);
        }
Ejemplo n.º 28
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate(bundle);
     SetContentView(Resource.Layout.Main);
     _sensorManager  = (SensorManager)GetSystemService(SensorService);
     _sensorTextView = FindViewById <TextView>(Resource.Id.accelerometer_text);
 }
Ejemplo n.º 29
0
        private void UnregisterSelfAsSensorListener(/* final */ SensorManager pSensorManager, /* final int */ SensorType pType)
        {
            /* final */
            Sensor sensor = pSensorManager.GetSensorList(pType)[0];

            pSensorManager.UnregisterListener(this, sensor);
        }
Ejemplo n.º 30
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (_loaded)
            {
                Process.KillProcess(Process.MyPid());
            }

            bool isPortrait = WindowManager.DefaultDisplay.Height > WindowManager.DefaultDisplay.Width;

            #region Set default android settings

            RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetSoftInputMode(SoftInput.AdjustPan);
            Window.RequestFeature(WindowFeatures.ActionBar);
            #endregion

            if (isPortrait)
            {
                _sensorManger = (SensorManager)GetSystemService(SensorService);

                var intent = new Intent(this, typeof(BaseService));
                StartService(intent);
                _serviceConnection = new ServiceConnection(null);
                BindService(intent, _serviceConnection, Bind.AutoCreate);

                BitBrowserApp.Current.PrepareApplication(this);

                _loaded = true;
            }
        }
        partial void Initialize()
        {
            var context = Catel.Android.ContextHelper.CurrentContext;
            _sensorManager = context.GetSystemService(Context.SensorService) as SensorManager;
            _sensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);

            _sensorListener = new AccelerometerSensorListener();
            _sensorListener.SensorChanged += OnSensorChanged;
        }