I'm building my app using the Nokia SDK 1.0 for the Asha 501
What I want to know, is how to capture events by pressing a TextArea. I'm porting an app from the S40 and using the code below, the TextArea doesn't capture the events
TextArea itemText = new TextArea("Hello I'm a TextArea", 2, 22) {
public void pointerPressed(int x, int y) {
System.out.println("PRESSED");
}
public void pointerReleased(int x, int y) {
System.out.println("HI!");
}
};
itemText.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("HI");
}
});
itemText.setEditable(false);
itemText.setFocusable(false);
itemText.getStyle().setBorder(null);
itemText.getStyle().setFgColor(Constants.Style.Color.GREY_DATE);
itemText.getStyle().setBgTransparency(Constants.Style.TRANSPARENT);
itemText.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
EDIT
Someone in the Nokia Forum, tells me to delete the itemText.setFocusable(false); line, but it doesn't work.
I've finally found what is the problem, I don't know the reason why but that's it.
Removing this line
itemText.setEditable(false);
the TextArea catches the events.
I don't find the reason that in Nokia SDK 2.0 this code is working and why here is not. Ande there is another fact. I set the TextAreato editable, and it is not editable o_O
Related
I've been developing with codenameone for over a year, and I never ran into this problem before, I feel like I'm losing my mind. I just redesigned one part of an app I'm working on, and now the ActionListeners aren't firing. I'm attaching them to a Button and a SpanButton in the code:
ActionListener goToDoc = new ActionListener() {
String mDocId = docId;
#Override
public void actionPerformed(ActionEvent evt) {
mStateMachine.currentExpertId = mDocId;
mStateMachine.showForm("DoctorDetails", null);
}
};
name.addActionListener(goToDoc);
Util.downloadImageToStorage(mStateMachine.URL_PREFIX+"images/doctors/"+(String)value.get("doc_pic"),
"doc_post_pic_"+(String)value.get("doc_id")+".png", new Callback<Image>() {
#Override
public void onSucess(Image img) {
pic.setIcon(img.scaledWidth(mStateMachine.getProportionalWidth(.23)));
StateMachine.applyGreenBorder(pic);
pic.addActionListener(goToDoc);
pic.getParent().revalidate();
}
#Override
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
System.out.println("Unable to download expert profile picture");
}
});
When I debug the code, the components do show that the ActionListener is attached, but the actionPerformed method is never reached, no matter how many times I click on the buttons. I experience this problem both on the simulator and on an Android device. I have yet to test on an iPhone.
Did you set a parent to be a lead component or focusable?
The reason the click event wasn't firing was because the Components weren't enabled, possibly a bug in the BUI Builder. After checking off the 'Enabled' and 'Focusable' checkboxes in the GUI Builder, and seeing they were unchecked every time I went back to that form, I just used component.setFocusable(true) and component.setEnabled(true) in the code, and it worked fine after that.
I've an Html String:
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=/"tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
I want to display the text as well as Image on my LWUIT Form Screen,For my Requirement I've used the below code:
public class LwuitMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, LWUIT!");
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=www.teluguone.com/tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
HTMLComponent com=new HTMLComponent();
com.setPreferredSize(new Dimension(300,300));
com.setHTML(html, null, null, false);
com.setShowImages(true);
//com.setHTML(image, null, null, false);
f.addComponent(com);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
If i use the above code,I'm able to display only the text,but i'm not able to display the image,I've tested my app on Nokia SDK 2.O and SDK 3.0.5
can any one help me?
You need to have the full HTML code not just a snippet. The HTML, body etc.
Your src attribute on the img tag is missing the (") character at the beginning. I have not tried but this can be it.
Have you try using
com.setBodyText(html);
instead
com.setHTML(html, null, null, false);
and. I am using HttpRequestHandler implementation from LWUIT example application (you can get the sample apps: LWUITBrowser), instead of DefaultRequestHandler or null.
HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);
Hope it helps.
Hi guys I tried to play a song and print its metadata using java fx 2.1 api using the following code
Media media = new Media(UIandControls.class.getResource("/assets/testData/mom.mp3").toExternalForm());
MediaPlayer mediaPlayer = new MediaPlayer(media);
ObservableMap list=media.getMetadata();
System.out.print(list);
mediaPlayer.play();
for some reason getMetadata() is empty observable Map.
Output looks like this
{}
plz help me.. Thank you.
Need to call mediaPlayer.play() before retrieving metadata.
I had troubles with this at first but I found that using this worked.
mediaPlayer.getMedia().getMetadata().addListener(new MapChangeListener<String, Object>(){
#Override
public void onChanged(Change<? extends String, ?> change) {
if(change.wasAdded()){
if(change.getKey().equals("artist"))
setArtist(change.getValueAdded().toString());
else if(change.getKey().equals("title"))
setTitle(change.getValueAdded().toString());
else if(change.getKey().equals("year"))
setYear(change.getValueAdded().toString());
}
}
});
Also I read that the media data won't always be there right after initialization, therefore calling the mediaPlayer.setOnReady() method can make sure that the data is there.
Example:
mediaPlayer.setOnReady(new Runnable(){
#Override
public void run() {
setTrackLength(mediaPlayer.getMedia().getDuration().toMinutes());
mediaPlayer.currentTimeProperty().addListener(progressChangeListener);
}
});
I am making an application using LWUIT.
There is a form
There is a list embedded on the form.
The list has 5 elements.
Initially, when I first load the app, if I choose the 1st element, 2nd gets chosen; when I choose the second the 3rd gets chose and and so on (Weird!)
I am not able to click any button on the screen either
next what I do is, shift to a different from using arrow keys (of the keyboard... I am running the app on a simulator btw)
Then I come back to the first form and now everything works as expected(no weird behaviour).
What could be the issue?
I am using Sun Java Micro Edition SDK 3.0 (default touch screen for testing)
My code is:
List dummy = new List();
dummy.addItem("wewerwer");
dummy.addItem("wewerdswer");
dummy.addItem("wewqweerwer");
dummy.addItem("dscxwewerwer");
dummy.addItem("jhgwewerwer");
mainListForm.setLayout(new BorderLayout());
mainListForm.addComponent(BorderLayout.CENTER,dummy);
mainListForm.show();
What could possible be going wrong here?
UPDATE 1
I think there is a bug here. I have attached the complete code below along with the screen shot
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
public class Demo extends MIDlet implements ActionListener {
private Form mForm;
List abc;
public void startApp() {
Display.init(this);
try {
Resources r = Resources.open("/Test.res");
UIManager.getInstance().setThemeProps(r.getTheme(
r.getThemeResourceNames()[0])
);
} catch (Exception e){
System.out.println(e.toString());
}
if (mForm == null) {
Button click = new Button("Press me!");
click.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("I have been pressed");
}
});
abc = new List();
abc.addItem("Str1");
abc.addItem("Str2");
abc.addItem("Str3");
abc.addItem("Str4");
abc.addItem("Str5");
abc.addItem("Str6");
Form f = new Form("Hello, LWUIT!");
abc.addActionListener(this);
f.addComponent(abc);
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.addCommandListener(this);
f.addComponent(click);
f.show();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void actionPerformed(ActionEvent ae) {
System.out.println(abc.getSelectedIndex());
}
}
So now when I click on 'Str1' of the list Str2 gets selected and so on.
IDE: Netbeans
Emulator: Default Touch screen phone
On the action event set the list to active again after the event by invoking setHandlesInput(true)
OK....so this is how you resolve it.
After the form is displayed remove the list from the form and again add it to the form and then repaint the form.
Earlier Code
1) form.addComponenet(BorderLayout.center,list);
2) form.show();
Word Around for the problem
1)form.addComponenet(BorderLayout.center,list);
2)form.show();
3)form.setScrollable(false);
I know its kind of strange, but this way the list index selection works smooth for touch screen phones.
I have the sample of softkeyboard. When I install it on a android 2.x, it has the following non-fullscreen view:
But when I install it on tablet 10in it gets whole of the screen like this:
How can I change the sample to have a non-fullscreen custom keyboard on tablet pcs like this image (default keyboard of tablet)?
The following code in InputMethodService solved my problem:
#Override
public boolean onEvaluateFullscreenMode() {
return false;
}
overide the following two methods from InputmethodService as bellow, this works always
#Override
public void onUpdateExtractingVisibility(EditorInfo ei) {
// TODO Auto-generated method stub
setExtractViewShown(false);
}
#Override
public boolean onEvaluateFullscreenMode() {
return false;
}
This worked for me :) and if you want to show keyboard in fullscreen mode always then change both false to true.