Back to project page NFCAndroid.
The source code is released under:
Copyright (c) 2012, Wireless Sensor Technologies, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following ...
If you think the Android project NFCAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gototags.nfc.records; /* www.java 2s .c o m*/ import com.google.common.base.Preconditions; import com.gototags.nfc.ndef.UriNdefRecord; import android.net.Uri; import android.nfc.NdefRecord; public class PhoneRecord extends Record { private String number; public PhoneRecord() { } public PhoneRecord(String number) { this.setNumber(number); } public String getNumber() { return this.number; } public void setNumber(String number) { this.number = number; } @Override public void Validate() { Preconditions.checkNotNull(this.getNumber(), "The number must not be null."); } @Override public boolean equals(Object obj) { if (this == obj) return true; else if (!(this instanceof PhoneRecord)) return false; else { PhoneRecord phoneRecord = (PhoneRecord)obj; return (this.getNumber() == null && phoneRecord.getNumber() == null) || (this.getNumber().equals(phoneRecord.getNumber())); } } @Override public int hashCode() { if (this.getNumber() == null) return 0; else return this.getNumber().hashCode(); } @Override public String toString() { return this.getNumber(); } @Override protected NdefRecord toNdefRecord() { try { String uriString = "tel:" + this.getNumber(); UriNdefRecord uriNdefRecord = new UriNdefRecord(Uri.parse(uriString)); return uriNdefRecord.toNdefRecord(); } catch (Exception exception) { throw new IllegalArgumentException(exception); } } public static PhoneRecord fromNdefRecord(NdefRecord ndefRecord) { Preconditions.checkNotNull(ndefRecord); try { UriNdefRecord uriNdefRecord = UriNdefRecord.fromNdefRecord(ndefRecord); Uri uri = uriNdefRecord.getUri(); String scheme = uri.getScheme().toLowerCase(); if ("tel".equals(scheme)) return new PhoneRecord(uri.toString().replace("tel:", "")); else throw new IllegalArgumentException("Invalid scheme '" + scheme + "'"); } catch (Exception exception) { throw new IllegalArgumentException(exception); } } public static boolean isPhoneRecord(NdefRecord ndefRecord) { try { PhoneRecord.fromNdefRecord(ndefRecord); return true; } catch (IllegalArgumentException illegalArgumentException) { return false; } } }