Hi
Here are the code changes I made to the Jivelite's Now Playing Applet to
allow an overlay be displayed and controlled by alternative devices e.g.
keyboard, Powermate or an appropriately programmed IR controller via
LIRC (sending the same keycodes). I'm not a lua expert so this can
probably be done much more elegantly.
1. Add a listener to NowPlaying s o that overlay window can be displayed
when Down Arrow is pressed.
In jivelite/share/jive/applets/NowPlaying/NowPlayingApplet.Lua amend the
function at line 1165 to add a listener for down arrow key. This is
inside the _installListeners Function.
BEFORE
Code:
--------------------
-- FIXME: hack to deal with removing actions from left/right - fix this in
more generic way?
window:addListener(EVENT_KEY_PRESS,
function(event)
local keycode = event:getKeycode()
if keycode == KEY_LEFT then
Framework:pushAction("back")
return EVENT_CONSUME
end
if keycode == KEY_RIGHT then
Framework:pushAction("go")
return EVENT_CONSUME
end
return EVENT_UNUSED
end
)
--------------------
AFTER
Code:
--------------------
-- FIXME: hack to deal with removing actions from left/right - fix this in
more generic way?
window:addListener(EVENT_KEY_PRESS,
function(event)
local keycode = event:getKeycode()
if keycode == KEY_LEFT then
Framework:pushAction("back")
return EVENT_CONSUME
end
if keycode == KEY_RIGHT then
Framework:pushAction("go")
return EVENT_CONSUME
end
if keycode == 8 then -- Down Arrow pressed
local playerStatus = self.player and
self.player:getPlayerStatus()
_powermate(playerStatus['playlist repeat'],
playerStatus['playlist shuffle'])
return EVENT_CONSUME
end
return EVENT_UNUSED
end
)
--------------------
2. Add the function that displays the overlay and processes keypresses
to display icons. The icons are from the existing set as I can't draw.
I added this after the _installListeners function in
NowPlayingApplet.Lua
The function just adds an overlay and puts the icon on the screen.
USE UP AND DOWN TO NAVIGATE THROUGH THE OPTIONS, PRESS ENTER TO SELECT.
Code:
--------------------
function _powermate(repeatMode, shuffleMode)
local popup = Window("window","Powermate Controller")
pmateActions = {
{icon='icon_popup_rew', action='jump_rew',
popupclose=true},
{icon='icon_popup_fwd', action='jump_fwd',
popupclose=true},
{icon='icon_popup_pause', action='pause',
popupclose=true},
{icon='icon_popup_stop', action='stop',
popupclose=true},
{icon='icon_popup_play', action='play',
popupclose=true},
{icon='icon_popup_repeat' .. repeatMode,
action='repeat_toggle', popupclose=false, submodes=true},
{icon='icon_popup_shuffle'.. shuffleMode,
action='shuffle_toggle', popupclose=false, submodes=true},
{icon='icon_popup_volume',
action='volume_up', popupclose=true},
{icon='icon_popup_mute', action='mute',
popupclose=true},
{icon='icon_popup_current_track_info',
action='go_current_track_info',popupclose=true},
}
popup.transparent = true
popup.bgImg = ""
iconindex = 1
icon_name = pmateActions[1].icon
action_txt = pmateActions[1].action
pmateButton = Button(
Icon(icon_name),
function()
Framework:pushAction(action_txt)
return EVENT_CONSUME
end
)
popup:addActionListener("back", self, _goHomeAction)
popup:addActionListener("go_home", self, _goHomeAction)
popup:addListener(EVENT_KEY_PRESS,
function(event)
local keycode = event:getKeycode()
if keycode == KEY_LEFT then -- Left Key
pressed, so exit
Framework:pushAction("back")
popup:close()
return EVENT_CONSUME
end
if keycode == KEY_HOME then -- HOME Key
pressed, so exit
Framework:pushAction("go_home")
popup:close()
return EVENT_CONSUME
end
if (keycode == KEY_ENTER or keycode == 1) and
pmateActions[iconindex].popupclose then -- Enter pressed, do something and
close window
Framework:pushAction(action_txt)
popup:hide()
return EVENT_CONSUME
end
if (keycode == KEY_ENTER or keycode == 1) and
pmateActions[iconindex].submodes then -- Enter pressed and sub mode exists
mode = (tonumber(icon_name:sub(-1))+1) % 3
icon_name = icon_name:sub(1,-2) .. mode
pmateActions[iconindex].icon = icon_name
action_txt = pmateActions[iconindex].action
Framework:pushAction(action_txt)
end
popup:show()
if keycode == 4 then -- up
iconindex = (iconindex - 1)
%(#pmateActions+1)
if iconindex == 0 then
iconindex = #pmateActions
end
icon_name = pmateActions[iconindex].icon
end
if keycode == 8 then -- down
iconindex = (iconindex + 1)
%(#pmateActions+1)
if iconindex == 0 then
iconindex = 1
end
icon_name = pmateActions[iconindex].icon
end
action_txt = pmateActions[iconindex].action
newButton = Button(
Icon(icon_name),
function()
Framework:pushAction(action_txt)
return EVENT_CONSUME
end
)
popup:removeWidget(pmateButton)
pmateButton = newButton
popup:addWidget(pmateButton)
popup:focusWidget(pmateButton)
return EVENT_CONSUME
end
)
popup:addWidget(pmateButton)
popup:focusWidget(pmateButton)
popup:show()
return EVENT_CONSUME
end
--------------------
Hope this helps
San
------------------------------------------------------------------------
San's Profile: http://forums.slimdevices.com/member.php?userid=1422
View this thread: http://forums.slimdevices.com/showthread.php?t=103051
_______________________________________________
diy mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/diy