collisiondetector.qml Example File
SensorDemo/assets/collisiondetector.qml
import bb.cascades 1.0
import bb.multimedia 1.0
import QtMobility.sensors 1.2
Container {
bottomPadding: 20
attachedObjects: [
SystemSound {
id: sound
sound: SystemSound.CameraBurstEvent
},
IRProximitySensor {
id: irProximity
property real reflectance: 0
active: true
alwaysOn: true
onReadingChanged: {
reflectance = reading.reflectance
}
},
ProximitySensor {
id: proximity
property bool close: false
active: true
alwaysOn: true
onReadingChanged: {
close = reading.close
if (close) {
sound.play();
anim.play();
}
}
}
]
layout: DockLayout {}
Label {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Bottom
text: qsTr("Reflectance: %1%").arg((irProximity.reflectance * 100).toPrecision(4))
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
}
Label {
id: alert
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: proximity.close ? qsTr("!! Mayday, Mayday !!") : qsTr("Cruising")
textStyle {
base: SystemDefaults.TextStyles.BigText
color: proximity.close ? Color.Red : Color.White
}
animations: [
FadeTransition {
id: anim
fromOpacity: 0.5
toOpacity: 1
duration: 300
easingCurve: StockCurve.BounceIn
}
]
}
}