summaryrefslogtreecommitdiff
path: root/src/com/android/car/media/widgets/MediaItemTabView.java
blob: 97019266d856f1174edb5cad01e2fe0870880b28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.car.media.widgets;

import android.annotation.NonNull;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.car.media.R;
import com.android.car.media.common.MediaItemMetadata;

/**
 * A view representing a media item to be included in the tab bar at the top of the UI.
 */
public class MediaItemTabView extends LinearLayout {
    private final TextView mTitleView;
    private final ImageView mImageView;
    private final MediaItemMetadata mItem;

    /**
     * Creates a new tab for the given media item.
     */
    public MediaItemTabView(@NonNull Context context, @NonNull MediaItemMetadata item) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.tab_view, this, true);
        setOrientation(LinearLayout.VERTICAL);
        setFocusable(true);
        setGravity(Gravity.CENTER);

        int[] attrs = new int[]{android.R.attr.selectableItemBackground};
        TypedArray typedArray = context.obtainStyledAttributes(attrs);
        int backgroundResource = typedArray.getResourceId(0, 0);
        setBackgroundResource(backgroundResource);

        mItem = item;
        mImageView = findViewById(R.id.icon);
        MediaItemMetadata.updateImageView(context, item, mImageView, 0);
        mTitleView = findViewById(R.id.title);
        mTitleView.setText(item.getTitle());
    }

    /**
     * Returns the item represented by this view
     */
    @NonNull
    public MediaItemMetadata getItem() {
        return mItem;
    }
}