How can key released (key listener) be implemented on codename one - keylistener

Am trying to implement an on key released event on codename one apparently it seems not to be included in its library. Is there a way/another way I can get to do this ? This java code will not work.
protected void onMain_PostalCodeKeyReleased(Component c, KeyEvent event) {
Dialog.show("WORK", "Hey", "OK", null);
}

This is answered here: https://groups.google.com/d/msg/codenameone-discussions/WI5W-DRWdpg/ebo_PEgQtZcJ
For your case you need DataChangeListener since iOS has no keys.

Related

Helix Toolkit How to use MouseWheelEventHandler to run specific methods in other classes

I would like to run particular methods of a custom Camera class whenever the user zooms in or out in the helix toolkit view that my program is running inside of.
A key feature of this functionality is getting the mouseargs from the event so I can adjust the camera in a way that is proportional to the number of scroll ticks.
I began to try this:
public event PropertyChangedEventHandler PropertyChanged;
public virtual void onMouseWheeled(MouseDevice Mouse, int time,
MouseWheelEventArgs e) {
MouseWheel?.Invoke(this, new MouseWheelEventArgs(Mouse, time,
e.Delta)); }
//This next line goes in a MainWindow_Loaded method that gets called in the
//MainWindowConstructor
void MainWindow_Loaded(object sender, RoutedEventArgs e) {
view1.MouseWheel += new MouseWheelEventHandler(onMouseWheeled(Cursor,
Time.simTime, view1.MouseWheeledEventArgs)); }
but was having a lot of trouble figuring out how to pass a MouseWheelEventArgs object into the onMouseWheeled method when I'm trying to add the onMouseWheeled method to the MouseWheelEventHandler. Assuming nothing is fundamentally wrong with that sentence, which is nothing more than wishful thinking, The last thing I am trying to figure out is how to get mouse wheel event args so that I can pass it into a method.
Then I tried this:
public event MouseWheelEventHandler MouseWheel;
public virtual void onMouseWheeled(object sender, MouseWheelEventArgs e)
{
Console.WriteLine(e.Delta);
}
//In Main Window Loaded method...
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
view1.MouseWheel += onMouseWheeled;
}
But I get no output when i scroll the wheel. I assumed this might actually work because view1 is the helix window I'm attaching all of my objects to, as children of view1.
Basically my main questions are:
What does invoke actually do? I only have this running to try to see if its working because onPropertyChanged methods I always use run the Invoke command like so. I'm actually not sure where I'm going with this.
How does the handler work?
How do the event args get called out so that I can use them and pass them as objects to other methods?
Thank you for your time. And Thank you twice for any and all pointers and advice you may give me.
Try to use preview mouse wheel event

Bukkit event for hunger?

I am trying to make a plugin that removes hunger from Minecraft. However, I cannot find the event for it!
Is there an event called when a player loses hunger?
Something like PlayerHungerChangeEvent?
I believe you are looking for the FoodLevelChangeEvent
It is very oddly named, for future reference, refer to the bukkit documentation :)
Yes, there is the FoodLevelChangeEvent
You can use FoodLevelChangeEvent.
#EventHandler
public void onFoodChange(FoodLevelChangeEvent e) {
Player foodChangedPlayer = (Player) e.getEntity();
//Cancelling event, thus cancelling hunger
e.setCancelled(true);
}
It is FoodLevelChangeEvent
#EventHandler
public void onFoodChange(FoodLevelChanceEvent ev) {
}

How to response MENU_SELECTED event in an Inherited wxMenuBar?

I had tried DECLARE_EVENT_TABLE() && Connect(),but it dosen't work.My code just like this.How to make it work?
//.h
class MainFrameMenuBar :public wxMenuBar
//...
private:
DECLARE_EVENT_TABLE();
};
/...
//.cpp
BEGIN_EVENT_TABLE(MainFrameMenuBar, wxMenuBar)
EVT_MENU(XRCID("ID_MENU_FIGURE"), MainFrameMenuBar::onMenuItemFigure)
END_EVENT_TABLE()
MainFrameMenuBar::MainFrameMenuBar(wxWindow* parent)
{
wxXmlResource::Get()->LoadMenuBar(parent,wxT("ID_MAIN_MENUBAR"));
//int id = XRCID("ID_MENU_FIGURE");
//Connect(id, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrameMenuBar::onMenuItemFigure), NULL, this);
}
void MainFrameMenuBar::onMenuItemFigure(wxCommandEvent& event)
{
printf("abc");
}
This used to be broken in older wxWidgets versions and you had to handle menu events only in the wxFrame containing the menu bar and not the menu bar itself, but it should have been fixed quite some time ago, so perhaps you need to upgrade?
If you do use a version affected by that bug and can't upgrade, handling the events in the frame is the simplest workaround.

Disable copy/paste on Xamarin forms input field i.e. Entry

I am working on disabling copy/paste option menus on xamarin forms Entry, I am able to disable copy option using IsPassword=true attribute but this attribute also converts the normal input field to password field, which is not a requirement.
<Entry IsPassword="true" Placeholder="Password" TextColor="Green" BackgroundColor="#2c3e50" />
Thanks in advance.
This has to do with how Forms functions. Using iOS as the example here, the CanPerform override referred to in the other answer's Bugzilla issue is using the UIMenuController as the withSender and not the UITextField itself that might otherwise be expected. This is because the EntryRenderer class is a ViewRenderer<TView, TNativeView> type and subsequently is using whatever TNativeView (in this case, the UITextView) has in its CanPerform. Because nothing is going to be overridden by default, one still sees all of the cut/copy/paste options in the UIMenuController.
As a result, there would be a couple options. You could first make the modification where if you don't want copy/paste but are fine with getting rid of everything else, you can use UIMenuController.SharedMenuController.SetMenuVisible(false, false) in a custom renderer inheriting from EntryRenderer. If you look around on SO, there are similar questions where this is a possible route.
Alternatively, you can create a "true" custom renderer inheriting from ViewRenderer<TView, TNativeView> as ViewRenderer<Entry, YourNoCopyPasteUITextFieldClassName>. The class inheriting from UITextField can then override CanPerform as something like follows:
public override bool CanPerform(Selector action, NSObject withSender)
{
if(action.Name == "paste:" || action.Name == "copy:" || action.Name == "cut:")
return false;
return base.CanPerform(action, withSender);
}
This will require more effort because the custom renderer will not have the same behavior as the EntryRenderer, but as Xamarin.Forms is now open source, you could look to it for some ideas as to how the EntryRenderer functions normally. Something similar would likely have to be done for Android.
Edit: For Android, you can probably use this SO answer as a starting point: How to disable copy/paste from/to EditText
Another custom renderer, this time inheriting from ViewRenderer<Entry, EditText>, and create a class inside of it like this (in the most basic form):
class Callback : Java.Lang.Object, ActionMode.ICallback
{
public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
{
return false;
}
public bool OnCreateActionMode(ActionMode mode, IMenu menu)
{
return false;
}
public void OnDestroyActionMode(ActionMode mode)
{
}
public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
{
return false;
}
}
Then, in your OnElementChanged method, you can set the native control and the CustomSelectionActionModeCallback value:
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.CustomSelectionActionModeCallback = new Callback();
}
}
Doing something like the following appears to disable all of the copy/paste/cut functionality on the custom entry as far as the toolbar goes. However, you can still long click to show the paste button, to which I've poked around a bit hadn't found an answer yet beyond setting LongClickable to false. If I do find anything else in that regard, I'd make sure to update this.

null TableCell when reading from BQ using dataflow

I got null element when reading from BigQuery table using dataflow as follows
private static class ParseBQInput extends DoFn<TableRow, KV<String, MyClass> > {
#Override
public void processElement(ProcessContext c) throws Exception {
TableRow row = c.element();
List<TableCell> cells = row.getF();
if (cells == null) {
throw new RuntimeException("Get null cells");
}
// Other operation
}
}
The cell I extracted with row.getF() is null regardless which table i read.
I noticed that there is similar question already asked here but the answer is sort of unclear to me... I have tried updated the library version to 1.3.0 but it seems that the problem is still not solved. (Due to some dependency issue, it is a little painful to go to version 1.4.0 at current...)
(As a newbie to stack overflow, i don't have enough points to post comments though, so have to ask again here...)
As noted in the updated https://stackoverflow.com/a/35326342/4392693, getF() will not be supported in newer versions. Please use get("fieldname"). Thank you for your patience.