コード例 #1
0
 @Override
 public ViewHolder onCreateViewHolder(ViewGroup parent) {
   ImageCardView cardView = new ImageCardView(parent.getContext());
   cardView.setFocusable(true);
   cardView.setFocusableInTouchMode(true);
   return new ViewHolder(cardView);
 }
コード例 #2
0
 private static void updateCardBackgroundColor(ImageCardView view, boolean selected) {
   int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor;
   // Both background colors should be set because the view's background is temporarily visible
   // during animations.
   view.setBackgroundColor(color);
   view.findViewById(R.id.info_field).setBackgroundColor(color);
 }
コード例 #3
0
 @Override
 public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
   Log.d(TAG, "onUnbindViewHolder");
   ImageCardView cardView = (ImageCardView) viewHolder.view;
   // Remove references to images so that the garbage collector can free up memory
   cardView.setBadgeImage(null);
   cardView.setMainImage(null);
 }
コード例 #4
0
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent) {
    Log.d(TAG, "onCreateViewHolder");
    mContext = parent.getContext();

    ImageCardView cardView = new ImageCardView(mContext);
    cardView.setFocusable(true);
    cardView.setFocusableInTouchMode(true);
    cardView.setBackgroundColor(mContext.getResources().getColor(R.color.fastlane_background));
    return new ViewHolder(cardView);
  }
コード例 #5
0
  @Override
  public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    super.onBindViewHolder(viewHolder, item);

    final CardViewHolder cardViewHolder = (CardViewHolder) viewHolder;
    final ImageCardView imageCardView = cardViewHolder.getImageCardView();

    AlbumSimple albumSimple = (AlbumSimple) item;

    // name
    imageCardView.setTitleText(albumSimple.name);

    // Load real album (not simple) from API
    SpotifyTvApplication app = SpotifyTvApplication.getInstance();
    app.getSpotifyService()
        .getAlbum(
            albumSimple.id,
            new Callback<Album>() {
              @Override
              public void success(final Album album, Response response) {
                // artists
                final StringBuilder artists = new StringBuilder();
                for (ArtistSimple artist : album.artists) {
                  if (artists.length() > 0) {
                    artists.append(", ");
                  }
                  artists.append(artist.name);
                }

                // image
                final String imageUrl = album.images.get(0).url;

                // run on UI thread
                imageCardView.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        imageCardView.setContentText(artists);

                        cardViewHolder.updateCardViewImage(URI.create(imageUrl));
                      }
                    });
              }

              @Override
              public void failure(RetrofitError error) {}
            });
  }
コード例 #6
0
  @Override
  public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    Movie movie = (Movie) item;
    ImageCardView cardView = (ImageCardView) viewHolder.view;

    Log.d(TAG, "onBindViewHolder");
    if (movie.getCardImageUrl() != null) {
      cardView.setTitleText(movie.getTitle());
      cardView.setContentText(movie.getStudio());
      cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);
      Glide.with(viewHolder.view.getContext())
          .load(movie.getCardImageUrl())
          .centerCrop()
          .error(mDefaultCardImage)
          .into(cardView.getMainImageView());
    }
  }
コード例 #7
0
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent) {
    Log.d(TAG, "onCreateViewHolder");

    sDefaultBackgroundColor = parent.getResources().getColor(R.color.default_background);
    sSelectedBackgroundColor = parent.getResources().getColor(R.color.selected_background);
    mDefaultCardImage = parent.getResources().getDrawable(R.drawable.movie);

    ImageCardView cardView =
        new ImageCardView(parent.getContext()) {
          @Override
          public void setSelected(boolean selected) {
            updateCardBackgroundColor(this, selected);
            super.setSelected(selected);
          }
        };

    cardView.setFocusable(true);
    cardView.setFocusableInTouchMode(true);
    updateCardBackgroundColor(cardView, false);
    return new ViewHolder(cardView);
  }
コード例 #8
0
    protected void updateCardViewImage(Context context, String link) {
      if (link == null || link.isEmpty()) {
        mCardView.setMainImage(context.getDrawable(R.drawable.recording_unkown));
        return;
      }

      Picasso.with(context)
          .load(link)
          .resize(266, 400)
          .centerCrop()
          .error(context.getDrawable(R.drawable.recording_unkown))
          .placeholder(context.getDrawable(R.drawable.recording_unkown))
          .into(mImageCardViewTarget);
    }
コード例 #9
0
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent) {
    Log.d(TAG, "onCreateViewHolder");
    mContext = parent.getContext();

    ImageCardView cardView = new ImageCardView(mContext);
    cardView.setCardType(BaseCardView.CARD_TYPE_INFO_UNDER);
    cardView.setInfoVisibility(BaseCardView.CARD_REGION_VISIBLE_ALWAYS);
    cardView.setFocusable(true);
    cardView.setFocusableInTouchMode(true);
    cardView.setBackgroundColor(mContext.getResources().getColor(R.color.fastlane_background));
    return new ViewHolder(cardView);
  }
コード例 #10
0
  @Override
  public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    ArtworkHolder holder = (ArtworkHolder) item;
    ViewHolder vh = (ViewHolder) viewHolder;

    ImageCardView cardView = vh.getCardView();
    Context context = cardView.getContext();

    cardView.setTitleText(holder.getTitle());
    cardView.setMainImageDimensions(266, 400);
    cardView.setInfoAreaBackgroundColor(Utils.getColor(context, R.color.primary_color));

    vh.updateCardViewImage(cardView.getContext(), holder.getPosterUrl());
  }
コード例 #11
0
 @Override
 public void onBitmapFailed(Drawable drawable) {
   mImageCardView.setMainImage(drawable);
 }
コード例 #12
0
 @Override
 public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
   Drawable bitmapDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
   mImageCardView.setMainImage(bitmapDrawable);
 }