I want to make a doodle sort of control on an embedded device and this is what I’ve done so far:
Placed an InkPresenter control (Home_Ink) and these are its events:
Home_Ink_MouseLeftButtonDown:
m_pHome_Ink->CaptureMouse(retValue);
pApplication->CreateObject(&s);
pApplication->CreateObject(&pStylusPoints);
pApplication->CreateObject(&pDrawingAttributes);
s->SetStylusPoints(pArgs->pStylusPoints);
pDrawingAttributes->SetHeight(pencilWidth);
pDrawingAttributes->SetWidth(pencilWidth);
pDrawingAttributes->SetColor(pencilColor);
s->SetDrawingAttributes(pDrawingAttributes);
m_pHome_Ink->GetStrokes(&pStrokes);
pStrokes->Add(s,NULL);
Home_Ink_MouseLeftButtonUp :
s=NULL;
m_pHome_Ink->ReleaseMouseCapture();
Home_Ink_MouseMove :
if(s!=NULL)
{
s->SetStylusPoints(pArgs->pStylusPoints);
pStrokes->Add(s,NULL);
}
There are no build errors and the application is running.
But nothing is getting drawn on the inkpresenter. What am I doing wrong??
Related
After taking Picture, how to select Ok in appium when tick mark cant be located?
only camara layout is Higlighted and i am not able to loacte tick mark or revert.
Please try below code snippet. If you are able to click using android keyboard then below code should work.
((AndroidDriver)driver).pressKey(new KeyEvent(AndroidKey.SEARCH));
I acheived this using TouchAction.
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(111, 222)).perform()
solution for accepting image using camera app in appium.
keyEvent=>27, is use to capture the image using camera app.
i used below code to accept the captured image. (but its not working)
i used keyEvent=> 66, Enter button to accept the image (but its not working).
i used keyEvent=> 84, Space button to accept the image (but its not working).
below working code.
i used keyEvent=> 22 and then i used keyEvent=> 66, it will accept the image.
$app.press_keycode(27) #click on camera accept button.
$app.press_keycode(22)
$app.press_keycode(66)
sleep 2
$app.press_keycode(27)
$app.press_keycode(22)
$app.press_keycode(66)
Note: repeat the code for 2 twice
i used keyEvent=> 21 and then i used keyEvent=> 66 and i used keyEvent=> 27, it will allow u to retake the image.
i used keyEvent=>4, it will take back u form camera app
The way I handled Camera and Tick button initially was using Android Key Codes:
Thread.sleep(2000);
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
In most of the devices which I researched earlier, the above snippet worked like a charm for me. However, when I started testing on Android versions 9, 10 and 11 recently, this wasn't working and the number of tabs increased to 3 or 4. To handle this in most of the devices like Samsung, OnePlus, Google Pixel, I refactored the code as:
Thread.sleep(2000);
// Click Camera shutter button
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
try {
WebDriverWait wait = new WebDriverWait(androidDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable((MobileBy.AccessibilityId("Done");
// Click Done or Tick after clicking photo (Mostly visible in OnePlus, Nokia, Google Pixel devices)
androidDriver.findElementByAccessibilityId("Done").click();
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for DONE Button");
}
if (flag) {
try {
// Click OK after clicking photo (Mostly visible in Samsung devices)
// No need to put WebDriverWait here as we already waited for 10 secs after clicking on Camera
androidDriver.findElementByXPath("//android.widget.TextView[#text='OK']").click();
flag = false;
System.out.println("OK Button Clicked");
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for OK Button");
}
}
if (flag) {
// If both above methods failed, then this may work (Mostly works for Xiaomi, Nokia devices)
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
System.out.println("TABS & ENTER Pressed");
}
I am making my first steps in Universal Windows Platform (Windows 10 store apps technology). I have an application with 2 pages and use the navigation service to navigate between them. I am used to having a transition applied when navigating between pages, but now I don't see any transition.
I tried to set the content transition manually but that does not work as well:
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
var shell = Shell as Frame;
shell.ContentTransitions = new TransitionCollection();
shell.ContentTransitions.Clear();
shell.ContentTransitions.Add(new ContentThemeTransition { HorizontalOffset = 300 });
this.NavigationService.Navigate(Experiences.Main, null);
return Task.FromResult<object>(null);
}
Is there any other way to configure the navigation service to apply a transition?
I found the solution for the problem. I ended up using the **EntranceThemeTransition** and it seemed to work:
shell.ContentTransitions.Add(new EntranceThemeTransition {
FromHorizontalOffset = 400,
FromVerticalOffset = 0,
IsStaggeringEnabled = true});
I want to be able to go to options menu in the game I am developing and set up my controls.
It is a simple game of pong (for now) and the controls for each player are just up and down.
This is how I want the process to look like: I click SETUP CONTROLS, game displays the name of the control I am supposed to change and it waits, I click the button on keyboard that i want it to be changed to, game reads it and displays the next control I am supposed to change and so on until i change all controls.
I have found a way how to do that here and my code now looks basicly like this:
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
while (waitingForKey)
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}
In this short code my goal is to change just one key. If I can make it change 1 key, changing more wont be a problem.
The problem is, I don't see why does my game stop responding when i click the SETUP CONTROLS button. I don't see an infinite loop here nor a memory leak.
Why is my game crashing and is there a better way to load controls in options menu?
If you saw the answer from the link you placed in your question, you would have noticed that he actually deleted the while loop and he made it an if statement.
Like Nico Schertler said : "while(waitingForKey) is your infinite loop. That loop blocks the game thread, so no further input is recognized."
Link to the answer from your link: https://stackoverflow.com/a/15935732/3239917
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
if (waitingForKey )
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}
I have already added 5 cammands in a form and I want to add a sixth but It does not display the sixth?
I am posting my codes below.
public Command getOk_Lastjourney() {
if (Ok_Lastjourney == null) {
// write pre-init user code here
Ok_Lastjourney = new Command("Last Journey", Command.OK, 0);
// write post-init user code here
}
return Ok_Lastjourney;
}
public Form getFrm_planjourney() {
if (frm_planjourney == null) {
// write pre-init user code here
frm_planjourney = new Form("Plan journey", new Item[] { getTxt_From(), getTxt_To(), getCg_usertype(), getCg_userpref(), getCg_searchalgo() });
frm_planjourney.addCommand(getExt_planjourney());
frm_planjourney.addCommand(getOk_planjourney());
frm_planjourney.addCommand(getOk_planFare());
frm_planjourney.addCommand(getOk_planDistance());
frm_planjourney.addCommand(getOk_planTime());
frm_planjourney.addCommand(getOk_planRoute());
frm_planjourney.setCommandListener(this);
// write post-init user code here
System.out.println("Appending.....");
System.out.println("Append completed...");
System.out.println(frm_planjourney.size());
frm_planjourney.setItemStateListener(this);
}
return frm_planjourney;
}
Given System.out.println I assume you were debugging with emulator, right? in that case it would be really helpful to provide a screen shot showing how exactly does not display the sixth looks like.
Most likely you just got too many commands to fit to area allocated so that some of them are not shown until scrolled. There is also a chance that sixth command was reassigned to some other soft-button and you didn't notice that. Or there's something else - hard to tell with details you provided.
A general note - handling six actions with commands might be not the best choice in MIDP UI. For stuff like that, consider using lcdui List API instead. IMPLICIT kind of lists allow for more reliable and user friendly design than commands.
In short:
I want to show a view or action sheet and only continue code execution after the user has dismissed the view / sheet. So: line one shows the view, line two reads some result variable.
In detail why I would need this:
I'm porting a Windows Forms application over to the iPad. The original implementation has a communication class which uses a web service to communicate with the server. It offers a couple of methods to get data. Conveniently it checks prior to each call if the user still has a valid connection or if he has to re-enter his password for security reasons.
If the password is required, the .NET class shows a modal dialog which blocks any further code executio and if the password was entered, retries the last call it has made before showing the dialog.
Now using CocoaTouch I'm facing a problem. I replaced the code that shows the dialog with a UIActionSheet. Works great but code execution continues immediately, whereas in Windows Forms it is blocked (the next line in Windows Forms after showing the dialogs is to read the entered password from the dialog) until the dialog has been closed.
I tried a Thread.Sleep() until the user dismisses the UIActionSheet but the Thread.Sleep() also blocks the main loop and my view won't even be drawn.
The alternative I currently see is to change all methods in the already working class and give them a return value: if password required, handle it, then retry.
But this means that all over my code I will have to add these checks because at any given moment the password might be needed. That's why it is nested in communication class in Windows Forms.
Any other ideas?
René
Yes, it is possible.
To do this, what you can do is to run the mainloop manually. I have not managed to stop the mainloop directly, so I instead run the mainloop for 0.5 seconds and wait until the user responds.
The following function shows how you could implement a modal query with the above approach:
int WaitForClick ()
{
int clicked = -1;
var x = new UIAlertView ("Title", "Message", null, "Cancel", "OK", "Perhaps");
x.Show ();
bool done = false;
x.Clicked += (sender, buttonArgs) => {
Console.WriteLine ("User clicked on {0}", buttonArgs.ButtonIndex);
clicked = buttonArgs.ButtonIndex;
};
while (clicked == -1){
NSRunLoop.Current.RunUntil (NSDate.FromTimeIntervalSinceNow (0.5));
Console.WriteLine ("Waiting for another 0.5 seconds");
}
Console.WriteLine ("The user clicked {0}", clicked);
return clicked;
}
I think this approach using async/await is much better, and doesn't suffer from freezing the app when rotating the device, or when the autoscrolling interferes and leaves you stuck in the RunUntil loop forever without the ability to click a button (at least these problems are easy to reproduce on iOS7).
Modal UIAlertView
Task<int> ShowModalAletViewAsync (string title, string message, params string[] buttons)
{
var alertView = new UIAlertView (title, message, null, null, buttons);
alertView.Show ();
var tsc = new TaskCompletionSource<int> ();
alertView.Clicked += (sender, buttonArgs) => {
Console.WriteLine ("User clicked on {0}", buttonArgs.ButtonIndex);
tsc.TrySetResult(buttonArgs.ButtonIndex);
};
return tsc.Task;
}