Android Open Source - tpblogr Post






From Project

Back to project page tpblogr.

License

The source code is released under:

MIT License

If you think the Android project tpblogr listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package blogr.vpm.fr.blogr.bean;
//w  w  w.ja v a2s.c o m
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by vincent on 29/08/14.
 */
public class Post implements Parcelable {

  public static final String INTENT_EXTRA_KEY = "intent_extra_post";

  private static final String TITLE_KEY = "title";

  private static final String CONTENT_KEY = "content";

  private static final String DATE_KEY = "date";

  private static final String PICTURES_KEY = "pictures";

  private static final String BLOG_KEY = "blog";

  private static final String DATE_PATTERN = "yyyy-MM-dd-HH:mm:ss-ZZZZZ";

  private String title;

  private String content;

  private Date date;

  private final ArrayList<Uri> pictures;

  private Blog blog;

  public Post(String title, String content, Blog blog) {
    this.title = title;
    this.content = content;
    this.pictures = new ArrayList<Uri>();
    this.blog = blog;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

  public Date getDate() {
    return date;
  }

  public Blog getBlog() {
    return blog;
  }

  public static Post emptyPost(Blog blog) {
    return new Post("", "", blog);
  }

  public void addPicture(Uri pictureUri) {
    pictures.add(pictureUri);
  }

  public ArrayList<Uri> getPicturesAsMediaContent() {
    return pictures;
  }

  public ArrayList<Uri> getPicturesAsFiles(Context context) {
    ArrayList<Uri> pictureFiles = new ArrayList<Uri>();
    for (Uri pic : pictures) {
      Cursor c = context.getContentResolver().query(pic, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
      if (c.getCount() > 0) {
        c.moveToFirst();
        String filePath = c.getString(c.getColumnIndex(MediaStore.Images.Media.DATA));
        File picFile = new File(filePath);
        picFile.setReadable(true, false);
        Uri pictureUri = Uri.fromFile(picFile);
        pictureFiles.add(pictureUri);
        c.close();
      }
    }
    return pictureFiles;
  }

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {
    Bundle b = new Bundle();
    b.putString(TITLE_KEY, title);
    b.putString(CONTENT_KEY, content);
    if (date != null) {
      b.putString(DATE_KEY, new SimpleDateFormat(DATE_PATTERN).format(date));
    }
    b.putParcelableArrayList(PICTURES_KEY, pictures);
    b.putParcelable(BLOG_KEY, blog);
    parcel.writeBundle(b);
  }

  private Post(Parcel in) {
    Bundle b = in.readBundle(Post.class.getClassLoader());
    // without setting the classloader, it fails on BadParcelableException : ClassNotFoundException when
    // unmarshalling Media class
    title = b.getString(TITLE_KEY);
    content = b.getString(CONTENT_KEY);
    try {
      String unparsedDate = b.getString(DATE_KEY);
      if (unparsedDate != null) {
        date = new SimpleDateFormat(DATE_PATTERN).parse(unparsedDate);
      }
    } catch (ParseException e) {
      date = Calendar.getInstance().getTime();
    }
    pictures = b.getParcelableArrayList(PICTURES_KEY);
    blog = b.getParcelable(BLOG_KEY);
  }

  public static final Parcelable.Creator<Post> CREATOR
          = new Parcelable.Creator<Post>() {
    public Post createFromParcel(Parcel in) {
      return new Post(in);
    }

    public Post[] newArray(int size) {
      return new Post[size];
    }
  };
}




Java Source Code List

blogr.vpm.fr.blogr.activity.AllPreferencesActivity.java
blogr.vpm.fr.blogr.activity.BlogActivity.java
blogr.vpm.fr.blogr.activity.BlogListDialogFragment.java
blogr.vpm.fr.blogr.activity.DialogDismissedListener.java
blogr.vpm.fr.blogr.activity.EmailBlogEditionFragment.java
blogr.vpm.fr.blogr.activity.FlickrDialogFragment.java
blogr.vpm.fr.blogr.activity.GithubBlogEditionFragment.java
blogr.vpm.fr.blogr.activity.InvalidatedModelListener.java
blogr.vpm.fr.blogr.activity.PostEditionActivity.java
blogr.vpm.fr.blogr.activity.PostEditionFragment.java
blogr.vpm.fr.blogr.activity.PostListActivity.java
blogr.vpm.fr.blogr.activity.PostListChoiceModeListener.java
blogr.vpm.fr.blogr.activity.PostListFragment.java
blogr.vpm.fr.blogr.activity.PostSelectionListener.java
blogr.vpm.fr.blogr.activity.PreferenceCategoryFragment.java
blogr.vpm.fr.blogr.apis.flickr.FlickrJAndroidProvider.java
blogr.vpm.fr.blogr.apis.flickr.FlickrJAsyncTaskProvider.java
blogr.vpm.fr.blogr.apis.flickr.FlickrProvider.java
blogr.vpm.fr.blogr.apis.flickr.ParcelableFlickrPhoto.java
blogr.vpm.fr.blogr.bean.Blog.java
blogr.vpm.fr.blogr.bean.EmailBlog.java
blogr.vpm.fr.blogr.bean.GithubBlog.java
blogr.vpm.fr.blogr.bean.Post.java
blogr.vpm.fr.blogr.bean.TPBlog.java
blogr.vpm.fr.blogr.format.AlignCenterTagsProvider.java
blogr.vpm.fr.blogr.format.AlignLeftTagsProvider.java
blogr.vpm.fr.blogr.format.AlignRightTagsProvider.java
blogr.vpm.fr.blogr.insertion.DefaultInserter.java
blogr.vpm.fr.blogr.insertion.Inserter.java
blogr.vpm.fr.blogr.insertion.SingleTagProvider.java
blogr.vpm.fr.blogr.insertion.SurroundingTagsProvider.java
blogr.vpm.fr.blogr.location.AndroidLocationProvider.java
blogr.vpm.fr.blogr.location.LatLongTagProvider.java
blogr.vpm.fr.blogr.location.LocationProvider.java
blogr.vpm.fr.blogr.persistence.BlogRetriever.java
blogr.vpm.fr.blogr.persistence.BlogSaver.java
blogr.vpm.fr.blogr.persistence.FileBlogManager.java
blogr.vpm.fr.blogr.persistence.FilePostRetriever.java
blogr.vpm.fr.blogr.persistence.FilePostSaver.java
blogr.vpm.fr.blogr.persistence.PostRetriever.java
blogr.vpm.fr.blogr.persistence.PostSaver.java
blogr.vpm.fr.blogr.picture.AsyncPictureLoader.java
blogr.vpm.fr.blogr.picture.ImageViewLoader.java
blogr.vpm.fr.blogr.picture.PictureLoadedListener.java
blogr.vpm.fr.blogr.picture.PictureMdTagsProvider.java
blogr.vpm.fr.blogr.picture.PicturePickedListener.java
blogr.vpm.fr.blogr.picture.PictureTagProvider.java
blogr.vpm.fr.blogr.picture.PictureTpTagsProvider.java
blogr.vpm.fr.blogr.publish.Formatter.java
blogr.vpm.fr.blogr.publish.HtmlFormatter.java
blogr.vpm.fr.blogr.publish.IdentityFormatter.java
blogr.vpm.fr.blogr.publish.PostPublisher.java
blogr.vpm.fr.blogr.publish.StdEmailPostPublisher.java
blogr.vpm.fr.blogr.publish.TPJavaMailPostPublisher.java
blogr.vpm.fr.blogr.publish.TPPostPublisher.java
blogr.vpm.fr.blogr.service.PostPublishingPreferencesProvider.java
blogr.vpm.fr.blogr.service.PostPublishingServiceProvider.java