how to get long press event of textfield in codename one - textfield

I am developing in Codename One.
I am having TextField in one form.
I want to open a dialog box on TextField's long press event
So how can I get long press event of TextField in codename one ?
I already tried by impementing ActionEvent and checked with
if(event.isLongEvent()){
}
but its not working..
Any idea ?
Thanks in advance.
Akash

This one works :
Button button = new Button("Test") {
#Override
public void longPointerPress(int x, int y) {
System.out.println("LONG PRESS");
}
};

Since text field uses native editing the long press event will be grabbed by the native editing functionality so for the text field it just won't work well.
You can derive most components and override longPress or add a long press listener to the form which will have a similar effect but its likely to cause an issue with the native input.

Related

How can I get a click on a row in a table in Cuba framework?

I have to detect a click in a row in a table in Cuba framework but I don't find how.
I have a TreeTable. Then I have a button. If I have nothing selected in the table, I want the button disabled. If I click on a item I want the button to be enabled. If I click on a sub-item, I want the button to be disabled.
It is possible, in the action of the button to use a:
trackSelection = true
That will work, but enabled the button too if I click on a sub-item.
Then The idea is, when anything is clicked on the table, then do something. I have only to track the selection of any item, and then do a logic.
How can I track this selection?
I have tried anything like:
table.setClickListener("columnId", new CellClickListener() {
#Override
public void onClick(Entity item, String columnId) {
// TODO Auto-generated method stub
LOG.info("On cell click");
}
});
First, that don't work, even if I click on a cell. Then even if it will work, I have the complete row and not only a cell.
Somebody have an idea?
Thanks
Best regards
You can react on selection change in Table using CollectionDatasource.ItemChangeListener:
employeesDs.addItemChangeListener(event -> {
log.info("Datasource {} item has been changed from {} to {}",
event.getDs(), event.getPrevItem(), event.getItem());
});
See also: https://doc.cuba-platform.com/manual-6.9/datasource_listeners.html

How to make a default button in UWP app using XAML?

I'm trying to declare a button as default in UWP app but receive an error:
The property 'IsDefault' was not found in type 'Button'
How can I make a default button in UWP app?
I down know what IsDefault is in WPF but to get if a button is pressed in UWP you can use CoreWindow.GetForCurrentThread().KeyDown. Create a Method that will be called from when the button is pressed or VirtualKey.Enter is clicked.
public MainPage()
{
this.InitializeComponent();
CoreWindow.GetForCurrentThread().KeyDown += MainPage_KeyDown; ;
}
private void MainPage_KeyDown(CoreWindow sender, KeyEventArgs args)
{
switch (args.VirtualKey)
{
case Windows.System.VirtualKey.Enter:
// handler for enter key
break;
default:
break;
}
}
You can use key down event which you can place on any textbox for example if you are making a login page then probably there will be 2 textboxes for username and password then just add key down event handler to textbox as it will be the last mandatory field like this:
<PasswordBox KeyDown="PasswordKeyDown"/>
then you can handle this event as:
using System.Windows.Input;
private void PasswordKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
Login();
}
Hope it will help you :)
There is not easy or clean way to solve your problem because IsDefault is not available for uwp apps.
if you are using MVVM or you want to reuse your code I recommend you to use Behaviors and follow the examples that the other guys posted.
I need a Button which user can invoke by pressing the ENTER key.
In an UWP app, by default a Button can be invoked by pressing the Enter key. So I guess what you want is setting the focus on this Button when there are some other UIElements in your page.
You can refer to Keyboard navigation among UI elements,
By default, the tab order of controls is the same as the order in which they are added to a design surface, listed in XAML, or programmatically added to a container.
To focus on the Button which is not the first element, you can just give the TabIndex="1" property to your Button, this property can make your Button get focus whenever the page is loaded, but if you change the focus on other controls in this page, you will need to reselect this button by mouse clicking, touching or TAB key.

Custom context menu XAML for WP8

I try to implement a custom ContextMenu in a LongListSelector.
I'm not using the ContextMenu from Microsoft.Phone.Controls.Toolkit, it's basically the same as in the Rowi App:
(source: hiddenpineapple.com)
Approach 1
My list item toggles a VisualState on hold and an overlay is shown with controls in it.
The problem
I can't find a way to go back to the default state when the user clicks outside of the list item (as in the default ContextMenu).
Approach 2
I've implemented a custom template for the toolkit ContextMenu which looks exactly the same. I had to move its margin top to -itemHeight, as by default it is below the item.
The problem
The problem with this solution is, that it automatically closes itself when opening and I couldn't figure out how to avoid this.
Another problem was that it didn't work well with TiltEffect.IsTiltEnabled from the Toolkit (visual problems).
I need your help
Any suggestions on how to get this working?
Answer
Thanks to Cheese, now I know how to properly close the menu when the user clicks outside.
His suggestion was to get the coordinates of a Tap event on the current page, and check if it's inside the menu. When not, close the menu.
So I added a Tap listener to the page when the menu opens, and removed it when the menu closes. From the page listener I got the event coordinates and could check if it's inside the control which holds the menu (same size and position). I received the position of the control with Point leftUpperPoint = control.TransformToVisual(page).Transform(new Point(0, 0)) and the rightLowerPoint by adding the ActualWidth and ActualHeight.
But then I realized:
Why should I even calculate if the tap is inside the menu? I always want to close the menu when the user taps anywhere on the screen. If it's outside, yes. If it's on a menu button, yes.
Another modification I made was to listen for MouseLeftButtonDown instead of Tap as it also triggers when the user swipes.
So I removed this code and came up with the following:
private void ToggleMenu(object sender, System.Windows.Input.GestureEventArgs e)
{
PhoneApplicationFrame frame = ((PhoneApplicationFrame)Application.Current.RootVisual);
VisualState state = this.States.CurrentState;
if (state == null || state.Name == "DefaultState")
{
frame.MouseLeftButtonDown += MouseDownDelegate;
this.State = "MenuState";
}
else
{
frame.MouseLeftButtonDown -= MouseDownDelegate;
this.State = "DefaultState";
}
}
private void MouseDownDelegate(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToggleMenu(sender, null);
}
This works perfectly!
Thanks to Cheese for the hint.
Something like this by #denniscode http://dotnet.dzone.com/articles/rowi-show-tap-menu
Approach 1 problem
The best solution would be:
Get the menus coordinates, when user makes a tap - you check are tap coordinates on menu or not, if not - dissmiss - simple.
Approach 2 problem
I guess you had some button in a corner and when you tapped on it - nothing happened? And when you dissmissed the Tilt all worked. It seems that tilt works faster than a click, so, tilt changes the button coordinates, and device thiks you have missed/or dragged off
You can use what #ScottIsAFool suggested and maybe create another Dependency Property on your TapMenu control of type UIElement named CloseWhenTappedElement and automatically listen for Tap events inside your control once set. For example
<Grid x:Name="TapArea"/>
<TapMenu CloseWhenTappedElement="{Binding ElementName=TapArea"}/>

VB.NET never get focus on any control

i have developed a simple calculator like in windows calculator,
but unlike in windows calculator, after clicking any button, the focus on that button is still there on the particular clicked button.
so how to never get focus for all buttons on calculator form ... ?
i don't think that it will better to write loose focus code on every button's click event ... so any better solution ?
Without seeing any code of yours, I am going to assume that you have a text box that displays the numbers pressed by the user, so you need to set the focus to the text box once a user clicks a button, like this:
TextBox1.Focus()
Note: If your text box is not named TextBox1, then change the name to whatever your text box is actually named.
Instead of a standard button use an instance of a NoFocusButton class derived from the Standard button. In this class override the ShowFocusCues property and return always false.
Form f = new Form();
// Need to add manually the buttons to your form unless you build a customcontrol
NoFocusButton b = new NoFocusButton();
b.Text = "ClickMe";
f.Controls.Add(b);
f.Show();
// Class derived by the Button control, it is identical but the
// property that control the drawing of the Focus rectangle returns FALSE
// tricking the WinForm system to avoid to draw the focus rectangle
class NoFocusButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
The credit goes to Remove Focus Rectangle from Button

Hide virtual keyboard in windows 8 metro

Now i am working on Windows 8 Metro application. For that i have a popup window with textbox and OK button. I need to hide Virtual Keyboard when "Enter" is clicked on Virtual keyboard. If i click "OK" button on popup keyboard hides automatically.
I got this Link as good reference (using HiddenField). Is there any way to done this work without using "HiddenField". Thanks in advance..
Well finally found a solution for this issue.. I just change the focus from textbox to button in my popup.. below is the sample code..
public void FocusTextbox(object sender, EventArgs e)
{
// set focus to textbox on popup open
Textbox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
public void Textbox_KeyDown(object sender, KeyRoutedEventArgs e)
{
// conforming the "Enter" button click
if (e.Key == Windows.System.VirtualKey.Enter)
{
// change the focus to OK button
this.OkButton.Focus(Windows.UI.Xaml.FocusState.Pointer);
}
}
Change the focus before closing the popup... it works great now..
And changing the focus to Label or Textblock is not hiding the Virtual keyboard...
i was also looking for this , but i found this approach first