Home | History | Annotate | Download | only in cards
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 
     15 package android.support.v17.leanback.supportleanbackshowcase.cards;
     16 
     17 import android.content.Context;
     18 import android.graphics.Bitmap;
     19 import android.graphics.BitmapFactory;
     20 import android.support.v17.leanback.supportleanbackshowcase.R;
     21 import android.support.v17.leanback.supportleanbackshowcase.models.Card;
     22 import android.support.v17.leanback.widget.BaseCardView;
     23 import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
     24 import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
     25 import android.view.LayoutInflater;
     26 import android.widget.ImageView;
     27 import android.widget.TextView;
     28 
     29 public class TextCardView extends BaseCardView {
     30 
     31     public TextCardView(Context context) {
     32         super(context, null, R.style.TextCardStyle);
     33         LayoutInflater.from(getContext()).inflate(R.layout.text_icon_card, this);
     34         setFocusable(true);
     35     }
     36 
     37     public void updateUi(Card card) {
     38         TextView extraText = findViewById(R.id.extra_text);
     39         TextView primaryText = findViewById(R.id.primary_text);
     40         final ImageView imageView = findViewById(R.id.main_image);
     41 
     42         extraText.setText(card.getExtraText());
     43         primaryText.setText(card.getTitle());
     44 
     45         // Create a rounded drawable.
     46         int resourceId = card.getLocalImageResourceId(getContext());
     47         Bitmap bitmap = BitmapFactory
     48                 .decodeResource(getContext().getResources(), resourceId);
     49         RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), bitmap);
     50         drawable.setAntiAlias(true);
     51         drawable.setCornerRadius(
     52                 Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
     53         imageView.setImageDrawable(drawable);
     54     }
     55 
     56 }
     57