Android Open Source - bv-android-sdk Bazaar Review






From Project

Back to project page bv-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project bv-android-sdk 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 com.bazaarvoice.example.reviewsubmission;
//from w ww  .ja va2s.c o m
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.util.Log;

/**
 * BazaarReview.java <br>
 * ReviewSubmissionExample<br>
 * 
 * This is a very basic class used to represent a review in the Bazaarvoice
 * system for the use of this example app.
 * 
 * <p>
 * <b>Note: This does not include all functionality of the Bazaarvoice
 * system.</b>
 * 
 * <p>
 * Created on 6/29/12. Copyright (c) 2012 BazaarVoice. All rights reserved.
 * 
 * @author Bazaarvoice Engineering
 */
public class BazaarReview {
  private int rating;
  private String title;
  private String authorId;
  private String userNickname;
  private String dateString;
  private String reviewText;
  private String imageUrl;
  private Bitmap imageBitmap;

  /**
   * Sets all variables to 0, null, or "null"
   */
  public BazaarReview() {
    rating = 0;
    title = "null";
    authorId = "null";
    userNickname = "null";
    dateString = "null";
    reviewText = "null";
    imageUrl = "null";
    imageBitmap = null;
  }

  /**
   * Parses the json response of a review query and builds the structure of
   * the object.
   * 
   * @param json
   *            the response of a review query
   * @throws NumberFormatException
   *             if the rating is not formatted as an <code>int</code> (this
   *             should never occur)
   * @throws JSONException
   *             if there is a missing field in the json response
   */
  public BazaarReview(JSONObject json) throws NumberFormatException,
      JSONException {
    String ratingText = json.getString("Rating");
    if (!"null".equals(ratingText))
      rating = Integer.parseInt(ratingText);
    else
      rating = 0;

    title = json.getString("Title");
    authorId = json.optString("AuthorId");
    userNickname = json.optString("UserNickname");
    dateString = formatDateString(json.getString("SubmissionTime"));
    reviewText = json.getString("ReviewText");

    JSONArray photos = json.optJSONArray("Photos");
    if (photos != null && photos.length() != 0) {
      Log.i("Photo", photos.toString());
      JSONObject photo = photos.getJSONObject(0);
      JSONObject sizes = photo.getJSONObject("Sizes");
      JSONObject thumb = sizes.getJSONObject("thumbnail");
      imageUrl = thumb.getString("Url");
    } else {
      imageUrl = "";
    }
    imageBitmap = null;
  }

  /**
   * Formats the date string from a json response into a readable format.
   * 
   * <p>
   * Assumes "yyyy-mm-ddThh:mm:ss.000-06:00" format
   * 
   * @param timestamp
   *            the timestamp string from the json response
   * @return the formatted string
   */
  private String formatDateString(String timestamp) {
    String year = timestamp.substring(0, 4);
    int monthNum = Integer.parseInt(timestamp.substring(5, 7));
    String day = timestamp.substring(8, 10);
    String month = "";

    switch (monthNum) {
    case 1:
      month = "January";
      break;
    case 2:
      month = "February";
      break;
    case 3:
      month = "March";
      break;
    case 4:
      month = "April";
      break;
    case 5:
      month = "May";
      break;
    case 6:
      month = "June";
      break;
    case 7:
      month = "July";
      break;
    case 8:
      month = "August";
      break;
    case 9:
      month = "September";
      break;
    case 10:
      month = "October";
      break;
    case 11:
      month = "November";
      break;
    case 12:
      month = "December";
      break;
    }

    return month + " " + day + ", " + year;

  }

  /**
   * Downloads the image from the URL stored in the object. This can be set by
   * constructing the object with a json response that has an image associated
   * with it. It also allows for passing a callback function for when the download
   * completes.
   * 
   * @param listener the callback function, or null if not needed
   */
  public void downloadImage(final OnImageDownloadComplete listener) {
    if ("".equals(imageUrl))
      return;

    Thread t = new Thread(new Runnable() {

      @Override
      public void run() {
        ImageDownloader downloader = new ImageDownloader();
        imageBitmap = downloader.download(imageUrl);
        if(listener != null)
          listener.onFinish(null);
      }

    });
    t.start();
  }

  /**
   * @return the rating
   */
  public int getRating() {
    return rating;
  }

  /**
   * @param rating
   *            the rating to set
   */
  public void setRating(int rating) {
    this.rating = rating;
  }

  /**
   * @return the title
   */
  public String getTitle() {
    return title;
  }

  /**
   * @param title
   *            the title to set
   */
  public void setTitle(String title) {
    this.title = title;
  }

  /**
   * @return the authorId
   */
  public String getAuthorId() {
    return authorId;
  }

  /**
   * @param authorId
   *            the authorId to set
   */
  public void setAuthorId(String authorId) {
    this.authorId = authorId;
  }

  /**
   * @return the dateString
   */
  public String getDateString() {
    return dateString;
  }

  /**
   * @param dateString
   *            the dateString to set
   */
  public void setDateString(String dateString) {
    this.dateString = dateString;
  }

  /**
   * @return the reviewText
   */
  public String getReviewText() {
    return reviewText;
  }

  /**
   * @param reviewText
   *            the reviewText to set
   */
  public void setReviewText(String reviewText) {
    this.reviewText = reviewText;
  }

  /**
   * @return the imageBitmap
   */
  public Bitmap getImageBitmap() {
    return imageBitmap;
  }

  /**
   * @param imageBitmap
   *            the imageBitmap to set
   */
  public void setImageBitmap(Bitmap imageBitmap) {
    this.imageBitmap = imageBitmap;
  }

  /**
   * @return the userNickname
   */
  public String getNickname() {
    return userNickname;
  }

  /**
   * @param userNickname
   *            the userNickname to set
   */
  public void setNickname(String userNickname) {
    this.userNickname = userNickname;
  }

  /**
   * Gets the correct name for display.
   * 
   * @return nickname if it exists, else the author ID
   */
  public String getDisplayName() {
    if (userNickname == "")
      return authorId;
    else
      return userNickname;
  }

}




Java Source Code List

com.bazaarvoice.BazaarException.java
com.bazaarvoice.BazaarParams.java
com.bazaarvoice.BazaarRequest.java
com.bazaarvoice.DisplayParams.java
com.bazaarvoice.Media.java
com.bazaarvoice.OnBazaarResponse.java
com.bazaarvoice.SubmissionMediaParams.java
com.bazaarvoice.SubmissionParams.java
com.bazaarvoice.example.browseproducts.BazaarFunctions.java
com.bazaarvoice.example.browseproducts.BazaarProduct.java
com.bazaarvoice.example.browseproducts.BazaarReview.java
com.bazaarvoice.example.browseproducts.BazaarUIThreadResponse.java
com.bazaarvoice.example.browseproducts.ImageDownloader.java
com.bazaarvoice.example.browseproducts.MainActivity.java
com.bazaarvoice.example.browseproducts.OnImageDownloadComplete.java
com.bazaarvoice.example.browseproducts.ProductAdapter.java
com.bazaarvoice.example.browseproducts.ProductsActivity.java
com.bazaarvoice.example.browseproducts.ReviewAdapter.java
com.bazaarvoice.example.browseproducts.ReviewDisplayActivity.java
com.bazaarvoice.example.browseproducts.ReviewsActivity.java
com.bazaarvoice.example.reviewsubmission.BazaarFunctions.java
com.bazaarvoice.example.reviewsubmission.BazaarReview.java
com.bazaarvoice.example.reviewsubmission.CameraUtils.java
com.bazaarvoice.example.reviewsubmission.ImageDownloader.java
com.bazaarvoice.example.reviewsubmission.MainActivity.java
com.bazaarvoice.example.reviewsubmission.OnImageDownloadComplete.java
com.bazaarvoice.example.reviewsubmission.OnImageUploadComplete.java
com.bazaarvoice.example.reviewsubmission.RatingActivity.java
com.bazaarvoice.example.reviewsubmission.RatingPreviewActivity.java
com.bazaarvoice.example.reviewsubmission.ReviewSubmissionApp.java
com.bazaarvoice.intentexample.BazaarFunctions.java
com.bazaarvoice.intentexample.BazaarUIThreadResponse.java
com.bazaarvoice.intentexample.CameraUtils.java
com.bazaarvoice.intentexample.MainActivity.java
com.bazaarvoice.types.Action.java
com.bazaarvoice.types.ApiVersion.java
com.bazaarvoice.types.Equality.java
com.bazaarvoice.types.FeedbackContentType.java
com.bazaarvoice.types.FeedbackType.java
com.bazaarvoice.types.FeedbackVoteType.java
com.bazaarvoice.types.IncludeStatsType.java
com.bazaarvoice.types.IncludeType.java
com.bazaarvoice.types.MediaParamsContentType.java
com.bazaarvoice.types.RequestType.java
com.chute.android.photopickerplus.adapter.AlbumsAdapter.java
com.chute.android.photopickerplus.adapter.PhotoSelectCursorAdapter.java
com.chute.android.photopickerplus.adapter.PhotosAdapter.java
com.chute.android.photopickerplus.app.AlbumsActivity.java
com.chute.android.photopickerplus.app.ChooseServiceActivity.java
com.chute.android.photopickerplus.app.GridActivity.java
com.chute.android.photopickerplus.app.PhotoPickerPlusApp.java
com.chute.android.photopickerplus.dao.MediaDAO.java
com.chute.android.photopickerplus.util.AppUtil.java
com.chute.android.photopickerplus.util.Constants.java
com.chute.android.photopickerplus.util.NotificationUtil.java
com.chute.android.photopickerplus.util.intent.AlbumsActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.IntentUtil.java
com.chute.android.photopickerplus.util.intent.IntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoPickerPlusIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotosIntentWrapper.java
com.example.productwidgetexample.BazaarFunctions.java
com.example.productwidgetexample.BazaarProduct.java
com.example.productwidgetexample.BazaarReview.java
com.example.productwidgetexample.BazaarUIThreadResponse.java
com.example.productwidgetexample.ImageDownloader.java
com.example.productwidgetexample.OnImageDownloadComplete.java
com.example.productwidgetexample.ProductWidgetProvider.java
com.example.productwidgetexample.ReviewAdapter.java
com.example.productwidgetexample.ReviewsActivity.java