i have a game developed using LWUIT.now i am implementing full touch in game.it is a multi player game so there are some options like chat and login. when we press on chat we need to enter the characters in the field. my question is
is it possible to invoke the native keypad when we press on the chat button .?
thanks in advance
kris
No. MIDP doesn't include such an API. You can use LWUIT's virtual keyboard (which isn't native) and define any character set you want as explained here:
http://lwuit.blogspot.com/2010/06/pimp-virtualkeyboard-by-chen-fishbein.html
You can show it using the display class.
On Symbian devices if you do not define some jad properties, a touch keypad will be always visible and you won't be able to hide it for more details look here:
http://lwuit.blogspot.com/2009/11/optimized-for-touch.html
Looking at the question again I'm thinking the VKB is probably an overkill for an always on keypad replacement. Just place your content in the center of a BorderLayout and stick a container in the south something like this:
addComponent(BorderLayout.CENTER, myUI);
Container keypad = new Container(new GridLayout(2, 2));
addComponent(BorderLayout.SOUTH, keypad);
Button up = new Button("Up");
Button down = new Button("Down");
Button left = new Button("Left");
Button right = new Button("Right");
up.setFocusable(false);
down.setFocusable(false);
left.setFocusable(false);
right.setFocusable(false);
keypad.addComponent(up);
keypad.addComponent(down);
keypad.addComponent(left);
keypad.addComponent(right);
up.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
int up = Display.getInstance().getKeyCode(Display.GAME_UP);
Display.getInstance().getCurrentForm().keyPressed(up);
Display.getInstance().getCurrentForm().keyReleased(up);
}
});
The rest and fire are pretty trivial to add (same thing) notice that getKeyCode is deprecated but should work for now since we have no alternative to that API.
Related
I'm using CUITe to automate the testing of a UI piece (captured as a Page Object model).
I have a class that captures the buttons in my UI, like so:
class Navigators : CUITe_BrowserWindow
{
public new string sWindowTitle = "Window";
public CUITe_HtmlInputButton next = new CUITe_HtmlInputButton("Id=Content_btnNext");
// Other such buttons
//And a method to click any button
public void ClickButton(string id)
{
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().Get<CUITe_HtmlInputButton>(string.Concat("Id=", id)).Click();
}
}
And the test I'm trying to automate is this, the click of a button:
CUITe_BrowserWindow.Launch<Navigators>("url");
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().ClickButton("Content_btnNext");
My problem is this:
When I project my screen to a secondary monitor and extend it, the 'Next' button is clicked perfectly. However, on my system, the mouse passes over the button to another position and the click doesn't happen.
I have tried refreshing the CodedUI cache (by setting SearchConfiguration to Always), but that hasn't worked. Also, SetFocus on the control works correctly, whereas DrawHighlight shows the wrong position.
Any help would be greatly appreciated.
EDIT
When I changed my screen's resolution to 1440x900 (which is that of the secondary monitor's), the click happened.
I would be glad if someone could provide links that show how to handle screens of different resolutions in Coded UI
This is how I click controls on Win 8.1 store app which may or maynot be of help to you:
Mouse.Click(new Microsoft.VisualStudio.TestTools.UITest.Input.Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
Below is how I've been doing it in my CUITe scripts & it works fine at 1920x1080 on my larger monitor & at 1280x1024 on my laptop screen.
Given your OR definition above.
using Navigators.ObjectRepository; //guessing the name here
var pgNavigator = new Navigators();
//whatever else you do before clicking on next
Navigators.next.Click();
I want to create a JavaFX table that, in the cells of one column, allows the user to edit XHTML text. I only need very basic formatting capabilities like bold, italic, striketrough.
I have already managed to implement this by using my own subclass of TableCell and using a WebView for each cell (HTMLEditor would of course have been another choice, but my guess is that for my requirements, WebView should be sufficient).
However, to make editing comfortable for the user, I need the following features:
1. The cell height needs to resize if the user enters multi-line text.
2. A context menu (or, if not possible, some other menu or button) should allow formatting parts of the text in a cell as described above (bold, italic..)
Has anybody been successful in implementing something similar ? I have seen suggestions on the web, but they rarely included code samples.
I have succedded doing something similar.
I figured I can share some of the basic clues that allowed me to achieve it.
Resize the whole WebView. For that, the whole WebView must be an editable html page. You achive that by setting contenteditable to true:
<body contenteditable='true' id='content'></body>
You can have a context menu over a webview. But it is something tricky, as you must first disable the original context menu associated to it.
WebView editView;
...
EventDispatcher originalDispatcher = editView.getEventDispatcher();
editView.setEventDispatcher(new WebmenuEventDispatcher(originalDispatcher));
And this is the event dispatcher class:
public class WebmenuEventDispatcher implements EventDispatcher {
private EventDispatcher originalDispatcher;
public WebmenuEventDispatcher(EventDispatcher originalDispatcher) {
this.originalDispatcher = originalDispatcher;
}
#Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
if (MouseButton.SECONDARY == mouseEvent.getButton()) {
mouseEvent.consume();
// Show our own menu
cmEdit.show(editView.getScene().getWindow(), mouseEvent.getScreenX(), mouseEvent.getScreenY());
}
}
return originalDispatcher.dispatchEvent(event, tail);
}
}
Now, for setting the font from within that menu, you need a bidirectional Java<->javascript bridge and use some javascript in the webview side.
NOTE: There are two similar SO questions (1) (2), but neither of them provides an answer.
TL;DR: How can one dismiss the keyboard in a MonoTouch.Dialog by letting the user touch any empty space in the view?
I'm writing an app using MonoTouch.Dialog and a UITabBarController. One of my tabs is "Settings"...
When the user starts typing, the keyboard obstructs the tabbar...
Using MonoTouch.Dialog, the only way to dismiss the keyboard is to go to the last field and press the "return" key. Considering the fact that the user cannot press any tab until the keyboard is gone, I would like a better way to do it. Namely, to dismiss if the user taps anywhere else on the screen.
Without MonoTouch.Dialog, it's a snap: simply override TouchesBegan and call EndEditing. But this doesn't work with MT.D. I've tried subclassing DialogViewController and overriding TouchesBegan there, but it doesn't work. I'm currently at a loss.
Or, I wonder, would I be better off ditching the tabbar so I can use a UINavigationController with a "Back" button on top, which won't be hidden by the keyboard?
I suggest you use a tap gesture recognizer that will not cause interference with the TableView event handlers:
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() => dvc.View.EndEditing (true));
dvc.View.AddGestureRecognizer (tap);
tap.CancelsTouchesInView = false;
You missed my question about it also: Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog?
:-)
This is my #1 feature request for MonoTouch.Dialog.
To answer your question: No. It is not possible. I have searched and asked around and have not found any answers.
I assume because it is just a sectioned (grouped) table and if it wasn't sectioned, there wouldn't be any spot to click. However, that is just my speculation.
I wish that miguel or someone that works on monotouch would answer this and say if it is even possible. Possibly a future enhancement?
I figured out a workaround that satisfies me well enough, so I'm answering my own question.
// I already had this code to set up the dialog view controller.
var bc = new BindingContext (this, settings, "Settings");
var dvc = new DialogViewController (bc.Root, false);
// **** ADD THIS ****
dvc.TableView.DraggingStarted += (sender, e) => {
dvc.View.EndEditing (true);
};
This will dismiss the keyboard whenever the user drags the view a little bit. There's no touch event I could find associated with the tableview, so this is the next best thing. I'd welcome any other ideas. Cheers!
One workaround to use the dragging gesture instead of the tap as proposed (that do not interfere with the table view gestures) is to override MonoTouch.Dialog.DialogViewController.SizingSource (or MonoTouch.Dialog.DialogViewController.Source if you don't want uneven rows) and give it to the DialogViewController. I don't know if it is very clean or safe.
public class CustomTableViewSource : MonoTouch.Dialog.DialogViewController.SizingSource
{
public CustomTableViewSource(MonoTouch.Dialog.DialogViewController dvc) : base(dvc)
{
}
public override void DraggingStarted(UIScrollView scrollView)
{
base.DraggingStarted(scrollView);
if (scrollView != null)
{
scrollView.EndEditing(true);
}
}
}
I am currently writing a J2ME app for a card game which begins at a menu screen which gives the option to select a number of different card games to play.
This menu screen is a form and I need to know how to navigate to the new form for the games.
public void commandAction(Command c, Displayable s) {
if(c.equals(exitComm)){
}
else if(c.equals(gameComm))
{
//start the queen game...create instance of QueensForm
QueensForm form = new QueensForm(null, "Queens");
display.setCurrent(form);
System.out.println("pressed play");
}
As it stands the app compiles and runs, however when the play button is clicked an error occurs and it says the problem is on the line display.setCurrent(form); I am unsure of the problem and was wondering if anybody could help me to sort this out or suggest a better way to navigate throughout the forms in the app.
According to the documentation, Display.setCurrent doesn't work if the current displayable is an alert. This is a problem as I would like to pop up another alert when the user selects a command. Does anyone know how to work around this so that we can go from one alert to another? I am using CLDC 1.0 and MIDP 2.0.
Additional Information
The spec does allow us to edit an alert while it is on screen, but some Nokia phones don't handle it well at all. So I am now trying to go from the alert to a blank canvas, then back to the alert. Of course I don't want the user to interact with the previous canvas, so it seems that I am forced to create a new blank canvas. As a sidenote, this has the slight disadvantage of looking worse on phones which still have the previous screen when an alert is shown.
The bigger problem is how to transition from the blank canvas back to an alert once the canvas is loaded. Testing on the Motorola emulator revealed that showNotify is not called after returning from an alert to the previous screen. I guess I could create the next alert in the paint method, but this seems like a ugly hack.
OK, so your problem is that you can't set it up to do:
Display.setCurrent(alert1, alert2);
and
Display.setCurrent(alert2);
is also not possible if the current Displayable is already alert1.
So how about put an intermediate Displayable item that is blank and that immediately changes to the next alert? Assuming the current Displayable is alert1, like this in your alert1's command block:
Display.setCurrent(blankForm);
Display.setCurrent(alert2);
That should work assuming you are not using the default 'Dismiss' command. So basically it goes from alert1->(blankForm->alert2).
I couldn't find a way around this, so I just used the paint hack.
public class AlertPage extends Canvas{
MIDlet midlet;
Alert alert;
private AlertPage(MIDlet midlet){
this.midlet=midlet;
}
protected void paint(Graphics arg0){
//Yep, this is a hack, but showNotify doesn't seem to work well for Motorola
if(alert!=null){
Display d=Display.getDisplay(midlet);
d.setCurrent(alert);
alert=null;
}
}
public static void showAlert(MIDlet m, Alert a){
AlertPage page=new AlertPage(m);
Display d=Display.getDisplay(m);
page.alert=a;
d.setCurrent(page);
}
}