FileDocCategorySizeDatePackage
Address.javaAPI DocAndroid 1.5 API14960Wed May 06 22:42:00 BST 2009android.location

Address

public class Address extends Object implements android.os.Parcelable
A class representing an Address, i.e, a set of Strings describing a location. The addres format is a simplified version of xAL (eXtensible Address Language) http://www.oasis-open.org/committees/ciq/ciq.html#6

Fields Summary
private Locale
mLocale
private String
mFeatureName
private HashMap
mAddressLines
private int
mMaxAddressLineIndex
private String
mAdminArea
private String
mSubAdminArea
private String
mLocality
private String
mThoroughfare
private String
mPostalCode
private String
mCountryCode
private String
mCountryName
private double
mLatitude
private double
mLongitude
private boolean
mHasLatitude
private boolean
mHasLongitude
private String
mPhone
private String
mUrl
private android.os.Bundle
mExtras
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Address(Locale locale)
Constructs a new Address object set to the given Locale and with all other fields initialized to null or false.


                             
       
        mLocale = locale;
    
Methods Summary
public voidclearLatitude()
Removes any latitude associated with this address.

        mHasLatitude = false;
    
public voidclearLongitude()
Removes any longitude associated with this address.

        mHasLongitude = false;
    
public intdescribeContents()


       
        return (mExtras != null) ? mExtras.describeContents() : 0;
    
public java.lang.StringgetAddressLine(int index)
Returns a line of the address numbered by the given index (starting at 0), or null if no such line is present.

throws
IllegalArgumentException if index < 0

        if (index < 0) {
            throw new IllegalArgumentException("index = " + index + " < 0");
        }
        return mAddressLines == null? null :  mAddressLines.get(index);
    
public java.lang.StringgetAdminArea()
Returns the administrative area name of the address, for example, "CA", or null if it is unknown

        return mAdminArea;
    
public java.lang.StringgetCountryCode()
Returns the country code of the address, for example "US", or null if it is unknown.

        return mCountryCode;
    
public java.lang.StringgetCountryName()
Returns the localized country name of the address, for example "Iceland", or null if it is unknown.

        return mCountryName;
    
public android.os.BundlegetExtras()
Returns additional provider-specific information about the address as a Bundle. The keys and values are determined by the provider. If no additional information is available, null is returned.

        return mExtras;
    
public java.lang.StringgetFeatureName()
Returns the feature name of the address, for example, "Golden Gate Bridge", or null if it is unknown

        return mFeatureName;
    
public doublegetLatitude()
Returns the latitude of the address if known.

throws
IllegalStateException if this Address has not been assigned a latitude.

        if (mHasLatitude) {
            return mLatitude;
        } else {
            throw new IllegalStateException();
        }
    
public java.util.LocalegetLocale()
Returns the Locale associated with this address.

        return mLocale;
    
public java.lang.StringgetLocality()
Returns the locality of the address, for example "Mountain View", or null if it is unknown.

        return mLocality;
    
public doublegetLongitude()
Returns the longitude of the address if known.

throws
IllegalStateException if this Address has not been assigned a longitude.

        if (mHasLongitude) {
            return mLongitude;
        } else {
            throw new IllegalStateException();
        }
    
public intgetMaxAddressLineIndex()
Returns the largest index currently in use to specify an address line. If no address lines are specified, -1 is returned.

        return mMaxAddressLineIndex;
    
public java.lang.StringgetPhone()
Returns the phone number of the address if known, or null if it is unknown.

throws
IllegalStateException if this Address has not been assigned a latitude.

        return mPhone;
    
public java.lang.StringgetPostalCode()
Returns the postal code of the address, for example "94110", or null if it is unknown.

        return mPostalCode;
    
public java.lang.StringgetSubAdminArea()
Returns the sub-administrative area name of the address, for example, "Santa Clara County", or null if it is unknown

        return mSubAdminArea;
    
public java.lang.StringgetThoroughfare()
Returns the thoroughfare name of the address, for example, "1600 Ampitheater Parkway", which may be null

        return mThoroughfare;
    
public java.lang.StringgetUrl()
Returns the public URL for the address if known, or null if it is unknown.

        return mUrl;
    
public booleanhasLatitude()
Returns true if a latitude has been assigned to this Address, false otherwise.

        return mHasLatitude;
    
public booleanhasLongitude()
Returns true if a longitude has been assigned to this Address, false otherwise.

        return mHasLongitude;
    
public voidsetAddressLine(int index, java.lang.String line)
Sets the line of the address numbered by index (starting at 0) to the given String, which may be null.

throws
IllegalArgumentException if index < 0

        if (index < 0) {
            throw new IllegalArgumentException("index = " + index + " < 0");
        }
        if (mAddressLines == null) {
            mAddressLines = new HashMap<Integer, String>();
        }
        mAddressLines.put(index, line);

        if (line == null) {
            // We've eliminated a line, recompute the max index
            mMaxAddressLineIndex = -1;
            for (Integer i : mAddressLines.keySet()) {
                mMaxAddressLineIndex = Math.max(mMaxAddressLineIndex, i);
            }
        } else {
            mMaxAddressLineIndex = Math.max(mMaxAddressLineIndex, index);
        }
    
public voidsetAdminArea(java.lang.String adminArea)
Sets the administrative area name of the address to the given String, which may be null

        this.mAdminArea = adminArea;
    
public voidsetCountryCode(java.lang.String countryCode)
Sets the country code of the address to the given String, which may be null.

        mCountryCode = countryCode;
    
public voidsetCountryName(java.lang.String countryName)
Sets the country name of the address to the given String, which may be null.

        mCountryName = countryName;
    
public voidsetExtras(android.os.Bundle extras)
Sets the extra information associated with this fix to the given Bundle.

        mExtras = (extras == null) ? null : new Bundle(extras);
    
public voidsetFeatureName(java.lang.String featureName)
Sets the feature name of the address to the given String, which may be null

        mFeatureName = featureName;
    
public voidsetLatitude(double latitude)
Sets the latitude associated with this address.

        mLatitude = latitude;
        mHasLatitude = true;
    
public voidsetLocality(java.lang.String locality)
Sets the locality of the address to the given String, which may be null.

        mLocality = locality;
    
public voidsetLongitude(double longitude)
Sets the longitude associated with this address.

        mLongitude = longitude;
        mHasLongitude = true;
    
public voidsetPhone(java.lang.String phone)
Sets the phone number associated with this address.

        mPhone = phone;
    
public voidsetPostalCode(java.lang.String postalCode)
Sets the postal code of the address to the given String, which may be null.

        mPostalCode = postalCode;
    
public voidsetSubAdminArea(java.lang.String subAdminArea)
Sets the sub-administrative area name of the address to the given String, which may be null

        this.mSubAdminArea = subAdminArea;
    
public voidsetThoroughfare(java.lang.String thoroughfare)
Sets the thoroughfare name of the address, which may be null.

        this.mThoroughfare = thoroughfare;
    
public voidsetUrl(java.lang.String Url)
Sets the public URL associated with this address.

        mUrl = Url;
    
public java.lang.StringtoString()

        StringBuilder sb = new StringBuilder();
        sb.append("Address[addressLines=[");
        for (int i = 0; i <= mMaxAddressLineIndex; i++) {
            if (i > 0) {
                sb.append(',");
            }
            sb.append(i);
            sb.append(':");
            String line = mAddressLines.get(i);
            if (line == null) {
                sb.append("null");
            } else {
                sb.append('\"");
                sb.append(line);
                sb.append('\"");
            }
        }
        sb.append(']");
        sb.append(",feature=");
        sb.append(mFeatureName);
        sb.append(",admin=");
        sb.append(mAdminArea);
        sb.append(",sub-admin=");
        sb.append(mSubAdminArea);
        sb.append(",locality=");
        sb.append(mLocality);
        sb.append(",thoroughfare=");
        sb.append(mThoroughfare);
        sb.append(",postalCode=");
        sb.append(mPostalCode);
        sb.append(",countryCode=");
        sb.append(mCountryCode);
        sb.append(",countryName=");
        sb.append(mCountryName);
        sb.append(",hasLatitude=");
        sb.append(mHasLatitude);
        sb.append(",latitude=");
        sb.append(mLatitude);
        sb.append(",hasLongitude=");
        sb.append(mHasLongitude);
        sb.append(",longitude=");
        sb.append(mLongitude);
        sb.append(",phone=");
        sb.append(mPhone);
        sb.append(",url=");
        sb.append(mUrl);
        sb.append(",extras=");
        sb.append(mExtras);
        sb.append(']");
        return sb.toString();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        parcel.writeString(mLocale.getLanguage());
        parcel.writeString(mLocale.getCountry());
        if (mAddressLines == null) {
            parcel.writeInt(0);
        } else {
            Set<Map.Entry<Integer, String>> entries = mAddressLines.entrySet();
            parcel.writeInt(entries.size());
            for (Map.Entry<Integer, String> e : entries) {
                parcel.writeInt(e.getKey());
                parcel.writeString(e.getValue());
            }
        }
        parcel.writeString(mFeatureName);
        parcel.writeString(mAdminArea);
        parcel.writeString(mSubAdminArea);
        parcel.writeString(mLocality);
        parcel.writeString(mThoroughfare);
        parcel.writeString(mPostalCode);
        parcel.writeString(mCountryCode);
        parcel.writeString(mCountryName);
        parcel.writeInt(mHasLatitude ? 1 : 0);
        if (mHasLatitude) {
            parcel.writeDouble(mLatitude);
        }
        parcel.writeInt(mHasLongitude ? 1 : 0);
        if (mHasLongitude){
            parcel.writeDouble(mLongitude);
        }
        parcel.writeString(mPhone);
        parcel.writeString(mUrl);
        parcel.writeBundle(mExtras);