Author: tom
Date: Mon Jan 19 12:17:09 2009
New Revision: 3878
URL: http://svn.slimdevices.com?rev=3878&root=Jive&view=rev
Log:
Bug: N/A
Description:
Action framework:
- added char handler
- making action names more functional
- added widget action listeners
Modified:
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua
Modified:
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=3878&root=Jive&r1=3877&r2=3878&view=diff
==============================================================================
---
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
(original)
+++
7.4/trunk/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
Mon Jan 19 12:17:09 2009
@@ -2054,19 +2054,9 @@
end
_playerKeyHandler = Framework:addListener(
- EVENT_KEY_DOWN | EVENT_KEY_PRESS | EVENT_KEY_HOLD |
EVENT_CHAR_PRESS,
+ EVENT_KEY_DOWN | EVENT_KEY_PRESS | EVENT_KEY_HOLD,
function(event)
local type = event:getType()
-
- if type == EVENT_CHAR_PRESS then
- local keyboardEntry =
string.char(event:getUnicode())
- if keyboardEntry == "/" then
- _goSearch()
- return EVENT_CONSUME
- else
- return EVENT_UNUSED
- end
- end
local actionName =
_keycodeActionName[event:getKeycode()]
if not actionName then
@@ -2509,6 +2499,8 @@
jiveMain:setTitle(_player:getName())
_installPlayerKeyHandler(self)
+
+ Framework:addActionListener("go_search", self, "SlimBrowser", _goSearch)
end
function notify_playerNeedsUpgrade(self, player, needsUpgrade, isUpgrading)
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua?rev=3878&root=Jive&r1=3877&r2=3878&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua Mon Jan 19
12:17:09 2009
@@ -72,6 +72,7 @@
local EVENT_SCROLL = jive.ui.EVENT_SCROLL
local EVENT_WINDOW_RESIZE = jive.ui.EVENT_WINDOW_RESIZE
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
+local EVENT_CONSUME = jive.ui.EVENT_CONSUME
local KEY_HOME = jive.ui.KEY_HOME
local KEY_FWD = jive.ui.KEY_FWD
@@ -126,13 +127,22 @@
["\27"] = { keyCode = KEY_BACK, event = EVENT_KEY_PRESS } -- ESC
}
-local keyActionMappingsPress = {
- [KEY_LEFT] = "arrow_left.press" -- using button naming convention from SC
default.map, though these are action events
+
+local charActionMappings = {}
+charActionMappings.press = {
+ ["/"] = "go_search"
}
-local keyActionMappingsHold = {
- [KEY_LEFT] = "arrow_left.hold",
+local keyActionMappings = {}
+keyActionMappings.press = {
+ [KEY_HOME] = "go_home"
+}
+
+
+keyActionMappings.hold = {
+ [KEY_BACK] = "disconnect_player",
+ [KEY_LEFT] = "go_home",
[KEY_REW | KEY_PAUSE] = "take_screenshot" -- a stab at how to handle
multi-press
}
@@ -165,10 +175,12 @@
log:debug("Keyboard entry: ", keyboardEntry)
- if keyboardShortcuts[keyboardEntry] then
- local keyCode = keyboardShortcuts[keyboardEntry].keyCode
-
Framework:pushEvent(Event:new(keyboardShortcuts[keyboardEntry].event, keyCode))
+ if not keyboardShortcuts[keyboardEntry] then
+ return EVENT_UNUSED
end
+
+ local keyCode = keyboardShortcuts[keyboardEntry].keyCode
+
Framework:pushEvent(Event:new(keyboardShortcuts[keyboardEntry].event, keyCode))
return EVENT_CONSUME
@@ -195,9 +207,11 @@
local action = nil
if eventType == EVENT_KEY_PRESS then
- action = keyActionMappingsPress[event:getKeycode()]
+ action = keyActionMappings.press[event:getKeycode()]
elseif eventType == EVENT_KEY_HOLD then
- action = keyActionMappingsHold[event:getKeycode()]
+ action = keyActionMappings.hold[event:getKeycode()]
+ elseif eventType == EVENT_CHAR_PRESS then
+ action = charActionMappings.press[string.char(event:getUnicode())]
end
return action
@@ -205,10 +219,13 @@
end
function registerDefaultActions()
- for key, action in pairs(keyActionMappingsPress) do
+ for key, action in pairs(keyActionMappings.press) do
Framework:registerAction(action)
end
- for key, action in pairs(keyActionMappingsHold) do
+ for key, action in pairs(keyActionMappings.hold) do
+ Framework:registerAction(action)
+ end
+ for key, action in pairs(charActionMappings.press) do
Framework:registerAction(action)
end
@@ -266,11 +283,11 @@
end,
10)
- registerDefaultActions()
+ registerDefaultActions()
-- action mapping listener, should be last listener in chain to allow
for direct access to keys/other input types if needed.
--todo add other input types
- Framework:addListener(EVENT_KEY_ALL,
+ Framework:addListener(EVENT_KEY_ALL | EVENT_CHAR_PRESS ,
function(event)
local action = getAction(event)
if not action then
@@ -285,13 +302,13 @@
log:debug("Pushing action event (", action, ") -
event:getAction: " , actionEvent:getAction())
Framework:pushEvent(actionEvent)
- return EVENT_CONSUMED
+ return EVENT_CONSUME
end,
9999)
- -- disconnect from player on press and hold left
- Framework:addActionListener("arrow_left.hold", self, _disconnectPlayer)
+ -- disconnect from player on press and hold left
+ Framework:addActionListener("disconnect_player", self, "JiveMain",
_disconnectPlayer)
-- show our window!
jiveMain.window:show()
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua?rev=3878&root=Jive&r1=3877&r2=3878&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua Mon Jan
19 12:17:09 2009
@@ -99,8 +99,9 @@
screen.bounds = { 0, 0, 240, 320 }
screen.bpp = 16
-actionsByName = {}
-actionsByIndex = {}
+actions = {}
+actions.byName = {}
+actions.byIndex = {}
-- Put default global settings here
default_global_settings = {
@@ -544,27 +545,27 @@
function dumpActions(self)
local result = "Available Actions: "
- for action in table.pairsByKeys(self.actionsByName) do
+ for action in table.pairsByKeys(self.actions.byName) do
result = result .. " " .. action
end
return result
end
function _getActionEventIndexByName(self, name)
- if (self.actionsByName[name] == nil) then
+ if (self.actions.byName[name] == nil) then
return nil
end
- return self.actionsByName[name].index
+ return self.actions.byName[name].index
end
function getActionEventNameByIndex(self, index)
- if (index > #self.actionsByIndex) then
+ if (index > #self.actions.byIndex) then
log:error("action event index out of bounds: " , index)
return nil
end
- return self.actionsByIndex[index].name
+ return self.actions.byIndex[index].name
end
--[[
@@ -588,30 +589,30 @@
--[[
-=head2 jive.ui.Framework:registerAction(action)
-
-Register an action. action is a unique string that represents an action.
+=head2 jive.ui.Framework:registerAction(actionName)
+
+Register an action. actionName is a unique string that represents an action.
Each action must be registered before listeners using it can be created (for
typo prevention, and other future uses).
=cut
--]]
function registerAction(self, actionName)
- if (self.actionsByName[actionName]) then
- log:error("Action already registered, doing nothing")
+ if (self.actions.byName[actionName]) then
+ log:error("Action already registered, doing nothing: ", actionName)
return
end
- local actionEventDefinition = { name = actionName, index =
#self.actionsByIndex + 1 }
+ local actionEventDefinition = { name = actionName, index =
#self.actions.byIndex + 1 }
log:debug("Registering action: ", actionEventDefinition.name, " with
index: ", actionEventDefinition.index)
- self.actionsByName[actionName] = actionEventDefinition
- table.insert(self.actionsByIndex, actionEventDefinition)
+ self.actions.byName[actionName] = actionEventDefinition
+ table.insert(self.actions.byIndex, actionEventDefinition)
end
---example: addActionListener("play", self, playAction)
-function addActionListener(self, action, obj, listener)
+--example: addActionListener("disconnect_player", self, "MyApplet"
disconnectPlayerAction)
+function addActionListener(self, action, obj, sourceBreadCrumb, listener)
_assert(type(listener) == "function")
@@ -619,8 +620,7 @@
log:error("action name not registered:(" , action, "). Available
actions: ", self:dumpActions() )
return
end
-
- log:debug("Creating action listener for action: (" , action, ") from
source: todo would be nice to be able to display the source of the listener in
a meaningful way for debugging")
+ log:debug("Creating action listener for action: (" , action, ") from
source: ", sourceBreadCrumb)
self:addListener(ACTION,
function(event)
@@ -628,7 +628,8 @@
if eventAction != action then
return EVENT_UNUSED
end
-
+ log:debug("Calling action listener for action: (" , action, ") from
source: ", sourceBreadCrumb)
+
local listenerResult = listener(obj, event)
--default to consume unless the listener specifically wants to set
a specific event return
return listenerResult and listenerResult or EVENT_CONSUME
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua?rev=3878&root=Jive&r1=3877&r2=3878&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua Mon Jan 19
12:17:09 2009
@@ -408,6 +408,32 @@
return handle
end
+
+function addActionListener(self, action, obj, sourceBreadCrumb, listener)
+ _assert(type(listener) == "function")
+
+
+ if not Framework:_getActionEventIndexByName(action) then
+ log:error("action name not registered:(" , action, ").
Available actions: ", self:dumpActions() )
+ return
+ end
+ log:debug("Creating widget action listener for action: (" , action, ")
from source: ", sourceBreadCrumb)
+
+ self:addListener(ACTION,
+ function(event)
+ local eventAction = event:getAction()
+ if eventAction != action then
+ return EVENT_UNUSED
+ end
+ log:debug("Calling widget action listener for
action: (" , action, ") from source: ", sourceBreadCrumb)
+
+ local listenerResult = listener(obj, event)
+ --default to consume unless the listener
specifically wants to set a specific event return
+ return listenerResult and listenerResult or
EVENT_CONSUME
+ end
+ )
+
+end
--[[
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins