From: jihye kim Date: Wed, 25 Apr 2012 09:14:30 +0000 (+0900) Subject: [Title] add check vconf value and check count of record list X-Git-Tag: 2.2.1_release^2~112 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f4fb0883f2fb8d532ed24ef9caa56de4a786bec;p=sdk%2Femulator%2Feventinjector-eplugin.git [Title] add check vconf value and check count of record list [Type] Enhancement [Module] event injector [Priority] major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/org.tizen.nfc/src/org/tizen/nfc/page/NDEFRecordPage.java b/org.tizen.nfc/src/org/tizen/nfc/page/NDEFRecordPage.java new file mode 100644 index 0000000..35bf7b5 --- /dev/null +++ b/org.tizen.nfc/src/org/tizen/nfc/page/NDEFRecordPage.java @@ -0,0 +1,430 @@ +package org.tizen.nfc.page; + +import java.util.ArrayList; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.tizen.injector.util.FormPageUtil; +import org.tizen.sdblib.IDevice; + +public class NDEFRecordPage { + // add NDEFMessage + private String[] RecordFormatList = RecordFormat.getInstance().getList(); + private String[] TypeNameList = TypeName.getInstance().getList(); + private Combo cmbRecordFormat; + private Combo cmbRecordTypeName; + private Text txtRecordTypeName; + private Text txtRecordID; + private Text txtRecordPayload; + private Button butSelectMediaFile; + + private Button butRecordAdd; + private Button butRecordEdit; + private Button butRecordRemove; + + // message list length + private Label lblRecords; + private int nTotalLength = 0; + private final int nMaxNDFEMessageLength = 4096; + private Combo cmbRecordList; + private ArrayList RecordList = new ArrayList(); + + // check invalid characters + private NDEFRecord oldRecord = new NDEFRecord(0, "", "", ""); + private boolean bCheckTypeNameText = true; + private boolean bCheckIDText = true; + private boolean bCheckPayloadText = true; + + private NfcHelpProcess process = null; + private Shell shell; + private IDevice currentDevice = null; + + public NDEFRecordPage(Shell shell) { + process = new NfcHelpProcess(shell); + this.shell = shell; + } + + public void createNDEFMessageSection(FormPageUtil formUtil, Composite parent) + { + Composite client = formUtil.createSection(parent, "NDEF Message"); + Composite messageComposite = formUtil.createComposite(client); + + createRecordComposite(formUtil, messageComposite); + + Composite buttonComposite = formUtil.createComposite(messageComposite, 3); + butRecordAdd = formUtil.createButton(buttonComposite, "Add", SWT.PUSH); + butRecordEdit = formUtil.createButton(buttonComposite, "Edit", SWT.PUSH); + butRecordRemove = formUtil.createButton(buttonComposite, "Remove",SWT.PUSH); + + GridData gd1 = new GridData(); + gd1.widthHint = 110; + butRecordAdd.setLayoutData(gd1); + butRecordEdit.setLayoutData(gd1); + butRecordRemove.setLayoutData(gd1); + + butRecordAdd.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + addRecord(); + } + }); + butRecordEdit.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + editRecord(); + } + }); + butRecordRemove.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeRecord(); + } + }); + + Composite RecordComposite = formUtil.createComposite(messageComposite, 2); + GridData gd2 = new GridData(); + gd2.widthHint = 160; + lblRecords = formUtil.createLabel(RecordComposite, String.format("Records [0/%d] ", nMaxNDFEMessageLength)); + lblRecords.setLayoutData(gd2); + + cmbRecordList = formUtil.createCombo(RecordComposite); + cmbRecordList.setLayoutData(gd2); + cmbRecordList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + selectRecord(); + } + }); + } + + private void createRecordComposite(FormPageUtil formUtil, Composite parent) + { + GridData gd1 = new GridData(); + gd1.widthHint = 200; + + Composite messageComposite = formUtil.createComposite(parent, 2); + + formUtil.createLabel(messageComposite, "Type Name Format "); + cmbRecordFormat = formUtil.createCombo(messageComposite); + cmbRecordFormat.setLayoutData(gd1); + formUtil.addComboItem(cmbRecordFormat, RecordFormatList); + + formUtil.createLabel(messageComposite, "Type Name "); + txtRecordTypeName = formUtil.createText(messageComposite, ""); + txtRecordTypeName.setLayoutData(gd1); + txtRecordTypeName.setTextLimit(250); + + formUtil.createLabel(messageComposite, ""); + cmbRecordTypeName = formUtil.createCombo(messageComposite); + formUtil.addComboItem(cmbRecordTypeName, TypeNameList); + cmbRecordTypeName.setLayoutData(gd1); + + formUtil.createLabel(messageComposite, "ID "); + txtRecordID = formUtil.createText(messageComposite, ""); + txtRecordID.setLayoutData(gd1); + txtRecordID.setTextLimit(250); + + formUtil.createLabel(messageComposite, "Payload "); + txtRecordPayload = formUtil.createText(messageComposite, ""); + txtRecordPayload.setLayoutData(gd1); + txtRecordPayload.setTextLimit(1024); + + formUtil.createLabel(messageComposite, ""); + butSelectMediaFile = formUtil.createButton(messageComposite, + "Select Media File", SWT.PUSH); + butSelectMediaFile.setEnabled(false); + butSelectMediaFile.setLayoutData(new GridData(GridData.END, + GridData.END, false, false)); + + checkRecordFormat(1); //NDEF_TNF_WELL_KNOWN + addListener(); + } + + private void addListener() { + cmbRecordFormat.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Selected(e); + } + public void widgetDefaultSelected(SelectionEvent e) { + Selected(e); + } + private void Selected(SelectionEvent e) { + int i = cmbRecordFormat.getSelectionIndex(); + if (i != -1) { + checkRecordFormat(i + 1); + txtRecordTypeName.setText(""); + cmbRecordTypeName.select(0); + txtRecordID.setText(""); + txtRecordPayload.setText(""); + } + } + }); + + txtRecordTypeName.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (bCheckTypeNameText == false) { + bCheckTypeNameText = true; + return; + } + if (process.checkInvalidCharaters(txtRecordTypeName.getText()) == false) { + txtRecordTypeName.setText(oldRecord.getTypeName()); + return; + } + oldRecord.setTypeName(txtRecordTypeName.getText()); + } + }); + + txtRecordID.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (bCheckIDText == false) { + bCheckIDText = true; + return; + } + if (process.checkInvalidCharaters(txtRecordID.getText()) == false) { + txtRecordID.setText(oldRecord.getId()); + return; + } + oldRecord.setId(txtRecordID.getText()); + } + }); + + txtRecordPayload.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (bCheckPayloadText == false) { + bCheckPayloadText = true; + return; + } + if (process.checkInvalidCharaters(txtRecordPayload.getText()) == false) { + txtRecordPayload.setText(oldRecord.getPayload()); + return; + } + oldRecord.setPayload(txtRecordPayload.getText()); + } + }); + + butSelectMediaFile.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + String filePath = process.selectMediaFile(currentDevice); + if (filePath != null) { + txtRecordTypeName.setEnabled(true); + txtRecordTypeName.setEditable(false); + txtRecordPayload.setEnabled(true); + txtRecordPayload.setEditable(false); + txtRecordTypeName.setText(process.checkFileType(filePath)); + txtRecordPayload.setText(filePath); + } + } + }); + } + + private void selectRecord() { + int i = cmbRecordList.getSelectionIndex(); + if (i != -1) { + NDEFRecord record = RecordList.get(i); + checkRecordFormat(record.getFormat()); + cmbRecordFormat.select(record.getFormat() - 1); + + if (record.getFormat() == 1) { + if (record.getTypeName().compareTo("U") == 0) + cmbRecordTypeName.select(0); + else + cmbRecordTypeName.select(1); + txtRecordTypeName.setText(""); + } else { + cmbRecordTypeName.select(0); + txtRecordTypeName.setText(record.getTypeName()); + } + + txtRecordID.setText(record.getId()); + txtRecordPayload.setText(record.getPayload()); + } + } + + private void checkRecordFormat(int format) + { + switch (format) { + case 0: // NDEF_TNF_EMPTY + cmbRecordTypeName.setEnabled(false); + txtRecordTypeName.setEnabled(false); + txtRecordID.setEnabled(false); + txtRecordPayload.setEnabled(false); + butSelectMediaFile.setEnabled(false); + break; + case 1: // NDEF_TNF_WELL_KNOWN + cmbRecordTypeName.setEnabled(true); + cmbRecordTypeName.select(0); + txtRecordTypeName.setEnabled(false); + txtRecordID.setEnabled(true); + txtRecordPayload.setEnabled(true); + txtRecordPayload.setEditable(true); + butSelectMediaFile.setEnabled(false); + break; + case 2: // NDEF_TNF_MIME_MEDIA + cmbRecordTypeName.setEnabled(false); + txtRecordTypeName.setEnabled(false); + txtRecordID.setEnabled(true); + txtRecordPayload.setEnabled(false); + butSelectMediaFile.setEnabled(true); + break; + case 3: // NDEF_TNF_ABSOLUTE_URI + cmbRecordTypeName.setEnabled(false); + txtRecordTypeName.setEnabled(true); + txtRecordTypeName.setEditable(true); + txtRecordID.setEnabled(true); + txtRecordPayload.setEnabled(false); + butSelectMediaFile.setEnabled(false); + break; + case 4: // NDEF_TNF_EXTERNAL + cmbRecordTypeName.setEnabled(false); + txtRecordTypeName.setEnabled(true); + txtRecordTypeName.setEditable(true); + txtRecordID.setEnabled(true); + txtRecordPayload.setEnabled(true); + txtRecordPayload.setEditable(true); + butSelectMediaFile.setEnabled(false); + break; + case 5: // NDEF_TNF_UNKNOWN + cmbRecordTypeName.setEnabled(false); + txtRecordTypeName.setEnabled(false); + txtRecordID.setEnabled(true); + txtRecordPayload.setEnabled(true); + txtRecordPayload.setEditable(true); + butSelectMediaFile.setEnabled(false); + break; + } + bCheckTypeNameText = false; + bCheckIDText = false; + bCheckPayloadText = false; + } + + private void addRecord() + { + if (RecordList.size() >= 5) { + NfcDialog.openInfoDialog(shell, NfcErrorString.RecordCountIsMax); + return; + } + + NDEFRecord record = new NDEFRecord(); + + setRecordValue(record); + RecordList.add(record); + int temp = process.checkRecordlistMaxLength(RecordList, nMaxNDFEMessageLength); + if (temp == 0) { + RecordList.remove(record); + return; + } else { + nTotalLength = temp; + } + + lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); + cmbRecordList.add("record item" + RecordList.indexOf(record)); + cmbRecordList.clearSelection(); + } + + private void editRecord() + { + int i = cmbRecordList.getSelectionIndex(); + if (i != -1) { + NDEFRecord record = RecordList.get(i); + NDEFRecord copyRecord = record; + setRecordValue(record); + + int temp = process.checkRecordlistMaxLength(RecordList, nMaxNDFEMessageLength); + if (temp == 0) { + record = copyRecord; + return; + } else { + nTotalLength = temp; + } + + lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); + } + } + + private void removeRecord() + { + int index = cmbRecordList.getSelectionIndex(); + if (index != -1) { + RecordList.remove(index); + cmbRecordList.removeAll(); + for (int i = 0; i < RecordList.size(); i++) { + cmbRecordList.add("record item" + i); + } + cmbRecordList.clearSelection(); + } + + nTotalLength = process.checkRecordlistMaxLength(RecordList, nMaxNDFEMessageLength); + lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); + txtRecordTypeName.setText(""); + cmbRecordTypeName.select(0); + txtRecordID.setText(""); + txtRecordPayload.setText(""); + } + + private void setRecordValue(NDEFRecord record) + { + record.setFormat(cmbRecordFormat.getSelectionIndex() + 1); + + if ((cmbRecordFormat.getSelectionIndex() + 1) == 1) { + record.setTypeName(TypeNameList[cmbRecordTypeName.getSelectionIndex()]); + } else { + if (txtRecordTypeName.getText().isEmpty() == true) + record.setTypeName("Null"); + else + record.setTypeName(txtRecordTypeName.getText()); + } + + if (txtRecordID.getText().isEmpty() == true) + record.setId("Null"); + else + record.setId(txtRecordID.getText()); + + if (txtRecordPayload.getText().isEmpty() == true) + record.setPayload("Null"); + else + record.setPayload(txtRecordPayload.getText()); + } + + public IDevice getCurrentDevice() { + return currentDevice; + } + + public void setCurrentDevice(IDevice currentDevice) { + this.currentDevice = currentDevice; + } + + public ArrayList getRecordList() { + return RecordList; + } + + public void setDisableState() { + cmbRecordFormat.setEnabled(false); + checkRecordFormat(0); + + cmbRecordList.setEnabled(false); + butRecordAdd.setEnabled(false); + butRecordEdit.setEnabled(false); + butRecordRemove.setEnabled(false); + } + + public void setEnableState() { + cmbRecordFormat.setEnabled(true); + + checkRecordFormat(cmbRecordFormat.getSelectionIndex() + 1); + txtRecordTypeName.setText(""); + cmbRecordTypeName.select(0); + txtRecordID.setText(""); + txtRecordPayload.setText(""); + + cmbRecordList.setEnabled(true); + butRecordAdd.setEnabled(true); + butRecordEdit.setEnabled(true); + butRecordRemove.setEnabled(true); + } +} diff --git a/org.tizen.nfc/src/org/tizen/nfc/page/NfcHelpProcess.java b/org.tizen.nfc/src/org/tizen/nfc/page/NfcHelpProcess.java new file mode 100644 index 0000000..21b309f --- /dev/null +++ b/org.tizen.nfc/src/org/tizen/nfc/page/NfcHelpProcess.java @@ -0,0 +1,282 @@ +package org.tizen.nfc.page; + +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.common.connection.ConnectionPlugin; +import org.tizen.common.connection.ui.TizenRemoteFileDialog; +import org.tizen.common.connection.ui.TizenRemoteFileDialog.TizenRemoteFileDialogResult; +import org.tizen.injector.socket.TelephonySocket; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.MultiLineReceiver; +import org.tizen.sdblib.SdbCommandRejectedException; +import org.tizen.sdblib.ShellCommandUnresponsiveException; +import org.tizen.sdblib.TimeoutException; +import org.tizen.sdblib.FileListingService.FileEntry; + +public class NfcHelpProcess { + private Shell shell = null; + + public NfcHelpProcess(Shell shell) { + this.shell = shell; + } + + public boolean checkInvalidCharaters(String text) + { + char[] textArray = new char[1000]; + text.getChars(0, text.length(), textArray, 0); + + for (int i = 0; i < text.length(); i++) { + char c = textArray[i]; + if (c == '\n') { + NfcDialog.openInfoDialog(shell, NfcErrorString.InvalidCharNewLine); + return false; + } + + if (c == ',') { + NfcDialog.openInfoDialog(shell, NfcErrorString.InvalidChar); + return false; + } + + if (c >= 0x80) { + NfcDialog.openInfoDialog(shell, NfcErrorString.InvalidCharAscii); + return false; + } + } + return true; + } + + public int checkRecordlistMaxLength(ArrayList RecordList, int maxLen) + { + int lenList = 0; + + for (NDEFRecord record : RecordList) { + lenList += 1 + record.getTypeName().length() + + record.getId().length() + record.getPayload().length() + 4; + } + + if (lenList > maxLen) { + NfcDialog.openInfoDialog(shell, "The length of the NDEF message has reached the maxium limit of " + + maxLen + " bytes\n"); + return 0; + } + + return lenList; + } + + private static String MediaFilePath = null; + private String shellCmd = null; + private String shellResult = null; + + public String selectMediaFile(final IDevice currentDevice) + { + MediaFilePath = null; + if (shell != null) { + shell.getDisplay().syncExec(new Runnable() { + public void run() { + TizenRemoteFileDialog dlg = new TizenRemoteFileDialog( + shell, "Select a media file", currentDevice, false, + "/opt/nfc"); + if (dlg.open() == TizenRemoteFileDialogResult.OK) { + FileEntry fileEntry = dlg.getSelectedFileEntry(); + MediaFilePath = fileEntry.getFullPath(); + } + } + }); + } else { + NfcDialog.openErrorDialog(NfcErrorString.FailOpenDialog); + } + + if (MediaFilePath == null) { + NfcDialog.openErrorDialog(shell, NfcErrorString.EmptyFilePath); + } else { + String type = null; + type = checkFileType(MediaFilePath); + if (type == null) { + NfcDialog.openErrorDialog(shell, NfcErrorString.NotMimeType); + return null; + } + if (checkFileSize(currentDevice, MediaFilePath) == false) { + NfcDialog.openErrorDialog(shell, NfcErrorString.BigSizeFile); + return null; + } + } + return MediaFilePath; + } + + public String checkFileType(String filePath) { + int index = filePath.lastIndexOf('.'); + String type = null; + if (index != -1) { + String ex = filePath.substring(index + 1); + MimeTypeList typelist = MimeTypeList.getInstance(); + + type = typelist.findMimeType(ex); + } + return type; + } + + private boolean checkFileSize(final IDevice currentDevice, String filePath) { + boolean result = false; + shellCmd = "du " + filePath; + try { + currentDevice.executeShellCommand(shellCmd, new MultiLineReceiver() { + @Override + public void processNewLines(String[] lines) { + shellResult = lines[0]; + } + + }); + } catch (TimeoutException e) { + errorSelectMediaFile(e); + return result; + } catch (SdbCommandRejectedException e) { + errorSelectMediaFile(e); + return result; + } catch (ShellCommandUnresponsiveException e) { + errorSelectMediaFile(e); + return result; + } catch (IOException e) { + errorSelectMediaFile(e); + return result; + } + + if (shellResult != null) { + int index = shellResult.indexOf('\t'); + if (index != -1) { + shellResult = shellResult.substring(0, index); + + if (Integer.valueOf(shellResult) <= 10) { + result = true; + } + } + } + return result; + } + + private void errorSelectMediaFile(Exception e) { + NfcDialog.openErrorDialog(shell, NfcErrorString.MediaFileException + e.getMessage()); + } + + private void errorCheckVconf(Exception e) { + NfcDialog.openErrorDialog(shell, NfcErrorString.CheckVconfException + e.getMessage()); + } + + private boolean checkVconfValue() { + boolean result = false; + IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); + shellCmd = "vconftool get db/nfc/enable"; + try { + currentDevice.executeShellCommand(shellCmd, new MultiLineReceiver() { + @Override + public void processNewLines(String[] lines) { + shellResult = lines[0]; + } + }); + } catch (TimeoutException e) { + errorCheckVconf(e); + return result; + } catch (SdbCommandRejectedException e) { + errorCheckVconf(e); + return result; + } catch (ShellCommandUnresponsiveException e) { + errorCheckVconf(e); + return result; + } catch (IOException e) { + errorCheckVconf(e); + return result; + } + + if (shellResult != null) { + if (shellResult.indexOf('1') != -1) { + result = true; + } else { + NfcDialog.openInfoDialog(shell, NfcErrorString.NFCIsDisable); + } + } + + return result; + } + + public boolean sendMessage(Integer type, int tagType, ArrayList RecordList) + { + if (!checkVconfValue()) { + if (type == NfcCommand.NFC_TAG_DISCOVERED + || type == NfcCommand.NFC_P2P_DISCOVERED) { + return false; + } else { + // for initializing the state + return true; + } + } + + String msg = null; + switch (type) { + case 100: // NFC_TAG_DISCOVERED + { + if (tagType != -1 && tagType != 0) { + String records = new String(); + records += "," + RecordList.size(); + for (NDEFRecord record : RecordList) { + records += "," + record.getFormat() + "," + + record.getTypeName() + "," + record.getId() + "," + + record.getPayload(); + } + + msg = NfcCommand.NFC_TAG_DISCOVERED.toString() + ":" + + String.valueOf(tagType) + records + "\n"; + + } else { + NfcDialog.openErrorDialog(shell, NfcErrorString.SelecTagType); + return false; + } + } + break; + case 101: // NFC_TAG_DETACHED + msg = NfcCommand.NFC_TAG_DETACHED.toString() + ":" + "\n"; + break; + case 102: // NFC_P2P_DISCOVERED + msg = NfcCommand.NFC_P2P_DISCOVERED.toString() + ":\n"; + break; + case 103: // NFC_P2P_DETACHED + msg = NfcCommand.NFC_P2P_DETACHED.toString() + ":\n"; + break; + case 104: // NFC_P2P_SEND + { + int tagtype = 5; // for peer to peer + String records = new String(); + records += "," + RecordList.size(); + for (NDEFRecord record : RecordList) { + records += "," + record.getFormat() + "," + + record.getTypeName() + "," + record.getId() + "," + + record.getPayload(); + } + + msg = NfcCommand.NFC_P2P_SEND.toString() + ":" + + String.valueOf(tagtype) + records + "\n"; + } + break; + } + + if (msg != null) { + return send(msg); + } else { + return false; + } + } + + private TelephonySocket injectorSocket = TelephonySocket.getInstance(); + private boolean send(String msg) + { + boolean result = false; + try { + result = injectorSocket.sendNfc(msg); + } catch (Exception e1) { + e1.printStackTrace(); + } + + return result; + } + +} diff --git a/org.tizen.nfc/src/org/tizen/nfc/page/NfcPage.java b/org.tizen.nfc/src/org/tizen/nfc/page/NfcPage.java index 12992a0..f06a9b6 100644 --- a/org.tizen.nfc/src/org/tizen/nfc/page/NfcPage.java +++ b/org.tizen.nfc/src/org/tizen/nfc/page/NfcPage.java @@ -26,62 +26,26 @@ package org.tizen.nfc.page; -import java.io.IOException; -import java.util.ArrayList; - import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; import org.tizen.common.connection.ConnectionPlugin; import org.tizen.common.connection.ConnectionPlugin.ISelectionListener; -import org.tizen.common.connection.ui.TizenRemoteFileDialog; -import org.tizen.common.connection.ui.TizenRemoteFileDialog.TizenRemoteFileDialogResult; import org.tizen.injector.provider.AbstractInjectorItem; import org.tizen.injector.provider.AbstractInjectorPage; import org.tizen.injector.view.InjectorView; import org.tizen.sdblib.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; -import org.tizen.sdblib.MultiLineReceiver; -import org.tizen.sdblib.SdbCommandRejectedException; -import org.tizen.sdblib.ShellCommandUnresponsiveException; -import org.tizen.sdblib.TimeoutException; public class NfcPage extends AbstractInjectorPage implements ISelectionListener { - // add NDEFMessage - private String[] RecordFormatList = RecordFormat.getInstance().getList(); - private String[] TypeNameList = TypeName.getInstance().getList(); - private Combo cmbRecordFormat; - private Combo cmbRecordTypeName; - private Text txtRecordTypeName; - private Text txtRecordID; - private Text txtRecordPayload; - private Button butSelectMediaFile; - - // check invalid characters - private NDEFRecord oldRecord = new NDEFRecord(0, "", "", ""); - private boolean bCheckTypeNameText = true; - private boolean bCheckIDText = true; - private boolean bCheckPayloadText = true; - - private Button butRecordAdd; - private Button butRecordEdit; - private Button butRecordRemove; - - private Label lblRecords; - private int nTotalLength = 0; - private final int nMaxNDFEMessageLength = 4096; - private Combo cmbRecordList; - private ArrayList RecordList = new ArrayList(); + // NDEF record + private NDEFRecordPage recordPage = null; // add Tag private String[] TagTypeList = TagType.getInstance().getList(); @@ -97,6 +61,8 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener private IDevice currentDevice; private Shell shell = null; + private NfcHelpProcess process = null; + public NfcPage(AbstractInjectorItem item, String name) { super(item, name); @@ -109,8 +75,11 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); shell = parent.getShell(); + process = new NfcHelpProcess(shell); + recordPage = new NDEFRecordPage(shell); + recordPage.setCurrentDevice(currentDevice); - createNDEFMessageSection(); + recordPage.createNDEFMessageSection(formUtil, parent); createTagSection(); createP2PSection(); @@ -120,169 +89,9 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener } } - private void createNDEFMessageSection() - { - Composite client = formUtil.createSection(parent, "NDEF Message"); - Composite messageComposite = formUtil.createComposite(client); - - createRecordComposite(messageComposite); - - Composite buttonComposite = formUtil.createComposite(messageComposite, - 3); - butRecordAdd = formUtil.createButton(buttonComposite, "Add", SWT.PUSH); - butRecordEdit = formUtil - .createButton(buttonComposite, "Edit", SWT.PUSH); - butRecordRemove = formUtil.createButton(buttonComposite, "Remove", - SWT.PUSH); - - GridData gd1 = new GridData(); - gd1.widthHint = 110; - butRecordAdd.setLayoutData(gd1); - butRecordEdit.setLayoutData(gd1); - butRecordRemove.setLayoutData(gd1); - - butRecordAdd.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - addRecord(); - } - }); - butRecordEdit.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - editRecord(); - } - }); - butRecordRemove.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - removeRecord(); - } - }); - - Composite RecordComposite = formUtil.createComposite(messageComposite, 2); - GridData gd2 = new GridData(); - gd2.widthHint = 160; - lblRecords = formUtil.createLabel(RecordComposite, String.format("Records [0/%d] ", nMaxNDFEMessageLength)); - lblRecords.setLayoutData(gd2); - - cmbRecordList = formUtil.createCombo(RecordComposite); - cmbRecordList.setLayoutData(gd2); - cmbRecordList.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - selectRecord(); - } - }); - } - - private void createRecordComposite(Composite parent) - { - GridData gd1 = new GridData(); - gd1.widthHint = 200; - - Composite messageComposite = formUtil.createComposite(parent, 2); - - formUtil.createLabel(messageComposite, "Type Name Format "); - cmbRecordFormat = formUtil.createCombo(messageComposite); - cmbRecordFormat.setLayoutData(gd1); - formUtil.addComboItem(cmbRecordFormat, RecordFormatList); - cmbRecordFormat.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - Selected(e); - } - - public void widgetDefaultSelected(SelectionEvent e) { - Selected(e); - } - - private void Selected(SelectionEvent e) { - int i = cmbRecordFormat.getSelectionIndex(); - if (i != -1) { - checkRecordFormat(i + 1); - txtRecordTypeName.setText(""); - cmbRecordTypeName.select(0); - txtRecordID.setText(""); - txtRecordPayload.setText(""); - } - } - }); - - formUtil.createLabel(messageComposite, "Type Name "); - txtRecordTypeName = formUtil.createText(messageComposite, ""); - txtRecordTypeName.setEnabled(false); - txtRecordTypeName.setLayoutData(gd1); - txtRecordTypeName.setTextLimit(250); - txtRecordTypeName.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (bCheckTypeNameText == false) { - bCheckTypeNameText = true; - return; - } - if (checkInvalidCharaters(txtRecordTypeName.getText()) == false) { - txtRecordTypeName.setText(oldRecord.getTypeName()); - return; - } - oldRecord.setTypeName(txtRecordTypeName.getText()); - } - }); - - formUtil.createLabel(messageComposite, ""); - cmbRecordTypeName = formUtil.createCombo(messageComposite); - formUtil.addComboItem(cmbRecordTypeName, TypeNameList); - cmbRecordTypeName.setEnabled(false); - cmbRecordTypeName.setLayoutData(gd1); - - formUtil.createLabel(messageComposite, "ID "); - txtRecordID = formUtil.createText(messageComposite, ""); - txtRecordID.setEnabled(false); - txtRecordID.setLayoutData(gd1); - txtRecordID.setTextLimit(250); - txtRecordID.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (bCheckIDText == false) { - bCheckIDText = true; - return; - } - if (checkInvalidCharaters(txtRecordID.getText()) == false) { - txtRecordID.setText(oldRecord.getId()); - return; - } - oldRecord.setId(txtRecordID.getText()); - } - }); - - formUtil.createLabel(messageComposite, "Payload "); - txtRecordPayload = formUtil.createText(messageComposite, ""); - txtRecordPayload.setEnabled(false); - txtRecordPayload.setLayoutData(gd1); - txtRecordPayload.setTextLimit(1024); - txtRecordPayload.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (bCheckPayloadText == false) { - bCheckPayloadText = true; - return; - } - if (checkInvalidCharaters(txtRecordPayload.getText()) == false) { - txtRecordPayload.setText(oldRecord.getPayload()); - return; - } - oldRecord.setPayload(txtRecordPayload.getText()); - } - }); - - formUtil.createLabel(messageComposite, ""); - butSelectMediaFile = formUtil.createButton(messageComposite, - "Select Media File", SWT.PUSH); - butSelectMediaFile.setEnabled(false); - butSelectMediaFile.setLayoutData(new GridData(GridData.END, - GridData.END, false, false)); - butSelectMediaFile.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - selectMediaFile(); - } - }); - } - private void createTagSection() { - Composite client = formUtil.createSection(parent, "NFC Tag"); + Composite client = formUtil.createSection(parent, "NFC Tag"); Composite mainComposite = formUtil.createComposite(client, 3); formUtil.createLabel(mainComposite, "Tag Type "); @@ -319,12 +128,12 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener private void createP2PSection() { - Composite client = formUtil.createSection(parent, "Peer to Peer"); + Composite client = formUtil.createSection(parent, "Peer to Peer"); Composite mainComposite = formUtil.createComposite(client, 2); - butP2PDiscover = formUtil.createButton(mainComposite, "P2P Discovered", SWT.PUSH); - butP2PDetach = formUtil.createButton(mainComposite, "P2P Detached", SWT.PUSH); - butP2PSend = formUtil.createButton(mainComposite, "P2PSend", SWT.PUSH); + butP2PDiscover = formUtil.createButton(mainComposite, "P2P Discovered", SWT.PUSH); + butP2PDetach = formUtil.createButton(mainComposite, "P2P Detached", SWT.PUSH); + butP2PSend = formUtil.createButton(mainComposite, "P2PSend", SWT.PUSH); // TODO butP2PDiscover.setEnabled(true); @@ -360,164 +169,86 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener }); } - private void selectRecord() { - int i = cmbRecordList.getSelectionIndex(); - if (i != -1) { - NDEFRecord record = RecordList.get(i); - checkRecordFormat(record.getFormat()); - cmbRecordFormat.select(record.getFormat() - 1); - - if (record.getFormat() == 1) { - if (record.getTypeName().compareTo("U") == 0) - cmbRecordTypeName.select(0); - else - cmbRecordTypeName.select(1); - txtRecordTypeName.setText(""); - } else { - cmbRecordTypeName.select(0); - txtRecordTypeName.setText(record.getTypeName()); - } - - txtRecordID.setText(record.getId()); - txtRecordPayload.setText(record.getPayload()); + private void clickTagDiscovered() { + // check count of record list; + if (recordPage.getRecordList().size() == 0) { + NfcDialog.openInfoDialog(shell, NfcErrorString.RecordCountIsZero); + return; } - } - private boolean checkInvalidCharaters(String text) - { - char[] textArray = new char[1000]; - text.getChars(0, text.length(), textArray, 0); - - for (int i = 0; i < text.length(); i++) { - char c = textArray[i]; - if (c == '\n') { - NfcDialog.openInfoDialog(shell, "Can not enter a newline character."); - return false; - } - - if (c == ',') { - NfcDialog.openInfoDialog(shell, "Can not enter ',' character.\nThis character is used separater character."); - return false; - } - - if (c >= 0x80) { - NfcDialog.openInfoDialog(shell, "Invalid characters are entered.\nOnly ASCII characters can be entered.\n"); - return false; - } - } - return true; - } + boolean result = process.sendMessage(NfcCommand.NFC_TAG_DISCOVERED, + cmbTagTypeList.getSelectionIndex(), recordPage.getRecordList()); + if (result) { + recordPage.setDisableState(); - private void clickTagDiscovered() { - String msg = makeSendMessage(NfcCommand.NFC_TAG_DISCOVERED); - if (msg != null) { - sendMessage(msg); - { - cmbRecordFormat.setEnabled(false); - checkRecordFormat(0); - - cmbRecordList.setEnabled(false); - butRecordAdd.setEnabled(false); - butRecordEdit.setEnabled(false); - butRecordRemove.setEnabled(false); - - cmbTagTypeList.setEnabled(false); - butTagAttach.setEnabled(false); - butTagDetach.setEnabled(true); - - butP2PDiscover.setEnabled(false); - butP2PDetach.setEnabled(false); - butP2PSend.setEnabled(false); - } + cmbTagTypeList.setEnabled(false); + butTagAttach.setEnabled(false); + butTagDetach.setEnabled(true); + + butP2PDiscover.setEnabled(false); + butP2PDetach.setEnabled(false); + butP2PSend.setEnabled(false); } } private void clickTagDetached() { - String msg = makeSendMessage(NfcCommand.NFC_TAG_DETACHED); - if (msg != null) { - sendMessage(msg); - { - cmbRecordFormat.setEnabled(true); - - checkRecordFormat(cmbRecordFormat.getSelectionIndex() + 1); - txtRecordTypeName.setText(""); - cmbRecordTypeName.select(0); - txtRecordID.setText(""); - txtRecordPayload.setText(""); - - cmbRecordList.setEnabled(true); - butRecordAdd.setEnabled(true); - butRecordEdit.setEnabled(true); - butRecordRemove.setEnabled(true); - - cmbTagTypeList.setEnabled(true); - butTagAttach.setEnabled(true); - butTagDetach.setEnabled(false); - - butP2PDiscover.setEnabled(true); - butP2PDetach.setEnabled(false); - butP2PSend.setEnabled(false); - } + boolean result = process.sendMessage(NfcCommand.NFC_TAG_DETACHED, + cmbTagTypeList.getSelectionIndex(), recordPage.getRecordList()); + if (result) { + recordPage.setEnableState(); + + cmbTagTypeList.setEnabled(true); + butTagAttach.setEnabled(true); + butTagDetach.setEnabled(false); + + butP2PDiscover.setEnabled(true); + butP2PDetach.setEnabled(false); + butP2PSend.setEnabled(false); } } private void clickP2PDiscovered() { - String msg = makeSendMessage(NfcCommand.NFC_P2P_DISCOVERED); - if (msg != null) { - sendMessage(msg); - { - cmbTagTypeList.setEnabled(false); - butTagAttach.setEnabled(false); - butTagDetach.setEnabled(false); - - butP2PDiscover.setEnabled(false); - butP2PDetach.setEnabled(true); - butP2PSend.setEnabled(true); - } + boolean result = process.sendMessage(NfcCommand.NFC_P2P_DISCOVERED, + cmbTagTypeList.getSelectionIndex(), recordPage.getRecordList()); + if (result) { + cmbTagTypeList.setEnabled(false); + butTagAttach.setEnabled(false); + butTagDetach.setEnabled(false); + + butP2PDiscover.setEnabled(false); + butP2PDetach.setEnabled(true); + butP2PSend.setEnabled(true); } } private void clickP2PDetached() { - String msg = makeSendMessage(NfcCommand.NFC_P2P_DETACHED); - if (msg != null) { - sendMessage(msg); - { - cmbRecordFormat.setEnabled(true); - - checkRecordFormat(cmbRecordFormat.getSelectionIndex() + 1); - txtRecordTypeName.setText(""); - cmbRecordTypeName.select(0); - txtRecordID.setText(""); - txtRecordPayload.setText(""); - - cmbRecordList.setEnabled(true); - butRecordAdd.setEnabled(true); - butRecordEdit.setEnabled(true); - butRecordRemove.setEnabled(true); - - cmbTagTypeList.setEnabled(true); - butTagAttach.setEnabled(true); - butTagDetach.setEnabled(false); - - butP2PDiscover.setEnabled(true); - butP2PDetach.setEnabled(false); - butP2PSend.setEnabled(false); - } + boolean result = process.sendMessage(NfcCommand.NFC_P2P_DETACHED, + cmbTagTypeList.getSelectionIndex(), recordPage.getRecordList()); + if (result) { + recordPage.setEnableState(); + + cmbTagTypeList.setEnabled(true); + butTagAttach.setEnabled(true); + butTagDetach.setEnabled(false); + + butP2PDiscover.setEnabled(true); + butP2PDetach.setEnabled(false); + butP2PSend.setEnabled(false); } } private void clickP2PSend() { - String msg = makeSendMessage(NfcCommand.NFC_P2P_SEND); - if (msg != null) { - sendMessage(msg); - cmbRecordFormat.setEnabled(false); - checkRecordFormat(0); + // check count of record list; + if (recordPage.getRecordList().size() == 0) { + NfcDialog.openInfoDialog(shell, NfcErrorString.RecordCountIsZero); + return; + } - cmbRecordList.setEnabled(false); - butRecordAdd.setEnabled(false); - butRecordEdit.setEnabled(false); - butRecordRemove.setEnabled(false); + boolean result = process.sendMessage(NfcCommand.NFC_P2P_SEND, + cmbTagTypeList.getSelectionIndex(), recordPage.getRecordList()); + if (result) { + recordPage.setDisableState(); cmbTagTypeList.setEnabled(false); butTagAttach.setEnabled(false); @@ -529,379 +260,6 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener } } - private void checkRecordFormat(int format) - { - switch (format) { - case 0: // NDEF_TNF_EMPTY - cmbRecordTypeName.setEnabled(false); - txtRecordTypeName.setEnabled(false); - txtRecordID.setEnabled(false); - txtRecordPayload.setEnabled(false); - butSelectMediaFile.setEnabled(false); - break; - case 1: // NDEF_TNF_WELL_KNOWN - cmbRecordTypeName.setEnabled(true); - cmbRecordTypeName.select(0); - txtRecordTypeName.setEnabled(false); - txtRecordID.setEnabled(true); - txtRecordPayload.setEnabled(true); - txtRecordPayload.setEditable(true); - butSelectMediaFile.setEnabled(false); - break; - case 2: // NDEF_TNF_MIME_MEDIA - cmbRecordTypeName.setEnabled(false); - txtRecordTypeName.setEnabled(false); - txtRecordTypeName.setEditable(false); - txtRecordID.setEnabled(true); - txtRecordPayload.setEnabled(false); - txtRecordPayload.setEditable(false); - butSelectMediaFile.setEnabled(true); - break; - case 3: // NDEF_TNF_ABSOLUTE_URI - case 4: // NDEF_TNF_EXTERNAL - cmbRecordTypeName.setEnabled(false); - txtRecordTypeName.setEnabled(true); - txtRecordTypeName.setEditable(true); - txtRecordID.setEnabled(true); - txtRecordPayload.setEnabled(true); - txtRecordPayload.setEditable(true); - butSelectMediaFile.setEnabled(false); - break; - case 5: // NDEF_TNF_UNKNOWN - cmbRecordTypeName.setEnabled(false); - txtRecordTypeName.setEnabled(false); - txtRecordID.setEnabled(true); - txtRecordPayload.setEnabled(true); - txtRecordPayload.setEditable(true); - butSelectMediaFile.setEnabled(false); - break; - } - bCheckTypeNameText = false; - bCheckIDText = false; - bCheckPayloadText = false; - } - - private void addRecord() - { - if (RecordList.size() >= 5) { - NfcDialog.openInfoDialog(shell, "The number of NDEF records has reached the maximum limit of 5.\n"); - return; - } - - NDEFRecord record = new NDEFRecord(); - - /* - // check duplicate id !! - if (cmbRecordFormat.getSelectionIndex() != 0) { - if (!checkRecordID(txtRecordID.getText() != null ? txtRecordID.getText() : "Null")) { - return; - } - } - */ - - setRecordValue(record); - RecordList.add(record); - if (!checkRecordlistMaxLength()) { - RecordList.remove(record); - return; - } - - lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); - cmbRecordList.add("record item" + RecordList.indexOf(record)); - cmbRecordList.clearSelection(); - } - - private void editRecord() - { - int i = cmbRecordList.getSelectionIndex(); - if (i != -1) { - NDEFRecord record = RecordList.get(i); - /* - // check duplicate id !! - if (record.getFormat() != 0) { - if (!checkRecordID(txtRecordID.getText() != null ? txtRecordID.getText() : "Null", i)) { - return; - } - } - */ - - NDEFRecord copyRecord = record; - setRecordValue(record); - - if (!checkRecordlistMaxLength()) { - record = copyRecord; - return; - } - - lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); - // cmbRecordFormat.select(record.getFormat()); - // checkFormat(record.getFormat()); - } - } - - private void removeRecord() - { - int index = cmbRecordList.getSelectionIndex(); - if (index != -1) { - RecordList.remove(index); - cmbRecordList.removeAll(); - for (int i = 0; i < RecordList.size(); i++) { - cmbRecordList.add("record item" + i); - } - cmbRecordList.clearSelection(); - } - - checkRecordlistMaxLength(); - lblRecords.setText(String.format("Records [%4d/%d] ", nTotalLength, nMaxNDFEMessageLength)); - txtRecordTypeName.setText(""); - cmbRecordTypeName.select(0); - txtRecordID.setText(""); - txtRecordPayload.setText(""); - } - - private void setRecordValue(NDEFRecord record) - { - record.setFormat(cmbRecordFormat.getSelectionIndex() + 1); - - if ((cmbRecordFormat.getSelectionIndex() + 1) == 1) { - record.setTypeName(TypeNameList[cmbRecordTypeName.getSelectionIndex()]); - } else { - if (txtRecordTypeName.getText().isEmpty() == true) - record.setTypeName("Null"); - else - record.setTypeName(txtRecordTypeName.getText()); - } - - if (txtRecordID.getText().isEmpty() == true) - record.setId("Null"); - else - record.setId(txtRecordID.getText()); - - if (txtRecordPayload.getText().isEmpty() == true) - record.setPayload("Null"); - else - record.setPayload(txtRecordPayload.getText()); - } - -/* - private boolean checkRecordID(String id) - { - for (NDEFRecord record : RecordList) { - if (id.equals(record.getId())) { - NfcDialog.openInfoDialog(shell, "Duplicate ID is not allowed.\n"); - return false; - } - } - - return true; - } - - private boolean checkRecordID(String id, int except) - { - NDEFRecord record; - for (int i = 0; i < RecordList.size(); i++) { - if (i == except) - continue; - - record = RecordList.get(i); - if (id.equals(record.getId())) { - NfcDialog.openInfoDialog(shell, "Duplicate ID is not allowed.\n"); - return false; - } - } - - return true; - - } -*/ - - private boolean checkRecordlistMaxLength() - { - int lenList = 0; - - for (NDEFRecord record : RecordList) { - lenList += 1 + record.getTypeName().length() - + record.getId().length() + record.getPayload().length() + 4; - } - - if (lenList > nMaxNDFEMessageLength) { - NfcDialog.openInfoDialog(shell, String.format("The length of the NDEF message has reached the maxium limit of %d bytes\n", nMaxNDFEMessageLength)); - return false; - } - - nTotalLength = lenList; - - return true; - } - - private static String MediaFilePath = null; - private String shellCmd = null; - private String shellResult = null; - - private void selectMediaFile() - { - MediaFilePath = null; - if (shell != null) { - shell.getDisplay().syncExec(new Runnable() { - public void run() { - TizenRemoteFileDialog dlg = new TizenRemoteFileDialog( - shell, "Select a media file", currentDevice, false, - "/opt/nfc"); - if (dlg.open() == TizenRemoteFileDialogResult.OK) { - FileEntry fileEntry = dlg.getSelectedFileEntry(); - MediaFilePath = fileEntry.getFullPath(); - } - } - }); - } else { - NfcDialog.openErrorDialog("Can not open emulator's file dialog.\n"); - } - - if (MediaFilePath == null) { - NfcDialog.openErrorDialog(shell, "Please choose media file.\n"); - } else { - String type = null; - type = checkFileType(MediaFilePath); - if (type == null) { - NfcDialog.openErrorDialog(shell, "Type of selected file is not mime media type.\n"); - return; - } - if (checkFileSize(MediaFilePath) == false) { - NfcDialog.openErrorDialog(shell, "Size of selected file is too big. Available file size is under of 10KB.\n"); - return; - } - txtRecordTypeName.setEnabled(true); - txtRecordTypeName.setEditable(false); - txtRecordPayload.setEnabled(true); - txtRecordPayload.setEditable(false); - txtRecordTypeName.setText(type); - txtRecordPayload.setText(MediaFilePath); - } - } - - private String checkFileType(String filePath) { - int index = filePath.lastIndexOf('.'); - String type = null; - if (index != -1) { - String ex = filePath.substring(index + 1); - MimeTypeList typelist = MimeTypeList.getInstance(); - - type = typelist.findMimeType(ex); - } - return type; - } - - private boolean checkFileSize(String filePath) { - boolean result = false; - shellCmd = "du " + filePath; - try { - currentDevice.executeShellCommand(shellCmd, new MultiLineReceiver() { - @Override - public void processNewLines(String[] lines) { - shellResult = lines[0]; - } - - }); - } catch (TimeoutException e) { - errorSelectMediaFile(e); - return result; - } catch (SdbCommandRejectedException e) { - errorSelectMediaFile(e); - return result; - } catch (ShellCommandUnresponsiveException e) { - errorSelectMediaFile(e); - return result; - } catch (IOException e) { - errorSelectMediaFile(e); - return result; - } - - if (shellResult != null) { - int index = shellResult.indexOf('\t'); - if (index != -1) { - shellResult = shellResult.substring(0, index); - - if (Integer.valueOf(shellResult) <= 10) { - result = true; - } - } - } - return result; - } - - private void errorSelectMediaFile(Exception e) { - NfcDialog.openErrorDialog(shell, String.format("Throw exception while select media file : %s\n", e.getMessage())); - } - - private String makeSendMessage(Integer type) - { - String msg = null; - switch (type) { - case 100: // NFC_TAG_DISCOVERED - { - int tagtype = cmbTagTypeList.getSelectionIndex(); - if (tagtype != -1 && tagtype != 0) { - String records = new String(); - records += "," + RecordList.size(); - for (NDEFRecord record : RecordList) { - records += "," + record.getFormat() + "," - + record.getTypeName() + "," + record.getId() + "," - + record.getPayload(); - } - - msg = NfcCommand.NFC_TAG_DISCOVERED.toString() + ":" - + String.valueOf(tagtype) + records + "\n"; - - } else { - NfcDialog.openErrorDialog(shell, "Select Tag Type\n"); - return null; - } - } - break; - case 101: // NFC_TAG_DETACHED - msg = NfcCommand.NFC_TAG_DETACHED.toString() + ":" + "\n"; - break; - case 102: // NFC_P2P_DISCOVERED - msg = NfcCommand.NFC_P2P_DISCOVERED.toString() + ":\n"; - break; - case 103: // NFC_P2P_DETACHED - msg = NfcCommand.NFC_P2P_DETACHED.toString() + ":\n"; - break; - case 104: // NFC_P2P_SEND - { - int tagtype = 5; // for peer to peer - String records = new String(); - records += "," + RecordList.size(); - for (NDEFRecord record : RecordList) { - records += "," + record.getFormat() + "," - + record.getTypeName() + "," + record.getId() + "," - + record.getPayload(); - } - - msg = NfcCommand.NFC_P2P_SEND.toString() + ":" - + String.valueOf(tagtype) + records + "\n"; - } - break; - } - - return msg; - } - - public boolean sendMessage(String msg) - { - boolean result = false; - try { - // add for test - //NfcDialog.openInfoDialog(shell, msg); - result = injectorSocket.sendNfc(msg); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - return result; - } - private boolean checkDeviceConnectedAlready() { if (currentDevice == null) @@ -913,28 +271,24 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener @Override protected void registerReceivers() { - // TODO Auto-generated method stub - } // @Override public void connect() { - // TODO Auto-generated method stub currentDevice = ConnectionPlugin.getDefault().getCurrentDevice(); + recordPage.setCurrentDevice(currentDevice); } // @Override public void disconnect() { - // TODO Auto-generated method stub } @Override protected void finalize() throws Throwable { InjectorView.getDefault().removeSelectionListener(this); - // TargetConnectionControl.removeTargetConnectionListener(this); super.finalize(); } @@ -944,17 +298,20 @@ public class NfcPage extends AbstractInjectorPage implements ISelectionListener if (selectedEntry == null) { disconnect(); return; - } else if (!selectedEntry.getFileListingService().getDevice() - .isEmulator()) + } else if (!selectedEntry.getFileListingService().getDevice().isEmulator()) { return; + } - if(currentDevice == null && selectedEntry.getName() != null) { - connect(); - } else if(currentDevice == null && selectedEntry.getName() == null) { - return; - } else if (currentDevice.getSerialNumber() != selectedEntry.getName()) { - disconnect(); - connect(); + String selectedName = selectedEntry.getFileListingService().getDevice().getSerialNumber(); + if (currentDevice == null) { + if (selectedName != null) { + connect(); + } + } else { + if (currentDevice.getSerialNumber() != selectedName) { + disconnect(); + connect(); + } } } } \ No newline at end of file diff --git a/org.tizen.nfc/src/org/tizen/nfc/page/NfcStringResource.java b/org.tizen.nfc/src/org/tizen/nfc/page/NfcStringResource.java index 2c93807..873b904 100644 --- a/org.tizen.nfc/src/org/tizen/nfc/page/NfcStringResource.java +++ b/org.tizen.nfc/src/org/tizen/nfc/page/NfcStringResource.java @@ -28,11 +28,35 @@ package org.tizen.nfc.page; import java.util.ArrayList; -public class NfcStringResource +class NfcErrorString { + public static String RecordCountIsZero = "NDEF record list is empty\nAt least one or more records are required."; + public static String RecordCountIsMax = "The number of NDEF records has reached the maximum limit of 5.\n"; + + public static String MediaFileException = "Throw exception while select media file.\n"; + public static String CheckVconfException = "Throw exception while check NFC state of emulator.\n"; + + public static String SelecTagType = "Select Tag Type !!\n"; + + // check char of NFDE record + public static String InvalidCharNewLine = "Can not enter a newline character.\n"; + public static String InvalidChar = "Can not enter ',' character.\nThis character is used separater character.\n"; + public static String InvalidCharAscii = "Invalid characters are entered.\nOnly ASCII characters can be entered.\n"; + + // select media file + public static String FailOpenDialog = "Can not open emulator's file dialog.\n"; + public static String EmptyFilePath = "Please choose media file.\n"; + public static String NotMimeType = "Type of selected file is not mime media type.\n"; + public static String BigSizeFile = "Size of selected file is too big.\nAvailable file size is under of 10KB.\n"; + + // check vconf + public static String NFCIsDisable = "NFC state is 'Off' in the emulator.\nPlease change NFC state is 'On' on the setting menu."; +} + +class NfcStringArray { private ArrayList list; - public NfcStringResource() + public NfcStringArray() { list = new ArrayList(); } @@ -53,7 +77,7 @@ public class NfcStringResource } } -class TagType extends NfcStringResource +class TagType extends NfcStringArray { private static TagType tagtype = new TagType(); public static TagType getInstance() @@ -72,7 +96,7 @@ class TagType extends NfcStringResource } -class RecordFormat extends NfcStringResource +class RecordFormat extends NfcStringArray { private static RecordFormat format = new RecordFormat(); public static RecordFormat getInstance() @@ -91,7 +115,7 @@ class RecordFormat extends NfcStringResource } } -class TypeName extends NfcStringResource +class TypeName extends NfcStringArray { private static TypeName typename = new TypeName(); public static TypeName getInstance()