Home | History | Annotate | Download | only in leanback
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.test.uibench.leanback;
     17 
     18 import android.content.Context;
     19 import android.graphics.drawable.Drawable;
     20 import android.support.v17.leanback.widget.ImageCardView;
     21 import android.support.v17.leanback.widget.Presenter;
     22 import android.support.v4.content.res.ResourcesCompat;
     23 import android.view.ContextThemeWrapper;
     24 import android.view.ViewGroup;
     25 import android.view.ViewGroup.LayoutParams;
     26 
     27 public class CardPresenter extends Presenter {
     28 
     29     private int mImageWidth = 0;
     30     private int mImageHeight = 0;
     31 
     32     public CardPresenter(int width, int height) {
     33         mImageWidth = width;
     34         mImageHeight = height;
     35     }
     36 
     37     @Override
     38     public ViewHolder onCreateViewHolder(ViewGroup parent) {
     39         Context context = parent.getContext();
     40         ImageCardView v = new ImageCardView(context);
     41         v.setFocusable(true);
     42         v.setFocusableInTouchMode(true);
     43         v.setMainImageAdjustViewBounds(true);
     44         v.setMainImageDimensions(mImageWidth, mImageHeight);
     45         return new ViewHolder(v);
     46     }
     47 
     48     @Override
     49     public void onBindViewHolder(ViewHolder viewHolder, Object item) {
     50         PhotoItem photoItem = (PhotoItem) item;
     51         ImageCardView cardView = (ImageCardView) viewHolder.view;
     52         cardView.setTitleText(photoItem.getTitle());
     53         BitmapLoader.loadBitmap(cardView.getMainImageView(), photoItem.getId(),
     54                 mImageWidth, mImageHeight);
     55     }
     56 
     57     @Override
     58     public void onUnbindViewHolder(ViewHolder viewHolder) {
     59         ImageCardView cardView = (ImageCardView) viewHolder.view;
     60         BitmapLoader.cancel(cardView.getMainImageView());
     61     }
     62 }
     63