예제 #1
0
        /// <summary>
        /// Called when the activity is first created. </summary>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Get an instance of the SensorManager
            mSensorManager = (SensorManager)GetSystemService(SENSOR_SERVICE);

            // Get an instance of the PowerManager
            mPowerManager = (PowerManager)GetSystemService(POWER_SERVICE);

            // Get an instance of the WindowManager
            mWindowManager = (IWindowManager)GetSystemService(WINDOW_SERVICE);
            mDisplay = mWindowManager.DefaultDisplay;

            // Create a bright wake lock
            mWakeLock = mPowerManager.NewWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, this.GetType().Name);

            // instantiate our simulation view and set it as the activity's content
            mSimulationView = new SimulationView(this);
            SetContentView(mSimulationView);
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.main);

            SetupViews();

            _batteryReceiver = new BatteryReceiver(_batteryTemp, _batteryLevel, _batteryHealth, _batteryVoltage);
            _powerManager = (PowerManager) GetSystemService(PowerService);
            _wakeLock = _powerManager.NewWakeLock(WakeLockFlags.Full, "BatteryDrainer");

            _startStopButton.Click += (s, e) =>
            {
                if (_startStopButton.Checked) //on
                {
                    Start();
                }
                else //off
                {
                    Stop();
                }
            };
        }
예제 #3
0
 public AndroidScreenProbe()
 {
     _powerManager = Application.Context.GetSystemService(global::Android.Content.Context.PowerService) as PowerManager;
 }
예제 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            powerManager = (PowerManager)GetSystemService(Context.PowerService);
            wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "MyWakeLock");
            wakeLock.Acquire();

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Pedometer);

            chrono = FindViewById<Chronometer>(Resource.Id.chronometer1);
            sensorManager = (SensorManager)GetSystemService(Context.SensorService);
            stepsTextView = FindViewById<TextView>(Resource.Id.pedometer);
            caloriesTextView = FindViewById<TextView>(Resource.Id.calories);
            speedTextView = FindViewById<TextView>(Resource.Id.speed);
            distanceTextView = FindViewById<TextView>(Resource.Id.distance);
            timeTextView = FindViewById<TextView>(Resource.Id.time);

            if (savedInstanceState != null)
            {
                steps = savedInstanceState.GetInt("steps", 0);
                calories = savedInstanceState.GetFloat("calories", 0.0f);
                speed = savedInstanceState.GetFloat("speed", 0.0f);
                distance = savedInstanceState.GetFloat("distance", 0.0f);
                chrono.Base = savedInstanceState.GetLong("time", SystemClock.ElapsedRealtime());
                run = savedInstanceState.GetBoolean("run", false);
            }

            chrono.Format = "00:0%s";
            chrono.OnChronometerTickListener = this;

            int h = 480;
            mYOffset = h * 0.5f;
            mScale[0] = -(h * 0.5f * (1.0f / (SensorManager.StandardGravity * 2)));
            mScale[1] = -(h * 0.5f * (1.0f / (SensorManager.MagneticFieldEarthMax)));

            if (run)
            {
                refreshTextViews();
                sensorsListenerRegister();
                chrono.Start();
            }
        }
예제 #5
0
 static PowerManager()
 {
     _batteryManager = (Android.OS.BatteryManager)Android.App.Application.Context.GetSystemService(Context.BatteryService);
     _powerManager   = (Android.OS.PowerManager)Android.App.Application.Context.GetSystemService(Context.PowerService);
 }
예제 #6
0
        public override void OnCreate()
        {
            base.OnCreate();
            try
            {
                //_logger = new Logger(Environment.ExternalStorageDirectory.AbsolutePath);
                _powerManager = (PowerManager)BaseContext.GetSystemService(PowerService);
                _sensorManager = (SensorManager)BaseContext.GetSystemService(SensorService);
                _wakeLockPartial = _powerManager.NewWakeLock(WakeLockFlags.Partial, _tag);
                _screenOffReceiver = new WakeUpServiceReceiver(() =>
                {
                    new Handler().PostDelayed(() =>
                    {
                        UnregisterListener();
                        RegisterListener();
                        Log.Debug("WakeUpServiceReceiver", "Screen turned off.");
                    }, 500);
                });
                RegisterReceiver(_screenOffReceiver, new IntentFilter(Intent.ActionScreenOff));

                Status = ServiceStatus.STARTED;
                Log.Debug("WakeUpService", "Service started.");
            }
            catch (Exception ex)
            {
                Log.Error("WakeUpService", ex.ToString());
                Status = ServiceStatus.FAILED;
            }
        }