package com.Facebook.entities;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import com.Facebook.utils.Logger;
import java.io.File;
import java.io.FileNotFoundException;
public class Photo
{
private static final String PICTURE = "picture";
private static final String PLACE = "place";
private static final String MESSAGE = "message";
private String mDescription = null;
private String mPlaceId = null;
private Parcelable mParcelable = null;
private byte[] mBytes = null;
public Photo(Bitmap bitmap)
{
mParcelable = bitmap;
}
public Photo(File file)
{
try
{
mParcelable = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
}
catch (FileNotFoundException e)
{
Logger.logError(Photo.class, "Failed to create photo from file", e);
}
}
public Photo(byte[] bytes)
{
mBytes = bytes;
}
/**
* Add description to the photo
*
* @param description The description of the photo
*/
public void addDescription(String description)
{
mDescription = description;
}
/**
* Add place id of the photo
*
* @param placeId The place id of the photo
*/
public void addPlace(String placeId)
{
mPlaceId = placeId;
}
public Bundle getBundle()
{
Bundle bundle = new Bundle();
// add description
if (mDescription != null)
{
bundle.putString(MESSAGE, mDescription);
}
// add place
if (mPlaceId != null)
{
bundle.putString(PLACE, mPlaceId);
}
// add image
if (mParcelable != null)
{
bundle.putParcelable(PICTURE, mParcelable);
}
if (mBytes != null)
{
bundle.putByteArray(PICTURE, mBytes);
}
return bundle;
}
}