Test you application in every possible resolution

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

Test you application in every possible resolution

Postby Obli » Thu Mar 31, 2011 6:31 pm

Hello,

This is just a tiny contribution, but I think many people will find it useful.
It is a replacement for your desktop launcher (the "main(String[] args)" method). It enables you to choose the display mode (portrait or landscape) as well as the desired resolution. Thus, you will be able to quickly test the render of you app onto many possible resolutions.

It comes as a Main.java class. You just need to insert you application startup code in the launch() method.

Since I don't know all the possible resolutions that can be found on Android phones and tablets, I would greatly appreciate if you knew any other possible resolution :D

Main.java
Code: Select all
import com.badlogic.gdx.backends.jogl.JoglApplication;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class Main {
   public static void launch(int width, int height) {
      new JoglApplication(new App(), "", width, height, false);
   }

    public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            // -------------------------------------------------------------
            // Display mode selection
            // -------------------------------------------------------------

            String[] modes = { "portrait", "landscape" };
            String modeResult = (String)JOptionPane.showInputDialog(
               null,
               "Select the display mode",
               "Initialization",
               JOptionPane.PLAIN_MESSAGE,
               null,
               modes,
               "portrait");

            // -------------------------------------------------------------
            // Resolution selection
            // -------------------------------------------------------------

            String[] resolutions = {
               "HVGA (320x480)",
               "WVGA800 (480x800)",
               "WVGA854 (480x854)",
               "Galaxy Tab (600x1024)",
               "Motorola Xoom (800x1280)"};
            String resolutionResult = (String)JOptionPane.showInputDialog(
               null,
               "Select your display",
               "Initialization",
               JOptionPane.PLAIN_MESSAGE,
               null,
               resolutions,
               "HVGA (320x480)");

            // -------------------------------------------------------------
            // App launch
            // -------------------------------------------------------------

            boolean isPortrait = modeResult.equals("portrait");

            if (resolutionResult != null && resolutionResult.length() > 0) {
               Matcher m = Pattern.compile("(\\d+)x(\\d+)").matcher(resolutionResult);
               m.find();
               int w = Integer.parseInt(m.group(isPortrait ? 1 : 2));
               int h = Integer.parseInt(m.group(isPortrait ? 2 : 1));
               launch(w, h);
            }
         }
      });
    }
}
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: Test you application in every possible resolution

Postby mzechner » Thu Mar 31, 2011 9:16 pm

Cool stuff! Once i get around reworking the application configuration i'll setup something similar or use your stuff with your permission. Thanks for all your awesome contributions!
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: Test you application in every possible resolution

Postby bach » Fri Apr 01, 2011 12:34 am

This is great! :) I was just doing the same thing manually..

Thanks heaps
Bach
bach
 
Posts: 713
Joined: Mon Mar 07, 2011 1:50 am

Re: Test you application in every possible resolution

Postby jbrin » Fri Apr 01, 2011 2:34 am

Awesome, thank you! This will be very useful during testing.

For now, I'm leaving it off since it requires more clicks.
-Jason
jbrin
 
Posts: 71
Joined: Thu Dec 30, 2010 9:16 pm


Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest