public override Result DoWork() { if (AwakeHelper.GetAwakeStatus() == AwakeStatus.Sleeping || AwakeHelper.GetAwakeStatus() == AwakeStatus.SleepingWithDeviceMotionEnabled) { return(Result.InvokeSuccess()); //We want to keep the job running but don't do the job itself while Awake is sleeping. } ConfigurationManager configurationManager = new ConfigurationManager(AppPreferences.Weather); string city = configurationManager.RetrieveAValue(ConfigurationParameters.WeatherCity, "New York"); string country = configurationManager.RetrieveAValue(ConfigurationParameters.WeatherCountryCode, "us"); string unit = configurationManager.RetrieveAValue(ConfigurationParameters.WeatherTemperatureMeasureUnit, "metric"); var result = OpenWeatherMapClient.GetWeather(city, country, unit); if (result != null) { Log.Info("LiveDisplay", "Job Result Sucess"); WeatherUpdated?.Invoke(null, true); return(Result.InvokeSuccess()); } else { Log.Info("LiveDisplay", "Job Result Not Sucess"); WeatherUpdated?.Invoke(null, false); return(Result.InvokeRetry()); } }
private void CatcherHelper_NotificationListSizeChanged(object sender, NotificationListSizeChangedEventArgs e) { RunOnUiThread(() => { if (e.ThereAreNotifications) { if (clearAll != null) { clearAll.Visibility = ViewStates.Visible; } } else { if (clearAll != null) { clearAll.Visibility = ViewStates.Invisible; } if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOffScreenAfterLastNotificationCleared) && ActivityLifecycleHelper.GetInstance().GetActivityState(typeof(LockScreenActivity)) == ActivityStates.Resumed) { AwakeHelper.TurnOffScreen(); } } }); }
private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e) { //if the incoming notification updates a previous notification, then verify if the current notification SHOWING is the same as the one //we are trying to update, because if this check is not done, the updated notification will show even if the user is seeing another notification. //the other case is simply when the notification is a new one. if (e.UpdatesPreviousNotification && e.OpenNotification.GetCustomId() == _openNotification?.GetCustomId() || e.UpdatesPreviousNotification == false) { ShowNotification(e.OpenNotification); } if (e.ShouldCauseWakeUp && configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnNewNotification)) { AwakeHelper.TurnOnScreen(); } if (configurationManager.RetrieveAValue(ConfigurationParameters.MusicWidgetMethod, "0") == "1") //1:"Use a notification to spawn the Music Widget" { if (e.OpenNotification.RepresentsMediaPlaying()) { MusicController.StartPlayback(e.OpenNotification.GetMediaSessionToken(), e.OpenNotification.GetCustomId()); maincontainer.Visibility = ViewStates.Invisible; WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs { Show = false, WidgetName = "NotificationFragment" }); //Also start the Widget to control the playback. WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs { Show = true, WidgetName = "MusicFragment", Active = true }); return; } } }
private void ToggleAwakeSettingsItems(bool enableItems) { Preference turnonusermovement = FindPreference("turnonusermovement?"); Preference awakecausesblackwallpaper = FindPreference("awakecausesblackwallpaper?"); Preference inactivehourssettingspreference = FindPreference("inactivetimesettings"); //Preference syncwithdigitalwellbeing = FindPreference("syncwithdigitalwellbeing?"); inactivehourssettingspreference.Enabled = enableItems; inactivehourssettingspreference.Selectable = enableItems; awakecausesblackwallpaper.Enabled = enableItems; awakecausesblackwallpaper.Selectable = enableItems; //syncwithdigitalwellbeing.Enabled = enableItems; //syncwithdigitalwellbeing.Selectable = enableItems; inactivehourssettingspreference.PreferenceClick += Inactivehourssettingspreference_PreferenceClick; if (new ConfigurationManager(AppPreferences.Default).RetrieveAValue(ConfigurationParameters.ListenForDeviceMotion) == false) { turnonusermovement.Enabled = false; turnonusermovement.Selectable = false; } else { turnonusermovement.Enabled = enableItems; turnonusermovement.Selectable = enableItems; if (enableItems == false) { //User disabled Device Motion, so the service should be stopped as well. AwakeHelper.ToggleStartStopAwakeService(false); } } }
private void WatchdogInterval_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //it works correctly, but I want to refactor this. (Regression) if (ActivityLifecycleHelper.GetInstance().GetActivityState(typeof(LockScreenActivity)) == ActivityStates.Resumed) { AwakeHelper.TurnOffScreen(); } }
private void WatchdogInterval_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //it works correctly, but I want to refactor this. (Regression) if (currentActivityState == ActivityStates.Resumed) { AwakeHelper.TurnOffScreen(); } }
public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key) { switch (key) { case ConfigurationParameters.DoubleTapOnTopActionBehavior: Preference doubletaptopbehavior = FindPreference("doubletapontoppactionbehavior"); switch (sharedPreferences.GetString(ConfigurationParameters.DoubleTapOnTopActionBehavior, "0")) { case "0": doubletaptopbehavior.SetSummary(Resource.String.doubletaptopactiondesc); break; case "1": doubletaptopbehavior.SetSummary(Resource.String.doubletaptopactioninverteddesc); break; } break; case ConfigurationParameters.ListenForDeviceMotion: Preference turnonusermovement = FindPreference("turnonusermovement?"); switch (sharedPreferences.GetBoolean(ConfigurationParameters.ListenForDeviceMotion, false)) { case true: AwakeHelper.ToggleStartStopAwakeService(true); ToggleAwakeSettingsItems(true); turnonusermovement.Enabled = true; turnonusermovement.Selectable = true; break; case false: AwakeHelper.ToggleStartStopAwakeService(false); ToggleAwakeSettingsItems(false); turnonusermovement.Enabled = false; turnonusermovement.Selectable = false; break; } break; case ConfigurationParameters.SyncWithDigitalWellbeing: if (PackageUtils.GetTheAppName(digitalWellbeingPackageName) == null) { Activity.RunOnUiThread(() => Toast.MakeText(Activity, Resource.String.youneeddigitalwellbeingapp, ToastLength.Long).Show()); } if (Checkers.IsNotificationListenerEnabled() == false) { SwitchPreference syncwithdigitalwellbeing = FindPreference("syncwithdigitalwellbeing?") as SwitchPreference; //new ConfigurationManager(AppPreferences.Default).SaveAValue(ConfigurationParameters.SyncWithDigitalWellbeing, false); syncwithdigitalwellbeing.Checked = false; Activity.RunOnUiThread(() => Toast.MakeText(Activity, Resource.String.unabletoenablesyncwbedmode, ToastLength.Long).Show()); } break; } }
/// <summary> /// Constructor of the Class /// </summary> /// <param name="statusBarNotifications">This list is sent by Catcher, and is used to fill the Adapter /// that the RecyclerView will use, it is tighly coupled with that adapter. /// </param> public CatcherHelper(List <StatusBarNotification> statusBarNotifications) { StatusBarNotifications = statusBarNotifications; notificationAdapter = new NotificationAdapter(statusBarNotifications); if (statusBarNotifications.Count > 0) { OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs { ThereAreNotifications = true }); } AwakeHelper awakeHelper = new AwakeHelper(); //Will help us to make certain operations as waking up the screen and such. }
protected override void OnResume() { base.OnResume(); AddFlags(); watchDog.Elapsed += WatchdogInterval_Elapsed; watchDog.Stop(); watchDog.Start(); ActivityLifecycleHelper.GetInstance().NotifyActivityStateChange(typeof(LockScreenActivity), ActivityStates.Resumed); if (configurationManager.RetrieveAValue(ConfigurationParameters.TutorialRead) == false) { welcome = FindViewById <TextView>(Resource.Id.welcomeoverlay); welcome.Text = Resources.GetString(Resource.String.tutorialtext); welcome.Visibility = ViewStates.Visible; welcome.Touch += Welcome_Touch; } //Check if Awake is enabled. //Refactor switch (AwakeHelper.GetAwakeStatus()) { case AwakeStatus.None: livedisplayinfo.Text = Resources.GetString(Resource.String.idk); break; case AwakeStatus.CompletelyDisabled: livedisplayinfo.Text = "Completely disabled"; break; case AwakeStatus.Up: livedisplayinfo.Text = "Awake is active"; break; case AwakeStatus.Sleeping: livedisplayinfo.Text = "Awake is Sleeping"; break; case AwakeStatus.UpWithDeviceMotionDisabled: livedisplayinfo.Text = "Awake is active but not listening orientation changes"; break; case AwakeStatus.SleepingWithDeviceMotionEnabled: livedisplayinfo.Text = "Awake is sleeping but listening orientation changes"; break; case AwakeStatus.DisabledbyUser: livedisplayinfo.Text = "Awake is disabled by the user."; break; default: break; } }
private void Inactivehourssettingspreference_PreferenceClick(object sender, Preference.PreferenceClickEventArgs e) { startTimeDialog = new TimePickerDialog(Activity, PreferencesFragmentCompat_starttimepicked, DateTime.Now.Hour, DateTime.Now.Minute, false); if (AwakeHelper.UserHasSetAwakeHours()) { int start = int.Parse(new ConfigurationManager(AppPreferences.Default).RetrieveAValue(ConfigurationParameters.StartSleepTime, "-1")); startTimeDialog.SetMessage("Start hour: "); //here it goes the set start hour, (but in a user readable way) } else { startTimeDialog.SetMessage("Start hour:"); } startTimeDialog.Show(); }
private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e) { openNotification = e.OpenNotification; if (e.ShouldCauseWakeUp) { AwakeHelper.TurnOnScreen(); } //if the current floating notification widget does not have a tag, let's set it. if (floatingNotificationView.GetTag(Resource.String.defaulttag) == null) { floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId()); } if (configurationManager.RetrieveAValue(ConfigurationParameters.TestEnabled)) { Toast.MakeText(floatingNotificationView.Context, "Progress Indeterminate?: " + openNotification.IsProgressIndeterminate().ToString() + "\n" + "Current Progress: " + openNotification.GetProgress().ToString() + "\n" + "Max Progress: " + openNotification.GetProgressMax().ToString() + "\n" + openNotification.GetGroupInfo() , ToastLength.Short).Show(); } if (e.UpdatesPreviousNotification) { if ((string)floatingNotificationView.GetTag(Resource.String.defaulttag) == openNotification.GetCustomId()) { floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId()); } } else { //Is a new notification, so set a new tag. floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId()); if (floatingNotificationView.Visibility != ViewStates.Visible) { if (currentActivityState == ActivityStates.Resumed) //most of the times it won't work, when the Screen turns on then it gets here too quickly //before the lockscreen is in a Resumed state, causing the floating notification not being showed when the screen turns on, TODO. { floatingNotificationView.Visibility = ViewStates.Visible; } } } }
private void PreferencesFragmentCompat_starttimepicked(object sender, TimePickerDialog.TimeSetEventArgs e) { startTimeDialog.Dismiss(); isSleepstarttimesetted = true; ConfigurationManager configurationManager = new ConfigurationManager(AppPreferences.Default); configurationManager.SaveAValue(ConfigurationParameters.StartSleepTime, string.Concat(e.HourOfDay.ToString() + e.Minute.ToString())); int end = int.Parse(new ConfigurationManager(AppPreferences.Default).RetrieveAValue(ConfigurationParameters.FinishSleepTime, "-1")); finishTimeDialog = new TimePickerDialog(Activity, PreferencesFragmentCompat_finishtimepicked, DateTime.Now.Hour, DateTime.Now.Minute, false); if (AwakeHelper.UserHasSetAwakeHours()) { finishTimeDialog.SetMessage("Finish hour: "); //here it goes the set finish hour, (but in a user readable way) } else { finishTimeDialog.SetMessage("Finish hour:"); } finishTimeDialog.Show(); }
public void OnSensorChanged(SensorEvent e) { switch (e.Sensor.Type) { case SensorType.Accelerometer: //Detect phone on plain surface: //Z axis must have the following value: //>10 m/s2; //Y axis must be less than 3m/s2 so, the device can be slightly tilted and still being //in a Plain surface. if (e.Values[2] > 9 && e.Values[1] < 3) { if (layDownTime == 0) { layDownTime = e.Timestamp; } if (e.Timestamp > (sleepTime + layDownTime)) { isLaidDown = true; Log.Info("SENSOR", "Is Laid down"); if (isSensorBlocked) { isInPocket = true; Log.Info("SENSOR", "Is in Pocket (horizontal)"); } else { Log.Info("SENSOR", "Is not in Pocket (horizontal)"); isInPocket = false; } } phoneInVerticalTime = 0; } if (e.Values[1] > 3 && isInPocket == false) { if (isLaidDown == true) { if (phoneInVerticalTime == 0) { phoneInVerticalTime = e.Timestamp; } if (e.Timestamp > (wakeUpWaitTime + phoneInVerticalTime)) { if (ScreenOnOffReceiver.IsScreenOn == false) { Log.Info("SENSOR", "Should turn on screen"); if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement)) { AwakeHelper.TurnOnScreen(); } } isLaidDown = false; layDownTime = 0; } } else if (isLaidDown == false && e.Timestamp > (phoneInVerticalTime + sleepTime) && isSensorBlocked) { isInPocket = true; Log.Info("SENSOR", "Is In Pocket (vertical) I guess"); } } //The less Z axis m/s2 value is, and the more Y axis m/s2 value is, the phone more vertically is. //Notes: //X axis is not necessary as I don't need to know if the phone is being moved Horizontally. break; case SensorType.Proximity: Log.Info("Livedisplay", "value 1 " + e.Values[0]); if (e.Values[0] == 0) { proxSensorBlockedTime = e.Timestamp; isSensorBlocked = true; } else { proxSensorBlockedTime = 0; isSensorBlocked = false; } break; default: break; } //Kind of works. :/ //If you turn off the screen when the phone is vertical then okay, the screen won't turn on, but if you lay down your phone //and get it back up it won't turn on the screen again. //Because the code doesn't recognize that I wan't to turn on the screen and that the phone is no longer vertical. //if I remove the third argument then when I turn off the Screen it will immediately turn on the screen //because it recognizes is vertical and also it isn't inside a pocket //TODO: Fix this behavior //if (isInPocket == false && isLaidDown == false && ScreenOnOffReceiver.ScreenTurnedOffWhileInVertical==false) //{ // if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement) == true) // { // AwakeHelper.TurnOnScreen(); // } //} }
public override bool OnOptionsItemSelected(IMenuItem item) { int id = item.ItemId; switch (id) { case Resource.Id.action_settings: using (Intent intent = new Intent(this, typeof(SettingsActivity))) { intent.AddFlags(ActivityFlags.NewDocument); StartActivity(intent); } return(true); case Resource.Id.action_sendtestnotification: if (isApplicationHealthy) { AwakeHelper.TurnOffScreen(); using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance()) { var notificationtext = Resources.GetString(Resource.String.testnotificationtext); if (Build.VERSION.SdkInt > BuildVersionCodes.NMr1) { slave.PostNotification(7, "LiveDisplay", notificationtext, true, NotificationImportance.Max); } else { slave.PostNotification(1, "LiveDisplay", notificationtext, true, NotificationPriority.Max); } //NotificationSlave.SendDumbNotification(); } using (Intent intent = new Intent(Application.Context, typeof(LockScreenActivity))) { StartActivity(intent); return(true); } } else { Toast.MakeText(Application.Context, "You dont have the required permissions yet", ToastLength.Long).Show(); } break; case Resource.Id.action_help: using (AlertDialog.Builder builder = new AlertDialog.Builder(this)) { builder.SetMessage(Resource.String.helptext); builder.SetPositiveButton("ok, cool", null as EventHandler <DialogClickEventArgs>); builder.Show(); } break; default: break; } return(base.OnOptionsItemSelected(item)); }
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; } } }
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 { //Finish(); //using (Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(TransparentActivity)))) //{ // intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.); // StartActivity(intent); //} MoveTaskToBack(true); } } //The other value is "1" which means Inverted. else { if (e.Event.RawY < halfscreenheight) { //Finish(); //using (Intent intent = new Intent(Application.Context, Java.Lang.Class.FromType(typeof(TransparentActivity)))) //{ // intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.MultipleTask); // StartActivity(intent); //} MoveTaskToBack(true); } else { AwakeHelper.TurnOffScreen(); } } } //Reset the values of touch firstTouchTime = -1; finalTouchTime = -1; } } }