コード例 #1
0
ファイル: MessageProvider.java プロジェクト: rbayer/k-9
  @Override
  public Cursor query(
      final Uri uri,
      final String[] projection,
      final String selection,
      final String[] selectionArgs,
      final String sortOrder) {
    if (K9.app == null) {
      return null;
    }

    if (K9.DEBUG) {
      Log.v(K9.LOG_TAG, "MessageProvider/query: " + uri);
    }

    final Cursor cursor;

    final int code = mUriMatcher.match(uri);

    if (code == -1) {
      throw new IllegalStateException("Unrecognized URI: " + uri);
    }

    try {
      // since we used the list index as the UriMatcher code, using it
      // back to retrieve the handler from the list
      final QueryHandler handler = mQueryHandlers.get(code);
      cursor = handler.query(uri, projection, selection, selectionArgs, sortOrder);
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Unable to execute query for URI: " + uri, e);
      return null;
    }

    return cursor;
  }
コード例 #2
0
ファイル: MusicPicker.java プロジェクト: powerbush/SPD8810GA
  /**
   * 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;
  }
コード例 #3
0
 /**
  * The query method processes a Fenius query for information relating to a previously issued
  * reservation.
  *
  * @param arg0 The un-marshaled JAXB object hold the Fenius query request.
  * @return The QueryResp object holding the reservation information returned by the query.
  * @throws ExternalFault or InternalFault depending on the type of error.
  */
 public is.glif.fenius.ws.connection.v1._interface.QueryResp query(
     is.glif.fenius.ws.connection.v1._interface.QueryReq arg0)
     throws ExternalFault, InternalFault {
   QueryHandler handler = new QueryHandler();
   handler.setContext(wsc);
   return handler.process(arg0);
 }
  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);
  }
コード例 #5
0
  public CalendarSelectionPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    List<Pair<String, Boolean>> allCalendars = CalendarExtension.getAllCalendars(context);
    Set<String> allVisibleCalendarsSet = new HashSet<String>();
    for (Pair<String, Boolean> pair : allCalendars) {
      if (pair.second) {
        allVisibleCalendarsSet.add(pair.first);
      }
    }

    mSelectedCalendars =
        new HashSet<String>(
            PreferenceManager.getDefaultSharedPreferences(context)
                .getStringSet(CalendarExtension.PREF_SELECTED_CALENDARS, allVisibleCalendarsSet));

    mAdapter = new CalendarListAdapter(context);
    mQueryHandler = new QueryHandler(context, mAdapter);

    mQueryHandler.startQuery(
        0,
        null,
        CalendarContract.Calendars.CONTENT_URI,
        CalendarQuery.PROJECTION,
        CalendarContract.Calendars.SYNC_EVENTS + "=1",
        null,
        CalendarContract.Calendars.CALENDAR_DISPLAY_NAME);
  }
コード例 #6
0
 public void close() {
   mShuttingDown = true;
   pruneAdapterInfo(QUERY_TYPE_CLEAN);
   if (mQueryHandler != null) {
     mQueryHandler.cancelOperation(0);
   }
 }
コード例 #7
0
    public void execute(QueryHandler qh) throws SQLException {
      try {
        int set = 1;
        boolean has_result = sql.execute();
        int update_count;

        while (true) {
          ResultSet result;

          if (has_result) {
            update_count = -1;
            result = sql.getResultSet();
          } else {
            update_count = sql.getUpdateCount();

            if (update_count == -1) {
              break;
            }

            result = sql.getGeneratedKeys();
          }

          qh.handleResult(set, update_count, result);
          ++set;

          has_result = sql.getMoreResults();
        }
      } finally {
        sql.clearParameters();
      }
    }
コード例 #8
0
  private void dismissFiredAlarms() {
    ContentValues values = new ContentValues(1 /* size */);
    values.put(PROJECTION[INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    String selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    mQueryHandler.startUpdate(
        0,
        null,
        CalendarAlerts.CONTENT_URI,
        values,
        selection,
        null /* selectionArgs */,
        Utils.UNDO_DELAY);

    if (mCursor == null) {
      Log.e(TAG, "Unable to globally dismiss all notifications because cursor was null.");
      return;
    }
    if (mCursor.isClosed()) {
      Log.e(TAG, "Unable to globally dismiss all notifications because cursor was closed.");
      return;
    }
    if (!mCursor.moveToFirst()) {
      Log.e(TAG, "Unable to globally dismiss all notifications because cursor was empty.");
      return;
    }

    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    do {
      long eventId = mCursor.getLong(INDEX_EVENT_ID);
      long eventStart = mCursor.getLong(INDEX_BEGIN);
      alarmIds.add(new AlarmId(eventId, eventStart));
    } while (mCursor.moveToNext());
    initiateGlobalDismiss(alarmIds);
  }
コード例 #9
0
  /**
   * Internal method to query for contacts with a given display name.
   *
   * @param contactDisplayName the display name to look for.
   */
  private void startDisambiguationQuery(String contactDisplayName) {
    // Apply a limit of 1 result to the query because we only need to
    // determine whether or not at least one other contact has the same
    // name. We don't need to find ALL other contacts with the same name.
    final Builder builder = Contacts.CONTENT_URI.buildUpon();
    builder.appendQueryParameter("limit", String.valueOf(1));
    final Uri uri = builder.build();

    final String displayNameSelection;
    final String[] selectionArgs;
    if (TextUtils.isEmpty(contactDisplayName)) {
      displayNameSelection = Contacts.DISPLAY_NAME_PRIMARY + " IS NULL";
      selectionArgs = new String[] {String.valueOf(mContactId)};
    } else {
      displayNameSelection = Contacts.DISPLAY_NAME_PRIMARY + " = ?";
      selectionArgs = new String[] {contactDisplayName, String.valueOf(mContactId)};
    }
    mQueryHandler.startQuery(
        TOKEN_DISAMBIGUATION_QUERY,
        null,
        uri,
        new String[] {Contacts._ID} /* unused projection but a valid one was needed */,
        displayNameSelection
            + " AND "
            + Contacts.PHOTO_ID
            + " IS NULL AND "
            + Contacts._ID
            + " <> ?",
        selectionArgs,
        null);
  }
コード例 #10
0
    public void bindParams(QueryHandler qh) throws SQLException {
      int p = 1;

      for (String param : params) {
        sql.setObject(p, qh.resolveParam(param));
        ++p;
      }
    }
コード例 #11
0
  /**
   * startContactQuery
   *
   * <p>internal method to query contact by Uri.
   *
   * @param contactUri the contact uri
   * @param resetQueryHandler whether to use a new AsyncQueryHandler or not
   */
  private void startContactQuery(Uri contactUri, boolean resetQueryHandler) {
    if (resetQueryHandler) {
      resetAsyncQueryHandler();
    }

    mQueryHandler.startQuery(
        TOKEN_CONTACT_INFO, null, contactUri, ContactQuery.COLUMNS, null, null, null);
  }
コード例 #12
0
 /**
  * Internal method to query contact photo by photo id and uri.
  *
  * @param photoId the photo id.
  * @param lookupKey the lookup uri.
  */
 private void startPhotoQuery(long photoId, Uri lookupKey) {
   mQueryHandler.startQuery(
       TOKEN_PHOTO_QUERY,
       lookupKey,
       ContentUris.withAppendedId(Data.CONTENT_URI, photoId),
       PhotoQuery.COLUMNS,
       null,
       null,
       null);
 }
コード例 #13
0
 /** Internal method to query for extra data fields for this contact. */
 private void startExtraInfoQuery() {
   mQueryHandler.startQuery(
       TOKEN_EXTRA_INFO_QUERY,
       null,
       Data.CONTENT_URI,
       ExtraInfoQuery.COLUMNS,
       RawContacts.CONTACT_ID + " = ?",
       new String[] {String.valueOf(mContactId)},
       null);
 }
コード例 #14
0
ファイル: MessageProvider.java プロジェクト: rbayer/k-9
  /**
   * Register a {@link QueryHandler} to handle a certain {@link Uri} for {@link #query(Uri,
   * String[], String, String[], String)}
   *
   * @param handler Never <code>null</code>.
   */
  protected void registerQueryHandler(final QueryHandler handler) {
    if (mQueryHandlers.contains(handler)) {
      return;
    }
    mQueryHandlers.add(handler);

    // use the index inside the list as the UriMatcher code for that handler
    final int code = mQueryHandlers.indexOf(handler);
    mUriMatcher.addURI(AUTHORITY, handler.getPath(), code);
  }
  private void resetNewCallsFlag() {
    // Mark all "new" missed calls as not new anymore
    StringBuilder where = new StringBuilder("type=");
    where.append(Calls.MISSED_TYPE);
    where.append(" AND new=1");

    ContentValues values = new ContentValues(1);
    values.put(Calls.NEW, "0");
    mQueryHandler.startUpdate(
        UPDATE_TOKEN, null, Calls.CONTENT_URI, values, where.toString(), null);
  }
コード例 #16
0
  /**
   * Convenience method for binding all available data from an existing contact.
   *
   * @param emailAddress The email address used to do a reverse lookup in the contacts database. If
   *     more than one contact contains this email address, one of them will be chosen to bind to.
   */
  public void bindFromEmail(String emailAddress) {
    resetAsyncQueryHandler();

    mQueryHandler.startQuery(
        TOKEN_EMAIL_LOOKUP,
        emailAddress,
        Uri.withAppendedPath(TEmail.CONTENT_LOOKUP_URI, Uri.encode(emailAddress)),
        EMAIL_LOOKUP_PROJECTION,
        null,
        null,
        null);
  }
コード例 #17
0
  /**
   * Convenience method for binding all available data from an existing contact.
   *
   * @param number The phone number used to do a reverse lookup in the contacts database. If more
   *     than one contact contains this phone number, one of them will be chosen to bind to.
   */
  public void bindFromPhoneNumber(String number) {
    resetAsyncQueryHandler();

    mQueryHandler.startQuery(
        TOKEN_PHONE_LOOKUP,
        number,
        Uri.withAppendedPath(TPhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)),
        PHONE_LOOKUP_PROJECTION,
        null,
        null,
        null);
  }
コード例 #18
0
 public void query() {
   mLoadingBar.setVisibility(View.VISIBLE);
   // 查询类型为游戏的所有数据
   String selectionString = AppData.App.TYPE + "=?";
   String args[] = {"" + AppManager.ZHAOYAN_APP};
   mQueryHandler.startQuery(
       11,
       null,
       AppData.App.CONTENT_URI,
       PROJECTION,
       selectionString,
       args,
       AppData.App.SORT_ORDER_LABEL);
 }
コード例 #19
0
  /**
   * startPhotoQuery
   *
   * <p>internal method to query contact photo by photo id and uri.
   *
   * @param photoId the photo id.
   * @param lookupKey the lookup uri.
   * @param resetQueryHandler whether to use a new AsyncQueryHandler or not.
   */
  protected void startPhotoQuery(long photoId, Uri lookupKey, boolean resetQueryHandler) {
    if (resetQueryHandler) {
      resetAsyncQueryHandler();
    }

    mQueryHandler.startQuery(
        TOKEN_PHOTO_QUERY,
        lookupKey,
        ContentUris.withAppendedId(TData.CONTENT_URI, photoId),
        PhotoQuery.COLUMNS,
        null,
        null,
        null);
  }
コード例 #20
0
  private void dismissAlarm(long id, long eventId, long startTime) {
    ContentValues values = new ContentValues(1 /* size */);
    values.put(PROJECTION[INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    String selection = CalendarAlerts._ID + "=" + id;
    mQueryHandler.startUpdate(
        0,
        null,
        CalendarAlerts.CONTENT_URI,
        values,
        selection,
        null /* selectionArgs */,
        Utils.UNDO_DELAY);

    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    alarmIds.add(new AlarmId(eventId, startTime));
    initiateGlobalDismiss(alarmIds);
  }
コード例 #21
0
ファイル: MessageProvider.java プロジェクト: rbayer/k-9
    @Override
    public Cursor query(
        Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
        throws Exception {
      mSemaphore.acquire();

      final Cursor cursor;
      cursor = mDelegate.query(uri, projection, selection, selectionArgs, sortOrder);

      /* Android content resolvers can only process CrossProcessCursor instances */
      if (!(cursor instanceof CrossProcessCursor)) {
        Log.w(K9.LOG_TAG, "Unsupported cursor, returning null: " + cursor);
        return null;
      }

      final MonitoredCursor wrapped = new MonitoredCursor((CrossProcessCursor) cursor, mSemaphore);

      /* use a weak reference not to actively prevent garbage collection */
      final WeakReference<MonitoredCursor> weakReference =
          new WeakReference<MonitoredCursor>(wrapped);

      /* make sure the cursor is closed after 30 seconds */
      mScheduledPool.schedule(
          new Runnable() {

            @Override
            public void run() {
              final MonitoredCursor monitored = weakReference.get();
              if (monitored != null && !monitored.isClosed()) {
                Log.w(K9.LOG_TAG, "Forcibly closing remotely exposed cursor");
                try {
                  monitored.close();
                } catch (Exception e) {
                  Log.w(K9.LOG_TAG, "Exception while forcibly closing cursor", e);
                }
              }
            }
          },
          30,
          TimeUnit.SECONDS);

      return wrapped;
    }
コード例 #22
0
  @Override
  protected void onResume() {
    super.onResume();

    // If the cursor is null, start the async handler. If it is not null just requery.
    if (mCursor == null) {
      Uri uri = CalendarAlerts.CONTENT_URI_BY_INSTANCE;
      mQueryHandler.startQuery(
          0,
          null,
          uri,
          PROJECTION,
          SELECTION,
          SELECTIONARG,
          CalendarContract.CalendarAlerts.DEFAULT_SORT_ORDER);
    } else {
      if (!mCursor.requery()) {
        Log.w(TAG, "Cursor#requery() failed.");
        mCursor.close();
        mCursor = null;
      }
    }
  }
コード例 #23
0
ファイル: FixedZone.java プロジェクト: qiniu/android-sdk
 @Override
 public void preQuery(String token, QueryHandler complete) {
   complete.onSuccess();
 }
コード例 #24
0
  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);
  }
コード例 #25
0
 /**
  * Internal method to query contact by Uri.
  *
  * @param contactUri the contact uri
  */
 private void startContactQuery(Uri contactUri) {
   mQueryHandler.startQuery(
       TOKEN_CONTACT_INFO, contactUri, contactUri, ContactQuery.COLUMNS, null, null, null);
 }
コード例 #26
0
ファイル: MusicPicker.java プロジェクト: zst123/p201-packages
  /**
   * 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;
  }
コード例 #27
0
ファイル: ADNList.java プロジェクト: risingsunm/Phone_4.0
 private void query() {
   Uri uri = resolveIntent();
   if (DBG) log("query: starting an async query");
   mQueryHandler.startQuery(QUERY_TOKEN, null, uri, COLUMN_NAMES, null, null, null);
   displayProgress(true);
 }
コード例 #28
0
ファイル: MessageProvider.java プロジェクト: rbayer/k-9
 @Override
 public String getPath() {
   return mDelegate.getPath();
 }