1a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim/*
2a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Copyright (C) 2015 The Android Open Source Project
3a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
4a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Licensed under the Apache License, Version 2.0 (the "License");
5a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * you may not use this file except in compliance with the License.
6a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * You may obtain a copy of the License at
7a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
8a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *      http://www.apache.org/licenses/LICENSE-2.0
9a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim *
10a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * Unless required by applicable law or agreed to in writing, software
11a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * distributed under the License is distributed on an "AS IS" BASIS,
12a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * See the License for the specific language governing permissions and
14a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * limitations under the License.
15a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim */
16a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
17a907614755847b2630561a1e5949b2b416600d97Sungsoo Limpackage com.example.android.supportv4.media;
18a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
19a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.app.Activity;
2067949f5f3bc1f721fa5f63250f0fd74a44f5381fAurimas Liutikasimport android.support.v4.content.ContextCompat;
21a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.support.v4.media.session.MediaSessionCompat;
22a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.view.LayoutInflater;
23a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.view.View;
24a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.view.ViewGroup;
25a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.widget.ArrayAdapter;
26a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.widget.ImageView;
27a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport android.widget.TextView;
28a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
2967949f5f3bc1f721fa5f63250f0fd74a44f5381fAurimas Liutikasimport com.example.android.supportv4.R;
3067949f5f3bc1f721fa5f63250f0fd74a44f5381fAurimas Liutikas
31a907614755847b2630561a1e5949b2b416600d97Sungsoo Limimport java.util.ArrayList;
32a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
33a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim/**
34a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim * A list adapter for items in a queue
35a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim */
36a907614755847b2630561a1e5949b2b416600d97Sungsoo Limpublic class QueueAdapter extends ArrayAdapter<MediaSessionCompat.QueueItem> {
37a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
38a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    // The currently selected/active queue item Id.
39a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    private long mActiveQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
40a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
41a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public QueueAdapter(Activity context) {
42a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        super(context, R.layout.media_list_item, new ArrayList<MediaSessionCompat.QueueItem>());
43a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
44a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
45a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public void setActiveQueueItemId(long id) {
46a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        this.mActiveQueueItemId = id;
47a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
48a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
49a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    private static class ViewHolder {
50a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        ImageView mImageView;
51a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        TextView mTitleView;
52a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        TextView mDescriptionView;
53a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
54a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
55e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas    @Override
56a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    public View getView(int position, View convertView, ViewGroup parent) {
57a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        ViewHolder holder;
58a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
59a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        if (convertView == null) {
60a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            convertView = LayoutInflater.from(getContext())
61a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim                    .inflate(R.layout.media_list_item, parent, false);
62a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder = new ViewHolder();
63a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
64a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
65a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
66a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            convertView.setTag(holder);
67a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        } else {
68a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder = (ViewHolder) convertView.getTag();
69a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        }
70a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
71a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        MediaSessionCompat.QueueItem item = getItem(position);
72a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        holder.mTitleView.setText(item.getDescription().getTitle());
73a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        if (item.getDescription().getDescription() != null) {
74a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mDescriptionView.setText(item.getDescription().getDescription());
75a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        }
76a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim
77a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        // If the itemId matches the active Id then use a different icon
78a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        if (mActiveQueueItemId == item.getQueueId()) {
79a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mImageView.setImageDrawable(
8067949f5f3bc1f721fa5f63250f0fd74a44f5381fAurimas Liutikas                    ContextCompat.getDrawable(getContext(), R.drawable.ic_equalizer_white_24dp));
81a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        } else {
82a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim            holder.mImageView.setImageDrawable(
8367949f5f3bc1f721fa5f63250f0fd74a44f5381fAurimas Liutikas                    ContextCompat.getDrawable(getContext(), R.drawable.ic_play_arrow_white_24dp));
84a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        }
85a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim        return convertView;
86a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim    }
87a907614755847b2630561a1e5949b2b416600d97Sungsoo Lim}
88