Project: titanium
Issue TIMOB-8582: BlackBerry: Implement important Gesture functionality
Implement the Gesture module. h3. Acceptance Test {code} function orientationToString(orientation) { switch (orientation) { case Ti.UI.PORTRAIT: return 'portrait'; case Ti.UI.UPSIDE_PORTRAIT: return 'upside portrait'; case Ti.UI.LANDSCAPE_LEFT: return 'landscape left'; case Ti.UI.LANDSCAPE_RIGHT: return 'landscape right'; case Ti.UI.FACE_UP: return 'face up'; case Ti.UI.FACE_DOWN: return 'face down'; default: return 'unknown'; } } var win = Ti.UI.createWindow({ backgroundColor: 'red', layout: 'vertical' }); var labelA = Ti.UI.createLabel({ width: Ti.UI.FILL, text: 'e.orientation = N/A' }); win.add(labelA); var labelB = Ti.UI.createLabel({ width: Ti.UI.FILL, text: 'Gesture.orientation = N/A' }); win.add(labelB); var labelC = Ti.UI.createLabel({ width: Ti.UI.FILL, wrap: true, text: 'No shake yet.' }); win.add(labelC); function onShake(e) { Ti.API.info('Shake: {' + e.x + ', ' + e.y + ', ' + e.z + '}'); labelC.text = 'Shake!'; win.backgroundColor = 'yellow'; setTimeout(function() { labelC.text = 'No shake yet.'; win.backgroundColor = 'red'; }, 500); } var toggleShake = Ti.UI.createButton({ title: 'Toggle Shake' }); var shakeEnabled = false; toggleShake.addEventListener('click', function() { shakeEnabled ? Ti.Gesture.removeEventListener('shake', onShake) : Ti.Gesture.addEventListener('shake', onShake); shakeEnabled = !shakeEnabled; }); win.add(toggleShake); Ti.Gesture.addEventListener('orientationchange', function(e) { labelA.text = 'e.orientation = ' + orientationToString(e.orientation); labelB.text = 'Gesture.orientation = ' + orientationToString(Ti.Gesture.orientation); }); win.open(); {code} # Rotate the device and flip it around. The first two labels should be equal and display the current orientation. # Try shaking the device, nothing should happen. # Click the "Toggle Shake" button and shake again. The background should flash yellow. # Try clicking the "Toggle Shake" button and shake again. Nothing should happen.
Story points: 17