Exemplo n.º 1
0
  @Override
  public void onStop() {
    super.onStop();

    // We don't want the list to display the empty state, since when we
    // resume it will still be there and show up while the new query is
    // happening. After the async query finishes in response to onResume()
    // setLoading(false) will be called.
    mAdapter.setLoading(true);
    mAdapter.changeCursor(null);
  }
Exemplo n.º 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;
  }