QR Code

QR Code

Youtube Demo

A printed QR code on a card will return one of the following text

the app shows up the corresponding image. you can trigger the animation or the action too.

If you run it on Corona simulator, the sample project will work in debug mode and it returns a dummy text of a QR code.

Sample project is here

Please open the page 1.

Art Layers

Kwik Components

Strictly Necessary to control the QR Code process

Option


qr_grp


qr_store


hide_qr_grp


but_qr


anim_fish


Build for device


that’s all. Build the app. You find QR codes in page3

qr_popup.lua

local QR_STORE_LOAD = false
--
local function listener(event)
	if not event.isError then
		-- event.message contains the value of a scanned QR Code or a barcode.
		print("Scanned message:", event.message)
		print("Scanned symbol:", event.symbol)
		-- native.showAlert('QR Code Scanner', event.message, {'OK'})
		local _target = event.message
		for i = 1, layer.qr_grp.numChildren do
			local child = layer.qr_grp[i]
			if child.name == _target then
				print(child.name)
				UI.qr_store[_target] = child
				child.alpha = 1
				--anim_fish
				UI.scene:dispatchEvent({name = "action_qr_act", message = _target})
				local _AC = require("commands.kwik.actionCommand")
				_AC.Animation:playAnimation("anim_" .. _target)
				break
			end
		end
	else
		print("Error occured:", event.errorCode, event.errorMessage)
		native.showAlert("Error: " .. event.errorCode, event.errorMessage, {"OK"})
	end
end
--
layer.qr_grp.alpha = 1
for i = 1, layer.qr_grp.numChildren do
	layer.qr_grp[i].alpha = 0
end
--
if QR_STORE_LOAD then
	for k, v in pairs(UI.qr_store) do -- {fish=layer.fish, }
		UI.qr_store[k] = layer[k]
		layer[k].alpha = 1
	end
end
layer.searching.alpha = 0
layer.found.alpha = 0
layer.mismatch.alpha = 0
--
if (system.getInfo("environment") == "simulator") then
	local i = math.random(layer.qr_grp.numChildren)
	local param = {message = layer.qr_grp[i].name}
	local function onComplete( event )
    if ( event.action == "clicked" ) then
        local i = event.index
        if ( i == 1 ) then
				  listener(param)
        elseif ( i == 2 ) then
        end
    end
 end
	native.showAlert("Dummy: QR will return" , layer.qr_grp[i].name, {"OK"},  onComplete)
else
	local qrscanner = require("plugin.qrscanner")
	qrscanner.show {
		listener = listener,
		topbar = {
			text = "QR Scanner",
			fontSize = 0.5,
			color = {0.5, 0.8, 0},
			backgroundColor = {0.2, 0.2, 0.8}
			--isHidden = true
		},
		overlays = {
			searching = {
				filename = "assets/images/p" .. UI.curPage .. "/searching.png",
				baseDir = system.ResourceDirectory
			},
			found = {
				filename = "assets/images/p" .. UI.curPage .. "/found.png",
				baseDir = system.ResourceDirectory
			},
			mismatch = {
				filename = "assets/images/p" .. UI.curPage .. "/mismatch.png"
			}
		},
		-- filter = "^https?://.*", -- Match an URL
		-- mask = {
		-- 	x = 0.2,
		-- 	y = 0.25,
		-- 	width = 0.6,
		-- 	height = 0.25,
		-- 	color = {1, 0, 1, 0.25}
		-- }
	}
end