Showing touch keyboard in custom control for Windows Phone 8.1 - windows-phone-8

We can show/hide touch keyboard for windows store apps using a Custom AutomationPeer, but for Windows Phone 8.1 OnCreateAutomationPeer() is not invoking on GotFocus().
How can I make it do so? Any help would be greatly appreciated.

You can get the focus using the FocusManager class.
In general it works like this to remove a focus and thus hide the keyboard:
var focusedObject = FocusManager.GetFocusedElement();
if (focusedObject != null)
{
var root = (Frame)Application.Current.RootVisual;
// Set Focus to Page to close the keyboard
if (root != null) root.Focus();
}

Related

Adobe AIR bring to front - activate() not working

I have an adobe desktop AIR app. When I send some data with a local connection, I want the app in front of all the other windows with focus on it.
I tested on a brand new air app with just this code:
import flash.display.NativeWindow;
var window:NativeWindow = stage.nativeWindow;
var aspa = setInterval (activateWin,8000);
function activateWin (){
trace("Activate window");
window.activate();
clearInterval(aspa);
}
And nothing happens. While if I write:
window.alwaysInFront=true;
window.alwaysInFront=false;
It brings the app to the front, but this command gives no focus to the window.
If I add
NativeApplication.nativeApplication.activate(stage.nativeWindow);
This makes the status bar icon blink, but still no focus or front action.
Reading this page, it seems it should work.
Am I missing something?
I've just use
window.activate();
window.alwaysInFront = true;
window.alwaysInFront = false;
and it's works fine on windows and mac os

MediaCapture and Window VisibilityChanged

[Question]
On Windows Phone 8.1, what exactly happens in between the time when the user leaves the app and the OnSuspended event fires? I'm having trouble with the ability to manage objects in that span, in particular MediaCpture object.
To better explain the problem, here is the scenario:
The user is on a page with a video preview being pumped to a CaptureElement
The user taps the Start button
The user taps Back button and returns to the page with a broken MediaCapture
With WinRT there isn't an ObscuredEvent and OnNavigatingFrom doesn’t fire unless you’re going to another page in the same Frame. After some investigation, I've found that the only event that fires is Window.Current.VisibilityChanged
I've gone ahead and hook it when the page is NavigatedTo and unhooked in OnNavigatedFrom (see ex2 below). Inside the event, I check for parameter that tells if the app is hiding or showing and dispose/initialize accordingly(see ex.1 below).
[Problem]
However, this only works with the debugger attached. If I do this without the debugger attached, it doesn't reinitialize and frequently crashes the camera and I have to literally reboot the device.
Code Example 1 (note: e.Visible == false is leaving the app and true when returning)
async void Current_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
if (!e.Visible) //means leaving the app
{
await DisposeAll(); //cleans the MediaCapture and CaptureElement
}
else
{
if(mediaCaptureManager != null) await DisposeAll();
await Initialization(); //set up camera again
}
}
Example 2 (hooking into the event)
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Window.Current.VisibilityChanged += Current_VisibilityChanged;
this.navigationHelper.OnNavigatedTo(e);
}
protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
this.navigationHelper.OnNavigatedFrom(e);
}
[Update: Resolution]
Instead of using VisibilityChanged, hook into Window.Current.Activated on the page's constructor. With the debugger completely detached, the Activated event will provide the WindowActivationState parameter in the WindowActivatedEventArgs. Like this:
private async void CurrentOnActivated(object sender, WindowActivatedEventArgs e)
{
if(e.WindowActivationState == CoreWindowActivationState.Deactivated)
{
//dispose MediaCapture here
}
else if(e.WindowActivationState == CoreWindowActivationState.CodeActivated || e.WindowActivationState == CoreWindowActivationState.PointerActivated)
{
//initialize MediaCapture here
}
}
See my answer in https://stackoverflow.com/a/28592882/3998132. Using Window.VisibilityChanged in conjunction with your Page\UserControl Loaded\Unloaded handler should solve your issue I believe.
Using Window.Activated is less desirable than Window.VisibilityChanged because Activated relates to being visible AND having focus where as VisibilityChanged only pertains to visibility. For showing a preview having focus is not applicable. Since Windows Store apps on Windows Phone can only have one Window showing there is no difference in using either however if your app becomes universal and runs on let's say on Windows 8+ Modern shell (which can show multiple Store apps with the Snap window feature) or Windows 10 desktop (which can support multiple Store apps showing at the same time) you will not want to stop preview when a user changes focus from your app but your app is still showing.
I'm not sure if it wouldn't be more suitable to use Suspending/Resuming events. Note only that in this case, you will have to debug it properly - it behaves little different while being run with/without debugger attached.
As for the code - hooking your event in OnNavigatedTo/OnNavigatedFrom is not a good idea - when the OS suspends the app and you are using SuspensionManager then OnNavigatedFrom will be called, but when you go back to your app (resume it), then OnNavigatedTo will not be called.
Using Window events may also work here, but why not subscribe it once, somewhere in constructor? - it's window-wide and hence in phone there is only one window, which stands for app, then subscribe once. In this case, you may add a line that recognizes the current page in window and if that page contains mediacapture then dispose (create similar). Then you can also dispose/initialize in navigation events in case user doesn't leave your app and just navigate.

How to make phone numbers into clickable links in Windows Phone?

In Android development, I'm able to use the Linkify object to transform a phone number into a clickable link that will present the phone's dialler to the user.
Is this possible with Windows Phone? If so, how can I make a phone number into a clickable link?
PhoneCallTask MSDN
What you could do is make a textblock that looks clickable. Then on its click event launch the PhoneCallTask
PhoneCallTask pct = new PhoneCallTask();
pct.PhoneNumber = "1112223333";
pct.Show();
I think you are trying to apply a style to a text which is detected to be a number?
If i guest what are you trying to do, then create a style for your text and do this:
if (var something == phonenumber) //think of a logic to detect that
{
something.Style = (Style)this.Resources["YourStyleKey"];
}

Detect mouse on Windows Runtime

I'd like to instruct users of my app to either "click" or "tap", depending whether they have a mouse or a touch screen.
Basically I'd like to do something like this:
if(Controls.hasMouse())
ShowMessage("Click here to continue");
else
ShowMessage("Tap here to continue");
Any ideas how to detect if a mouse is connected to the system?
I found a solution to the problem:
using namespace Windows::Devices::Input;
MouseCapabilities^ mcap = ref new MouseCapabilities();
bool has_mouse = mcap->MousePresent == 1;

Fast App Resume issues in windows phone 8

When i set ActivationPolicy="Resume" in WMAppManifest.xml page tile navigation(navigation URL) is not working in Tombstone state, it reloads the last back stack page(URL). It works fine with Dormant state with out reloading the page. If don't set this property (ActivationPolicy="Resume") it reloads the page in both states [Dormant state and Tombstone state].
But how can we achieve the navigation to secondary url's, when we set that property.
Please help me .
Adding ActivationPolicy="Resume" is not the only step needed to have your app support Fast App Resume. I believe the behavior you are describing is normal when you only set that one property. I think there are a few ways to implement "Fast App Resume", but I found this to be the easiest way.
Set the activation policy like you just described and then do the following:
Go into App.xaml.cs in the "App" class add:
private bool reset
You should then have a method for InitializePhoneApplication that initializes the RootFrame. Add this:
RootFrame.Navigating += RootFrame_Navigating;
RootFrame.Navigated += RootFrame_Navigated;
Then you can go and add those methods:
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (reset && e.IsCancelable && e.Uri.OriginalString == "/MainPage.xaml")
{
e.Cancel = true;
reset = false;
}
}
void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
reset = e.NavigationMode == NavigationMode.Reset;
}
If you implement this properly, your app should resume from the last page you were on.
Same problem here. I got WP8 application with Fast App Resume enabled. I can pin tiles pointing to specific pages in my apps. It works fine when app is just Suspended, but when the app is Tombstoned, then clicking secondary tile has the same effect as clicking the main tile.
I receive only one RootFrameNavigating event with NavigationMode == Back and Uri == /MainPage.xaml. The app then shows the previous page that was there before I suspended the app.
I guess this is actual bug in the platform for this specific scenario - Fast App Resume + tombstoned app + navigation from pinned tile, that we as developers cannot solve.