Ways of detecting Windows Phone idle - windows-phone-7

I want to perform some calculations while the phone is in locked screen mode, regardless if the app is on the foreground or the background.
I know that in order to do this, I need to use OnObscured event from App class. However, it is only launched when the app is in the foreground, but not in the background.
So, I would like to know if exist any way to detect the phone state while the App runs the background.
I have thought something that would be crazy, but is to access an API property which is not allowed to use while the phone is in locked screen, and then catch the exception and, with that, get if the phone is active or sleeping.
I am open to hear new ideas.

I figured out a simple thing - maybe it will help you:
I assume that you already disabled Idle Detection to run your calculations in background.
So why not to create the variable in which you hold the state of the App? Since you have to launch first your App, so it goes to foreground and when Obscured is called and IsLocked = true, set the variable. Then you can check it whenever you want:
public MainPage()
{
InitializeComponent();
App.RootFrame.Obscured+=RootFrame_Obscured;
App.RootFrame.Unobscured+=RootFrame_Unobscured;
}
private bool AppIsLocked = false;
private void RootFrame_Unobscured(object sender, EventArgs e)
{
if (AppIsLocked) AppIsLocked = false;
}
private void RootFrame_Obscured(object sender, ObscuredEventArgs e)
{
if (e.IsLocked) AppIsLocked = true;
}

Is this what you searching for Running a Windows Phone Application under the lock screen?
This article describes - how to avoid tombstoning. But you can't do a lot of work under lock screen.

Related

XamarinForms Shell OnResume - previous page is showing

I want to achieve lock mechanism in XF 4.5.0 Shell app.
I have static timer that counts how much seconds passed, and based on some logic present either screen that user was before put the app in behind (user went to instagram, but app is in the background running)
So, my OnResume() method looks like this:
private bool IsUserExists()
{
if (!string.IsNullOrWhiteSpace(GlobalAppSettings.Email) && !string.IsNullOrWhiteSpace(GlobalAppSettings.Password) && !string.IsNullOrWhiteSpace(GlobalAppSettings.Pin))
{
return true;
}
else
{
return false;
}
}
protected override void OnResume()
{
if ((!OnSleepOrPauseTime.HasValue || OnSleepOrPauseTime.Value.AddSeconds(5) <= DateTime.Now)
&&(IsUserExists()))
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
{
await Shell.Current.GoToAsync(Routes.LoginPinPage, false);
});
}
}
The problem: user sees for a like half second the screen where he was before, and then it redirects to LoginPinPage.
The happy path: Should be that user doesnt see that flickering page that was before exiting form an app, just immediately lock screen.
Possible solution: That crossed on my mind, before leaving the app to somehow redirect in background app to login pin screen?
PushAsync has 2 overloads - docs
By default the PushAsync method pushes the new page with animation. I think that this is the so-called "flickering" that you are referring to.
You can try to use the second overload and pass false for the animated property and see if it makes any difference.
PushAsync(new LoginPinPage(), false);
If you want to redirect the user on app leave - you can use another of the Application's lifecycle methods - OnSleep and invoke your navigation there. But I suggest to try it without animations first.
Keep in mind that, should you choose to use the OnSleep method, you will also have to push the page without animations. I have just tested pushing with animations and I do indeed see the flickering that you are mentioning. Setting the animated flag to false, removed any flickering for me.

Wearable DataAPI syncing issue with multiple watches (Looping)

I have a watchface with a companion app for phone. It uses Wearable.DataApi to sync changes between the phone and watch. I have a DataApi.DataListener setup and sync changes made on the watch or phone side. I have no issue with a phone and ONE watch communicating.
The issue is when i have multiple watches using the same watch face if changes on watch or phone side are made quickly it seems to go into a loop and start flashing the changes on all devices. So if im changing the color by tapping watch if I press a few times quickly to do that all devices start cycling through all colors and takes some time before it catches up and stops.
If I change options slowly there is no problem. I put a log in the DataApi listener and I see both uri's making the change but just seems to loop for some reason when changed quickly. Is there anyway to prevent this?
I know this might not seem like a big issue but if a user has 2 watches and accidently changes an option or options quickly it will start with the options and or colors changing. I want to prevent that from happening.
This is how im adding my listener in the onConnected method
Wearable.DataApi.addListener(mGoogleApiClient, dataListener);
And this is my listener method
DataApi.DataListener dataListener = new DataApi.DataListener() {
#Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(TAG, "onDataChanged");
for (DataEvent event : dataEvents) {
Log.d(TAG, "dataEvent.uri: " + event.getDataItem().getUri().toString());
DataMap item = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
/////other code to set data/////
}
updateCanvas();
}
};
You should be able to avoid this by filtering out dataEvents that originated from the local node (i.e., the device that the code is running on).
Get the local node ID with code like this:
NodeApi.GetLocalNodeResult nodeResult = Wearable.NodeApi.getLocalNode(googleApiClient).await();
String localNodeID = getLocalNodeResult.getNode().getId();
Then, put code like this inside your for loop to do the filtering:
Uri uri = item.getUri();
String nodeID = uri.getHost();
if (nodeID.equals(localNodeID)) {
// Skip changes originating on this device
continue;
}

How to get the position of touch in a simple windows phone 8 app?

I am making an app for windows phone 8.
On one of the pages of the app, I want to get the co-ordinates of the touch.
I tried searching on net but I got results related to games.
I want to know is it possible to get the position of touch on canvas/or any other component in a simple app.
If yes, plz guide me through it.
Hook up to Tap event of the Control, and use GetPosition of event args.
<Canvas Tap="HandleTap/>
private void HandleTap(object sender, GestureEventArgs e)
{
Point point = e.GetPosition(null);
}

Converting from 3.1 to 4.0... gamestates

I'm restarting development of a game I was working on, and have successfully converted it over to XNA 4.0 using the cheat sheet. Most of it works, some of it doesn't, and I'm in the process of fixing what doesn't work.
One thing that I had was a state system that was heavily based on the state system used as an example of XNA Unleashed, the ebook. I didn't have much in it.... basically just the ability to pause the game.
When I paused the game, the action of the game would stop, and the word "PAUSED" would appear in block letters across the screen, and you'd see the paused action. However, now it seems that the sprite batch automatically clears out everything between frames, so when I pause the game now, the screen clears, leaving PAUSED over a purple background. Back then, I believe that adding "SaveStateMode.SaveState" would prevent that from happening, but that functionality was removed. When I did some research, I found out that it was removed because it was essentially useless, that's all handled in the game state manager.
However, I can't find any documentation on this. Where should I start? Right now, my code looks like this:
In the Playing Game State update method:
if (input.WasPressed(0, Buttons.Start, Keys.Enter))
{
GameManager.PushState((GameState)ThisGame.PausedGameState.Value);
}
public void PushState(GameState newState)
{
AddState(newState);
//Let everyone know we just changed states
if (OnStateChange != null)
{
OnStateChange(this, null);
}
}
private void AddState(GameState state)
{
states.Push(state);
Game.Components.Add(state);
//Register the event for this state
OnStateChange += state.StateChanged;
}
//PausedGameState Draw method:
public override void Draw(GameTime gameTime)
{
ThisGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null);
DrawPaused(); //draws the Paused Text
ThisGame.SpriteBatch.End();
}
The goal is to make "PAUSED" appear over the screen, with a snapshot of where the gameplay left off... and not "PAUSED" over a cleared purple screen.
Do you suppose that GraphicsDevice.Clear() somehow got called after the state changed to paused? What does the DrawPaused() method do in your code?

Possible to intercept "unminimize" event on windows?

Is it programmatically possible to intercept the maximize/restore event on Windows such that when you click on a minimized button on the taskbar, it asks you for a password?
Update: To clarify, I'm asking if it is possible systemwide. For example, I may pick a browser/im/editor window that I want to secure if I need to walk away from the machine for a few minutes.
It is possible to capture a "SizeChange" event. I don't see anything specific to Minimizing/Restoring.
With .NET (C#), you'd do something like this:
private void Form1_Load(object sender, EventArgs e)
{
// Tie in a new event handler.
this.SizeChanged += new EventHandler(Form1_SizeChanged);
}
void Form1_SizeChanged(object sender, EventArgs e)
{
if(WindowState == FormWindowState.Minimized)
MessageBox.Show("Window is now: " + WindowState.ToString());
}
If you can be more specific as to which language you are using, perhaps me or someone else can better answer.
Well, you could write a program that deep hooks the target program.
Seriously, however, if I can walk up to your computer and encounter that you got away lucky the first time. Next time I'll be back with a powerful tool to read disk files, scrape memory, or worse.
Winkey+L, dude!

Resources