private void LlNotification_Click(object sender, EventArgs e) { Activity?.RunOnUiThread(() => { try { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(Activity); } } Activity?.RunOnUiThread(() => _openNotification.ClickNotification()); if (_openNotification.IsAutoCancellable()) { WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs { Show = false, WidgetName = "NotificationFragment" }); maincontainer.Visibility = ViewStates.Invisible; } } catch { Log.Wtf("OnNotificationClicked", "Metodo falla porque no existe una notificacion con esta acción"); } }); }
private void LoadConfiguration() { //Load configurations based on User configuration. LoadWallpaper(configurationManager); int interval = int.Parse(configurationManager.RetrieveAValue(ConfigurationParameters.TurnOffScreenDelayTime, "5000")); watchDog.Interval = interval; doubletapbehavior = configurationManager.RetrieveAValue(ConfigurationParameters.DoubleTapOnTopActionBehavior, "0"); if (configurationManager.RetrieveAValue(ConfigurationParameters.HideShortcutsWhenKeyguardSafe)) { if (KeyguardHelper.IsSystemSecured()) { using (var shortcuts = FindViewById <FrameLayout>(Resource.Id.shortcutcontainer)) { shortcuts.Visibility = ViewStates.Invisible; } } } else { using (var shortcuts = FindViewById <FrameLayout>(Resource.Id.shortcutcontainer)) { if (shortcuts.Visibility != ViewStates.Visible) { shortcuts.Visibility = ViewStates.Visible; } } } }
public static void TurnOffScreen() { PowerManager pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService); DevicePolicyManager policy; if (Build.VERSION.SdkInt < BuildVersionCodes.KitkatWatch) { #pragma warning disable CS0618 // El tipo o el miembro están obsoletos if (pm.IsScreenOn == true) { policy = (DevicePolicyManager)Application.Context.GetSystemService(Context.DevicePolicyService); try { policy.LockNow(); } catch (Exception) { Log.Warn("LiveDisplay", "Lock device failed, check Device Admin permission"); } } } else { if (pm.IsInteractive == true) { policy = (DevicePolicyManager)Application.Context.GetSystemService(Context.DevicePolicyService); try { //Special workaround that still makes harm but not as much as it would without the workaround. //So, if the next line of code gets triggered 'policy.LockNow()' it would lock the device, but, if //the device has been locked when the user has set a fingerprint and also if the lockscreen is still present //then after unlocking by using the fingerprint the user has to write //the pattern, aaand also double tap to exit LiveDisplay, lol. //this workaround is to prevent that, when I don't call policy.LockNow() the user doesn't have to write the pattern //or whatever side security method they have set along the fingerprint, the cost of this btw is that double tap won't work //neither the automatic screen off. (I don't know how to solve that yet) it is the lesser of two evils. //However it doesn't work sometimes, I guess it is better to simply warn the user about it. //And disable the turn off screen capabilities of LiveDisplay while a fingerprint lock is active. if (KeyguardHelper.IsDeviceCurrentlyLocked() && KeyguardHelper.IsFingerprintSet()) { //Do nothing. } else { policy.LockNow(); } } catch (Exception) { Log.Warn("LiveDisplay", "Lock device failed, check Device Admin permission"); } } } #pragma warning restore CS0618 // El tipo o el miembro están obsoletos }
private void MusicPlayerContainer_Click(object sender, EventArgs e) { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(Activity); } } try { activityIntent.Send(); } catch { Log.Info("LiveDisplay", "Failed to send the Music pending intent"); } }
private void Clock_Click(object sender, EventArgs e) { using (Intent intent = new Intent(AlarmClock.ActionShowAlarms)) { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(Activity); } } StartActivity(intent); } }
private void StartDialer_Click(object sender, EventArgs e) { using (Intent intent = new Intent(Intent.ActionDial)) { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(this); } } StartActivity(intent); } }
private void BtnLaunchNotification_Click(object sender, EventArgs e) { if (configurationManager.RetrieveAValue(ConfigurationParameters.LaunchNotification)) { KeyguardHelper.RequestDismissKeyguard(Activity); CatcherHelper.GetOpenNotification(openNotificationId)?.ClickNotification(); } else { if (MusicController.MediaSessionAssociatedWThisNotification(openNotificationId)) { WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs { Active = false, Show = true, WidgetName = "NotificationFragment", WidgetAskingForShowing = "MusicFragment", AdditionalInfo = openNotificationId }); } } }
private void Lockscreen_Touch(object sender, View.TouchEventArgs e) { if (e.Event.Action == MotionEventActions.Down) { if (firstTouchTime == -1) { firstTouchTime = e.Event.DownTime; } else if (firstTouchTime != -1) { finalTouchTime = e.Event.DownTime; if (firstTouchTime + threshold < finalTouchTime) { firstTouchTime = finalTouchTime; //Let's set the last tap as the first, so the user doesnt have to press twice again return; } else if (firstTouchTime + threshold > finalTouchTime) { //0 Equals: Normal Behavior if (doubletapbehavior == "0") { if (e.Event.RawY < halfscreenheight) { AwakeHelper.TurnOffScreen(); } else { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(this); } } MoveTaskToBack(true); } } //The other value is "1" which means Inverted. else { if (e.Event.RawY < halfscreenheight) { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { if (KeyguardHelper.IsDeviceCurrentlyLocked()) { KeyguardHelper.RequestDismissKeyguard(this); } } MoveTaskToBack(true); } else { AwakeHelper.TurnOffScreen(); } } } //Reset the values of touch firstTouchTime = -1; finalTouchTime = -1; } } }