Android Open Source - akuplayer Track List Adapter






From Project

Back to project page akuplayer.

License

The source code is released under:

Copyright (c) 2014, Dmitry Kuznetsov aka kudzmi All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditi...

If you think the Android project akuplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
Copyright (c) 2014, Dmitry Kuznetsov aka kudzmi
All rights reserved./*from ww  w .  j av a  2  s  . c om*/

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.kudzmi.akuplayer;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kudzmi.akuplayer.player.ItemHighlighter;

import java.util.List;

/**
 * Created by Dmitry on 12.05.2014.
 */
public class TrackListAdapter extends SimpleListAdapter<Audio> implements ItemHighlighter {
    private long currentItemId = -1L;

    public TrackListAdapter(Context c, List<Audio> data) {
        super(c, data);
    }

    @Override
    public long getItemId(int i) {
        return items.get(i).audio_id;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Holder h;
        if(convertView == null){
            h = new Holder();
            convertView = mInflater.inflate(R.layout.item_player_list, null);
            h.isPlaying = (ImageView) convertView.findViewById(R.id.item_player_is_playing);
            h.title = (TextView) convertView.findViewById(R.id.item_player_track_name);
            h.time = (TextView) convertView.findViewById(R.id.item_player_track_time);
            convertView.setTag(h);
        }else{
            h = (Holder) convertView.getTag();
        }
        Audio item = items.get(position);

        h.title.setText(item.name);
        h.time.setText(getStringTime(item.duration));

        if(item.audio_id == currentItemId){
            h.isPlaying.setVisibility(View.VISIBLE);
            h.title.setTextColor(context.getResources().getColor(android.R.color.holo_red_dark));
            h.title.setSelected(true);
            h.title.requestFocus();
        }else{
            h.isPlaying.setVisibility(View.GONE);
            h.title.setTextColor(context.getResources().getColor(android.R.color.black));
        }


        return convertView;
    }

    @Override
    public void highlightItem(long itemId) {
        currentItemId = itemId;
        notifyDataSetChanged();
    }

    @Override
    public void clearHighlight() {
        currentItemId = -1L;
        notifyDataSetChanged();
    }

    private class Holder{
        ImageView isPlaying;
        TextView title, time;
    }

    /**
     * Convert time in secinds to string: mm:ss
     * @param sec
     * @return
     */
    public static String getStringTime(int sec){
        int h = sec/60;
        int m = sec%60;
        return  ((h<10)?"0"+h:h) + ":" + ((m<10)?"0"+m:m);
    }
}




Java Source Code List

com.kudzmi.akuplayer.Audio.java
com.kudzmi.akuplayer.MainActivity.java
com.kudzmi.akuplayer.PrefStorage.java
com.kudzmi.akuplayer.SimpleListAdapter.java
com.kudzmi.akuplayer.TrackListAdapter.java
com.kudzmi.akuplayer.player.AKuPlayerService.java
com.kudzmi.akuplayer.player.BroadcastCommander.java
com.kudzmi.akuplayer.player.ItemHighlighter.java
com.kudzmi.akuplayer.player.PlayerCommand.java
com.kudzmi.akuplayer.player.PlayerSeekCommand.java
com.kudzmi.akuplayer.player.PlayerStatus.java
com.kudzmi.akuplayer.player.TrackList.java