--[[ =head1 NAME applets.AutoSkin.AutoSkinApplet - An applet to select different SqueezePlay skins =head1 DESCRIPTION This applet allows the SqueezePlay skin to be selected. =head1 FUNCTIONS Applet related methods are described in L. AutoSkinApplet overrides the following methods: =cut --]] local oo = require("loop.simple") local Applet = require("jive.Applet") local Framework = require("jive.ui.Framework") local Surface = require("jive.ui.Surface") local jiveMain = jiveMain local appletManager = appletManager module(..., Framework.constants) oo.class(_M, Applet) --service method function getActiveSkinType(self) return self.mode end function init(self, ...) -- skins, could be configurable via settings local touchSkin = "touch" local remoteSkin = "remote" --temp workaround, until it is resolved how to avoid self.mode being null on startup if not self.mode then self.mode = touchSkin end Framework:addListener(EVENT_IR_ALL, function(event) self:changeSkin(remoteSkin) return EVENT_UNUSED end, -100) Framework:addListener(EVENT_MOUSE_ALL, function(event) self:changeSkin(touchSkin) return EVENT_UNUSED end, -100) return self end function changeSkin(self, skinType) if self.mode == skinType then return false end local skinName = appletManager:callService("getSelectedSkinNameForType", skinType) if jiveMain:getSelectedSkin() == skinName then log:debug("skin already selected, not switching: ", skinName) return false end local img1 = _capture("foo") self.mode = skinType jiveMain:setSelectedSkin(skinName) local img2 = _capture("bar") Framework:_startTransition(self._transitionFadeIn(img1, img2)) return true end function _capture(name) local sw, sh = Framework:getScreenSize() local img = Surface:newRGB(sw, sh) Framework:draw(img) return img end function _transitionFadeIn(oldImage, newImage) -- use a fast transition local startT local transitionDuration = 100 local remaining = transitionDuration local sw, sh = Framework:getScreenSize() local scale = (transitionDuration * transitionDuration * transitionDuration) / sw local animationCount = 0 local scale = 255 / transitionDuration return function(widget, surface) if animationCount == 0 then --getting start time on first loop avoids initial delay that can occur startT = Framework:getTicks() end local x = remaining * scale newImage:blit(surface, 0, 0) oldImage:blitAlpha(surface, 0, 0, x) local elapsed = Framework:getTicks() - startT remaining = transitionDuration - elapsed if remaining <= 0 then Framework:_killTransition() end animationCount = animationCount + 1 end end --[[ =head1 LICENSE Copyright 2010 Logitech. All Rights Reserved. This file is licensed under BSD. Please see the LICENSE file for details. =cut --]]