Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2次元と仲良くしようと思いました

 2次元と仲良くしようと思いました

NFCLab8月定例会の発表資料

Takahiro Shimokawa

August 25, 2012
Tweet

More Decks by Takahiro Shimokawa

Other Decks in Programming

Transcript

  1. NDEFϝοηʔδಡΈࠐΈ private String getUrl(NdefMessage msg) { // NDEFϨίʔυ͔ΒTNFΛऔΓग़͢ NdefRecord[] records

    = msg.getRecords(); short tnf = records[0].getTnf(); if (tnf == NdefRecord.TNF_WELL_KNOWN) { return parseWellKnown(records[0]); } else if (tnf == NdefRecord.TNF_ABSOLUTE_URI) { return parseAbsolute(records[0]); } throw new IllegalArgumentException("Unknown TNF " + tnf); } 12೥8݄25೔౔༵೔
  2. NDEFϨίʔυಡΈࠐΈ private String parseAbsolute(NdefRecord record) { byte[] payload = record.getPayload();

    return new String(payload, Charset.forName("UTF-8")); } private String parseWellKnown(NdefRecord record) { // RTD Uri͔νΣοΫ if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) { byte[] payload = record.getPayload(); String prefix = prefixMap.get(payload[0]); byte[] uriData = Arrays.copyOfRange(payload, 1, payload.length); String uri = new String(uriData, Charset.forName("UTF-8")); return prefix.concat(uri); } throw new IllegalArgumentException("Not Support RTD"); } 12೥8݄25೔౔༵೔
  3. RecordsϚοϐϯά Name Offset Size Value Description Identifier code 0 1

    byte URI identifier code The URI identifier code, as specified in Table 3. URI field 1 N UTF-8 string The rest of the URI, or the entire URI (if identifier code is 0x00). Ҿ༻ɿNFC URI RTD Technical Specification http://www.nfc-forum.org/specs/spec_list/#rtds 12೥8݄25೔౔༵೔
  4. Decimal Hex Protocol 0 0x00 N/A 1 0x01 http://www. 2

    0x02 https://www. 3 0x03 http:// 4 0x04 https:// 5 0x05 tel: 6 0x06 mailto: 7 0x07 ftp://anonymous:anonymous@ 8 0x08 ftp://ftp. 9 0x09 ftps:// 10 0x0A sftp:// 11 0x0B smb:// 12 0x0C nfs:// 13 0x0D ftp:// 14 0x0E dav:// 15 0x0F news: 16 0x10 telnet:// 17 0x11 imap: Decimal Hex Protocol 18 0x12 rtsp:// 19 0x13 urn: 20 0x14 pop: 21 0x15 sip: 22 0x16 sips: 23 0x17 tftp: 24 0x18 btspp:// 25 0x19 btl2cap:// 26 0x1A btgoep:// 27 0x1B tcpobex:// 28 0x1C irdaobex:// 29 0x1D file:// 30 0x1E urn:epc:id: 31 0x1F urn:epc:tag: 32 0x20 urn:epc:pat: 33 0x21 urn:epc:raw: 34 0x22 urn:epc: 35 0x23 urn:nfc: 36...255 0x24...0xFF RFU URI identifier code 12೥8݄25೔౔༵೔
  5. private String getUrl(NdefMessage msg) { // NDEFϨίʔυ͔ΒTNFΛऔΓग़͢ NdefRecord[] records =

    msg.getRecords(); short tnf = records[0].getTnf(); if (tnf == NdefRecord.TNF_WELL_KNOWN) { // URLΛऔΓग़͢ return parseWellKnown(records[0]); } else if (tnf == NdefRecord.TNF_ABSOLUTE_URI) { // URLΛऔΓग़͢ return parseAbsolute(records[0]); } throw new IllegalArgumentException("Unknown TNF " + tnf); } 12೥8݄25೔౔༵೔
  6. public Bitmap createQRCodeByZxing(String contents, int size) throws WriterException { QRCodeWriter

    qrWriter = new QRCodeWriter(); // ҟͳΔܕͷ஋ΛೖΕΔͨΊgeneric͸࢖͑ͳ͍ @SuppressWarnings("rawtypes") Hashtable encodeHint = new Hashtable(); encodeHint.put(EncodeHintType.CHARACTER_SET, "shiftjis"); // Τϥʔम෮ϨϕϧΛࢦఆ encodeHint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); BitMatrix qrCodeData = qrWriter.encode(contents, BarcodeFormat.QR_CODE, size, size, encodeHint); // QRίʔυͷbitmapը૾Λੜ੒ Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); bitmap.eraseColor(Color.argb(255, 255, 255, 255)); for(int x = 0; x < qrCodeData.getWidth(); x++) { for(int y = 0; y < qrCodeData.getHeight(); y++) { if(qrCodeData.get(x, y)) { // true͸Black bitmap.setPixel(x, y, Color.BLACK); } else { // false͸White bitmap.setPixel(x, y, Color.WHITE); } } } return bitmap; } 12೥8݄25೔౔༵೔
  7. QRίʔυੜ੒ͷΠϝʔδ T F T T F T T F F

    F F F T T T F T F T T F T F T T F T T F T T F T F F F F F T F F F T T T F T T F F F T T F F F T T F T F F F T T F F T T F T F F T T T F F T F T 12೥8݄25೔౔༵೔
  8. ·ͱΊ̍ NDEFϝοηʔδ ࢓༷Λཧղ͢Δ TNF = Type Name Format RTD =

    Record Type Definition 12೥8݄25೔౔༵೔