How Programmatically tap the Wp8 screen - xaml

In my app i am working with tap events, by taping on my WP screen im displaying the X,Y Coordinates in Text-block. now trying to tap Programmatically on Screen with passing X,Y Coordinates.
How can i do that .
Hear is my code to get X,Y Values
private void GestureListener_Tap(object sender,
Microsoft.Phone.Controls.GestureEventArgs e)
{
try
{
Point tapLocation = e.GetPosition(viewfinderCanvas);
if (tapLocation != null)
{
focusBracket.SetValue(Canvas.LeftProperty,
tapLocation.X);
focusBracket.SetValue(Canvas.TopProperty,
tapLocation.Y);
double tapX = tapLocation.X;
double tapY = tapLocation.Y;
focusBracket.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke(delegate()
{
this.txtDebug.Text = string.Format("Tapping Coordinates are X={0:N2}, Y={1:N2}", tapX, tapY);
});
}
}
catch (Exception error){
this.Dispatcher.BeginInvoke(delegate()
{
txtDebug.Text = error.Message;
}); }}
Thanks in Advance

Related

Codename One location sometimes not working

Old question: Codename One app not provide real location
We still have problem getting current location.
Sometimes it's ok, "Localizzazione..." dialog shows, then location ok callback dispose the dialog.
Sometimes the dialog is never disposed and I don't see GPS in the top bar, which is visible when location is ok and dispose the dialog.
Slider s1 = new Slider();
Display.getInstance().callSerially(() -> {
blocco_loc_in_corso = makeDialog("Localizzazione...", s1, null, 'a');
blocco_loc_in_corso.show();
});
LocationManager locationManager = LocationManager.getLocationManager();
locationManager.setLocationListener(new LocationListener() {
#Override
public void locationUpdated(Location location) {
if(location != null) {
Display.getInstance().callSerially(() -> {
if(blocco_loc_in_corso != null) {
blocco_loc_in_corso.dispose();
}
});
paintLocation(location, true);
}
}
#Override
public void providerStateChanged(int newState) {
}
}, new LocationRequest(LocationRequest.PRIORITY_HIGH_ACCUARCY, 1000));
I have this problem for at least 6 months. We only need to block user until we have his GPS location which may can change (GPS updates callback).
Edited:
public Dialog makeDialog(String label, Component c, String buttonText, char btIcon) {
Dialog dlg_r = new Dialog();
Style dlgStyle = dlg_r.getDialogStyle();
dlgStyle.setBorder(Border.createEmpty());
dlgStyle.setBgTransparency(255);
dlgStyle.setBgColor(0xffffff);
Label title = dlg_r.getTitleComponent();
title.getUnselectedStyle().setFgColor(0xff);
title.getUnselectedStyle().setAlignment(Component.LEFT);
dlg_r.setLayout(BoxLayout.y());
Label blueLabel = new Label(label);
blueLabel.setShowEvenIfBlank(true);
blueLabel.getUnselectedStyle().setBgColor(0xff);
blueLabel.getStyle().setFgColor(0x0a0afc);
blueLabel.getStyle().setAlignment(Component.CENTER);
blueLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
blueLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
dlg_r.add(blueLabel);
dlg_r.add(c);
if (buttonText != null) {
Button dismiss = new Button(buttonText);
dismiss.getAllStyles().setBorder(Border.createEmpty());
dismiss.getAllStyles().setFgColor(0);
dismiss.getAllStyles().set3DText(true, true);
dismiss.setIcon(FontImage.createMaterial(btIcon, dismiss.getStyle()));
dismiss.addActionListener(((evt) -> {
dlg_r.dispose();
}));
dlg_r.add(dismiss);
}
return dlg_r;
}
To make sure this code is threadsafe make the following change:
public void locationUpdated(Location location) {
locationFound = true;
// ...
}
Then in the make dialog method:
dlg_r.addShowListener(e -> {
if(locationFound) {
dlg_r.dispose();
}
});
Since this event can happen in the dead time of showing the dialog transition.

C++/winRT xaml ContentDialog example

The documentation shows this C# snippet:
async void DisplayDeleteFileDialog(){
ContentDialog deleteFileDialog = new ContentDialog{
Title = "Delete file permanently?",
Content = "If you delete this file, you won't be able to recover it. Do you want to delete it?",
PrimaryButtonText = "Delete",
CloseButtonText = "Cancel"
};
ContentDialogResult result = await deleteFileDialog.ShowAsync();
// Delete the file if the user clicked the primary button.
/// Otherwise, do nothing.
if (result == ContentDialogResult.Primary) {
// Delete the file.
}
else {
// The user clicked the CLoseButton, pressed ESC, Gamepad B, or the system back button.
// Do nothing.
}
}
What I'm requesting is a C++/winRT version of this snippet.
IAsyncAction Async()
{
ContentDialog dialog;
dialog.Title(box_value(L"title"));
dialog.Content(box_value(L"content"));
dialog.PrimaryButtonText(L"primary");
dialog.CloseButtonText(L"close");
auto result = co_await dialog.ShowAsync();
if (result == ContentDialogResult::Primary)
{
}
}
I wanted to open content dialog on button click so I tried the code snippet provided by Kenny Kerr. Everything seemed to work fine without error but when i clicked the button no dialog was seen. i fixed it by placing below code
dialog.XamlRoot(myButton().XamlRoot());
Before auto result = co_await dialog.ShowAsync() line.
ContentDialog.xaml, xaml.h, xaml.cpp should not have the name or classes
named Windows::UI::Xaml::Controls::ContentDialog!!! My name is
ContentDialog1
DirectXPage.xaml.cpp
void YourNamespace::DirectXPage::UpdateStatus(String^ strMessage,
NotifyType type)
{
switch (type)
{
case NotifyType::StatusMessage:
StatusBorder->Background = ref new
SolidColorBrush(Windows::UI::Colors::Green);
break;
case NotifyType::ErrorMessage:
StatusBorder->Background = ref new
SolidColorBrush(Windows::UI::Colors::Red);
break;
default:
break;
}
StatusBlock->Text = strMessage;
// Collapse the StatusBlock if it has no text to conserve real estate.
if (StatusBlock->Text != "")
{
StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Visible;
StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
else
{
StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
// Raise an event if necessary to enable a screen reader to announce
the status update.
auto peer = dynamic_cast<FrameworkElementAutomationPeer^>
(FrameworkElementAutomationPeer::FromElement(StatusBlock));
if (peer != nullptr)
{
peer->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged);
}
}
void YourNameSpace::DirectXPage::NotifyUser(Platform::String^ strMessage,
NotifyType type)
{
if (Dispatcher->HasThreadAccess)
{
UpdateStatus(strMessage, type);
}
else
{
Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new
DispatchedHandler([strMessage, type, this]()
{
UpdateStatus(strMessage, type);
ContentDialog1^ dlg = ref new ContentDialog1();
dlg->ContentDialog_SetTitle(L"Error Message");
dlg->ContentDialog_SetTextBlock(L"All textures must be chosen from
the x64\\Release or Debug\\YourNamespace\\AppX\\Assets\\
(Folder or sub-Folders)");
Windows::Foundation::IAsyncOperation<ContentDialogResult>^ result =
dlg->ShowAsync();
if (result->GetResults() == ContentDialogResult::Primary) {}
if (result->GetResults() == ContentDialogResult::Secondary) {}
}));
}
}

how to set xaml mapcontrol mapicon always visible

I'm fairly new to programming in XAML and I'm making a test application on windows phone 8.1 emulator with a MapControl.
I wanted to add a MapIcon to my map but the icon doesn't appear when the map is zoomed out. I've searched the internet and couldn't find anything regarding my problem.
I want my zoomlevel 12 and show the mapicon on that zoomlevel.
namespace TEST.APPLICATION
{
public partial class MapView : Page
{
Geolocator geo = null;
public MapView()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
if (Frame.CanGoBack)
{
e.Handled = true;
Frame.GoBack();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
map.Center = new Geopoint(new BasicGeoposition()
{
Latitude = 51.5856935784736,
Longitude = 4.79448171225132
});
map.ZoomLevel = 12;
displaySightings();
}
private void displaySightings()
{
MapIcon sighting1 = new MapIcon();
sighting1.Location = new Geopoint(new BasicGeoposition()
{
Latitude = 51.5940,
Longitude = 4.7795
});
//sighting1.NormalizedAnchorPoint = new Point(0.5, 1.0);
sighting1.Title = "VVV";
map.MapElements.Add(sighting1);
}
}
Is there any way to make the MapIcon always visible?
The MapIcon is not guaranteed to be shown. It may be hidden when it obscures other elements or labels on the map.
For some stupid reason, Microsoft thought that labels and other map elements should outrank map icons when rendering the display. So, if you're making an app displaying the locations of all the nearby Starbucks, the name of the high school across the street from the Starbucks is more important than the pushpin, according to them.
You'll need to render the pushpins using XAML instead.

Capturing Black image with Flash_ON in Nexus 4 in android

I am using custom camera in android.When i am capturing image with Flash_ON, the image is too dark almost black in Nexus 4 only.But it is fine on other devices.Please help me .
My code is given below :-
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(cameraId, cameraInfo);
Camera.Parameters parameters = camera.getParameters();
Size bestPreviewSize = determineBestPreviewSize(parameters);
Size bestPictureSize = determineBestPictureSize(parameters);
mSize = bestPreviewSize;
parameters.setPreviewSize(bestPreviewSize.width,.setPreviewSize(bestPreviewSize.width,
parameters.setPictureSize(bestPictureSize.width, bestPictureSize.height);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
} else {
parameters.setFlashMode(Parameters.FLASH_MODE_ON);
parameters.setSceneMode(Parameters.SCENE_MODE_AUTO);
parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
}
camera.setParameters(parameters);
Just change the value of Parameter you need to set as follows
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
Flash should turn off automatically. If it doesn't then turn off it manually in shutter callback
ShutterCallback shutterCallback = new ShutterCallback() {
#Override
public void onShutter() {
try {
Parameters params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
} catch (Exception e) {
}
}
};

Always show the navigation arrows on a flipview control in RTXAML

I'm using a XAML FlipView Control for a Windows 8 store application.
When I use the mouse and the mouse is over the FlipView control the previous/next navigation buttons are shown.
However if I don't use a mouse and use touch, the navigation buttons hide.
I would like navigation buttons to always be visible. How can I do this?
I've looked at the control template but I can't see anything in there that sets the visibility of the navigation buttons.
Ta
Try dynamically hide/show the buttons.
private void Show(object sender, RoutedEventArgs e)
{
ButtonShow(fv, "PreviousButtonHorizontal");
ButtonShow(fv, "NextButtonHorizontal");
ButtonShow(fv, "PreviousButtonVertical");
ButtonShow(fv, "NextButtonVertical");
}
private void Hide(object sender, RoutedEventArgs e)
{
ButtonHide(fv, "PreviousButtonHorizontal");
ButtonHide(fv, "NextButtonHorizontal");
ButtonHide(fv, "PreviousButtonVertical");
ButtonHide(fv, "NextButtonVertical");
}
private void ButtonHide(FlipView f, string name)
{
Button b;
b = FindVisualChild<Button>(f, name);
b.Opacity = 0.0;
b.IsHitTestVisible = false;
}
private void ButtonShow(FlipView f, string name)
{
Button b;
b = FindVisualChild<Button>(f, name);
b.Opacity = 1.0;
b.IsHitTestVisible = true;
}
private childItemType FindVisualChild<childItemType>(DependencyObject obj, string name) where childItemType : FrameworkElement
{
// Exec
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child is childItemType && ((FrameworkElement)child).Name == name)
return (childItemType)child;
else
{
childItemType childOfChild = FindVisualChild<childItemType>(child, name);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}