lwuit wizard and deploy - java

I am developing J2ME application with lwuit and Codenameone and created it in lots of time. After I created it I wanted to deploy it in some devices like Nokia, Samsung, LG and etc. that they supported MIDP. So I figure out Nokia devices run it with no error and Samsung and other companies devices have some problems that I can't understand why?!
So I tried different way of creating this application. I used Codenameone wizard with blank theme and manual template and then I tried to deploy it. Well, that right. I got success and it ran in Samsung devices too.
After that I tried to add some forms to "theme" in this appliaction and run it in simulator. I changed some code in my main class like this:
public class Main extends UIBuilder {
private Form current;
public void init(Object context) {
try{
Resources theme = Resources.openLayered("/theme");
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
}catch(IOException e){
e.printStackTrace();
}
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = findMain();//new Form("Hi World");
//hi.addComponent(new Label("Hi World"));
hi.show();
}
public void stop() {
current = Display.getInstance().getCurrent();
}
public void destroy() {
}
public com.codename1.ui.Form findMain() {
return (com.codename1.ui.Form)findByName("Main", Display.getInstance().getCurrent());
}}
I got error when I ran it.
So this is my questions:
I created one application in Visual Mode of Codenameone.
How can I run it in Samsung and some other devices like Samsung (without opertaing system, just support java or MIDP)?
How can I change my Visual Mode application to Manual Mode in Codenameone?
Thanks in advance.

You are deriving from UIBuilder within the lifecycle class and trying to use a finder method on something that isn't showing yet. There is absolutely no way that your code works in the simulator and it is not the code that was generated by the wizard.

Thanks Shai. For creating I did hard coding and create all of forms one by one.
I implement base Form that derive from com.codenameone.ui.Form and every forms derive from base Form.

Related

libGDX HTML5 Project Builds Differently on Different Machine

This is a strange one! On my old desktop, I was able to build and run my libGDX project for HTML5 using the gradlew html:dist gradle command.
I uploaded the files to my site and everything worked well.
But on my laptop I synced the project via GitHub to Android Studio, ran the same command and it appears that the default ApplicationListener runs instead of my own custom one.
The only thing that appears is a red rectangle: http://johnathongoss.com/jaggybattles/
The desktop and android versions run and build fine on my laptop.
I'm using Android Studio and the latest version of libGDX.
Here is some code:
public class HtmlLauncher extends GwtApplication {
#Override
public ApplicationListener createApplicationListener() {
return new MyGame();
}
#Override
public GwtApplicationConfiguration getConfig () {
GwtApplicationConfiguration cfg = new GwtApplicationConfiguration(1280, 720);
return cfg;
}
}
//MyGame Class (Doesn't seem to get this far?)
#Override
public void create() {
camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
setScreen(new LoadingScreen(this)); //Loads the assets and sets Main Menu Screen
}
I've had this problem before but it was because I didn't change the createApplicationListener() method to return my own custom ApplicationListener. Now it seems to return the right one, I really don't know what could be causing this.
I should point out I can't access my desktop computer anymore due to relocating.
Any advice would be gratefully received!
Edit: Loading Class
https://gist.github.com/jaggygames/79b1bd821f4203aadecfe5e8ba925150
Assets Class:
https://gist.github.com/jaggygames/5b863f1692b0974b769d5694b5a3334f
MyDistance Font Class
https://gist.github.com/ea7b5965488cd5672e9e7c20917df9a1

UISpec4J and external application

I am trying to launch an external application for testing using UISpec4J.
Here are the questions and their answers I referred so far:
How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?
Getting all windows using UISpec4J
UISpec4J Capturing modal dialog, before the trigger finish
my.exe referred below is a Java application wrapped in exe using some tool. Internally it uses the jars and is Java GUI application.
This executable launches a splash screen first, then a dialog to choose where you want to connect to and after that main window is shown. Unless I can automate where I can connect to I won't get main window.
Based on these questions I have come up with following code fragments:
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
return WindowInterceptor.run(new Trigger() {
#Override
public void run() throws Exception {
// running jnlp by netx launcher
Runtime.getRuntime().exec("C:\\my.exe");
Thread.sleep(10000);
}
});
}
});
In the approach above I simple get "No window was shown" error.
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
final Window[] result = new Window[1];
WindowInterceptor
.init(new Trigger() {
#Override
public void run() throws Exception {
Runtime.getRuntime().exec("C:\\my.exe");
//Thread.sleep(10000);
}
})
//.processTransientWindow()
.process(new WindowHandler() {
public Trigger process(Window window) throws Exception {
result[0] = window;
return Trigger.DO_NOTHING;
}
})
.run();
return result[0];
}
});
In the second approach above, I still get "No window shown" error AND control never reaches to overriden "process" method.
I referred to http://www.uispec4j.org/reports/apidocs/org/uispec4j/interception/WindowInterceptor.html and recommended approach is to use init to capture modal dialog is init\process sequence.
To capture non-modal it is recommended that we should use following:
Window window = WindowInterceptor.run(panel.getButton("open").triggerClick());
But I have NO idea where and how I am supposed to call it..
From the first question I referred, mentioned above, we should be able to do that because the answer to it mentions launching jnlp application which is external application.
I tried with jre 6 update 0 and I can at least run test. In java update 37, from the third question I referred above, I get abstract method not implemented error.
What am I doing wrong? Any idea?
I am using latest UISpec4J package - version 2.4.
Thanks in advance,
-Neel.
I'm very new to UISpec4J but I'm guessing it needs to run in the same JVM in order to intercept and interact with the GUI components. When you start the exe file with exec, it will create a new process and a new, separate JVM. That'll not work, if I understand UISpec4J correctly.
Regarding the non-modal example, the documentation says "You would retrieve the window from within the test...", so in a setup method or in a test should work.

codenameone setURL with HTML file doesn't work on device

i'm re writing an app with codename one for other devices other android.
On the simulator everything is working fine, iv'e got some buttons that, when pressed, give access to an HTML page, the actual code for this is:
wifi.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
Form form = new Form("WiFi");
Container container = new Container();
WebBrowser wb = new WebBrowser();
container.addComponent(wb);
wb.setURL("jar:///assets/html/wifi.html");
System.out.println("url:"+wb.getURL());
Command backCommand = new Command("Back") {
public void actionPerformed(ActionEvent ev) {
wifi.getComponentForm().showBack();
}};
form.addCommand(backCommand);
form.setBackCommand(backCommand);
form.addComponent(container);
form.show();
}
});
When i first want to getURL() back, the string is empty; then when i want to build for an android device (Galaxy Nexus with Android 4.3) when i tap on the button it returns me nothing but a blank page.
I also tried with an http link like https://www.google.com, on simulator no problem, on device the usual blank page.
Then i tried modifying the position of the html file, putting it in src like for the image file (that works on device), but still nothing.
I've checked the developer guide and every example i could find, and everyone got no problem with this (and on the simulator me neither). Could anyone solve this?
Thank you :)
Place the file in the root of the src directory and point directly at it without the assets hierarchy for it to work properly across platforms.

I want to run the application in background of mobile without any GUI in mobile using J2ME?

I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.

How to make a J2ME application run in Background?

I have a written a J2ME application which uses Bluetooth and search a file within the peer mobile and download it. I would like to make my application run in background , whenever I get a call , or message and later resume after few seconds , Has anybody worked on this please share your experience . Is there any way to run a Midlet in background ?
to set a j2me app to the background use the following in your midlet class:
Display.getDisplay (this).setCurrent (null);
to get the screen back use the following:
Display.getDisplay (this).setCurrent (myCanvas);
Where myCanvas is your canvas instantiation
R
p.s. You can still use a thread or timer to do things in the background while your midlet is hidden.
p.s.2: this does not work on all models. (Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices.
For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And to come in Fore ground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But be aware that it not supports every device.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).

Categories