main.qml Example File
nfcshare/assets/main.qml
import bb.cascades 1.0
import custom 1.0
Page {
Container {
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
imageSource: "asset:///images/background.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
SegmentedControl {
Option {
text: qsTr("Data Share")
value: NfcShareHandler.DataShare
}
Option {
text: qsTr("File Share")
value: NfcShareHandler.FileShare
}
onSelectedValueChanged: {
_nfcShareHandler.shareMode = selectedValue
}
}
Container {
leftPadding: 20
rightPadding: 20
visible: (_nfcShareHandler.shareMode == NfcShareHandler.DataShare)
TextField {
hintText: qsTr("Content")
onTextChanging: {
_nfcShareHandler.data = text
}
}
Label {
text: qsTr("Type some text into the text field and then tap an NFC tag or device to share content")
multiline: true
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
textAlign: TextAlign.Center
}
}
}
Container {
topPadding: 20
leftPadding: 10
rightPadding: 10
bottomPadding: 10
visible: (_nfcShareHandler.shareMode == NfcShareHandler.FileShare)
ListView {
horizontalAlignment: HorizontalAlignment.Fill
dataModel: _nfcShareHandler.fileModel
listItemComponents: [
ListItemComponent {
type: ""
Container {
id: root
leftPadding: 20
preferredHeight: 150
Label {
horizontalAlignment: HorizontalAlignment.Fill
text: ListItemData
textStyle {
base: SystemDefaults.TextStyles.SmallText
color: Color.White
}
contextActions: [
ActionSet {
DeleteActionItem {
onTriggered: {
root.ListItem.view.removeFile(ListItemData)
}
}
}
]
}
Divider {}
}
}
]
function removeFile(filePath)
{
_nfcShareHandler.fileModel.removeFile(filePath)
}
}
Button {
horizontalAlignment: HorizontalAlignment.Right
topMargin: 30
text: qsTr("Add File...")
onClicked: {
filePicker.open()
}
}
attachedObjects: [
FilePicker {
id: filePicker
title: qsTr("Select File")
directories: ["/accounts/1000/shared/"]
onFileSelected: {
_nfcShareHandler.fileModel.addFile(selectedFiles[0])
}
}
]
}
}
}
}