Android Open Source - bv-android-sdk Review Adapter






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.example.productwidgetexample;
import java.util.ArrayList;
/*  w  ww.  j ava  2 s. co m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

/**
 * ReviewAdapter.java <br>
 * ProductWidgetExample<br>
 * 
 * <p>
 * This is an adapter tailored for displaying BazaarReview objects.
 * 
 * <p>
 * Created on 7/3/12. Copyright (c) 2012 BazaarVoice. All rights reserved.
 * 
 * @author Bazaarvoice Engineering
 */
public class ReviewAdapter extends BaseAdapter {

  private ArrayList<BazaarReview> reviews;
  private LayoutInflater inflater;
  private Context context;

  /**
   * Internalizes the list of reviews and sets up the adapter.
   * 
   * @param c
   *            the application context
   * @param reviewList
   *            the list of reviews
   */
  public ReviewAdapter(Context c, ArrayList<BazaarReview> reviewList) {
    context = c;
    reviews = reviewList;
    inflater = LayoutInflater.from(context);
  }

  /**
   * How many items are in the data set represented by this Adapter.
   */
  @Override
  public int getCount() {
    return reviews.size();
  }

  /**
   * Get the data item associated with the specified position in the data set.
   */
  @Override
  public Object getItem(int position) {
    return reviews.get(position);
  }

  /**
   * Get the row id associated with the specified position in the list.
   * 
   * <p>
   * Not implemented.
   */
  @Override
  public long getItemId(int position) {
    return 0;
  }

  /**
   * Get a View that displays the data at the specified position in the data
   * set.
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
      convertView = inflater.inflate(R.layout.review_item, null);
      holder = new ViewHolder();
      holder.reviewImage = (ImageView) convertView
          .findViewById(R.id.reviewImage);
      holder.reviewTitle = (TextView) convertView
          .findViewById(R.id.reviewTitle);
      holder.byLine = (TextView) convertView.findViewById(R.id.byLine);
      holder.reviewRating = (RatingBar) convertView
          .findViewById(R.id.reviewRating);
      holder.reviewText = (TextView) convertView
          .findViewById(R.id.reviewText);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    if (reviews.get(position).getImageBitmap() != null) {
      Bitmap scaledImage = Bitmap.createScaledBitmap(reviews
          .get(position).getImageBitmap(), 150, 150, true);
      holder.reviewImage.setImageBitmap(scaledImage);
    } else
      holder.reviewImage.setImageResource(R.drawable.camera_icon);

    holder.reviewTitle.setText(reviews.get(position).getTitle());
    holder.byLine.setText(Html.fromHtml("By <b>"
        + reviews.get(position).getAuthorId() + "</b> on "
        + reviews.get(position).getDateString()));
    holder.reviewRating.setRating(reviews.get(position).getRating());
    holder.reviewText.setText(reviews.get(position).getReviewText());

    return convertView;
  }

  /**
   * ViewHolder
   * 
   * <p>
   * Holds the Views that are contained in an item of the list.
   * 
   * <p>
   * Created on 7/3/12. Copyright (c) 2012 BazaarVoice. All rights reserved.
   * 
   * @author Bazaarvoice Engineering
   */
  class ViewHolder {
    ImageView reviewImage;
    TextView reviewTitle;
    TextView byLine;
    RatingBar reviewRating;
    TextView reviewText;
  }
}




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