TextCardView.java revision 31475959eb09fd873551909dd21d00304b6a4ee9
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
15package android.support.v17.leanback.supportleanbackshowcase.cards;
16
17import android.content.Context;
18import android.graphics.Bitmap;
19import android.graphics.BitmapFactory;
20import android.support.v17.leanback.supportleanbackshowcase.R;
21import android.support.v17.leanback.supportleanbackshowcase.cards.models.Card;
22import android.support.v17.leanback.widget.BaseCardView;
23import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
24import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
25import android.view.LayoutInflater;
26import android.widget.FrameLayout;
27import android.widget.ImageView;
28import android.widget.TextView;
29
30public class TextCardView extends BaseCardView {
31
32    public TextCardView(Context context) {
33        super(context);
34        LayoutInflater.from(getContext()).inflate(R.layout.text_icon_card, this);
35        setFocusable(true);
36    }
37
38    public void updateUi(Card card) {
39        TextView extraText = (TextView) findViewById(R.id.extra_text);
40        TextView primaryText = (TextView) findViewById(R.id.primary_text);
41        final ImageView imageView = (ImageView) findViewById(R.id.main_image);
42
43        extraText.setText(card.getExtraText());
44        primaryText.setText(card.getTitle());
45
46        // Create a rounded drawable.
47        int resourceId = card.getLocalImageResourceId(getContext());
48        Bitmap bitmap = BitmapFactory
49                .decodeResource(getContext().getResources(), resourceId);
50        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(), bitmap);
51        drawable.setAntiAlias(true);
52        drawable.setCornerRadius(
53                Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
54        imageView.setImageDrawable(drawable);
55    }
56
57}
58