[go: nahoru, domu]

blob: 80c53f6939948b051efc654d0f15fb19847307e3 [file] [log] [blame]
Sungsoo Lima9076142016-03-21 13:35:56 +09001/*
2 * Copyright (C) 2015 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
17package com.example.android.supportv4.media;
18
Sungsoo Lima9076142016-03-21 13:35:56 +090019import android.app.Activity;
Aurimas Liutikas67949f52016-10-04 11:33:19 -070020import android.support.v4.content.ContextCompat;
Sungsoo Lima9076142016-03-21 13:35:56 +090021import android.support.v4.media.session.MediaSessionCompat;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.ArrayAdapter;
26import android.widget.ImageView;
27import android.widget.TextView;
28
Aurimas Liutikas67949f52016-10-04 11:33:19 -070029import com.example.android.supportv4.R;
30
Sungsoo Lima9076142016-03-21 13:35:56 +090031import java.util.ArrayList;
32
33/**
34 * A list adapter for items in a queue
35 */
36public class QueueAdapter extends ArrayAdapter<MediaSessionCompat.QueueItem> {
37
38 // The currently selected/active queue item Id.
39 private long mActiveQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
40
41 public QueueAdapter(Activity context) {
42 super(context, R.layout.media_list_item, new ArrayList<MediaSessionCompat.QueueItem>());
43 }
44
45 public void setActiveQueueItemId(long id) {
46 this.mActiveQueueItemId = id;
47 }
48
49 private static class ViewHolder {
50 ImageView mImageView;
51 TextView mTitleView;
52 TextView mDescriptionView;
53 }
54
Aurimas Liutikase2104f42017-03-05 09:55:41 -080055 @Override
Sungsoo Lima9076142016-03-21 13:35:56 +090056 public View getView(int position, View convertView, ViewGroup parent) {
57 ViewHolder holder;
58
59 if (convertView == null) {
60 convertView = LayoutInflater.from(getContext())
61 .inflate(R.layout.media_list_item, parent, false);
62 holder = new ViewHolder();
63 holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
64 holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
65 holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
66 convertView.setTag(holder);
67 } else {
68 holder = (ViewHolder) convertView.getTag();
69 }
70
71 MediaSessionCompat.QueueItem item = getItem(position);
72 holder.mTitleView.setText(item.getDescription().getTitle());
73 if (item.getDescription().getDescription() != null) {
74 holder.mDescriptionView.setText(item.getDescription().getDescription());
75 }
76
77 // If the itemId matches the active Id then use a different icon
78 if (mActiveQueueItemId == item.getQueueId()) {
79 holder.mImageView.setImageDrawable(
Aurimas Liutikas67949f52016-10-04 11:33:19 -070080 ContextCompat.getDrawable(getContext(), R.drawable.ic_equalizer_white_24dp));
Sungsoo Lima9076142016-03-21 13:35:56 +090081 } else {
82 holder.mImageView.setImageDrawable(
Aurimas Liutikas67949f52016-10-04 11:33:19 -070083 ContextCompat.getDrawable(getContext(), R.drawable.ic_play_arrow_white_24dp));
Sungsoo Lima9076142016-03-21 13:35:56 +090084 }
85 return convertView;
86 }
87}