コード例 #1
0
ファイル: NDEFRecord.cs プロジェクト: zerenat/testRepo
        public virtual void ParseJSON(JSONObject jsonObject)
        {
            int typeValue;

            jsonObject.TryGetInt("type", out typeValue);
            type = (NDEFRecordType)typeValue;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        public void OnAddRecordClick()
        {
            if (pendingMessage == null)
            {
                pendingMessage = new NDEFMessage();
            }

            NDEFRecord     record = null;
            string         value  = view.TypeDropdown.options[view.TypeDropdown.value].text;
            NDEFRecordType type   = (NDEFRecordType)Enum.Parse(typeof(NDEFRecordType), value);

            switch (type)
            {
            case NDEFRecordType.TEXT:
                string text         = view.TextInput.text;
                string languageCode = view.LanguageCodeInput.text;
                if (languageCode.Length != 2)
                {
                    languageCode = "en";
                }
                TextRecord.TextEncoding textEncoding = (TextRecord.TextEncoding)view.TextEncodingDropdown.value;
                record = new TextRecord(text, languageCode, textEncoding);
                break;

            case NDEFRecordType.URI:
                string uri = view.UriInput.text;
                record = new UriRecord(uri);
                break;

            case NDEFRecordType.MIME_MEDIA:
                string mimeType = "image/png";                         //We're only using png images atm
                IconID iconID   = (IconID)view.IconDropdown.value;
                byte[] mimeData = GetIconBytes(iconID);
                record = new MimeMediaRecord(mimeType, mimeData);
                break;

            case NDEFRecordType.EXTERNAL_TYPE:
                string domainName       = view.DomainNameInput.text;
                string domainType       = view.DomainTypeInput.text;
                string domainDataString = view.DomainDataInput.text;
                byte[] domainData       = Encoding.UTF8.GetBytes(domainDataString);                   //Data represents a string in this example
                record = new ExternalTypeRecord(domainName, domainType, domainData);
                break;
            }

            pendingMessage.Records.Add(record);

            view.UpdateNDEFMessage(pendingMessage);
        }
コード例 #4
0
        public void OnRecordTypeChanged(int index)
        {
            string         value = view.TypeDropdown.options[index].text;
            NDEFRecordType type  = (NDEFRecordType)Enum.Parse(typeof(NDEFRecordType), value);

            switch (type)
            {
            case NDEFRecordType.TEXT: view.SwitchToTextRecordInput(); break;

            case NDEFRecordType.URI: view.SwitchToUriInput(); break;

            case NDEFRecordType.MIME_MEDIA: view.SwitchToMimeMediaInput(); break;

            case NDEFRecordType.EXTERNAL_TYPE: view.SwitchToExternalTypeInput(); break;
            }
        }
コード例 #5
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++)
                {
                    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);
        }