Setting a Loading Screen Within the Theme.res CodenameOne - java

I'm trying to make a loading screen that pops up for my app for purely cosmetic reasons. I have read these two articles https://www.codenameone.com/javadoc/com/codename1/ui/InfiniteContainer.html https://www.codenameone.com/javadoc/com/codename1/components/InfiniteProgress.html
but neither have really addressed what I want to create. I want to create a small loading symbol (infinite progress) on top of a logo and then have it disappear after a certain amount of time and display the rest of the app (this whole operation preferably built in to my theme). Is this possible?

The infinite progress is meant for in-app progress. You just want a splash screen which you can do like this:
Form myForm = new Form(new BorderLayout());
myForm.add(CENTER, new ScaleImageLabel(myLogoImage));
myForm.add(SOUTH, new InfiniteProgress());
myForm.show();
UITimer.timer(4000, false, myForm, () -> showNextForm());

Related

Map image blinks while adding more layers to it

I have an application in java swing and geotools. I have displayed a map image and trying to add images as layers to it. When it adds layer it blinks and after some time at the call to addLayer function map image and other few layers disappear for some time. How to stop this? I am loging all the information at the same time in SQLite and then to my own customised file.
I have stopped trying refreshing all after addLayer function call. The all process should work smoothly without blinking and disappearing. Please Help.
The gt-swing module is really only intended for simple demonstrations. If you intend to use it in production you should add in off screen buffering to allow "fast" refreshes of the map without rereading all the displayed data.

Loading and parsing file and displaying said file as graph with Java GraphStream

The loading and parsing of the file proceeds without an obvious problem but the ViewPanel in which I try to display the graph does not show immediately when initiating the action that should lead to this. Instead the container in which the ViewPanel (=an object that inherits from JPanel) with the graph should show remains empty. This changes when I then click twice on the application window, for instance by first clicking the minimization icon and then enlarging the window again with a click on the corresponding icon. After these two clicks the desired graphs shows up on the screen which implies that the ViewPanel too is then doing what it should be doing. Those two clicks, however, are a nuisance, as far as I can see they have nothing to do with the code I wrote and they should not be necessary. How can I get rid of the necessity for them and have the graph displayed seamlessly after prompting the action that should lead to the graph being displayed?
I am grateful for any kind of helpful advice.

Natural approach to create a dynamic game engine for Android

I want to create a simple game engine for Android. I am fairly new to the OS, and I want to be sure that I do not start off in the wrong direction.
My requirements are fairly simple:
The game engine is an application that runs a game that comes as a bundle of media files (images, audio) + one "description" file (e.g. xml or yaml format) that describes and links different "scenes".
A "scene" is just a background image + a background music + different actions that can be triggered with buttons.
Typically, clicking a button moves the game to a different "scene".
The first question I have is: Should I have one or multiple Activity objects to create the scenes? That is: Is it better to have one single activity which content is dynamically updated when clicking the buttons; or to have one activity per scene.
Note that the difficulty is that the game engine has to generate the activities dynamically. So the list of buttons cannot be hard-coded inside a layout file, as they come from the description file. I have found this example that shows how to create a layout dynamically. Would you recommend using the same approach?
Assuming I use a single activity for all scenes, it means that when I switch scene (by clicking a button), I need to fully update the view (background and buttons). To do that, should I rather remove each element one by one with removeView(), or rather create a new blank layout with setContentView(), and then populate it with the new background and buttons?
Any advice is welcome.
Example of scene:
Background image: A bedroom image
Background music: bedroom_music.mp3
Actions:
Leave the room => Go to Living room scene
Leave the room through the window => Go to Garden scene
Pick up alarm clock => Add clock to inventory
Activities are usually used for different "views". For example:
A chat app will have a lobby activity and starts a new activity when opening a chat screen.
Following the analogy above I would say you should use only one activity and load the correct scene in that activity. There could be an activity controlling these changes? Or an activity that shows a layout while loading.
Having said that. I think you have to design custom objects that can be converted to buttons/walls/monsters or such. This will make the dynamically loading of buttons/objects easier. In Android you must define buttons/visual objects in a layout xml file. This file will be loaded by an activity. I don't think these xml files can be modified on the fly.

One layout over another at run time?

My game app has many complex graphical elements and I am worried that having a banner ad continuously on screen will detract too much from the game. My plan is that the user will be able to play each "level" in the game using the full screen without any ads, but upon completion of each level an ad will slide in, on top of the top part of the screen. Presumably this means I have to somehow create a layout programatically that will appear on top of the existing screen layout. Can this be done? If so how?
It can be done.
Afaik you simply have to create a layout which is android:backgroundcolor="transparent".
Else you could do it so you started a new activity on each level completion?

How to show loading

I want to know how to show the loading of an application. Normally (let's say Netbeans IDE,)
the application will show how far it has loaded and how far to load. Also, loading classes as well can be seen in welcome page. How is this is done and how we can show our classes loading and loaded status (in a progress bar) in our applications? Also let's say that we have used Hibernate, and there is a login on first page, it takes time to start but only for the starting (I think it is because that the Hibernate factory is getting started and load its classes). The answer is hoped in Java.
I want to know how to show the loading of an application.
See the java.awt.SplashScreen class. But..
..show how far it has loaded and how far to load.
..with a customized image. Call SplashScreen.createGraphics() to get a Graphics object (from the image defined as a splash in the manifest) which can be drawn on. Draw the progress bar at an appropriate location on the Graphics object. For the progress bar, either use a JProgressBar as already mentioned, or to keep it lean (using pure AWT), draw one big Rectangle to represent the bar, and fill a smaller Rectangle to represent the progress.
See also How to Create a Splash Screen in the Java Tutorial. (Where you can see that image above.)
That sounds for using JProgressBar, combined with Splash Screen or JDialog.
Be sure that JProgressBar must be updated on the Event Dispatch Thread, more about that in Concurrency in Swing,
Then you have two choices as to how to update a JProgressBar correctly - by wrapping code into:
SwingWorker
Runnable/Thread
There is some support built into swing for this. See the tutorial on How to Use Progress Bars to get started.
Here is a very basic code:
JProgressBar progressBar;
progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(33); // put here the percentage you want to display...
progressBar.setStringPainted(true);

Categories

Resources