Example usage for android.database Cursor isNull

List of usage examples for android.database Cursor isNull

Introduction

In this page you can find the example usage for android.database Cursor isNull.

Prototype

boolean isNull(int columnIndex);

Source Link

Document

Returns true if the value in the indicated column is null.

Usage

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Sets the proper icon (star or presence or nothing) and/or status message.
 *//*from w  w w . j av a  2s . com*/
public void showPresenceAndStatusMessage(Cursor cursor, int presenceColumnIndex, int contactStatusColumnIndex) {
    Drawable icon = null;
    int presence = 0;
    if (!cursor.isNull(presenceColumnIndex)) {
        presence = cursor.getInt(presenceColumnIndex);
        icon = ContactPresenceIconUtil.getPresenceIcon(getContext(), presence);
    }
    setPresence(icon);

    String statusMessage = null;
    if (contactStatusColumnIndex != 0 && !cursor.isNull(contactStatusColumnIndex)) {
        statusMessage = cursor.getString(contactStatusColumnIndex);
    }
    // If there is no status message from the contact, but there was a presence value, then use
    // the default status message string
    if (statusMessage == null && presence != 0) {
        statusMessage = ContactStatusUtil.getStatusString(getContext(), presence);
    }
    setStatus(statusMessage);
}

From source file:nl.privacybarometer.privacyvandaag.adapter.FeedsCursorAdapter.java

@Override
protected void bindChildView(View view, Context context, Cursor cursor) {
    view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE);

    TextView textView = ((TextView) view.findViewById(android.R.id.text1));
    // if FetchMode is 99 then DO-NOT-REFRESH feed channel. activeFeedChannel = false;
    boolean activeFeedChannel = !(cursor.getInt(mFetchModePos) == FETCHMODE_DO_NOT_FETCH);

    // Use icons in package instead of fetching favicons from internet. See comment below.
    Drawable mDrawable;/*from w ww  .  j  av  a 2  s . c  om*/
    int mIconResourceId = cursor.getInt(mIconId);
    if (mIconResourceId > 0) {
        mDrawable = ContextCompat.getDrawable(context, mIconResourceId);
    } else {
        mDrawable = ContextCompat.getDrawable(context, R.drawable.logo_icon_pv);
    }
    mDrawable.setBounds(0, 0, 50, 50); // define the size of the drawable
    textView.setCompoundDrawables(mDrawable, null, null, null);

    //  Code not needed since we no longer use favicons retrieved from the internet,
    //but use the logo's included in the resource directory of the app using the code above.
    /*
        final long feedId = cursor.getLong(mIdPos);
        Bitmap bitmap = UiUtils.getFaviconBitmap(feedId, cursor, mIconPos);
        if ((bitmap != null) && (activeFeedChannel)) {   // if a favicon is available, show it next to the feed name.
            textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
    */
    textView.setText((cursor.isNull(mNamePos) ? cursor.getString(mLinkPos) : cursor.getString(mNamePos)));
    // if FetchMode is 99 then DO-NOT-REFRESH is active. Add remark and change style
    if (activeFeedChannel) {
        textView.setTextColor(ACTIVE_TEXT_COLOR);
    } else { // inactive feed channel. Is not refreshed.
        textView.append(" - niet volgen");
        textView.setTextColor(DO_NOT_FETCH_COLOR_TEXT_COLOR);
    }
}

From source file:com.android.contacts.common.model.ContactLoader.java

/**
 * Extracts Contact level columns from the cursor.
 *///from   w w  w . j  a  v  a2  s  .  c o  m
private Contact loadContactHeaderData(final Cursor cursor, Uri contactUri) {
    final String directoryParameter = contactUri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
    final long directoryId = directoryParameter == null ? Directory.DEFAULT
            : Long.parseLong(directoryParameter);
    final long contactId = cursor.getLong(ContactQuery.CONTACT_ID);
    final String lookupKey = cursor.getString(ContactQuery.LOOKUP_KEY);
    final long nameRawContactId = cursor.getLong(ContactQuery.NAME_RAW_CONTACT_ID);
    final int displayNameSource = cursor.getInt(ContactQuery.DISPLAY_NAME_SOURCE);
    final String displayName = cursor.getString(ContactQuery.DISPLAY_NAME);
    final String altDisplayName = cursor.getString(ContactQuery.ALT_DISPLAY_NAME);
    final String phoneticName = cursor.getString(ContactQuery.PHONETIC_NAME);
    final long photoId = cursor.getLong(ContactQuery.PHOTO_ID);
    final String photoUri = cursor.getString(ContactQuery.PHOTO_URI);
    final boolean starred = cursor.getInt(ContactQuery.STARRED) != 0;
    final Integer presence = cursor.isNull(ContactQuery.CONTACT_PRESENCE) ? null
            : cursor.getInt(ContactQuery.CONTACT_PRESENCE);
    final boolean sendToVoicemail = cursor.getInt(ContactQuery.SEND_TO_VOICEMAIL) == 1;
    final String customRingtone = cursor.getString(ContactQuery.CUSTOM_RINGTONE);
    final boolean isUserProfile = cursor.getInt(ContactQuery.IS_USER_PROFILE) == 1;

    Uri lookupUri;
    if (directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE) {
        lookupUri = ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey),
                contactId);
    } else {
        lookupUri = contactUri;
    }

    return new Contact(mRequestedUri, contactUri, lookupUri, directoryId, lookupKey, contactId,
            nameRawContactId, displayNameSource, photoId, photoUri, displayName, altDisplayName, phoneticName,
            starred, presence, sendToVoicemail, customRingtone, isUserProfile);
}

From source file:com.amytech.android.library.views.imagechooser.threads.MediaProcessorThread.java

public String checkExtension(Uri uri) {

    String extension = "";

    // The query, since it only applies to a single document, will only
    // return//w  w w  .  j  a  v a  2  s.c  o m
    // one row. There's no need to filter, sort, or select fields, since we
    // want
    // all fields for one document.
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    try {
        // moveToFirst() returns false if the cursor has 0 rows. Very handy
        // for
        // "if there's anything to look at, look at it" conditionals.
        if (cursor != null && cursor.moveToFirst()) {

            // Note it's called "Display Name". This is
            // provider-specific, and might not necessarily be the file
            // name.
            String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            int position = displayName.indexOf(".");
            extension = displayName.substring(position + 1);
            Log.i(TAG, "Display Name: " + displayName);

            int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
            // If the size is unknown, the value stored is null. But since
            // an
            // int can't be null in Java, the behavior is
            // implementation-specific,
            // which is just a fancy term for "unpredictable". So as
            // a rule, check if it's null before assigning to an int. This
            // will
            // happen often: The storage API allows for remote files, whose
            // size might not be locally known.
            String size = null;
            if (!cursor.isNull(sizeIndex)) {
                // Technically the column stores an int, but
                // cursor.getString()
                // will do the conversion automatically.
                size = cursor.getString(sizeIndex);
            } else {
                size = "Unknown";
            }
            Log.i(TAG, "Size: " + size);
        }
    } finally {
        cursor.close();
    }
    return extension;
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyMainFragment.java

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.
     *//*  ww w  .  jav a  2s.  c  om*/
    // 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);
}

From source file:pl.selvin.android.syncframework.content.TableInfo.java

public void GetChanges(SQLiteDatabase db, JsonGenerator gen, ArrayList<TableInfo> notifyTableInfo)
        throws IOException {
    String[] cols = new String[columns.length + 3];
    int i = 0;/* w  w  w  .ja va 2 s .c  om*/
    for (; i < columns.length; i++)
        cols[i] = columns[i].name;
    cols[i] = _.uri;
    cols[i + 1] = _.tempId;
    cols[i + 2] = _.isDeleted;
    Cursor c = db.query(name, cols, _.isDirtyP, new String[] { "1" }, null, null, null);
    //to fix startPos  > actual rows for large cursors db operations should be done after cursor is closed ...
    final ArrayList<OperationHolder> operations = new ArrayList<OperationHolder>();
    if (c.moveToFirst()) {
        if (!notifyTableInfo.contains(this))
            notifyTableInfo.add(this);
        do {

            gen.writeStartObject();
            gen.writeObjectFieldStart(_.__metadata);
            gen.writeBooleanField(_.isDirty, true);
            gen.writeStringField(_.type, scope_name);
            //Log.d("before", scope_name + ":" + c.getLong(i + 3));
            String uri = c.getString(i);
            //Log.d("after", scope_name + ":" + c.getLong(i + 3));
            if (uri == null) {
                gen.writeStringField(_.tempId, c.getString(i + 1));
            } else {
                gen.writeStringField(_.uri, uri);
                final ContentValues update = new ContentValues(1);
                update.put(_.isDirty, 0);
                operations.add(new OperationHolder(name, OperationHolder.UPDATE, update, uri));
            }
            boolean isDeleted = c.getInt(i + 2) == 1;
            if (isDeleted) {
                gen.writeBooleanField(_.isDeleted, true);
                gen.writeEndObject();// meta
                operations.add(new OperationHolder(name, OperationHolder.DELETE, null, uri));
            } else {
                gen.writeEndObject();// meta
                for (i = 0; i < columns.length; i++) {
                    if (columns[i].nullable && c.isNull(i)) {
                        gen.writeNullField(columns[i].name);
                    } else {
                        switch (columns[i].type) {
                        case ColumnType.BLOB:
                            gen.writeBinaryField(columns[i].name, c.getBlob(i));
                            break;
                        case ColumnType.BOOLEAN:
                            gen.writeBooleanField(columns[i].name, c.getLong(i) == 1);
                            break;
                        case ColumnType.INTEGER:
                            gen.writeNumberField(columns[i].name, c.getLong(i));
                            break;
                        case ColumnType.DATETIME:
                            try {
                                gen.writeStringField(columns[i].name,
                                        String.format(msdate, sdf.parse(c.getString(i)).getTime()));
                            } catch (Exception e) {
                                if (BuildConfig.DEBUG) {
                                    Log.e("ListSync", e.getLocalizedMessage());
                                }
                            }
                            break;
                        case ColumnType.NUMERIC:
                            gen.writeNumberField(columns[i].name, c.getDouble(i));
                            break;
                        default:
                            gen.writeStringField(columns[i].name, c.getString(i));
                            break;
                        }
                    }
                }
            }
            gen.writeEndObject(); // end of row
        } while (c.moveToNext());
    }
    c.close();
    for (OperationHolder operation : operations)
        operation.execute(db);
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyActivity.java

@Override
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.
     */// w ww . jav a 2 s . com
    // 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()) {
            // get name, email, and comment from USER_ID
            String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(INDEX_UNIFIED_USER_ID));
            if (mainUserId[0] != null) {
                setTitle(mainUserId[0]);
            } else {
                setTitle(R.string.user_id_no_name);
            }

            // get key id from MASTER_KEY_ID
            long masterKeyId = data.getLong(INDEX_UNIFIED_MASTER_KEY_ID);
            String keyIdStr = PgpKeyHelper.convertKeyIdToHex(masterKeyId);
            getSupportActionBar().setSubtitle(keyIdStr);

            // If this key is revoked, it cannot be used for anything!
            if (data.getInt(INDEX_UNIFIED_IS_REVOKED) != 0) {
                mStatusDivider.setVisibility(View.VISIBLE);
                mStatusRevoked.setVisibility(View.VISIBLE);
                mStatusExpired.setVisibility(View.GONE);
            } else {
                mStatusRevoked.setVisibility(View.GONE);

                Date expiryDate = new Date(data.getLong(INDEX_UNIFIED_EXPIRY) * 1000);
                if (!data.isNull(INDEX_UNIFIED_EXPIRY) && expiryDate.before(new Date())) {
                    mStatusDivider.setVisibility(View.VISIBLE);
                    mStatusExpired.setVisibility(View.VISIBLE);
                } else {
                    mStatusDivider.setVisibility(View.GONE);
                    mStatusExpired.setVisibility(View.GONE);
                }
            }

            break;
        }
    }
    }
}

From source file:cz.maresmar.sfm.view.menu.MenuDetailsFragment.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case MENU_LOADER_ID: {
        Timber.d("Menu data loaded");

        if (BuildConfig.DEBUG) {
            Assert.isOne(cursor.getCount());
        }//from   www . ja v  a2 s . c o  m

        cursor.moveToFirst();

        @ProviderContract.MenuStatus
        int status = cursor.getInt(0);
        @ProviderContract.PortalFeatures
        int features = cursor.getInt(1);

        // Menu detail text
        final long rawDate = cursor.getLong(2);
        mDateText.setText(MenuUtils.getDateStr(mDateText.getContext(), rawDate));
        final int rawPrice = cursor.getInt(3);
        mPriceText.setText(MenuUtils.getPriceStr(mPriceText.getContext(), rawPrice));
        mTextText.setText(cursor.getString(4));
        mPortalName.setText(cursor.getString(5));

        // Taken amount handling
        mSyncedTaken = cursor.getInt(12);
        mTakenAmountText.setText(String.valueOf(mSyncedTaken));

        // Amount table
        // Synced
        mSyncedReserved = cursor.getInt(6);
        int syncedOffered = cursor.getInt(7);

        mSyncedReservedText.setText(String.valueOf(mSyncedReserved));
        if ((status & ProviderContract.MENU_STATUS_CANCELABLE) == ProviderContract.MENU_STATUS_CANCELABLE) {
            mMinReserved = mSyncedTaken;
        } else {
            mMinReserved = mSyncedReserved;
        }
        mSyncedOfferedText.setText(String.valueOf(syncedOffered));

        int reserved = mSyncedReserved;
        int offered = syncedOffered;

        // To sync
        if (!cursor.isNull(8)) {
            reserved = cursor.getInt(8);
            offered = cursor.getInt(9);
            mToSyncReservedText.setText(String.valueOf(reserved));
            mToSyncOfferedText.setText(String.valueOf(offered));
        } else {
            mToSyncReservedText.setText(R.string.menu_detail_empty);
            mToSyncOfferedText.setText(R.string.menu_detail_empty);
        }
        // Change
        if (!cursor.isNull(10)) {
            reserved = cursor.getInt(10);
            offered = cursor.getInt(11);
        }
        mChangedReservedEditText.setText(String.valueOf(reserved));
        mChangedOfferedEditText.setText(String.valueOf(offered));

        // To take handling
        final int toTake = cursor.getInt(13);
        if (toTake != ProviderContract.NO_INFO) {
            mToTakeText.setText(String.valueOf(toTake));
            mToTakeGroup.setVisibility(View.VISIBLE);
        } else {
            mToTakeText.setText(R.string.menu_detail_not_available);
            mToTakeGroup.setVisibility(View.GONE);
        }

        // To order handling
        final int toOrder = cursor.getInt(14);
        if (toOrder != ProviderContract.NO_INFO) {
            mToOrderText.setText(String.valueOf(Math.max(0, toOrder - syncedOffered)));
            if ((features
                    & ProviderContract.FEATURE_MULTIPLE_ORDERS) == ProviderContract.FEATURE_MULTIPLE_ORDERS) {
                mMaxReserved = mSyncedReserved + Math.max(0, toOrder - syncedOffered);
            } else {
                mMaxReserved = Math.min(1, mSyncedReserved + Math.max(0, toOrder - syncedOffered));
            }
        } else {
            if ((status & ProviderContract.MENU_STATUS_ORDERABLE) == ProviderContract.MENU_STATUS_ORDERABLE) {
                mToOrderText.setText(R.string.menu_detail_unlimited);
                if ((features
                        & ProviderContract.FEATURE_MULTIPLE_ORDERS) == ProviderContract.FEATURE_MULTIPLE_ORDERS) {
                    mMaxReserved = Integer.MAX_VALUE;
                } else {
                    mMaxReserved = 1;
                }
            } else {
                mToOrderText.setText("0");
                mMaxReserved = mSyncedReserved;
            }
        }

        // Last change
        final long rawLastChange = cursor.getLong(15);
        if (rawLastChange != ProviderContract.NO_INFO) {
            mLastChangeText.setText(MenuUtils.getDateTimeStr(mLastChangeText.getContext(), rawLastChange));
        } else {
            mLastChangeText.setText(R.string.menu_detail_not_available);
        }

        // Reserved change button
        if (rawDate >= MenuUtils.getTodayDate()) {
            mChangedReservedEditText.setEnabled(mMinReserved != mMaxReserved);
        } else {
            mChangedReservedEditText.setEnabled(false);
        }

        // Offer change button
        if ((status & ProviderContract.FEATURE_FOOD_STOCK) == ProviderContract.FEATURE_FOOD_STOCK) {
            mChangedOfferedEditText.setEnabled(rawDate >= MenuUtils.getTodayDate() && 0 != mSyncedReserved);
            mOfferGroup.setVisibility(View.VISIBLE);
        } else {
            mChangedOfferedEditText.setEnabled(false);
            mOfferGroup.setVisibility(View.INVISIBLE);
        }

        // Label
        getActivity().setTitle(cursor.getString(16));

        break;
    }
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + loader.getId());
    }
}

From source file:edu.mit.mobile.android.locast.data.MediaSync.java

/**
 * Synchronize the media of the given castMedia. It will download or upload
 * as needed.//from   w  w  w  .  j a  v  a 2  s. c o m
 *
 * @param castMediaUri
 * @throws SyncException
 */
public void syncItemMedia(Uri castMediaUri) throws SyncException {

    final Cursor castMedia = cr.query(castMediaUri, PROJECTION, null, null, null);

    final Uri castUri = CastMedia.getCast(castMediaUri);
    final Cursor cast = cr.query(castUri, CAST_PROJECTION, null, null, null);

    try {
        if (!castMedia.moveToFirst()) {
            throw new IllegalArgumentException("uri " + castMediaUri + " has no content");
        }

        if (!cast.moveToFirst()) {
            throw new IllegalArgumentException(castMediaUri + " cast " + castUri + " has no content");
        }

        // cache the column numbers
        final int mediaUrlCol = castMedia.getColumnIndex(CastMedia._MEDIA_URL);
        final int localUriCol = castMedia.getColumnIndex(CastMedia._LOCAL_URI);

        final boolean isFavorite = cast.getInt(cast.getColumnIndex(Cast._FAVORITED)) != 0;
        final boolean keepOffline = castMedia.getInt(castMedia.getColumnIndex(CastMedia._KEEP_OFFLINE)) != 0;

        final String mimeType = castMedia.getString(castMedia.getColumnIndex(CastMedia._MIME_TYPE));

        final boolean isImage = (mimeType != null) && mimeType.startsWith("image/");

        // we don't need to sync this
        if ("text/html".equals(mimeType)) {
            return;
        }

        final Uri locMedia = castMedia.isNull(localUriCol) ? null : Uri.parse(castMedia.getString(localUriCol));
        final String pubMedia = castMedia.getString(mediaUrlCol);
        final boolean hasLocMedia = locMedia != null && new File(locMedia.getPath()).exists();
        final boolean hasPubMedia = pubMedia != null && pubMedia.length() > 0;

        final String localThumb = castMedia.getString(castMedia.getColumnIndex(CastMedia._THUMB_LOCAL));

        if (hasLocMedia && !hasPubMedia) {
            final String uploadPath = castMedia.getString(castMedia.getColumnIndex(CastMedia._PUBLIC_URI));
            uploadMedia(uploadPath, castMediaUri, mimeType, locMedia);

        } else if (!hasLocMedia && hasPubMedia) {
            // only have a public copy, so download it and store locally.
            final Uri pubMediaUri = Uri.parse(pubMedia);
            final File destfile = getFilePath(pubMediaUri);

            // the following conditions indicate that the cast media should be downloaded.
            if (keepOffline || isFavorite) {
                final boolean anythingChanged = downloadMediaFile(pubMedia, destfile, castMediaUri);

                // the below is inverted from what seems logical, because downloadMediaFile()
                // will actually update the castmedia if it downloads anything. We'll only be getting
                // here if we don't have any local record of the file, so we should make the association
                // by ourselves.
                if (!anythingChanged) {
                    File thumb = null;
                    if (isImage && localThumb == null) {
                        thumb = destfile;
                    }
                    updateLocalFile(castMediaUri, destfile, thumb);
                    // disabled to avoid spamming the user with downloaded
                    // items.
                    // checkForMediaEntry(castMediaUri, pubMediaUri, mimeType);
                }
            }
        }
    } finally {
        cast.close();
        castMedia.close();
    }
}

From source file:org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView keyId = (TextView) view.findViewById(R.id.keyId);
    TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
    TextView keyExpiry = (TextView) view.findViewById(R.id.keyExpiry);
    ImageView masterKeyIcon = (ImageView) view.findViewById(R.id.ic_masterKey);
    ImageView certifyIcon = (ImageView) view.findViewById(R.id.ic_certifyKey);
    ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
    ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey);
    ImageView revokedKeyIcon = (ImageView) view.findViewById(R.id.ic_revokedKey);

    String keyIdStr = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexKeyId));
    String algorithmStr = PgpKeyHelper.getAlgorithmInfo(context, cursor.getInt(mIndexAlgorithm),
            cursor.getInt(mIndexKeySize));

    keyId.setText(keyIdStr);/*from w w w  . j a  va 2 s  . com*/
    // may be set with additional "stripped" later on
    if (hasAnySecret && cursor.getInt(mIndexHasSecret) == 0) {
        keyDetails.setText(algorithmStr + ", " + context.getString(R.string.key_stripped));
    } else {
        keyDetails.setText(algorithmStr);
    }

    // Set icons according to properties
    masterKeyIcon.setVisibility(cursor.getInt(mIndexRank) == 0 ? View.VISIBLE : View.INVISIBLE);
    certifyIcon.setVisibility(cursor.getInt(mIndexCanCertify) != 0 ? View.VISIBLE : View.GONE);
    encryptIcon.setVisibility(cursor.getInt(mIndexCanEncrypt) != 0 ? View.VISIBLE : View.GONE);
    signIcon.setVisibility(cursor.getInt(mIndexCanSign) != 0 ? View.VISIBLE : View.GONE);

    boolean valid = true;
    if (cursor.getInt(mIndexRevokedKey) > 0) {
        revokedKeyIcon.setVisibility(View.VISIBLE);

        valid = false;
    } else {
        keyId.setTextColor(mDefaultTextColor);
        keyDetails.setTextColor(mDefaultTextColor);
        keyExpiry.setTextColor(mDefaultTextColor);

        revokedKeyIcon.setVisibility(View.GONE);
    }

    if (!cursor.isNull(mIndexExpiry)) {
        Date expiryDate = new Date(cursor.getLong(mIndexExpiry) * 1000);

        valid = valid && expiryDate.after(new Date());
        keyExpiry.setText(context.getString(R.string.label_expiry) + ": "
                + DateFormat.getDateFormat(context).format(expiryDate));
    } else {
        keyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none));
    }

    // if key is expired or revoked, strike through text
    if (!valid) {
        keyId.setText(OtherHelper.strikeOutText(keyId.getText()));
        keyDetails.setText(OtherHelper.strikeOutText(keyDetails.getText()));
        keyExpiry.setText(OtherHelper.strikeOutText(keyExpiry.getText()));
    }
    keyId.setEnabled(valid);
    keyDetails.setEnabled(valid);
    keyExpiry.setEnabled(valid);
}