Search in sources :

Example 1 with Review

use of com.hackvg.model.entities.Review in project Material-Movies by saulmm.

the class MovieDetailActivity method showReviews.

/**
     * Creates a TextView with a Spannable format programmatically
     * containing the author by whom was the review written and the
     * review text
     *
     * @param reviewList a list containing reviews of the film
     */
@Override
public void showReviews(List<Review> reviewList) {
    final int reviewMarginTop = getResources().getDimensionPixelOffset(R.dimen.activity_vertical_margin_half);
    final LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(0, reviewMarginTop, 0, 0);
    movieHeaders.get(REVIEWS_HEADER).setVisibility(View.VISIBLE);
    for (Review result : reviewList) {
        // Creates a TextView
        TextView reviewTextView = new TextView(this);
        reviewTextView.setTextAppearance(this, R.style.MaterialMoviesReviewTextView);
        if (mReviewsColor != -1)
            reviewTextView.setTextColor(mReviewsColor);
        // Configure the review text
        String reviewCredit = "Review written by " + result.getAuthor();
        String reviewText = String.format("%s - %s", reviewCredit, result.getContent());
        Spannable spanColorString = new SpannableString(reviewText);
        spanColorString.setSpan(new ForegroundColorSpan(mReviewsAuthorColor), 0, reviewCredit.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        reviewTextView.setText(spanColorString);
        mMovieDescriptionContainer.addView(reviewTextView, layoutParams);
    }
}
Also used : SpannableString(android.text.SpannableString) LayoutParams(android.widget.LinearLayout.LayoutParams) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) Review(com.hackvg.model.entities.Review) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable)

Aggregations

Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 TextView (android.widget.TextView)1 Review (com.hackvg.model.entities.Review)1