Code example for Parcel

Methods: writeInt, writeList, writeParcelable, writeString

0
			return 0; 
		} 
 
		@Override 
		public void writeToParcel(Parcel dest, int flags) {
			dest.writeString(mId);
			dest.writeParcelable(mGeoPoint, 0);
			dest.writeString(mTitle);
			dest.writeString(mPhotoUrl);
			dest.writeInt(mStatus.ordinal());
		} 
		 
		public GeoPoint getGeoPoint() { 
			return mGeoPoint;
		} 
		 
		public String getId() {
			return mId;
		} 
		 
		public String getTitle() {
			return mTitle;
		} 
		 
		public String getPhotoUrl() {
			return mPhotoUrl;
		} 
		 
		public TourSiteStatus getStatus() { 
			return mStatus;
		} 
		 
		public static interface LocationSupplier { 
			public Location getLocation();
		} 
		 
		LocationSupplier mLocationSupplier;
		public void setLocationSupplier(LocationSupplier locationSupplier) {
			mLocationSupplier = locationSupplier;
		} 
		 
		public Float distance() {
			if(mLocationSupplier == null) {
				return null; 
			} 
			 
			Location location = mLocationSupplier.getLocation();
			if(location == null) {
				return null; 
			} 
			 
			float[] distance = new float[1];
			double endLatitude = mGeoPoint.getLatitudeE6() / 1E6;
			double endLongitude = mGeoPoint.getLongitudeE6() / 1E6;
			 
			Location.distanceBetween(location.getLatitude(), location.getLongitude(), endLatitude, endLongitude, distance);
			return distance[0];
		} 
		 
		public float distanceBetween(TourMapItem other) {
			float[] distance = new float[1];
			double startLatitude = this.getGeoPoint().getLatitudeE6() / 1E6;
			double startLongitude = this.getGeoPoint().getLongitudeE6() / 1E6;
			 
			double endLatitude = other.getGeoPoint().getLatitudeE6() / 1E6;
			double endLongitude = other.getGeoPoint().getLongitudeE6() / 1E6;
			 
			Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, distance);
			return distance[0];
		} 
	} 
	 
	public static class SiteTourMapItem extends TourMapItem { 
		private ArrayList<SideTripTourMapItem> mSideTrips = new ArrayList<SideTripTourMapItem>();
		 
		SiteTourMapItem(TourMapItem i) {
			super(i.mId, i.mGeoPoint, i.mTitle, i.mPhotoUrl, i.mStatus);
		}		 
		 
		public static final Parcelable.Creator<SiteTourMapItem> CREATOR = new Parcelable.Creator<SiteTourMapItem>() {
 
			@Override 
			public SiteTourMapItem createFromParcel(Parcel source) { 
				TourMapItem item = TourMapItem.readItem(source); 
				SiteTourMapItem site = new SiteTourMapItem(item); 
				 
				@SuppressWarnings("unchecked") 
				ArrayList<SideTripTourMapItem> sideTrips = source.readArrayList(SideTripTourMapItem.class.getClassLoader()); 
				for(SideTripTourMapItem sideTrip : sideTrips) { 
					sideTrip.setParent(site); 
					site.addSideTrip(sideTrip); 
				} 
				return site; 
			} 
 
			@Override 
			public SiteTourMapItem[] newArray(int size) { 
				return new SiteTourMapItem[size]; 
			} 
		}; 
		 
		@Override 
		public int describeContents() { 
			return 0; 
		} 
		 
		@Override 
		public void writeToParcel(Parcel dest, int flags) {
			super.writeToParcel(dest, flags);
			dest.writeList(mSideTrips);
		} 
		 
		String getSiteGuid() {
			return getId(); 
		}