Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();
            StrictMode.SetThreadPolicy(policy);

            var wifi = (WifiManager)GetSystemService(WifiService);
            var ConnectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);

            wifilock = wifi.CreateWifiLock(WifiMode.FullHighPerf, "WifiLock");
            wifilock.Acquire();

            game = new Game1(
                CreateUdpService(wifi, ConnectivityManager)
                , RuningOnAndroid: true
                );

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                Vibrator vibrator = (Vibrator)GetSystemService(VibratorService);
                Game1.AndroidVibrate = f => vibrator.Vibrate(VibrationEffect.CreateOneShot(f, VibrationEffect.DefaultAmplitude));
            }
            else
            {
                //TODO:
            }

            SetViewFullScreen();

            //PowerManager pm = (PowerManager)GetSystemService(PowerService);
            //this.mWakeLock = pm.NewWakeLock(WakeLockFlags.ScreenDim, "My Tag");
            //this.mWakeLock.Acquire();
            game.Run();
        }
        void UpdateReceivedData(byte[] data)
        {
            try
            {
                ConnectivityManager ConnectivityManager = (ConnectivityManager)Application.Context.GetSystemService(Context.ConnectivityService);
                NetworkInfo         connection          = ConnectivityManager.ActiveNetworkInfo;
                if (connection != null && connection.IsConnected && CrossConnectivity.Current.IsConnected)
                {
                    var message = HexDump.DumpHexString(data) + "\n\n";
                    dumpTextView.Append(message);
                    scrollView.SmoothScrollTo(0, dumpTextView.Bottom);
                }
                else
                {
                    if (wake.IsHeld && wifilock.IsHeld)
                    {
                        wake.Release();     //libera wakeLock
                        wifilock.Release(); //libera wifiLock
                    }
                    activateSleep = false;
                    PowerManager pwm = (PowerManager)GetSystemService(Context.PowerService);
                    WakeLock     wkl = pwm.NewWakeLock(WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup | WakeLockFlags.OnAfterRelease, "wakeup device");
                    wkl.Acquire();
                    wkl.Release();

                    Finish();
                    intent = PackageManager.GetLaunchIntentForPackage("com.flexolumens.MonitorInteligente");
                    StartActivity(intent);
                    //OnDestroy();
                }

                if (activateSleep == true && (connection != null && connection.IsConnected) && CrossConnectivity.Current.IsConnected)
                {
                    wake.Acquire();
                    wifilock.Acquire();
                    activateSleep = false;
                    intento       = PackageManager.GetLaunchIntentForPackage("com.ssaurel.lockdevice");
                    StartActivity(intento);
                    //if (!wifi.IsWifiEnabled)
                    //{
                    //wifi.SetWifiEnabled(true);
                    //}
                }
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
            }
        }
Example #3
0
        /// <summary>
        /// Called when the fragment is visible to the user and actively running.
        /// </summary>
        public override void OnResume()
        {
            base.OnResume();

            WakeLock.Acquire();
            WifiLock.Acquire();

            var url = Data.FromJson <string>();

            if (AutoResumePosition.HasValue)
            {
                PlayVideo(url, AutoResumePosition);
            }
            else if (LastUrl == url && LastPosition.HasValue)
            {
                ShowResumeDialog();
            }
            else
            {
                PlayVideo(url, null);
            }
        }