Package org.nfctools.ndef.wkt.records

Examples of org.nfctools.ndef.wkt.records.SmartPosterRecord


    UriRecord uriRecord = new UriRecord("http://www.google.com/");
    return uriRecord;
  }

  public static SmartPosterRecord createSmartPoster() {
    SmartPosterRecord spr = new SmartPosterRecord();
    spr.setTitle(new TextRecord("Hello, this is a SmartPosterTag for NFC Tools", Charset.forName("UTF8"),
        Locale.ENGLISH));
    spr.setUri(new UriRecord("http://www.nfctools.org"));
    spr.setAction(new ActionRecord(Action.DEFAULT_ACTION));
    return spr;
  }
View Full Code Here


  @Test
  public void testDecode() throws Exception {
    Record record = NdefContext.getNdefMessageDecoder().decodeToRecord(NfcUtils.convertASCIIToBin(smartPoster));
    assertTrue(record instanceof SmartPosterRecord);
    SmartPosterRecord smartPosterRecord = (SmartPosterRecord)record;

    assertEquals("Title", smartPosterRecord.getTitle().getText());
    assertEquals(Action.DEFAULT_ACTION, smartPosterRecord.getAction().getAction());
    assertEquals("http://www.winfuture.de", smartPosterRecord.getUri().getUri());

  }
View Full Code Here

    byte[] payload = NfcUtils.convertASCIIToBin(innerSmartPoster);

    Record record = decoder.decodePayload(payload, NdefContext.getNdefMessageDecoder());
    assertTrue(record instanceof SmartPosterRecord);

    SmartPosterRecord smartPosterRecord = (SmartPosterRecord)record;

    assertEquals("Test", smartPosterRecord.getTitle().getText());
    assertEquals(Locale.GERMAN.getLanguage(), smartPosterRecord.getTitle().getLocale().getLanguage());
    assertEquals("sms:+491234567890?body=Hi!%20Wie%20geht%20es%20dir%3F", smartPosterRecord.getUri().getUri());
  }
View Full Code Here

  private String innerSmartPoster = "D10245537091010754026465546573745101365500736D733A2B3439313233343536373839"
      + "303F626F64793D486921253230576965253230676568742532306573253230646972253346";

  @Test
  public void testEncode() throws Exception {
    SmartPosterRecord smartPosterRecord = new SmartPosterRecord();
    smartPosterRecord.setTitle(new TextRecord("Test", Charset.forName("UTF8"), Locale.GERMAN));
    smartPosterRecord.setUri(new UriRecord("sms:+491234567890?body=Hi!%20Wie%20geht%20es%20dir%3F"));
    byte[] payload = messageEncoder.encodeSingle(smartPosterRecord);
    assertEquals(innerSmartPoster, NfcUtils.convertBinToASCII(payload));
  }
View Full Code Here

    assertEquals(innerSmartPoster, NfcUtils.convertBinToASCII(payload));
  }

  @Test
  public void testEncode2() throws Exception {
    SmartPosterRecord smartPosterRecord = new SmartPosterRecord();
    smartPosterRecord.setTitle(new TextRecord("Title", Charset.forName("UTF8"), Locale.GERMANY));
    smartPosterRecord.setUri(new UriRecord("http://www.winfuture.de"));
    smartPosterRecord.setAction(new ActionRecord(Action.DEFAULT_ACTION));
    byte[] payload = messageEncoder.encodeSingle(smartPosterRecord);
    assertEquals(SmartPosterDecoderTest.smartPoster, NfcUtils.convertBinToASCII(payload));
  }
View Full Code Here

public class SmartPosterRecordDecoder implements WellKnownRecordPayloadDecoder {

  @Override
  public WellKnownRecord decodePayload(byte[] payload, NdefMessageDecoder messageDecoder) {
    SmartPosterRecord smartPosterRecord = new SmartPosterRecord();

    List<Record> records = messageDecoder.decodeToRecords(messageDecoder.decode(payload));

    for (Record record : records) {
      if (record instanceof UriRecord) {
        smartPosterRecord.setUri((UriRecord)record);
      }
      else if (record instanceof TextRecord) {
        smartPosterRecord.setTitle((TextRecord)record);
      }
      else if (record instanceof ActionRecord) {
        smartPosterRecord.setAction((ActionRecord)record);
      }
    }
    return smartPosterRecord;
  }
View Full Code Here

public class SmartPosterRecordEncoder implements WellKnownRecordPayloadEncoder {

  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {
    SmartPosterRecord myRecord = (SmartPosterRecord)wellKnownRecord;
    return createPayload(messageEncoder, myRecord);
  }
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.wkt.records.SmartPosterRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.