Android Open Source - ampdroid Song Array Adapter






From Project

Back to project page ampdroid.

License

The source code is released under:

MIT License

If you think the Android project ampdroid 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

/**
 * The MIT License (MIT)/*from w w  w  .j  ava 2s . c  om*/
 * 
 * Copyright (c) 2014 Daniel Schruhl
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */
package com.racoon.ampdroid;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;

import com.racoon.ampache.Song;

/**
 * @author Daniel Schruhl
 * 
 */
public class SongArrayAdapter extends ArrayAdapter<String> implements SectionIndexer {
  private final Context context;
  private final ArrayList<String> textValues;
  private ArrayList<Song> objectValues;
  HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
  private String[] sections;
  private String[] sectionsChar;

  public SongArrayAdapter(Context context, ArrayList<String> list, ArrayList<Song> objects) {
    super(context, R.layout.song_list_item, list);
    this.context = context;
    this.textValues = list;
    this.objectValues = objects;

    for (int i = 0; i < objects.size(); ++i) {
      mIdMap.put(list.get(i), i);
    }

    Set<String> sectionLetters = mIdMap.keySet();
    ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
    Collections.sort(sectionList);
    sections = new String[sectionList.size()];
    sectionsChar = new String[sectionList.size()];
    for (int i = 0; i < sectionList.size(); i++) {
      sections[i] = sectionList.get(i);
      sectionsChar[i] = sectionList.get(i).substring(0, 2);
    }
  }

  @SuppressLint("ViewHolder")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.song_list_item, parent, false);
    TextView songTitle = (TextView) rowView.findViewById(R.id.songTitle);
    TextView songArtist = (TextView) rowView.findViewById(R.id.songArtist);

    songTitle.setText(textValues.get(position));
    songArtist.setText(objectValues.get(position).getArtist());
    return rowView;
  }

  @Override
  public long getItemId(int position) {
    String item = getItem(position);
    return mIdMap.get(item);
  }

  @Override
  public boolean hasStableIds() {
    return true;
  }

  public int getPositionForSection(int section) {
    if ((sections.length == section) && section == 1) {
      return mIdMap.get(sections[section - 1]);
    }
    return mIdMap.get(sections[section]);
  }

  public int getSectionForPosition(int position) {
    return 1;
  }

  public Object[] getSections() {
    return sectionsChar;
  }

}




Java Source Code List

com.racoon.ampache.Album.java
com.racoon.ampache.Artist.java
com.racoon.ampache.CachedData.java
com.racoon.ampache.Playlist.java
com.racoon.ampache.ServerConnection.java
com.racoon.ampache.Song.java
com.racoon.ampdroid.AlbumArrayAdapter.java
com.racoon.ampdroid.ArtistArrayAdapter.java
com.racoon.ampdroid.Controller.java
com.racoon.ampdroid.CurrentlyPlayingPlaylistArrayAdapter.java
com.racoon.ampdroid.ImageLoadTask.java
com.racoon.ampdroid.MainActivity.java
com.racoon.ampdroid.Mp3PlayerService.java
com.racoon.ampdroid.PlaylistArrayAdapter.java
com.racoon.ampdroid.ServerConnector.java
com.racoon.ampdroid.SongArrayAdapter.java
com.racoon.ampdroid.views.AlbumsView.java
com.racoon.ampdroid.views.ArtistsView.java
com.racoon.ampdroid.views.CurrentPlaylistView.java
com.racoon.ampdroid.views.PlaylistsView.java
com.racoon.ampdroid.views.SelectedAlbumsView.java
com.racoon.ampdroid.views.SelectedArtistsView.java
com.racoon.ampdroid.views.SelectedPlaylistsView.java
com.racoon.ampdroid.views.SelectedSongsView.java
com.racoon.ampdroid.views.SettingsView.java
com.racoon.ampdroid.views.SongsView.java