Beispiel #1
0
 /**
  * This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
  * We need to make sure we are no longer using it.
  */
 public void onLoaderReset(Loader<Cursor> loader) {
   switch (loader.getId()) {
     case LOADER_ID_USER_IDS:
       mUserIdsAdapter.swapCursor(null);
       break;
   }
 }
Beispiel #2
0
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    /* TODO better error handling? May cause problems when a key is deleted,
     * because the notification triggers faster than the activity closes.
     */
    // Avoid NullPointerExceptions...
    if (data.getCount() == 0) {
      return;
    }
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    switch (loader.getId()) {
      case LOADER_ID_UNIFIED:
        {
          if (data.moveToFirst()) {
            if (data.getInt(INDEX_UNIFIED_HAS_ANY_SECRET) != 0) {
              // certify button
              mActionCertify.setVisibility(View.GONE);
              mActionCertifyDivider.setVisibility(View.GONE);

              // edit button
              mActionEdit.setVisibility(View.VISIBLE);
              mActionEditDivider.setVisibility(View.VISIBLE);
            } else {
              // certify button
              mActionCertify.setVisibility(View.VISIBLE);
              mActionCertifyDivider.setVisibility(View.VISIBLE);

              // edit button
              mActionEdit.setVisibility(View.GONE);
              mActionEditDivider.setVisibility(View.GONE);
            }

            // If this key is revoked, it cannot be used for anything!
            if (data.getInt(INDEX_UNIFIED_IS_REVOKED) != 0) {
              mActionEdit.setEnabled(false);
              mActionCertify.setEnabled(false);
              mActionEncrypt.setEnabled(false);
            } else {
              mActionEdit.setEnabled(true);

              Date expiryDate = new Date(data.getLong(INDEX_UNIFIED_EXPIRY) * 1000);
              if (!data.isNull(INDEX_UNIFIED_EXPIRY) && expiryDate.before(new Date())) {
                mActionCertify.setEnabled(false);
                mActionEncrypt.setEnabled(false);
              } else {
                mActionCertify.setEnabled(true);
                mActionEncrypt.setEnabled(true);
              }
            }

            mHasEncrypt = data.getInt(INDEX_UNIFIED_HAS_ENCRYPT) != 0;

            break;
          }
        }

      case LOADER_ID_USER_IDS:
        mUserIdsAdapter.swapCursor(data);
        break;
    }
    setContentShown(true);
  }