move the marker to selected location on MapContainer - codenameone

In my application, user can select a location on map and save its latlong. I'm using Mapcontainer to display map. When user selects a location, a marker should be displayed and if another location is selected then the marker should be moved to that location. How can I achieve it?

You can achieve this using map addTapListener(), see below code:
final MapContainer map = new MapContainer();
map.addTapListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
map.clearMapLayers();
map.addMarker(encImageMarkerIcon, new Coord(map.getCoordAtPosition(evt.getX(), evt.getY())), "", "", (evt1) -> {
//whatever you want the marker to do when touched
});
form.revalidate();
}
});

Related

AutoCompleteTextField + GoogleMap in Codename One

I tried to put an AutoCompleteTextField (used for address completion) and a Google Map peer component (using the cn1lib) in the same container, but it doesn’t work fine on real device (it's ok only in the Simulator).
Using a BoxLayout.y, the completion list appears only on iPhone but not on Android.
Using a BorderLayout.totalBelow, with Google Map in the center and the AutoCompleteTextField on the north, after selecting an address from the autocompletion list, the AutoCompleteTextField disappears (tested on iPhone).
Could you please give me any hint to make the two components working correctly? The cn1lib I’m using is updated. Thank you
Container innerContent = new Container(BorderLayout.totalBelow());
// Start content
AutoCompleteTextField autoCompleteTextField = (AutoCompleteTextField) InputUtilities.getAutoCompleteAddress(true);
autoCompleteTextField.setUIID("BaseStructureForm-InnerBoxMap");
// Google Map
final MapContainer googleMap = new MapContainer() {
#Override
public Dimension calcPreferredSize() {
int width = contentBox.getWidth() - CN.convertToPixels(10, true);
int height = CN.convertToPixels(50, false);
return new Dimension(width, height);
}
};
innerContent.add(BorderLayout.NORTH, autoCompleteTextField);
innerContent.add(BorderLayout.CENTER, googleMap);
// End content
autoCompleteTextField.addListListener(e -> {
String selectedItem = (String) ((com.codename1.ui.List) e.getSource()).getSelectedItem();
String place_id = (String) autoCompleteTextField.getClientProperty("place_id");
//googleMap.setCameraPosition(new Coord(43.0511, 10.8892274));
GoogleMapUtilities.setMapPlace(place_id, (latitudine, longitude) -> {
googleMap.zoom(new Coord(latitudine, longitude), 3);
});
});

How to get the current swipe tabs selected index value in codename one?

I am using codename one swipe tabs dynamically to prepare some radio button but on swiping of tabs getSelectedIndex () method is giving the previous tabs value(previous in the sense suppose I move my tabs from 0 to 1 so it's giving me 0) so how to get the current tab value at which my tab is because on basis of this selectedIndexTab value I want my radio button to get selected.
Here is my code
TableLayout t1=new TableLayout(1, 5);
radioTypeContainer=new Container(t1);
for(i=0;i<5;i++){
t.addTab("Tab2"+i, new SpanLabel("Some text directly in the tab"));
firstTab = new RadioButton[i];
plain = new RadioButton("");
plain.setName("rdb"+i);
rbt =new RadioButton();
rbt.setName("rbt"+i);
radioTypeContainer.add(rbt);
finalRadioList.add(rbt.getName());
finalRadioList.add(t.getTabUIID());
}
borderLayoutContainer.add(BorderLayout.SOUTH,radioTypeContainer);
t.addSelectionListener((i1, i) -> {
Log.p("====***======="+t.getSelectedIndex());
});
Thanks in Advance
newSelected in selectionchanged method gives the current position of tab as shown in below code.
t.addSelectionListener(new SelectionListener() {
#Override
public void selectionChanged(int oldSelected, int newSelected) {
Log.p("====***======="+newSelected);
}
});

How can i add pull to fresh option in swipe tabs in codename one?

I want to add pull to fresh option in swipe tabs but it's not working I have taken container also and try to add it but its seems to same.
Here is my code
displayContainer = new Container();
getDisplay(displayContainer);
for(i=0;i<totalRadioButton;i++){
tabs.hideTabs();
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
getDisplay(displayContainer);
tabs.addTab("",displayContainer);
//tabs.add(flowContainer);
tabs.setName("t"+i);
tabs.setTabUIID(tabs.getName());
radioButton =new RadioButton();
radioButton.setName("rbt"+i);
radioTypeContainer.add(radioButton);
finalRadioList.add(radioButton.getName());
tabsListName.add(tabs.getTabUIID());
radioList.add(radioButton);
tabIndex0="rbt0";
if(radioList.get(i).getName().equals(tabIndex0)){
radioList.get(i).setSelected(true);
}
buttonGroup.addAll(radioButton);
}
tabs.getContentPane().addPullToRefresh(new Runnable() {
#Override
public void run() {
getMyList();
}
});
Thanks in Advance
As Chen mentioned you need to add it to displayContainer but notice that it needs to be Y scrollable to work. I would suggest placing the whole Tabs container into the center of a border layout so it's parent is scrollable.

The removeCommand is not working for the toolbar commands - codenameone

The removeCommand and removeAllCommand is not working. If i put it in a button action listener removeCommand(command) works but removeAllcommand() is not working?
Is it a bug? Please check it out. Thankyou
Command d = new Command("back") {
#Override
public void actionPerformed(ActionEvent evt) {
}
};
f.setBackCommand(d);
f.getToolbar().addCommandToLeftBar(d);
//Either of these two doesnt remove above back command...
f.removeAllCommands();
f.removeCommand(d);
If i put it in action listener, one of them work
Button add = new Button("remove");
add.addActionListener((e) -> {
f.removeCommand(d);// it removes back command
f.removeAllCommands(); // it doesnt work
});
Try to revalidate the Form
Button add = new Button("remove");
add.addActionListener((e) -> {
f.removeAllCommands();
f.revalidate();
});

Localizing buttons of a FacesContext.addMessage in adf

Hi i want to localize the buttons eg: OK, Cancel in ADF,
I am using the following code
FacesContext fctx = FacesContext.getCurrentInstance();
fctx.addMessage(VALIDATIONERROR,new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
fctx.renderResponse();
I get the pop and the error message is localized, My question is how to localize the buttons which are on the pop up, ex: OK,CANCEL
I suppose you are talking about a af:dialog component. In that case i can think about two ways of doing so:
The af:dialog component has two properties: cancelTextAndAccessKey and affermativeTextAndAccessKey. They can take an EL which can take the key of a specific record into a .properties file (which is loaded as a resource bundle into the project. An example: cancelTextAndAccessKey="#{lang['popUp.dialog.button.cancel']}" (where lang is the name of the declared bundle in my case)
You can override the default component label, by creating a ListResourceBundle (which should be also loaded as a resource bundle into faces-config.xml, Application tab).
The code should be something like:
public class CTSResourceBundle extends ListResourceBundle {
public CTSResourceBundle() {
super();
}
#Override
protected Object[][] getContents() {
return new Object[][] {
{ "af_dialog.LABEL_YES", "Po" },
{ "af_dialog.LABEL_NO", "Jo" },
{ "af_dialog.LABEL_OK", "Ok" },
{ "af_dialog.LABEL_CANCEL", "Anullo" }
};
}
}

Resources