2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*jslint devel: true*/
18 /*global $, tizen, App, app, localStorage */
20 (function () { // strict mode wrapper
26 * @param {NFCControl} nfc
28 App.NFCCard = function nfc_NFCCard(nfc) {
32 App.NFCCard.prototype = {
34 readMessageErr: function nfc_card_readMessageErr(e) {
35 console.error('Read error! ' + e.message, e);
36 this.nfc.timeExpired('Read error! ' + e.message);
40 * Read contents from a tag
43 sucTagReadAttach: function nfc_card_sucTagReadAttach(tag) {
45 if (!tag.isSupportedNDEF) {
47 message: "This tag doesn't support NDEF"
51 this.nfc.readMessage.bind(this.nfc),
52 this.readMessageErr.bind(this)
55 this.readMessageErr(e);
62 setTagDetectRead: function nfc_card_setTagDetectRead() {
64 this.nfc.nfcAdapter.unsetTagListener();
65 this.nfc.nfcAdapter.setTagListener({
66 onattach: this.sucTagReadAttach.bind(this),
67 ondetach: this.nfc.sucDetach.bind(this.nfc)
70 this.readMessageErr(error);
74 sucSend: function nfc_card_sucSend() {
75 this.nfc.timeExpired('Send success!');
78 errSend: function nfc_card_errSend(e) {
79 console.warn('errSend', e);
80 this.nfc.timeExpired('Write error! ' + e.message);
83 sucTagWriteAttach: function nfc_card_sucTagWriteAttach(tag) {
84 var newMessage = null,
88 fullContact = this.nfc.prepareForNFC(localStorage);
89 newMessage = this.nfc.phoneNumber2NDEF(fullContact);
90 if (!tag.isSupportedNDEF) {
92 message: "This tag doesn't support NDEF"
97 this.sucSend.bind(this),
98 this.errSend.bind(this)
105 setTagDetectWrite: function nfc_card_setTagDetectWrite() {
107 onattach: this.sucTagWriteAttach.bind(this),
108 ondetach: this.nfc.sucDetach.bind(this.nfc)
112 this.nfc.nfcAdapter.unsetTagListener();
113 this.nfc.nfcAdapter.setTagListener(suc);
115 console.error(error);