Main forum > FAQ

Android Tips

(1/2) > >>

ampos:
Some tips/things I have learned from Android

NATIVE RESOLUTION

On Android, screens can be landscape (horizontal) or portrait (vertical) natively (hardware coded). Mostly, all phones are vertical and tablets are horizontal.

If you try to open a horizontal screen on a vertical device, you will get a mess, as acelerators (joyx & joyy) are coded for the native screen orientation.

You need to know the native resolution of the android device. The best idea is to set your GLB project for Android as 9000x9000, and the device will open its native reolution. Then, check it on your device and use setorientation to rotate it to your program desiree.

You are making a vertical app. Run the app at 9000x9000, it will be open at 800x480. It is a horizontal device. SETORIENTATION 3 to turn -90ยบ left. Pseudocode:


--- Code: (glbasic) ---setscreen 9000,9000,0
getscreensize xres,yres
if xres>yres
   setorientation 3
   swap xres,yres
   turn=true
endif

if turn=true or webos_touchpad=true  //gravity!
  dx=-getjoyy(0)
  dy=-getjoyx(0)
else
   dx=getjoyx(0)
   dy=-getjoy(0)
endif
--- End code ---

(notice that WebOS touchpad has the acelerometers also rotated and not the screen, but this thread is about Android)

MANIFIEST and SCREEN ROTATION

You have to disable screen rotation automatically by Android OS, or your app will crash when the device is tilt. It is being done throught the manifiest.xml

I have removed the line android:configChanges="orientation|keyboardHidden" to avoid autochanges from Android. Also the line android:screenOrientation="portrait" has to be changed to avoid messing more with Android screens. So, I ended with


--- Quote ---<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.diniplay.magicbox"
      android:installLocation="preferExternal"
      android:versionCode="01200"
      android:versionName="1.200">
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
   <supports-screens android:resizeable="false"
                 android:smallScreens="true"
                 android:normalScreens="true"
                 android:largeScreens="true"
                 android:anyDensity="true" />
    <application android:label="@string/app_name" android:icon="@drawable/icon" android:debuggable="false">
        <activity   android:name="org.libsdl.app.SDLActivity"
               android:label="MagicCoinBox"
               android:screenOrientation="nosensor" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
--- End quote ---

This will make your app compatible with 690 devices, acording to Android Markt.

If you don't remove the line configChanges..., it will be compatible with "just" 689 devices, but this one is MY device, so I am asuming this extra device is a really generic one, as my tablet did not come with Google Market and had to be installed "by hand".

Also anyDensity="true" to make it even more compatible.

PLACEHOLDER FOR HARDWARE BUTTONS info :)

r0ber7:
Thanks for the info, I'll be sure to return to this thread once I get around to compiling for Android. I'm wondering though, why 9000x9000? Any specific reason or does it just need to be big?

ampos:
To be sure it will work on future devices with 8000x5000 pixels resolution  :nana:

planetm:
Sorry to dig up an old topic. I've been working on an android based game for the past few weeks, and things seem to be going pretty well. The final hurdle is getting to to run on devices other than my own phone! I've made the screen scale (based on another ampos post - thank you!), and it works fine on a friends phone with a higher resolution than mine. The problem is tablets, I have two tablets one running android honeycomb and a new nexus 7. To try and work out what was happening I wrote this quick code based on that posted by ampos above. It displays the current xres and yres, then draws a rectangle to a virtual screen before scaling it to display on the real screen.


--- Code: (glbasic) ---SETSCREEN 9000,9000,0

GLOBAL xres,yres

GETSCREENSIZE xres,yres

GLOBAL device$=PLATFORMINFO$("DEVICE")

PRINT "xres="+xres,10,10
PRINT "yres="+yres,10,30
PRINT "device="+device$,10,50

IF xres>yres
PRINT "Landscape",10,70
ELSEIF yres>xres
PRINT "Portrait",10,70
ELSE
PRINT "Square?",10,70
ENDIF

SHOWSCREEN

MOUSEWAIT

CREATESCREEN 1,100,800,480

USESCREEN 1
CLEARSCREEN RGB(0,0,255)
DRAWRECT 100,100,600,280,RGB(255,0,0)
PRINT "xres="+xres,10,10
PRINT "yres="+yres,10,30
PRINT "device="+device$,10,50

IF xres>yres
PRINT "Landscape",10,70
ELSEIF yres>xres
PRINT "Portrait",10,70
ELSE
PRINT "Square?",10,70
ENDIF

USESCREEN -1
CLEARSCREEN RGB(0,0,0)
STRETCHSPRITE 100,0,0,xres,yres

SHOWSCREEN

MOUSEWAIT

END
--- End code ---

Both the tablets report landscape resolutions (i.e. xres > yres), but they fail completely to display the scaled rectangles. It works perfectly on my phone.  In my game I get a display on the tablets, but it is rotated through 90 degrees (SETORIENTATION 3 made no difference).

Any ideas?

Thank you.

erico:
GREAT AMPOS! :O

This will sure help me out, million thanks! :nw:

Navigation

[0] Message Index

[#] Next page

Go to full version