예제 #1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    int sortMode = TRACK_MENU;
    if (icicle == null) {
      mSelectedUri = getIntent().getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
      mDrmLevel = getIntent().getIntExtra(DrmStore.DrmExtra.EXTRA_DRM_LEVEL, -1);
      MusicLogUtils.d(TAG, "onCreate: drmlevel=" + mDrmLevel);
    } else {
      mSelectedUri = (Uri) icicle.getParcelable(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
      // Retrieve list state. This will be applied after the
      // QueryHandler has run
      mListState = icicle.getParcelable(LIST_STATE_KEY);
      mListHasFocus = icicle.getBoolean(FOCUS_KEY);
      sortMode = icicle.getInt(SORT_MODE_KEY, sortMode);
      mPrevSelectedPos = icicle.getInt(SELECTED_POS, -1);
      mDrmLevel = icicle.getInt(DRM_LEVEL, -1);
      MusicLogUtils.d(TAG, "onCreate: drmlevel(restored)=" + mDrmLevel);
    }
    if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) {
      mBaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    } else {
      mBaseUri = getIntent().getData();
      if (mBaseUri == null) {
        MusicLogUtils.w(TAG, "No data URI given to PICK action");
        finish();
        return;
      }
    }

    setContentView(R.layout.music_picker);

    LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
    /*
            if (FeatureOption.MTK_THEMEMANAGER_APP) {
                mainLayout.setThemeContentBgColor(0xff000000);
            }
    */
    mSortOrder = MediaStore.Audio.Media.TITLE_KEY;

    if (FeatureOption.MTK_DRM_APP) {
      mDrmClient = new DrmManagerClient(this);
    }

    final ListView listView = getListView();

    listView.setItemsCanFocus(false);

    mAdapter =
        new TrackListAdapter(
            this, listView, R.layout.music_picker_item, new String[] {}, new int[] {});

    setListAdapter(mAdapter);

    listView.setTextFilterEnabled(true);

    // We manually save/restore the listview state
    listView.setSaveEnabled(false);

    mQueryHandler = new QueryHandler(this);

    mProgressContainer = findViewById(R.id.progressContainer);
    mListContainer = findViewById(R.id.listContainer);

    mOkayButton = findViewById(R.id.okayButton);
    mOkayButton.setOnClickListener(this);
    mCancelButton = findViewById(R.id.cancelButton);
    mCancelButton.setOnClickListener(this);

    // If there is a currently selected Uri, then try to determine who
    // it is.
    if (mSelectedUri != null) {
      Uri.Builder builder = mSelectedUri.buildUpon();
      String path = mSelectedUri.getEncodedPath();
      int idx = path.lastIndexOf('/');
      if (idx >= 0) {
        path = path.substring(0, idx);
      }
      builder.encodedPath(path);
      Uri baseSelectedUri = builder.build();
      MusicLogUtils.v(TAG, "Selected Uri: " + mSelectedUri);
      MusicLogUtils.v(TAG, "Selected base Uri: " + baseSelectedUri);
      MusicLogUtils.v(TAG, "Base Uri: " + mBaseUri);
      if (baseSelectedUri.equals(mBaseUri)) {
        // If the base Uri of the selected Uri is the same as our
        // content's base Uri, then use the selection!
        mSelectedId = ContentUris.parseId(mSelectedUri);
      }
    }

    setSortMode(sortMode);
  }
예제 #2
0
  /**
   * Common method for performing a query of the music database, called for both top-level queries
   * and filtering.
   *
   * @param sync If true, this query should be done synchronously and the resulting cursor returned.
   *     If false, it will be done asynchronously and null returned.
   * @param filterstring If non-null, this is a filter to apply to the query.
   */
  Cursor doQuery(boolean sync, String filterstring) {
    MusicLogUtils.d(TAG, "doQuery(" + sync + ", " + filterstring + ")");
    // Cancel any pending queries
    mQueryHandler.cancelOperation(MY_QUERY_TOKEN);

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Media.TITLE + " != ''");

    if (FeatureOption.MTK_DRM_APP) {
      String sIsDrm = MediaStore.Audio.Media.IS_DRM;
      String sDrmMethod = MediaStore.Audio.Media.DRM_METHOD;
      switch (mDrmLevel) {
        case DrmStore.DrmExtra.DRM_LEVEL_FL:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + DrmStore.DrmMethod.METHOD_FL
                  + "))");
          break;
        case DrmStore.DrmExtra.DRM_LEVEL_SD:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + DrmStore.DrmMethod.METHOD_SD
                  + "))");
          break;
        case DrmStore.DrmExtra.DRM_LEVEL_ALL:
          break;
        case -1:
          // this intent does not contain DRM Extras
          where.append(" AND " + sIsDrm + "!=1");
          break;
      }

      MusicLogUtils.d(TAG, "doQuery: where=" + where);
    }

    // We want to show all audio files, even recordings.  Enforcing the
    // following condition would hide recordings.
    // where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");

    Uri uri = mBaseUri;
    if (!TextUtils.isEmpty(filterstring)) {
      uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filterstring)).build();
    }

    if (sync) {
      try {
        return getContentResolver().query(uri, CURSOR_COLS, where.toString(), null, mSortOrder);
      } catch (UnsupportedOperationException ex) {
      }
    } else {
      mAdapter.setLoading(true);
      setProgressBarIndeterminateVisibility(true);
      mQueryHandler.startQuery(
          MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
    }
    return null;
  }
예제 #3
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);
      }
    }