コード例 #1
0
ファイル: LibraryTab.java プロジェクト: kairon007/UpMobile
 @Override
 protected FilterResults performFiltering(CharSequence constraint) {
   FilterResults results = new FilterResults();
   String prefix = constraint.toString().toLowerCase();
   if (mOriginalValues == null) {
     mOriginalValues = new ArrayList<MusicData>(mObjects);
   }
   if (prefix == null || prefix.length() == 0) {
     ArrayList<MusicData> list = new ArrayList<MusicData>(mOriginalValues);
     results.values = list;
     results.count = list.size();
   } else {
     ArrayList<MusicData> list = new ArrayList<MusicData>(mOriginalValues);
     ArrayList<MusicData> nlist = new ArrayList<MusicData>();
     int count = list.size();
     for (int i = 0; i < count; i++) {
       MusicData data = list.get(i);
       String value = data.toString();
       if (value.contains(prefix)) {
         nlist.add(data);
       }
       results.values = nlist;
       results.count = nlist.size();
     }
   }
   return results;
 }
コード例 #2
0
ファイル: LibraryTab.java プロジェクト: kairon007/UpMobile
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolderItem holder;
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.library_item, null);
      holder = new ViewHolderItem();
      holder.hThreedot = (ImageButton) convertView.findViewById(R.id.threedotButton);
      holder.hButtonPlay = (ImageButton) convertView.findViewById(R.id.play_song);
      holder.hSongTitle = (TextView) convertView.findViewById(R.id.title_song);
      holder.hSongArtist = (TextView) convertView.findViewById(R.id.artist);
      holder.hCoverImage = (ImageView) convertView.findViewById(R.id.cover_song);
      holder.hSongDuration = (TextView) convertView.findViewById(R.id.duration_song);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolderItem) convertView.getTag();
    }
    MusicData music = getItem(position);
    String strArtist = music.getSongArtist();
    String strTitle = music.getSongTitle();
    String strDuration = music.getSongDuration();
    Bitmap bitmap = music.getSongBitmap();
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
      holder.hButtonPlay.setBackgroundDrawable(
          activity.getResources().getDrawable(R.drawable.selectable_item_bg_honeycomb));
    }
    if (null != bitmap) {
      holder.hCoverImage.setImageBitmap(bitmap);
    } else {
      holder.hCoverImage.setImageResource(R.drawable.fallback_cover);
    }
    holder.hSongTitle.setText(strTitle);
    holder.hSongDuration.setText(strDuration);
    holder.hSongArtist.setText(strArtist);
    final int pos = position;
    activity.registerForContextMenu(convertView);
    convertView.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View arg0) {
            MusicData music = getItem(pos);
            activity.setDeletedItem(music);
            activity.setSelectedItem(music);
            return false;
          }
        });
    holder.hThreedot.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            MusicData music = getItem(pos);
            activity.setDeletedItem(music);
            activity.setSelectedItem(music);
            arg0.performLongClick();
          }
        });
    holder.hButtonPlay.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            MusicData musicData = getItem(pos);
            activity.play(null, musicData);
          }
        });
    return convertView;
  }