Beispiel #1
0
        public override void ParseJSON(JSONObject jsonObject)
        {
            base.ParseJSON(jsonObject);

            JSONObject uriRecordJSON;

            if (jsonObject.TryGetObject("uri_record", out uriRecordJSON))
            {
                uriRecord = new UriRecord(uriRecordJSON);
            }

            titleRecords = new List <TextRecord>();
            JSONArray titleRecordsJSON;

            if (jsonObject.TryGetArray("title_records", out titleRecordsJSON))
            {
                int length = titleRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    titleRecords.Add(new TextRecord(titleRecordsJSON[i].Object));
                }
            }

            iconRecords = new List <MimeMediaRecord>();
            JSONArray iconRecordsJSON;

            if (jsonObject.TryGetArray("icon_records", out iconRecordsJSON))
            {
                int length = iconRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    iconRecords.Add(new MimeMediaRecord(iconRecordsJSON[i].Object));
                }
            }

            extraRecords = new List <NDEFRecord>();
            JSONArray extraRecordsJSON;

            if (jsonObject.TryGetArray("extra_records", out extraRecordsJSON))
            {
                int length = extraRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    extraRecords.Add(new MimeMediaRecord(extraRecordsJSON[i].Object));
                }
            }

            int actionValue;

            jsonObject.TryGetInt("action", out actionValue);
            action = (RecommendedAction)actionValue;

            jsonObject.TryGetInt("size", out size);
            jsonObject.TryGetString("mime_type", out mimeType);
        }
Beispiel #2
0
 public SmartPosterRecord(string uri, RecommendedAction action, int size, string mimeType, List <TextRecord> titleRecords, List <MimeMediaRecord> iconRecords, List <NDEFRecord> extraRecords)
 {
     this.type         = NDEFRecordType.SMART_POSTER;
     this.uriRecord    = new UriRecord(uri);
     this.titleRecords = titleRecords;
     this.iconRecords  = iconRecords;
     this.extraRecords = extraRecords;
     this.action       = action;
     this.size         = size;
     this.mimeType     = mimeType;
 }
Beispiel #3
0
 public SmartPosterRecord(string uri, RecommendedAction action = RecommendedAction.UNKNOWN, int size = 0, string mimeType = "")
 {
     this.type         = NDEFRecordType.SMART_POSTER;
     this.uriRecord    = new UriRecord(uri);
     this.action       = action;
     this.size         = size;
     this.mimeType     = mimeType;
     this.titleRecords = new List <TextRecord>();
     this.iconRecords  = new List <MimeMediaRecord>();
     this.extraRecords = new List <NDEFRecord>();
 }
        public void ParseJSON(JSONObject jsonObject)
        {
            JSONArray recordsJSON;

            if (jsonObject.TryGetArray("records", out recordsJSON))
            {
                int length = recordsJSON.Length;
                records = new List <NDEFRecord>();
                for (int i = 0; i < length; i++)
                {
                    JSONObject recordJSON = recordsJSON[i].Object;
                    int        typeValue;
                    recordJSON.TryGetInt("type", out typeValue);
                    NDEFRecordType type   = (NDEFRecordType)typeValue;
                    NDEFRecord     record = null;
                    switch (type)
                    {
                    case NDEFRecordType.ABSOLUTE_URI: record = new AbsoluteUriRecord(recordJSON); break;

                    case NDEFRecordType.EMPTY: record = new EmptyRecord(recordJSON); break;

                    case NDEFRecordType.EXTERNAL_TYPE: record = new ExternalTypeRecord(recordJSON); break;

                    case NDEFRecordType.MIME_MEDIA: record = new MimeMediaRecord(recordJSON); break;

                    case NDEFRecordType.SMART_POSTER: record = new SmartPosterRecord(recordJSON); break;

                    case NDEFRecordType.TEXT: record = new TextRecord(recordJSON); break;

                    case NDEFRecordType.UNKNOWN: record = new UnknownRecord(recordJSON); break;

                    case NDEFRecordType.URI: record = new UriRecord(recordJSON); break;
                    }

                    records.Add(record);
                }
            }
            else
            {
                records = new List <NDEFRecord>();
            }

            jsonObject.TryGetString("tag_id", out tagID);

            int writeStateValue;

            jsonObject.TryGetInt("write_state", out writeStateValue);
            writeState = (NDEFMessageWriteState)writeStateValue;

            int writeErrorValue;

            jsonObject.TryGetInt("write_error", out writeErrorValue);
            writeError = (NDEFMessageWriteError)writeErrorValue;
        }
        public override void ParseJSON(JSONObject jsonObject)
        {
            base.ParseJSON(jsonObject);

            JSONObject uriRecordJSON;

            if (jsonObject.TryGetObject("uri_record", out uriRecordJSON))
            {
                uriRecord = new UriRecord(uriRecordJSON);
            }

            titleRecords = new List <TextRecord>();
            JSONArray titleRecordsJSON;

            if (jsonObject.TryGetArray("title_records", out titleRecordsJSON))
            {
                int length = titleRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    titleRecords.Add(new TextRecord(titleRecordsJSON[i].Object));
                }
            }

            iconRecords = new List <MimeMediaRecord>();
            JSONArray iconRecordsJSON;

            if (jsonObject.TryGetArray("icon_records", out iconRecordsJSON))
            {
                int length = iconRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    iconRecords.Add(new MimeMediaRecord(iconRecordsJSON[i].Object));
                }
            }

            extraRecords = new List <NDEFRecord>();
            JSONArray extraRecordsJSON;

            if (jsonObject.TryGetArray("extra_records", out extraRecordsJSON))
            {
                int length = extraRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    JSONObject     extraRecordJSON = extraRecordsJSON[i].Object;
                    NDEFRecord     record          = null;
                    NDEFRecordType type            = (NDEFRecordType)extraRecordJSON["type"].Integer;
                    switch (type)
                    {
                    case NDEFRecordType.ABSOLUTE_URI: record = new AbsoluteUriRecord(extraRecordJSON); break;

                    case NDEFRecordType.EMPTY: record = new EmptyRecord(extraRecordJSON); break;

                    case NDEFRecordType.EXTERNAL_TYPE: record = new ExternalTypeRecord(extraRecordJSON); break;

                    case NDEFRecordType.MIME_MEDIA: record = new MimeMediaRecord(extraRecordJSON); break;

                    case NDEFRecordType.SMART_POSTER: record = new SmartPosterRecord(extraRecordJSON); break;

                    case NDEFRecordType.TEXT: record = new TextRecord(extraRecordJSON); break;

                    case NDEFRecordType.UNKNOWN: record = new UnknownRecord(extraRecordJSON); break;

                    case NDEFRecordType.URI: record = new UriRecord(extraRecordJSON); break;

                    default: record = new UnknownRecord(extraRecordJSON); break;
                    }

                    extraRecords.Add(record);
                }
            }

            int actionValue;

            jsonObject.TryGetInt("action", out actionValue);
            action = (RecommendedAction)actionValue;

            jsonObject.TryGetInt("size", out size);
            jsonObject.TryGetString("mime_type", out mimeType);
        }