/** * 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_KEYRING: // No resources need to be freed for this ID break; case LOADER_ID_USER_IDS: mUserIdsAdapter.swapCursor(null); break; case LOADER_ID_KEYS: mKeysAdapter.swapCursor(null); break; default: break; } }
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) switch (loader.getId()) { case LOADER_ID_KEYRING: if (data.moveToFirst()) { // get name, email, and comment from USER_ID String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(KEYRING_INDEX_USER_ID)); if (mainUserId[0] != null) { getActivity().setTitle(mainUserId[0]); mName.setText(mainUserId[0]); } else { getActivity().setTitle(R.string.user_id_no_name); mName.setText(R.string.user_id_no_name); } mEmail.setText(mainUserId[1]); mComment.setText(mainUserId[2]); } break; case LOADER_ID_USER_IDS: mUserIdsAdapter.swapCursor(data); break; case LOADER_ID_KEYS: // the first key here is our master key if (data.moveToFirst()) { // get key id from MASTER_KEY_ID long keyId = data.getLong(KEYS_INDEX_KEY_ID); String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId); mKeyId.setText(keyIdStr); // get creation date from CREATION if (data.isNull(KEYS_INDEX_CREATION)) { mCreation.setText(R.string.none); } else { Date creationDate = new Date(data.getLong(KEYS_INDEX_CREATION) * 1000); mCreation.setText( DateFormat.getDateFormat(getActivity().getApplicationContext()) .format(creationDate)); } // get expiry date from EXPIRY if (data.isNull(KEYS_INDEX_EXPIRY)) { mExpiry.setText(R.string.none); } else { Date expiryDate = new Date(data.getLong(KEYS_INDEX_EXPIRY) * 1000); mExpiry.setText( DateFormat.getDateFormat(getActivity().getApplicationContext()).format(expiryDate)); } String algorithmStr = PgpKeyHelper.getAlgorithmInfo( data.getInt(KEYS_INDEX_ALGORITHM), data.getInt(KEYS_INDEX_KEY_SIZE)); mAlgorithm.setText(algorithmStr); byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT); if (fingerprintBlob == null) { // FALLBACK for old database entries fingerprintBlob = ProviderHelper.getFingerprint(getActivity(), mDataUri); } String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob, true); mFingerprint.setText(OtherHelper.colorizeFingerprint(fingerprint)); } mKeysAdapter.swapCursor(data); break; default: break; } }