コード例 #1
0
 @Override
 public View newView(Context context, Cursor cursor, ViewGroup parent) {
   View v = super.newView(context, cursor, parent);
   ViewHolder vh = new ViewHolder();
   vh.line1 = (TextView) v.findViewById(R.id.line1);
   vh.line2 = (TextView) v.findViewById(R.id.line2);
   vh.duration = (TextView) v.findViewById(R.id.duration);
   vh.radio = (RadioButton) v.findViewById(R.id.radio);
   vh.play_indicator = (ImageView) v.findViewById(R.id.play_indicator);
   vh.drm_lock = (ImageView) v.findViewById(R.id.drm_lock);
   vh.buffer1 = new CharArrayBuffer(100);
   vh.buffer2 = new char[200];
   v.setTag(vh);
   return v;
 }
コード例 #2
0
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
      ViewHolder vh = (ViewHolder) view.getTag();

      cursor.copyStringToBuffer(mTitleIdx, vh.buffer1);
      vh.line1.setText(vh.buffer1.data, 0, vh.buffer1.sizeCopied);

      int secs = cursor.getInt(mDurationIdx) / 1000;
      if (secs == 0) {
        vh.duration.setText("");
      } else {
        vh.duration.setText(MusicUtils.makeTimeString(context, secs));
      }

      final StringBuilder builder = mBuilder;
      builder.delete(0, builder.length());

      String name = cursor.getString(mAlbumIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownAlbum);
      } else {
        builder.append(name);
      }
      builder.append('\n');
      name = cursor.getString(mArtistIdx);
      if (name == null || name.equals("<unknown>")) {
        builder.append(mUnknownArtist);
      } else {
        builder.append(name);
      }
      int len = builder.length();
      if (vh.buffer2.length < len) {
        vh.buffer2 = new char[len];
      }
      builder.getChars(0, len, vh.buffer2, 0);
      vh.line2.setText(vh.buffer2, 0, len);

      // Update the checkbox of the item, based on which the user last
      // selected.  Note that doing it this way means we must have the
      // list view update all of its items when the selected item
      // changes.
      final long id = cursor.getLong(mIdIdx);
      vh.radio.setChecked(id == mSelectedId);
      MusicLogUtils.v(
          TAG,
          "Binding id="
              + id
              + " sel="
              + mSelectedId
              + " playing="
              + mPlayingId
              + " cursor="
              + cursor);

      // Likewise, display the "now playing" icon if this item is
      // currently being previewed for the user.
      ImageView iv = vh.play_indicator;
      if (id == mPlayingId) {
        iv.setImageResource(R.drawable.indicator_ic_mp_playing_list);
        iv.setVisibility(View.VISIBLE);
      } else {
        iv.setVisibility(View.GONE);
      }

      // Show drm lock when necessary
      iv = vh.drm_lock;
      if (FeatureOption.MTK_DRM_APP) {
        int isDRM = cursor.getInt(mIsDrmIdx);
        int drmMethod = cursor.getInt(mDrmMethodIdx);
        MusicLogUtils.d(TAG, "bindView(" + view + "): isDRM=" + isDRM + ", drmMethod=" + drmMethod);
        try {
          if (isDRM == 1 && drmMethod != DrmStore.DrmMethod.METHOD_FL) {
            if (mDrmClient.checkRightsStatus(
                    ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id),
                    DrmStore.Action.PLAY)
                == DrmStore.RightsStatus.RIGHTS_VALID) {
              iv.setImageResource(com.mediatek.internal.R.drawable.drm_green_lock);
            } else {
              iv.setImageResource(com.mediatek.internal.R.drawable.drm_red_lock);
            }
            iv.setVisibility(View.VISIBLE);
          } else {
            iv.setVisibility(View.GONE);
          }
        } catch (Exception ex) {
          MusicLogUtils.e(TAG, "bindView: ", ex);
          iv.setVisibility(View.GONE);
        }
      } else {
        iv.setVisibility(View.GONE);
      }
    }