Exemple #1
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) {
    // Cancel any pending queries
    mQueryHandler.cancelOperation(MY_QUERY_TOKEN);

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

    // 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;
  }
 public void close() {
   mShuttingDown = true;
   pruneAdapterInfo(QUERY_TYPE_CLEAN);
   if (mQueryHandler != null) {
     mQueryHandler.cancelOperation(0);
   }
 }
  private void startQuery() {
    mAdapter.setLoading(true);

    // Cancel any pending queries
    mQueryHandler.cancelOperation(QUERY_TOKEN);
    mQueryHandler.startQuery(
        QUERY_TOKEN,
        null,
        Calls.CONTENT_URI,
        CALL_LOG_PROJECTION,
        null,
        null,
        Calls.DEFAULT_SORT_ORDER);
  }
  /**
   * 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 + " != ''");

    /// M: determine the Dim level for query @{
    if (MusicFeatureOption.IS_SUPPORT_DRM) {
      String sIsDrm = MediaStore.Audio.Media.IS_DRM;
      String sDrmMethod = MediaStore.Audio.Media.DRM_METHOD;
      switch (mDrmLevel) {
        case OmaDrmStore.DrmExtra.DRM_LEVEL_FL:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + OmaDrmStore.DrmMethod.METHOD_FL
                  + "))");
          break;

        case OmaDrmStore.DrmExtra.DRM_LEVEL_SD:
          where.append(
              " AND ("
                  + sIsDrm
                  + "!=1 OR ("
                  + sIsDrm
                  + "=1"
                  + " AND "
                  + sDrmMethod
                  + "="
                  + OmaDrmStore.DrmMethod.METHOD_SD
                  + "))");
          break;

        case OmaDrmStore.DrmExtra.DRM_LEVEL_ALL:
          break;

        case -1:
        default:
          // 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);
      mQueryHandler.startQuery(
          MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
    }
    return null;
  }
  private void doQuery(QuerySpec queryData) {
    if (!mAdapterInfos.isEmpty()) {
      int start = mAdapterInfos.getFirst().start;
      int end = mAdapterInfos.getLast().end;
      int queryDuration = calculateQueryDuration(start, end);
      switch (queryData.queryType) {
        case QUERY_TYPE_OLDER:
          queryData.end = start - 1;
          queryData.start = queryData.end - queryDuration;
          break;
        case QUERY_TYPE_NEWER:
          queryData.start = end + 1;
          queryData.end = queryData.start + queryDuration;
          break;
      }

      // By "compacting" cursors, this fixes the disco/ping-pong problem
      // b/5311977
      if (mRowCount < 20 && queryData.queryType != QUERY_TYPE_CLEAN) {
        if (DEBUGLOG) {
          Log.e(
              TAG,
              "Compacting cursor: mRowCount="
                  + mRowCount
                  + " totalStart:"
                  + start
                  + " totalEnd:"
                  + end
                  + " query.start:"
                  + queryData.start
                  + " query.end:"
                  + queryData.end);
        }

        queryData.queryType = QUERY_TYPE_CLEAN;

        if (queryData.start > start) {
          queryData.start = start;
        }
        if (queryData.end < end) {
          queryData.end = end;
        }
      }
    }

    if (BASICLOG) {
      Time time = new Time(mTimeZone);
      time.setJulianDay(queryData.start);
      Time time2 = new Time(mTimeZone);
      time2.setJulianDay(queryData.end);
      Log.v(
          TAG,
          "startQuery: "
              + time.toString()
              + " to "
              + time2.toString()
              + " then go to "
              + queryData.goToTime);
    }

    mQueryHandler.cancelOperation(0);
    if (BASICLOG) queryData.queryStartMillis = System.nanoTime();

    Uri queryUri = buildQueryUri(queryData.start, queryData.end, queryData.searchQuery);
    mQueryHandler.startQuery(
        0, queryData, queryUri, PROJECTION, buildQuerySelection(), null, AGENDA_SORT_ORDER);
  }