2 /*global $, tizen, App, app */
4 (function () { // strict mode wrapper
7 App.NFCCard = function (nfcControl) {
8 this.app = nfcControl.app;
12 App.NFCCard.prototype = {
18 readMessageErr: function readMessageErr(e) {
19 app.nfc.timeExpired('Read error!');
22 sucTagReadAttach: function sucTagReadAttach(tag) {
23 if (tag.isSupportedNDEF) {
24 tag.readNDEF(this.app.nfc.readMessage.bind(this.app.nfc), this.readMessageErr.bind(this));
26 console.warn("This Tag doesn't support NDEF");
30 setTagDetectRead: function setTagDetectRead() {
31 var suc = { onattach: this.sucTagReadAttach.bind(this), ondetach: this.app.nfc.sucDetach.bind(this.app.nfc) };
33 app.nfc.nfcAdapter.setTagListener(suc);
35 console.error('error: ' + error.message);
42 sucSend: function sucSend() {
43 app.nfc.timeExpired('Send success!');
46 errSend: function errSend(e) {
47 console.warn('errSend');
48 app.nfc.timeExpired('Send problem! ' + e.message);
51 sucTagWriteAttach: function sucTagWriteAttach(tag) {
52 var newMessage = null,
53 separator = String.fromCharCode(30),
54 endOfText = String.fromCharCode(3),
55 fullContact = localStorage.phoneNumber + separator + localStorage.firstName + separator + localStorage.lastName,
58 prepareForNFC = this.prepareForNFC || function prepareForNFC(contact) {
59 if (contact.length > 31) {
60 contact = contact.substring(0, 31);
61 if (contact[29] !== separator) {
62 contact = contact.substring(0, 30) + endOfText;
68 fullContact = prepareForNFC(fullContact);
71 newMessage = this.app.nfc.phoneNumber2NDEF(fullContact);
73 console.error("NDEFMessage problem: " + err.message);
76 if (tag.isSupportedNDEF) {
77 tag.writeNDEF(newMessage, this.sucSend.bind(this), this.errSend.bind(this));
79 console.warn("This Tag doesn't support NDEF");
83 setTagDetectWrite: function setTagDetectWrite() {
84 var suc = { onattach: this.sucTagWriteAttach.bind(this), ondetach: this.app.nfc.sucDetach };
86 app.nfc.nfcAdapter.setTagListener(suc);
88 console.error('error: ' + error.message);