Page 1 of 2

api extensions: api discussion

Posted: Thu Nov 17, 2011 10:31 pm
by ghoulsblade
How should phone/android specific api extensions be made accessible ?

things like multi-touch, sensors like accellerometer, magnetic field (compass?), orientation (gravity?), gps, light
and possibly stuff like phone specific popup notifcations, home/menu button overrides, maybe opening map and browser apps...

currently the love-android apk makes them available as love.phone.getSensorList() etc,
including new user-defined callbacks like

function love.phone.touch (action,data) ... end -- for multitouch
function love.phone.sensorevent (sensorid,data) ... end

is there interest/need to agree on common naming/api schemes now for possible future projects like iphone ?
are there maybe love2d ports for handheld devices that already have apis like that ?

possibly interesting links regarding sensor and multitouch abstraction in the android java sdk :
http://developer.android.com/reference/ ... Event.html
http://developer.android.com/reference/ ... ensor.html
http://developer.android.com/reference/ ... Event.html (touch)

Re: api extensions: api discussion

Posted: Thu Nov 17, 2011 10:56 pm
by josefnpat
There also needs to be a way to test these functions on the computer.

Installing a Gyrometer on my computer does not sound like a cup of tea.

Re: api extensions: api discussion

Posted: Thu Nov 17, 2011 11:06 pm
by Taehl
Just as an initial suggestion...

Code: Select all

-- love sensor functions:

love.sensor.getTouches(n)	-- returns the x and y coordinate of touch-point n (or nil,nil). If n is nil, returns a vararg of all touch point pairs
love.sensor.getCompass()	-- returns the the compass sensor's numbers
love.sensor.getOrientation()	-- returns the orientation sensor's numbers
love.sensor.getGPS()		-- returns the coordinates from the GPS
love.sensor.getLight()		-- returns the lightness level, from 0 to 1 (divide lux by 120000)

-- other functions:

love.android.showToast(message, long)	-- displays a Toast of message. If long is true, then make the toast long, else short.
love.android.startActivity(n, ...)		-- summons an Activity via an Intent. I have no idea what parameters this should have, honestly. Getting data to the Activity would be great.
love.android.getActivityResults(n)	-- returns the results Activity n may have sent (vararg), or nil


-- new callbacks:

function love.androidHome() end		-- called when the Home button is pressed (a good time for saving the game)
function love.androidMenu() end		-- called when the Menu button is pressed
function love.androidBack() end		-- called when the Back button is pressed (another good time for saving the game)
function love.androidFind() end		-- called when the Find button is pressed
One thing I think is very important is for Love-Android itself to maintain a best estimate for stuff like GPS data, and return the best estimate instead of raw data. This is not a wheel every Love game should have to reinvent.

Also, maybe it would be a good idea to have callbacks for onCreate, onStart, onRestart, onResume, onPause, onStop, and onDestroy events?

Also, should Love-Android expose the remapCoordinateSystem function? Food for thought.

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:06 am
by tentus
Taehl wrote:

Code: Select all

function love.androidHome() end		-- called when the Home button is pressed (a good time for saving the game)
function love.androidMenu() end		-- called when the Menu button is pressed
function love.androidBack() end		-- called when the Back button is pressed (another good time for saving the game)
function love.androidFind() end		-- called when the Find button is pressed
Shouldn't there be two functions for each of those, a pressed and a released version? That'd be more in keeping with Love, and more flexible.

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:09 am
by Taehl
I would agree with that... But I don't think Android tells you pressed/released status, it just fires off a function when pressed.

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:10 am
by thelinx
A callback for every button is stupid, imho.

Just tie it in with love.keyboard.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    ...
  end
end

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:21 am
by TechnoCat
thelinx wrote:A callback for every button is stupid, imho.

Just tie it in with love.keyboard.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    ...
  end
end
I like this if a function that virtually presses the homekey is provided. Otherwise it might be hard to get the default function.

Code: Select all

function love.keypressed(key)
  if key == "android_home" then
    love.mobile.pressHome()
  end
end

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:26 am
by thelinx
???????????????

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 1:39 am
by ghoulsblade
as expected the home key is on purpose left outside the control of the application :
http://groups.google.com/group/android- ... 3f5e8c8013

it might be possible to at least detect it or similar using (android) activity:onUserLeaveHint()
http://developer.android.com/reference/ ... Hint%28%29

Re: api extensions: api discussion

Posted: Fri Nov 18, 2011 2:24 am
by Taehl
Oh, I just realized: It would be really good to know what kind of a screen a game is on - QVGA or whatnot. So it's important that love.graphics.getHeight and and such all work. I guess you'd need to disable love.graphics.setMode, though.