local device = {} device.platform = "unknown" device.model = "unknown" local sharedApplication = cc.Application:getInstance() local target = sharedApplication:getTargetPlatform() if target == cc.PLATFORM_OS_WINDOWS then device.platform = "windows" elseif target == cc.PLATFORM_OS_MAC then device.platform = "mac" elseif target == cc.PLATFORM_OS_ANDROID then device.platform = "android" elseif target == cc.PLATFORM_OS_ANDROID then device.platform = "android" elseif target == cc.PLATFORM_OS_IPHONE or target == cc.PLATFORM_OS_IPAD then device.platform = "ios" if target == cc.PLATFORM_OS_IPHONE then device.model = "iphone" else device.model = "ipad" end elseif target == cc.PLATFORM_OS_WINRT or target == cc.PLATFORM_OS_WIN8 then device.platform = "wp" if target == cc.PLATFORM_OS_WINRT then device.model = "winrt" else device.model = "wp8" end end local language_ = sharedApplication:getCurrentLanguage() if language_ == cc.LANGUAGE_CHINESE then language_ = "cn" else language_ = "en" end device.language = language_ device.writablePath = cc.FileUtils:getInstance():getWritablePath() device.directorySeparator = "/" device.pathSeparator = ":" if device.platform == "windows" then device.directorySeparator = "\\" device.pathSeparator = ";" end print("# device.platform = " .. device.platform) print("# device.model = " .. device.model) print("# device.language = " .. device.language) print("# device.writablePath = " .. device.writablePath) print("# device.directorySeparator = " .. device.directorySeparator) print("# device.pathSeparator = " .. device.pathSeparator) print("#") function device.showActivityIndicator() cc.Native:showActivityIndicator() end function device.hideActivityIndicator() cc.Native:hideActivityIndicator() end function device.showAlert(title, message, buttonLabels, listener) if type(buttonLabels) ~= "table" then buttonLabels = {tostring(buttonLabels)} end if device.platform == "android" then local tempListner = function(event) if type(event) == "string" then event = require("framework.json").decode(event) event.buttonIndex = tonumber(event.buttonIndex) end if listener then listener(event) end end luaj.callStaticMethod("org/cocos2dx/utils/PSNative", "createAlert", {title, message, buttonLabels, tempListner}, "(Ljava/lang/String;Ljava/lang/String;Ljava/util/Vector;I)V"); else local defaultLabel = "" if #buttonLabels > 0 then defaultLabel = buttonLabels[1] table.remove(buttonLabels, 1) end cc.Native:createAlert(title, message, defaultLabel) for i, label in ipairs(buttonLabels) do cc.Native:addAlertButton(label) end if type(listener) ~= "function" then listener = function() end end cc.Native:showAlert(listener) end end function device.cancelAlert() cc.Native:cancelAlert() end function device.getOpenUDID() return cc.Native:getOpenUDID() end function device.openURL(url) cc.Native:openURL(url) end function device.showInputBox(title, message, defaultValue) title = title or "INPUT TEXT" message = message or "INPUT TEXT, CLICK OK BUTTON" defaultValue = defaultValue or "" return cc.Native:getInputText(title, message, defaultValue) end return device