Working AndroidExtras Sample [Windows]

Previous topic - Next topic

spicypixel

Android Extras is awesome but...... Can I compile the example to run under Windows without _android_javacall error and have the build failed?? I really want to work with the new version but unless I can implement it to compile under a development environment (win) then its annoying. An older version of AE had stub functions to allow Windows compilation, is there a similar sample we can see :)

Pretty Please :D
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

spacefractal

Im have answear in comply of posts about this one. its a bug in glbasic, which dosent DEFINE ANDROID when compile on Android, so you need doing that your self. Just uncomment ?DEFINE ANDROID, and its should compile on Windows.

If you wont doing that each time between Windows and Android, do something like this (and for other platforms you might uses?):

Code (glbasic) Select

?DEFINE ANDROID
?IFDEF WIN32
?UNDEF ANDROID
?ENDIF
?IFDEF IPHONE
?UNDEF ANDROID
?ENDIF
?IFDEF OSXUNI
?UNDEF ANDROID
?ENDIF


Then the example should work. Im fix that in one of the next versions.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

Also there is a another dumb bug, resoulution for Windows was set to 9999x9998, which should been example 640x480, or you got a freeze app insetad. That is fixed in next version too.

Howover there is a fixed version around ?IFDEF, top of the AndroidSample.gbas:
Code (glbasic) Select

// ---------------------------------------------- //
// Android Extras
//
// Project to show example uses of Android Extras
//
// Music by Deceased Superior Technician:
//    http://www.nosoapradio.us/
//
// Version 1.1
//
// Andy White / FiveSprites
//
// Version 1.2 using Space Fractal Assest Copy system
// ---------------------------------------------- //

// **** DEFINE FOR ANDROID ****
// **** PLEASE NOTE:
// **** IF YOU USES OTHER PLATFORMS THAN ON THOSE UNDEF, YOU NEED TO ADD THEM MANUALLY SO ANDROID IS UNDEFINED CORRECTLY
?DEFINE ANDROID
?IFDEF WIN32
        ?UNDEF ANDROID
?ENDIF
?IFDEF IPHONE
        ?UNDEF ANDROID
?ENDIF
?IFDEF OSXUNI
        ?UNDEF ANDROID
?ENDIF



IMPORT "C" double round(double)

// The TSound instances for this demo
GLOBAL sound1 AS TSound
GLOBAL sound2 AS TSound
GLOBAL sound3 AS TSound
GLOBAL sound4 AS TSound

// The single TMusic instance for this demo (you never have more than one!)
GLOBAL music  AS TMusic

GLOBAL box1 AS TBox
GLOBAL box2 AS TBox
GLOBAL box3 AS TBox
GLOBAL box4 AS TBox
GLOBAL box5 AS TBox

GLOBAL sound4Volume#    = 0.0 // Silent
GLOBAL sound4VolumeInc# = 0.01

// Will be set to true if the textures need reloading when resuming
GLOBAL reloadTextures = FALSE

EXTRASSTARTUP()

DEBUG "GETCURRENTDIR$(): "+GETCURRENTDIR$()

init:

loadTextures()

// Load in the sound files
//
// There are 4 SoundPool instances available and each of your sounds
// should be evenly distributed across them.  SoundPool loads the
// sounds into memory rather than streaming from storage, so ensure
// they are small (mono/22.5khz/16bit).  If you have one that is
// say 100KB in size and 5 more that are 20KB or less, then place
// the large one its own soundpool instance and spread the others
// out.
Check_Asset("subfolder/sound1.ogg") // copy assest file from APK to Memory
Check_Asset("subfolder/sound2.ogg") // copy assest file from APK to Memory
Check_Asset("subfolder/sound3.ogg") // copy assest file from APK to Memory
Check_Asset("subfolder/sound4.ogg") // copy assest file from APK to Memory
sound1.initialise(0, GETCURRENTDIR$()+"subfolder/sound1.ogg") // Place on soundpool 0 (full path)
sound2.initialise(1, GETCURRENTDIR$()+"subfolder/sound2.ogg") // Place on soundpool 1 (full path)
sound3.initialise(2, GETCURRENTDIR$()+"subfolder/sound3.ogg") // Place on soundpool 2 (full path)
sound4.initialise(3, GETCURRENTDIR$()+"subfolder/sound4.ogg") // Place on soundpool 3 (full path)

// Now wait until all sounds have been loaded
waitForSoundLoad()

// Initialise and start GPS
// Note: This may prompt the user to enable GPS
//       if it isn't already
startGPS()

// Start playing the music track
// Here we're giving the filename and setting the volume to HALF (0.5)
// We've also requested that it loops.  Note: There is no discernible
// latency/delay when looping and this MediaPlayer does not seem to
// affect the performance (FPS) of your app when on Android.
Check_Asset("subfolder/DST-Factor.mp3") // copy assest file from APK to Memory
music.play(GETCURRENTDIR$()+"subfolder/DST-Factor.mp3", 0.5, TRUE)

// Sound 4 is intended to loop so we'll start it now
sound4.play(TRUE)

box1.set(50, 350, 50, 50, 0xffffff)
box2.set(150, 350, 50, 50, 0x0000ff)
box3.set(250, 350, 50, 50, 0xff0000)
box4.set(350, 350, 50, 50, 0x00ff00)
box5.set(450, 350, 50, 50, 0xff00ff)

// check if the license is valid (this is the app key im got for com.spacefractal.androidextras.
// you should of course change this to your own APP KEY.
CheckLicense("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6Pfs/7cc9d1t79jtjzWzaYyth2zDonWA8VJK62M4fhqBKMde5hAcJ584alYiZlBxVRdv3PgHzFdltWLkYoqo6t5lg/Qf+GFpipkr93/Z4DsYn2iudtWbgnlt4su3DACcOQkDrMw1eMF6POUcwdBwUoRLvTxsjjFsLKfRslaeqiLufMIJ7phLOMZss+jK7zpikrxYrwETyvE49h3tDjPQXZUJ7Qj1qkFb2Tj1NBYtwv44ASoKThz1md8oNge3b/skgiJLb1v+MtfHu6FFiQbolNCSC3G11HBNO3AKIXGF0omx4QFekJ6pTfkVHroycOXdvox/PgWVaINJ38LG2+uOfwIDAQAB")

// try to download a file
LOCAL ExtFile$=DownloadExternalFile$("www.spacefractal.com/files/testdownload.zip", "testdownload.zip", "Glbasic Download Test", "Android Extras Test Download")

// This function can enable or disable Android BACK buttons. This can been neat to prevent the app to been destroyed.
// Example, you can enable it when you are on a menu, and disable it, when you are in a game.
EnableBackButton(TRUE)

main:

// If the app was paused then on some devices the OpenGL context is
// deleted (Samsung Galaxy S1 for example).  In this case, we need
// to reload textures when the app starts up again.
// In order to do this, we check a variable every time in the main
// loop - if it's set the we reload the textures.
checkAndroidState()

MouseUpdate()

CLEARSCREEN RGB(0, 0, 0)

// Pull back the GPS details that are currently being recorded
PRINT "LATITUDE  : " + convertLat$(getGPSLatitude()), 50, 50

PRINT "LONGITUDE : " + convertLon$(getGPSLongitude()), 50, 70

PRINT "SPEED     : " + getGPSSpeed() + " m/s", 50, 90

PRINT "BEARING   : " + getGPSBearing() + "°", 50, 110

PRINT "ALTITUDE  : " + getGPSAltitude() + " m", 50, 130

PRINT "FIX TIME  : " + getGPSFixTime$() + " ms", 50, 150


PRINT "TEXTENTRY : " + getVKText$(), 50, 190
PRINT "PRESS GREEN BUTTON TO ENTER SOME TEXT!", 50, 250

box1.draw()
box2.draw()
box3.draw()
box4.draw()
box5.draw()

IF (box1.isPressed() = TRUE)
// NOTE: When playing a sound, you can keep hitting Play, BUT
// a new stream is created when you do so.  If you run out of
// available streams then some sounds already playing will stop
// Try to keep looping sounds on a different Pool if this is
// an issue
sound1.play(FALSE)
ENDIF

IF (box2.isPressed() = TRUE)
sound2.play(FALSE)
ENDIF

IF (box3.isPressed() = TRUE)
sound3.play(FALSE)
ENDIF

IF (box5.isPressed() = TRUE)
music.togglePlayPause()
ENDIF

// Since sound4 is looping, we'll play around with the volume :D
sound4Volume = sound4Volume + sound4VolumeInc
IF (sound4Volume > 0.99)
sound4Volume = 0.99
sound4VolumeInc = -sound4VolumeInc
ELSEIF (sound4Volume < 0)
sound4Volume = 0
sound4VolumeInc = -sound4VolumeInc
ENDIF
sound4.setVolume(sound4Volume)

// To get text entry from the user, we first call startVKText()
// This will cause a text entry box to appear. Depending on the
// Android device type, a virtual keyboard will already be present
// or you will have to tap on the text entry box to get it to
// appear.  Once the user has completed text entry, the value they
// entered will be available via a call to getVKText$()
IF (box4.isPressed() = TRUE)
startVKText("Text Entry Title", "Text Entry Message")
ENDIF

ALPHAMODE 0.99
DRAWSPRITE 0, 165, 520

PRINT "MUSIC LENGTH  (ms) : " + music.getDuration(), 300, 50
PRINT "MUSIC CURRENT (ms) : " + music.getCurrentPosition(), 300, 70

LOCAL status$, Procent$
DownloadStatus$(status$, Procent$)

PRINT "DOWNLOAD TEST: "+status$+" :: "+Procent$, 300, 90
PRINT "ANDROID FILE: "+ExtFile$, 300, 110
PRINT "IS LICENSED: "+CheckLicenseStatus(), 300, 130

SHOWSCREEN

GOTO main
END

FUNCTION loadTextures:
Check_Asset("subfolder/woo.png")
Check_Asset("subfolder/testfont.png")
LOADSPRITE "subfolder/woo.png", 0
LOADFONT "subfolder/testfont.png", 1
SETFONT 1
ENDFUNCTION


FUNCTION checkAndroidState:
IF (reloadTextures = TRUE)
IF (isReloadTextures() = TRUE)
// The OpenGL context has been deleted, so we need to
// reload all textures/sprites/fonts/etc
loadTextures()
ENDIF

reloadTextures = FALSE
ENDIF
ENDFUNCTION

SUB GLB_ON_PAUSE:
STDERR "Got a pause event!\n"

// Pause the repeating sound
sound4.pause()
ENDSUB

SUB GLB_ON_RESUME:
STDERR "Got a resume event!\n"
// Set this flag so we check for texture reloads
reloadTextures = TRUE

// Resume the repeating sound
sound4.resume()
ENDSUB


GLOBAL gMouseDown[], gMouseState[]
GLOBAL mouseX, mouseY, mouseB1, mouseB2

FUNCTION MouseUpdate:
MOUSESTATE mouseX, mouseY, mouseB1, mouseB2

IF (BOUNDS(gMouseDown[],0)=0)
DIM gMouseDown[10]
DIM gMouseState[10]
ENDIF

LOCAL mb
FOR i=0 TO 1
IF (i = 0)
mb = mouseB1
ELSE
mb = mouseB2
ENDIF

IF mb
IF gMouseDown[i]
gMouseState[i]=1
ELSE
gMouseDown[i]=1
gMouseState[i]=2
ENDIF
ELSE
IF gMouseDown[i]
gMouseDown[i]=0
gMouseState[i]=-1
ELSE
gMouseState[i]=0
ENDIF
ENDIF
NEXT
ENDFUNCTION

FUNCTION MouseHit: mb%
RETURN gMouseState[mb]
ENDFUNCTION

TYPE TBox

x%
y%
w%
h%
colour

FUNCTION set: x%, y%, w%, h%, colour
self.x = x
self.y = y
self.w = w
self.h = h
self.colour = colour
ENDFUNCTION

FUNCTION draw:
DRAWRECT self.x, self.y, self.w, self.h, self.colour
ENDFUNCTION

FUNCTION isPressed:
IF (MouseHit(0) = 2)
RETURN (BOXCOLL(self.x, self.y, self.w, self.h, mouseX-25, mouseY-25, 20, 20))
ENDIF
ENDFUNCTION

ENDTYPE


Functions does of course nothing, but its does compile and run.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spicypixel

Spacefractal you are a god amongst men  :enc:

I'm in Portugal on holiday so my internet is limited otherwise I would have thanked you sooner  =D
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

MrPlow

Does that mean I leave the // ?DEFINE ANDROID as it is on the glbstorekit gbas file when compiling for ANDROID?
Or should it be uncommented ??


Quote from: spacefractal on 2014-Jan-02
Im have answear in comply of posts about this one. its a bug in glbasic, which dosent DEFINE ANDROID when compile on Android, so you need doing that your self. Just uncomment ?DEFINE ANDROID, and its should compile on Windows.

If you wont doing that each time between Windows and Android, do something like this (and for other platforms you might uses?):

Code (glbasic) Select

?DEFINE ANDROID
?IFDEF WIN32
?UNDEF ANDROID
?ENDIF
?IFDEF IPHONE
?UNDEF ANDROID
?ENDIF
?IFDEF OSXUNI
?UNDEF ANDROID
?ENDIF


Then the example should work. Im fix that in one of the next versions.
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

spacefractal

#5
The glbstorekit works for iOS and Android, and hence need to uses different apis on iOS. ?DEFINE make sure code that only compiles for ANDROID and not for others systems when compile on runtime. Its a great a feature.

But GLBASIC have a bug, which forget to automatic add ?DEFINE ANDROID when its compiled on Android!!

So its important to NOT comment that for compiling for Android, howover its can been annoying and forget when compiling too Windows (which will out the above bug).

So that UNDEF part for other systems is simply make sure ?DEFINE ANDROID does NOT exists on other than Android (with only some platforms added here).

Im hope Gernot fix that issue in a glbasic update..... But this is a nice workaround throught.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/