Libgdx controller unresponsive after making application fullscreen - java

When making the application full screen with the following call:
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
I no longer have signals from my controller. The issue is not solved by changing the display back from full screen like:
Gdx.graphics.setWindowedMode(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
I'm using Gdx version: 1.9.8. It appears this was an issue fixed in a previous version, but I'm not sure what the necessary steps are to get the work around functioning.
Here's some posts I found about the issue:
https://github.com/libgdx/libgdx/issues/4723
https://github.com/GoranM/bdx/issues/518
(this one is old) http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=10692
Any help is much appreciated.
*Edit: This is using the controller extension that can be checked from the libgdx set up application. *
Edit2: I can get a responsive controller if I re-poll the controllers like the following:
Array<Controller> controllers = Controllers.getControllers();
However, this cannot be done instantly after changing the display mode; I have to wait some amount of time after. I'm not sure what I need to poll to determine how long I have to wait until the controller instances are valid (also, when it is valid to assign a listener).
Edit3: The only solution I've been able to come up with is to set a flag inside the resize callback like the following
#Override
public void resize(int width, int height) {
resizeDirty = true;
resizeTimestamp = System.currentTimeMillis();
}
Then in my main loop call:
private void controllerCheck() {
if (resizeDirty) {
long currentTime = System.currentTimeMillis();
if (currentTime > resizeTimestamp + controllerResetDelay) {
resizeDirty = false;
//get new controller instance | re-add a controller listener
}
}
}
This isn't ideal, I'd rather find a way to listen to when the change in context is done initializing then update the controllers. But I haven't been able to find a hook for that. I'd appreciate it if anyone knows a better way to go about maintaining controllers with change in display mode.

Why don't you try to use the immersive fullscreen?
If the objective is to set the fullscreen mode, I think this is the better way to.

Related

Android Studio Webview (Java) - Is there a way to wait until a loading inside a web page is finished before loading url?

I'm trying to get some elements in a web page using webView.loadUrl(...);.
However, I found out that there is a loading that "creates" these elements after the page is already loaded. So, I didn't find a way to get these.
I tried to use onPageFinished but it doesn't look like it is called when the loading inside the web page finishes.
I also tried to put a button that triggers the webView.loadUrl(...);. This tip only works if the user doesn't click too fast on the button, because then the loading doesn't have the time to finish before.
Here is a video of the page booting up, hoping for you to better understand what I mean by a loading inside the page :
https://www.youtube.com/watch?v=q1267dcJai8&feature=youtu.be
If I haven't been clear enough, I'd be happy to clarify things further.
Thank you in advance!
Edit : To clarify something, I'm not exactly asking for a way to get these elements. A way to delay the webView.loadUrl(...); while the webpage is loading would also be perfect for me.
Try onProgressChanged() of WebChromeClient like below.
Documentation link:
https://developer.android.com/reference/android/webkit/WebChromeClient#onProgressChanged(android.webkit.WebView,%20int)
#Override
public void onProgressChanged(WebView view, final int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
//Page load done
}
else
{
//Page is still loading wait...
}
}

JAVA gwt - saving info after refreshing page

At the moment , im working with java gwt and i stopped studdenly because one problem occured. I want that my information (for example string) will save after refresh button is clicked.
// user enters something in TextArea textArea1 object
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
//maybe there is a function or what
pleaseSaveInfomation(textArea1);
}
});
I tried this , but i know how to implement it correctly to my source code:
https://stackoverflow.com/a/14220746/5010218
The last(worst) chance is to store data from textArea in file.txt , after refreshing i could read info from file and thats all. But maybe GWT has a specific handler/method/class or what to handle this.
Thats for your opinion and help.
I had the same problem. You can easily overcome it with this.
import com.google.gwt.storage.client.Storage;
private Storage stockStore = null;
stockStore = Storage.getLocalStorageIfSupported();
Please read documentation
http://www.gwtproject.org/doc/latest/DevGuideHtml5Storage.html#UsingStorage
When a browser close a window (because of a refresh, or the user has closed the window, changed the url, etc), a script is not allowed to prevent this action. It's not specific to GWT.
However, you can suggest to the browser-agent to show a confirmation to the user. You can do this with the message property of the closing event.
In GWT:
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
closingEvent.setMessage("Confirm ?");
}
});
You shouldn't rely on this event to store your data, as a lot of condition can prevent you to do this. You should maybe periodically store a draft to the local-storage or to the server.
You probably want to store your data in sessionStorage. In GWT, this the Storage class.

drag and drop progress Vaadin and Java

I have a Vaadin DragAndDropEvent from here but there's something weird about the progress indicator
#Override
public boolean listenProgress() {return true;}
#Override
public void onProgress(final StreamingProgressEvent event) {
Notification.show("De upload is bezig", Notification.Type.WARNING_MESSAGE);
}
Could someone explain me where I need to put my Notification so that the notification is showed when the upload is in progress and not when it's done?
TLDR: put UI.getCurrent().setPollInterval(10) before your progress = new ProgressIndicator();
line or enable Push Mode.
There are 2 solutions to this problem. You can either stick to ProgressIndicator which is used in your sample or use brand new ProgressBar together with Push Mode.
Javadoc for ProgressIndicator states:
#Deprecated
Deprecated. as of 7.1, use ProgressBar combined with
UI.setPushMode(PushMode) or UI.setPollInterval(int) instead.
your code does not work because your poll interval is higher (or disabled at all) than time needed for transfer the file.
Second, similar approach is to use ProgressBar as suggested in JavaDoc. However, you still need to make sure that either PushMode or PollInterval is set.

Custom message when closing a part in Eclipse RCP 4

we have the following problem:
In our Eclipse RCP 4 application there are multiple parts and the parts are closable. When the user is closing a part there should be a custom pop-up (depending on some internal part state) which is asking the user if he really wants to close the part or not.
It seems to be not that easy to implement in Eclipse RCP 4 or we have just totally overseen something.
I'll just give you a short brieifing about the things we tried:
Use dirtable with a #persist method in the part. Though the problem is, we don't want this standard eclipse save dialog. So is there a way to override this?
public int promptToSaveOnClose(): This seemed to be promising but not for Eclipse 4 or is there a way to integrate it that way? Compare: http://e-rcp.blogspot.de/2007/09/prevent-that-rcp-editor-is-closed.html
Our last try was to integrate a custom part listener, simple example shown in the following:
partService.addPartListener(new IPartListener() {
public void partVisible(MPart part) {
}
public void partHidden(MPart part) {
partService.showPart(part, PartState.ACTIVATE);
}
public void partDeactivated(MPart part) {
}
public void partBroughtToTop(MPart part) {
}
public void partActivated(MPart part) {
}
});
The problem with this was we are running into a continuous loop. Something similar is posted over here in the last comment: Detect tab close in Eclipse editor
So I could write some more about this problem, but I think that's enough for the moment. If you need some more input just give me a hint.
Thanks for helping.
The save prompt is generated by the ISaveHandler registered in the context of the MWindow containing the MPart. You can write your own ISaveHandler and set it in the window context to replace the default.
You might also want to look at the IWindowCloseHandler also in the window context.
Thanks greg, this has helped and I was able to achieve changing the pop-up when the user closes a part. Here's a short description of what I've done:
Use the MDirtyable for marking the part as dirty whenever it's needed.
Create a custom save handler which implements ISaveHandler (when a part got closed the save method is called). Add the additional logic to this handler (e.g. a custom message dialog)
Register this handler at application start-up (I just chose a method which is called at the start-up):
#Inject
private MWindow window;
...
ISaveHandler saveHandler = new CustomSaveHandler(shell);
window.getContext().set(ISaveHandler.class, saveHandler);
Note that the registration via a model processor was sadly not that easy because the model processor is called too early. (Take a look at: http://www.eclipse.org/forums/index.php/t/369989/)
The IWindowCloseHandler is just needed when the complete window is closed, though this was not an requirement for us :).

JInput Multiple Controllers?

i'm somewhat new to jinput and java in general and was wondering, what's the easiest way to set up multiple xbox 360 controllers (particularly 4) with jinput? currently, i'm currently going off of theuzo007's tutorial on jinput with controllers, and have a basic working controller setup going on. it would be fantastic if i could set what controller moves certain entities around. (i'm using my friend's homemade library, just so you know.)
screenshot -
http://imgur.com/a/1Ocu5
top one is the main block of code, last one is the header (sorry for putting them in the wrong order, imgur does that sometimes!)
if anyone could help me out, that would be great, thanks!
edit: if there's no possible way to do it, if anyone could try to reccomend a new library to me, that would be cool.
There is a possible way
That tutorial is pretty good. Furthermore, I think you can do the 4 controllers stuff by copy-pasting some code inside the zip theuzo007 provides you and a bit more. By the way, that page that you liked says that there is a better version of that tutorial where you can download an also better version of his code -> theuzo007's JInput tutorial V2
Once you download the code you can see that in JoystickTest.java there is a method called searchForControllers() that you can put (With the corresponding private ArrayList<Controller> foundControllers; as field) in a class called ControllerChecker or some cooler name. Make them all static and you will get something like this:
public class ControllerChecker {
private static ArrayList<Controller> foundControllers = null;
/**
* Just used for checking all available controllers.
*/
private static void searchForControllers() {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for(int i = 0; i < controllers.length; i++){
Controller controller = controllers[i];
if (
controller.getType() == Controller.Type.STICK ||
controller.getType() == Controller.Type.GAMEPAD ||
controller.getType() == Controller.Type.WHEEL ||
controller.getType() == Controller.Type.FINGERSTICK
)
{
// Add new controller to the list of all controllers.
foundControllers.add(controller);
// Add new controller to the list on the window.
window.addControllerName(controller.getName() + " - " + controller.getType().toString() + " type");
}
}
}
/**
* Returns null if there is no controller available. Otherwise, it retrieves the last controller in the list by removing it.
*/
public static Controller getController() {
if(foundControllers == null) {
foundControllers = new ArrayList<Controller>();
searchForControllers();
}
return foundControllers.size() == 0 ? null : foundControllers.remove(foundControllers.size() - 1);
}
}
You would use the static method getController() to make the players have a different controller, checking if the returned controller is null, meaning that there is no available controller. Also you can change my code and check for controllers everytime you ask for one, but you have to check if the controller is already in use.
I hope this helps you in your purpose. This solution just checks for all available controllers and returns then in the last order it found them (maybe using a Stack is more efficient). But probably you will want more functionality like being able to tell the program to select a specific controller by pressing a button, maybe in a screen that says "Please, connect your controller and press any key/button". This can be achieve easily if you understand theuzo007's code (the JoystickTest.java has a lot of useful lines!).
Also you can make some mechanism to detect unpluged controllers and just by plugging in them again the system recognize it. Maybe there is some controller id, I haven't found it yet.
Finally, there is more code here.

Categories