Example usage for android.os Bundle putBoolean

List of usage examples for android.os Bundle putBoolean

Introduction

In this page you can find the example usage for android.os Bundle putBoolean.

Prototype

public void putBoolean(@Nullable String key, boolean value) 

Source Link

Document

Inserts a Boolean value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onBufferSelected(int bid) {
    launchBid = -1;//from  ww  w  .  j ava 2  s  .c om
    launchURI = null;
    cidToOpen = -1;
    bufferToOpen = null;
    setIntent(new Intent(this, MainActivity.class));

    if (suggestionsTimerTask != null)
        suggestionsTimerTask.cancel();
    sortedChannels = null;
    sortedUsers = null;

    if (drawerLayout != null) {
        drawerLayout.closeDrawers();
    }
    if (bid != -1 && conn != null && conn.getUserInfo() != null) {
        conn.getUserInfo().last_selected_bid = bid;
    }
    for (int i = 0; i < backStack.size(); i++) {
        if (buffer != null && backStack.get(i) == buffer.bid)
            backStack.remove(i);
    }
    if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) {
        backStack.add(0, buffer.bid);
        buffer.draft = messageTxt.getText().toString();
    }
    if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid)
        shouldFadeIn = false;
    else
        shouldFadeIn = true;
    buffer = BuffersDataSource.getInstance().getBuffer(bid);
    if (buffer != null) {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = ServersDataSource.getInstance().getServer(buffer.cid);

        try {
            TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance()
                    .getEventsForBuffer(buffer.bid);
            if (events != null) {
                events = (TreeMap<Long, EventsDataSource.Event>) events.clone();
                for (EventsDataSource.Event e : events.values()) {
                    if (e != null && e.highlight && e.from != null) {
                        UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from);
                        if (u != null && u.last_mention < e.eid)
                            u.last_mention = e.eid;
                    }
                }
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

        try {
            if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) {
                NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
                if (nfc != null) {
                    String uri = "irc";
                    if (server.ssl > 0)
                        uri += "s";
                    uri += "://" + server.hostname + ":" + server.port;
                    if (buffer.type.equals("channel")) {
                        uri += "/" + URLEncoder.encode(buffer.name, "UTF-8");
                        ChannelsDataSource.Channel c = ChannelsDataSource.getInstance()
                                .getChannelForBuffer(buffer.bid);
                        if (c != null && c.hasMode("k"))
                            uri += "," + c.paramForMode("k");
                    }
                    nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this);
                }
            }
        } catch (Exception e) {
        }
    } else {
        Crashlytics.log(Log.DEBUG, "IRCCloud",
                "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn);
        server = null;
    }
    update_subtitle();
    final Bundle b = new Bundle();
    if (buffer != null)
        b.putInt("cid", buffer.cid);
    b.putInt("bid", bid);
    b.putBoolean("fade", shouldFadeIn);
    BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.BuffersList);
    final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager()
            .findFragmentById(R.id.messageViewFragment);
    UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment);
    UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager()
            .findFragmentById(R.id.usersListFragment2);
    if (mvf != null)
        mvf.ready = false;
    if (blf != null)
        blf.setSelectedBid(bid);
    if (ulf != null)
        ulf.setArguments(b);
    if (ulf2 != null)
        ulf2.setArguments(b);

    if (shouldFadeIn) {
        Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out");
        if (Build.VERSION.SDK_INT < 16) {
            AlphaAnimation anim = new AlphaAnimation(1, 0);
            anim.setDuration(150);
            anim.setFillAfter(true);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            try {
                mvf.getListView().startAnimation(anim);
                ulf.getListView().startAnimation(anim);
            } catch (Exception e) {

            }
        } else {
            mvf.getListView().animate().alpha(0).withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (mvf != null)
                        mvf.setArguments(b);
                    messageTxt.setText("");
                    if (buffer != null && buffer.draft != null)
                        messageTxt.append(buffer.draft);
                }
            });
            ulf.getListView().animate().alpha(0);
        }
        mvf.showSpinner(true);
    } else {
        if (mvf != null)
            mvf.setArguments(b);
        messageTxt.setText("");
        if (buffer != null && buffer.draft != null)
            messageTxt.append(buffer.draft);
    }

    updateUsersListFragmentVisibility();
    supportInvalidateOptionsMenu();
    if (excludeBIDTask != null)
        excludeBIDTask.cancel(true);
    excludeBIDTask = new ExcludeBIDTask();
    excludeBIDTask.execute(bid);
    if (drawerLayout != null)
        new RefreshUpIndicatorTask().execute((Void) null);
    if (buffer != null && buffer.cid != -1) {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
    }
    update_suggestions(false);
}

From source file:com.android.mail.ui.AbstractActivityController.java

@Override
public void onSaveInstanceState(Bundle outState) {
    mViewMode.handleSaveInstanceState(outState);
    if (mAccount != null) {
        outState.putParcelable(SAVED_ACCOUNT, mAccount);
    }// ww w.j  a  v  a  2s .  c om
    if (mFolder != null) {
        outState.putParcelable(SAVED_FOLDER, mFolder);
    }
    // If this is a search activity, let's store the search query term as well.
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        outState.putString(SAVED_QUERY, mConvListContext.searchQuery);
    }
    if (mCurrentConversation != null && mViewMode.isConversationMode()) {
        outState.putParcelable(SAVED_CONVERSATION, mCurrentConversation);
    }
    if (!mCheckedSet.isEmpty()) {
        outState.putParcelable(SAVED_SELECTED_SET, mCheckedSet);
    }
    if (mToastBar.getVisibility() == View.VISIBLE) {
        outState.putParcelable(SAVED_TOAST_BAR_OP, mToastBar.getOperation());
    }
    final ConversationListFragment convListFragment = getConversationListFragment();
    if (convListFragment != null) {
        convListFragment.getAnimatedAdapter().onSaveInstanceState(outState);
    }
    // If there is a dialog being shown, save the state so we can create a listener for it.
    if (mDialogAction != -1) {
        outState.putInt(SAVED_ACTION, mDialogAction);
        outState.putBoolean(SAVED_ACTION_FROM_SELECTED, mDialogFromSelectedSet);
    }
    if (mDetachedConvUri != null) {
        outState.putParcelable(SAVED_DETACHED_CONV_URI, mDetachedConvUri);
    }

    outState.putParcelable(SAVED_HIERARCHICAL_FOLDER, mFolderListFolder);
    mSafeToModifyFragments = false;

    outState.putParcelable(SAVED_INBOX_KEY, mInbox);

    outState.putBundle(SAVED_CONVERSATION_LIST_SCROLL_POSITIONS, mConversationListScrollPositions);

    mSearchViewController.saveState(outState);
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putString("message", "Restoring GuardTrax");
    outState.putString("darfileName", GTConstants.darfileName);
    outState.putString("tarfileName", GTConstants.tarfileName);
    outState.putString("trpfilename", GTConstants.trpfilename);
    outState.putString("srpfileName", GTConstants.srpfileName);
    outState.putString("currentState", Utility.getcurrentState());
    outState.putString("getsessionStart", Utility.getsessionStart());
    outState.putString("selectedCode", selectedCode);
    outState.putString("lunchTime", lunchTime);
    outState.putString("breakTime", breakTime);
    outState.putString("signaturefileName", signaturefileName);
    outState.putString("tourName", GTConstants.tourName);
    outState.putString("tourTime", tourTime);
    outState.putLong("tourEnd", tourEnd);
    outState.putInt("lunchoutLocation", lunchoutLocation);
    outState.putInt("breakoutLocation", breakoutLocation);
    outState.putInt("touritemNumber", touritemNumber);
    outState.putBoolean("chekUpdate", chekUpdate);
    outState.putBoolean("send_data", GTConstants.sendData);
    outState.putBoolean("isTour", GTConstants.isTour);
    outState.putBoolean("isGeoFence", GTConstants.isGeoFence);

    //Save data for main service
    String value = String.valueOf(GTConstants.sendData) + "," + GTConstants.darfileName + ","
            + GTConstants.tarfileName + "," + GTConstants.trpfilename + "," + GTConstants.srpfileName + ","
            + GTConstants.tourName;/*from   w  w w.j a  v a 2  s .  c  o  m*/
    Utility.storesharedPreference(HomeScreen.this, "serviceString", value);

    // Save away the original text, so we still have it if the activity
    // needs to be killed while paused.
    //outState.putString("my_text", sMyText);
    //outState.putInt("my_int", nMyInt);
    //Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show();
}

From source file:android.content.pm.PackageParser.java

private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data,
        String[] outError) throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData);

    if (data == null) {
        data = new Bundle();
    }//from  www.  j a v  a 2  s  .  c o m

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name,
            0);
    if (name == null) {
        outError[0] = "<meta-data> requires an android:name attribute";
        sa.recycle();
        return null;
    }

    name = name.intern();

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource);
    if (v != null && v.resourceId != 0) {
        //Slog.i(TAG, "Meta data ref " + name + ": " + v);
        data.putInt(name, v.resourceId);
    } else {
        v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value);
        //Slog.i(TAG, "Meta data " + name + ": " + v);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                data.putString(name, cs != null ? cs.toString().intern() : null);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                data.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) {
                data.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                data.putFloat(name, v.getFloat());
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG,
                            "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
                                    + parser.getName() + " at " + mArchiveSourcePath + " "
                                    + parser.getPositionDescription());
                } else {
                    outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
                    data = null;
                }
            }
        } else {
            outError[0] = "<meta-data> requires an android:value or android:resource attribute";
            data = null;
        }
    }

    sa.recycle();

    XmlUtils.skipCurrentTag(parser);

    return data;
}

From source file:com.android.mail.compose.ComposeActivity.java

private void saveState(Bundle state) {
    // We have no accounts so there is nothing to compose, and therefore, nothing to save.
    if (mAccounts == null || mAccounts.length == 0) {
        return;/*from  ww w  . j  a va  2s .  c om*/
    }
    // The framework is happy to save and restore the selection but only if it also saves and
    // restores the contents of the edit text. That's a lot of text to put in a bundle so we do
    // this manually.
    View focus = getCurrentFocus();
    if (focus != null && focus instanceof EditText) {
        EditText focusEditText = (EditText) focus;
        state.putInt(EXTRA_FOCUS_SELECTION_START, focusEditText.getSelectionStart());
        state.putInt(EXTRA_FOCUS_SELECTION_END, focusEditText.getSelectionEnd());
    }

    final List<ReplyFromAccount> replyFromAccounts = mFromSpinner.getReplyFromAccounts();
    final int selectedPos = mFromSpinner.getSelectedItemPosition();
    final ReplyFromAccount selectedReplyFromAccount = (replyFromAccounts != null && replyFromAccounts.size() > 0
            && replyFromAccounts.size() > selectedPos) ? replyFromAccounts.get(selectedPos) : null;
    if (selectedReplyFromAccount != null) {
        state.putString(EXTRA_SELECTED_REPLY_FROM_ACCOUNT, selectedReplyFromAccount.serialize().toString());
        state.putParcelable(Utils.EXTRA_ACCOUNT, selectedReplyFromAccount.account);
    } else {
        state.putParcelable(Utils.EXTRA_ACCOUNT, mAccount);
    }

    if (mDraftId == UIProvider.INVALID_MESSAGE_ID && mRequestId != 0) {
        // We don't have a draft id, and we have a request id,
        // save the request id.
        state.putInt(EXTRA_REQUEST_ID, mRequestId);
    }

    // We want to restore the current mode after a pause
    // or rotation.
    int mode = getMode();
    state.putInt(EXTRA_ACTION, mode);

    final Message message = createMessage(selectedReplyFromAccount, mRefMessage, mode,
            removeComposingSpans(mBodyView.getText()));
    if (mDraft != null) {
        message.id = mDraft.id;
        message.serverId = mDraft.serverId;
        message.uri = mDraft.uri;
    }
    state.putParcelable(EXTRA_MESSAGE, message);

    if (mRefMessage != null) {
        state.putParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE, mRefMessage);
    } else if (message.appendRefMessageContent) {
        // If we have no ref message but should be appending
        // ref message content, we have orphaned quoted text. Save it.
        state.putCharSequence(EXTRA_QUOTED_TEXT, mQuotedTextView.getQuotedTextIfIncluded());
    }
    state.putBoolean(EXTRA_SHOW_CC, mCcBccView.isCcVisible());
    state.putBoolean(EXTRA_SHOW_BCC, mCcBccView.isBccVisible());
    state.putBoolean(EXTRA_RESPONDED_INLINE, mRespondedInline);
    state.putBoolean(EXTRA_SAVE_ENABLED, mSave != null && mSave.isEnabled());
    state.putParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS, mAttachmentsView.getAttachmentPreviews());

    state.putParcelable(EXTRA_VALUES, mExtraValues);

    state.putBoolean(EXTRA_TEXT_CHANGED, mTextChanged);
    // On configuration changes, we don't actually need to parse the body html ourselves because
    // the framework can correctly restore the body EditText to its exact original state.
    state.putBoolean(EXTRA_SKIP_PARSING_BODY, isChangingConfigurations());
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

/**
 * Converts a {@link DataItem} into an {@link ExpandingEntryCardView.Entry} for display.
 * If the {@link ExpandingEntryCardView.Entry} has no visual elements, null is returned.
 *
 * This runs on a background thread. This is set as static to avoid accidentally adding
 * additional dependencies on unsafe things (like the Activity).
 *
 * @param dataItem The {@link DataItem} to convert.
 * @param secondDataItem A second {@link DataItem} to help build a full entry for some
 *  mimetypes//from w  w  w .  ja  v  a 2  s  .  c  o  m
 * @return The {@link ExpandingEntryCardView.Entry}, or null if no visual elements are present.
 */
private static Entry dataItemToEntry(DataItem dataItem, DataItem secondDataItem, Context context,
        Contact contactData, final MutableString aboutCardName) {
    Drawable icon = null;
    String header = null;
    String subHeader = null;
    Drawable subHeaderIcon = null;
    String text = null;
    Drawable textIcon = null;
    StringBuilder primaryContentDescription = new StringBuilder();
    Spannable phoneContentDescription = null;
    Spannable smsContentDescription = null;
    Intent intent = null;
    boolean shouldApplyColor = true;
    Drawable alternateIcon = null;
    Intent alternateIntent = null;
    StringBuilder alternateContentDescription = new StringBuilder();
    final boolean isEditable = false;
    EntryContextMenuInfo entryContextMenuInfo = null;
    Drawable thirdIcon = null;
    Intent thirdIntent = null;
    int thirdAction = Entry.ACTION_NONE;
    String thirdContentDescription = null;
    Bundle thirdExtras = null;
    int iconResourceId = 0;

    context = context.getApplicationContext();
    final Resources res = context.getResources();
    DataKind kind = dataItem.getDataKind();

    if (dataItem instanceof ImDataItem) {
        final ImDataItem im = (ImDataItem) dataItem;
        intent = ContactsUtils.buildImIntent(context, im).first;
        final boolean isEmail = im.isCreatedFromEmail();
        final int protocol;
        if (!im.isProtocolValid()) {
            protocol = Im.PROTOCOL_CUSTOM;
        } else {
            protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : im.getProtocol();
        }
        if (protocol == Im.PROTOCOL_CUSTOM) {
            // If the protocol is custom, display the "IM" entry header as well to distinguish
            // this entry from other ones
            header = res.getString(R.string.header_im_entry);
            subHeader = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString();
            text = im.getData();
        } else {
            header = Im.getProtocolLabel(res, protocol, im.getCustomProtocol()).toString();
            subHeader = im.getData();
        }
        entryContextMenuInfo = new EntryContextMenuInfo(im.getData(), header, dataItem.getMimeType(),
                dataItem.getId(), dataItem.isSuperPrimary());
    } else if (dataItem instanceof OrganizationDataItem) {
        final OrganizationDataItem organization = (OrganizationDataItem) dataItem;
        header = res.getString(R.string.header_organization_entry);
        subHeader = organization.getCompany();
        entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(),
                dataItem.getId(), dataItem.isSuperPrimary());
        text = organization.getTitle();
    } else if (dataItem instanceof NicknameDataItem) {
        final NicknameDataItem nickname = (NicknameDataItem) dataItem;
        // Build nickname entries
        final boolean isNameRawContact = (contactData.getNameRawContactId() == dataItem.getRawContactId());

        final boolean duplicatesTitle = isNameRawContact
                && contactData.getDisplayNameSource() == DisplayNameSources.NICKNAME;

        if (!duplicatesTitle) {
            header = res.getString(R.string.header_nickname_entry);
            subHeader = nickname.getName();
            entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(),
                    dataItem.getId(), dataItem.isSuperPrimary());
        }
    } else if (dataItem instanceof NoteDataItem) {
        final NoteDataItem note = (NoteDataItem) dataItem;
        header = res.getString(R.string.header_note_entry);
        subHeader = note.getNote();
        entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(),
                dataItem.getId(), dataItem.isSuperPrimary());
    } else if (dataItem instanceof WebsiteDataItem) {
        final WebsiteDataItem website = (WebsiteDataItem) dataItem;
        header = res.getString(R.string.header_website_entry);
        subHeader = website.getUrl();
        entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(),
                dataItem.getId(), dataItem.isSuperPrimary());
        try {
            final WebAddress webAddress = new WebAddress(website.buildDataStringForDisplay(context, kind));
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toString()));
        } catch (final ParseException e) {
            Log.e(TAG, "Couldn't parse website: " + website.buildDataStringForDisplay(context, kind));
        }
    } else if (dataItem instanceof EventDataItem) {
        final EventDataItem event = (EventDataItem) dataItem;
        final String dataString = event.buildDataStringForDisplay(context, kind);
        final Calendar cal = DateUtils.parseDate(dataString, false);
        if (cal != null) {
            final Date nextAnniversary = DateUtils.getNextAnnualDate(cal);
            final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
            builder.appendPath("time");
            ContentUris.appendId(builder, nextAnniversary.getTime());
            intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
        }
        header = res.getString(R.string.header_event_entry);
        if (event.hasKindTypeColumn(kind)) {
            subHeader = EventCompat.getTypeLabel(res, event.getKindTypeColumn(kind), event.getLabel())
                    .toString();
        }
        text = DateUtils.formatDate(context, dataString);
        entryContextMenuInfo = new EntryContextMenuInfo(text, header, dataItem.getMimeType(), dataItem.getId(),
                dataItem.isSuperPrimary());
    } else if (dataItem instanceof RelationDataItem) {
        final RelationDataItem relation = (RelationDataItem) dataItem;
        final String dataString = relation.buildDataStringForDisplay(context, kind);
        if (!TextUtils.isEmpty(dataString)) {
            intent = new Intent(Intent.ACTION_SEARCH);
            intent.putExtra(SearchManager.QUERY, dataString);
            intent.setType(Contacts.CONTENT_TYPE);
        }
        header = res.getString(R.string.header_relation_entry);
        subHeader = relation.getName();
        entryContextMenuInfo = new EntryContextMenuInfo(subHeader, header, dataItem.getMimeType(),
                dataItem.getId(), dataItem.isSuperPrimary());
        if (relation.hasKindTypeColumn(kind)) {
            text = Relation.getTypeLabel(res, relation.getKindTypeColumn(kind), relation.getLabel()).toString();
        }
    } else if (dataItem instanceof PhoneDataItem) {
        final PhoneDataItem phone = (PhoneDataItem) dataItem;
        String phoneLabel = null;
        if (!TextUtils.isEmpty(phone.getNumber())) {
            primaryContentDescription.append(res.getString(R.string.call_other)).append(" ");
            header = sBidiFormatter.unicodeWrap(phone.buildDataStringForDisplay(context, kind),
                    TextDirectionHeuristics.LTR);
            entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup),
                    dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
            if (phone.hasKindTypeColumn(kind)) {
                final int kindTypeColumn = phone.getKindTypeColumn(kind);
                final String label = phone.getLabel();
                phoneLabel = label;
                if (kindTypeColumn == Phone.TYPE_CUSTOM && TextUtils.isEmpty(label)) {
                    text = "";
                } else {
                    text = Phone.getTypeLabel(res, kindTypeColumn, label).toString();
                    phoneLabel = text;
                    primaryContentDescription.append(text).append(" ");
                }
            }
            primaryContentDescription.append(header);
            phoneContentDescription = com.android.contacts.common.util.ContactDisplayUtils
                    .getTelephoneTtsSpannable(primaryContentDescription.toString(), header);
            icon = res.getDrawable(R.drawable.ic_phone_24dp);
            iconResourceId = R.drawable.ic_phone_24dp;
            if (PhoneCapabilityTester.isPhone(context)) {
                intent = CallUtil.getCallIntent(phone.getNumber());
            }
            alternateIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phone.getNumber(), null));

            alternateIcon = res.getDrawable(R.drawable.ic_message_24dp);
            alternateContentDescription.append(res.getString(R.string.sms_custom, header));
            smsContentDescription = com.android.contacts.common.util.ContactDisplayUtils
                    .getTelephoneTtsSpannable(alternateContentDescription.toString(), header);

            int videoCapability = CallUtil.getVideoCallingAvailability(context);
            boolean isPresenceEnabled = (videoCapability & CallUtil.VIDEO_CALLING_PRESENCE) != 0;
            boolean isVideoEnabled = (videoCapability & CallUtil.VIDEO_CALLING_ENABLED) != 0;

            if (CallUtil.isCallWithSubjectSupported(context)) {
                thirdIcon = res.getDrawable(R.drawable.ic_call_note_white_24dp);
                thirdAction = Entry.ACTION_CALL_WITH_SUBJECT;
                thirdContentDescription = res.getString(R.string.call_with_a_note);
                // Create a bundle containing the data the call subject dialog requires.
                thirdExtras = new Bundle();
                thirdExtras.putLong(CallSubjectDialog.ARG_PHOTO_ID, contactData.getPhotoId());
                thirdExtras.putParcelable(CallSubjectDialog.ARG_PHOTO_URI,
                        UriUtils.parseUriOrNull(contactData.getPhotoUri()));
                thirdExtras.putParcelable(CallSubjectDialog.ARG_CONTACT_URI, contactData.getLookupUri());
                thirdExtras.putString(CallSubjectDialog.ARG_NAME_OR_NUMBER, contactData.getDisplayName());
                thirdExtras.putBoolean(CallSubjectDialog.ARG_IS_BUSINESS, false);
                thirdExtras.putString(CallSubjectDialog.ARG_NUMBER, phone.getNumber());
                thirdExtras.putString(CallSubjectDialog.ARG_DISPLAY_NUMBER, phone.getFormattedPhoneNumber());
                thirdExtras.putString(CallSubjectDialog.ARG_NUMBER_LABEL, phoneLabel);
            } else if (isVideoEnabled) {
                // Check to ensure carrier presence indicates the number supports video calling.
                int carrierPresence = dataItem.getCarrierPresence();
                boolean isPresent = (carrierPresence & Phone.CARRIER_PRESENCE_VT_CAPABLE) != 0;

                if ((isPresenceEnabled && isPresent) || !isPresenceEnabled) {
                    thirdIcon = res.getDrawable(R.drawable.ic_videocam);
                    thirdAction = Entry.ACTION_INTENT;
                    thirdIntent = CallUtil.getVideoCallIntent(phone.getNumber(),
                            CALL_ORIGIN_QUICK_CONTACTS_ACTIVITY);
                    thirdContentDescription = res.getString(R.string.description_video_call);
                }
            }
        }
    } else if (dataItem instanceof EmailDataItem) {
        final EmailDataItem email = (EmailDataItem) dataItem;
        final String address = email.getData();
        if (!TextUtils.isEmpty(address)) {
            primaryContentDescription.append(res.getString(R.string.email_other)).append(" ");
            final Uri mailUri = Uri.fromParts(ContactsUtils.SCHEME_MAILTO, address, null);
            intent = new Intent(Intent.ACTION_SENDTO, mailUri);
            header = email.getAddress();
            entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.emailLabelsGroup),
                    dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
            if (email.hasKindTypeColumn(kind)) {
                text = Email.getTypeLabel(res, email.getKindTypeColumn(kind), email.getLabel()).toString();
                primaryContentDescription.append(text).append(" ");
            }
            primaryContentDescription.append(header);
            icon = res.getDrawable(R.drawable.ic_email_24dp);
            iconResourceId = R.drawable.ic_email_24dp;
        }
    } else if (dataItem instanceof StructuredPostalDataItem) {
        StructuredPostalDataItem postal = (StructuredPostalDataItem) dataItem;
        final String postalAddress = postal.getFormattedAddress();
        if (!TextUtils.isEmpty(postalAddress)) {
            primaryContentDescription.append(res.getString(R.string.map_other)).append(" ");
            intent = StructuredPostalUtils.getViewPostalAddressIntent(postalAddress);
            header = postal.getFormattedAddress();
            entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.postalLabelsGroup),
                    dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
            if (postal.hasKindTypeColumn(kind)) {
                text = StructuredPostal.getTypeLabel(res, postal.getKindTypeColumn(kind), postal.getLabel())
                        .toString();
                primaryContentDescription.append(text).append(" ");
            }
            primaryContentDescription.append(header);
            alternateIntent = StructuredPostalUtils.getViewPostalAddressDirectionsIntent(postalAddress);
            alternateIcon = res.getDrawable(R.drawable.ic_directions_24dp);
            alternateContentDescription.append(res.getString(R.string.content_description_directions))
                    .append(" ").append(header);
            icon = res.getDrawable(R.drawable.ic_place_24dp);
            iconResourceId = R.drawable.ic_place_24dp;
        }
    } else if (dataItem instanceof SipAddressDataItem) {
        final SipAddressDataItem sip = (SipAddressDataItem) dataItem;
        final String address = sip.getSipAddress();
        if (!TextUtils.isEmpty(address)) {
            primaryContentDescription.append(res.getString(R.string.call_other)).append(" ");
            if (PhoneCapabilityTester.isSipPhone(context)) {
                final Uri callUri = Uri.fromParts(PhoneAccount.SCHEME_SIP, address, null);
                intent = CallUtil.getCallIntent(callUri);
            }
            header = address;
            entryContextMenuInfo = new EntryContextMenuInfo(header, res.getString(R.string.phoneLabelsGroup),
                    dataItem.getMimeType(), dataItem.getId(), dataItem.isSuperPrimary());
            if (sip.hasKindTypeColumn(kind)) {
                text = SipAddress.getTypeLabel(res, sip.getKindTypeColumn(kind), sip.getLabel()).toString();
                primaryContentDescription.append(text).append(" ");
            }
            primaryContentDescription.append(header);
            icon = res.getDrawable(R.drawable.ic_dialer_sip_black_24dp);
            iconResourceId = R.drawable.ic_dialer_sip_black_24dp;
        }
    } else if (dataItem instanceof StructuredNameDataItem) {
        // If the name is already set and this is not the super primary value then leave the
        // current value. This way we show the super primary value when we are able to.
        if (dataItem.isSuperPrimary() || aboutCardName.value == null || aboutCardName.value.isEmpty()) {
            final String givenName = ((StructuredNameDataItem) dataItem).getGivenName();
            if (!TextUtils.isEmpty(givenName)) {
                aboutCardName.value = res.getString(R.string.about_card_title) + " " + givenName;
            } else {
                aboutCardName.value = res.getString(R.string.about_card_title);
            }
        }
    } else {
        // Custom DataItem
        header = dataItem.buildDataStringForDisplay(context, kind);
        text = kind.typeColumn;
        intent = new Intent(Intent.ACTION_VIEW);
        final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataItem.getId());
        intent.setDataAndType(uri, dataItem.getMimeType());

        if (intent != null) {
            final String mimetype = intent.getType();

            // Build advanced entry for known 3p types. Otherwise default to ResolveCache icon.
            switch (mimetype) {
            case MIMETYPE_GPLUS_PROFILE:
                // If a secondDataItem is available, use it to build an entry with
                // alternate actions
                if (secondDataItem != null) {
                    icon = res.getDrawable(R.drawable.ic_google_plus_24dp);
                    alternateIcon = res.getDrawable(R.drawable.ic_add_to_circles_black_24);
                    final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent,
                            alternateIntent, dataItem, secondDataItem, alternateContentDescription, header,
                            text, context);

                    populateGPlusOrHangoutsDataItemModel(itemModel);
                    intent = itemModel.intent;
                    alternateIntent = itemModel.alternateIntent;
                    alternateContentDescription = itemModel.alternateContentDescription;
                    header = itemModel.header;
                    text = itemModel.text;
                } else {
                    if (GPLUS_PROFILE_DATA_5_ADD_TO_CIRCLE.equals(intent.getDataString())) {
                        icon = res.getDrawable(R.drawable.ic_add_to_circles_black_24);
                    } else {
                        icon = res.getDrawable(R.drawable.ic_google_plus_24dp);
                    }
                }
                break;
            case MIMETYPE_HANGOUTS:
                // If a secondDataItem is available, use it to build an entry with
                // alternate actions
                if (secondDataItem != null) {
                    icon = res.getDrawable(R.drawable.ic_hangout_24dp);
                    alternateIcon = res.getDrawable(R.drawable.ic_hangout_video_24dp);
                    final GPlusOrHangoutsDataItemModel itemModel = new GPlusOrHangoutsDataItemModel(intent,
                            alternateIntent, dataItem, secondDataItem, alternateContentDescription, header,
                            text, context);

                    populateGPlusOrHangoutsDataItemModel(itemModel);
                    intent = itemModel.intent;
                    alternateIntent = itemModel.alternateIntent;
                    alternateContentDescription = itemModel.alternateContentDescription;
                    header = itemModel.header;
                    text = itemModel.text;
                } else {
                    if (HANGOUTS_DATA_5_VIDEO.equals(intent.getDataString())) {
                        icon = res.getDrawable(R.drawable.ic_hangout_video_24dp);
                    } else {
                        icon = res.getDrawable(R.drawable.ic_hangout_24dp);
                    }
                }
                break;
            default:
                entryContextMenuInfo = new EntryContextMenuInfo(header, mimetype, dataItem.getMimeType(),
                        dataItem.getId(), dataItem.isSuperPrimary());
                icon = ResolveCache.getInstance(context).getIcon(dataItem.getMimeType(), intent);
                // Call mutate to create a new Drawable.ConstantState for color filtering
                if (icon != null) {
                    icon.mutate();
                }
                shouldApplyColor = false;
            }
        }
    }

    if (intent != null) {
        // Do not set the intent is there are no resolves
        if (!PhoneCapabilityTester.isIntentRegistered(context, intent)) {
            intent = null;
        }
    }

    if (alternateIntent != null) {
        // Do not set the alternate intent is there are no resolves
        if (!PhoneCapabilityTester.isIntentRegistered(context, alternateIntent)) {
            alternateIntent = null;
        } else if (TextUtils.isEmpty(alternateContentDescription)) {
            // Attempt to use package manager to find a suitable content description if needed
            alternateContentDescription.append(getIntentResolveLabel(alternateIntent, context));
        }
    }

    // If the Entry has no visual elements, return null
    if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) && subHeaderIcon == null
            && TextUtils.isEmpty(text) && textIcon == null) {
        return null;
    }

    // Ignore dataIds from the Me profile.
    final int dataId = dataItem.getId() > Integer.MAX_VALUE ? -1 : (int) dataItem.getId();

    return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon,
            phoneContentDescription == null ? new SpannableString(primaryContentDescription.toString())
                    : phoneContentDescription,
            intent, alternateIcon, alternateIntent,
            smsContentDescription == null ? new SpannableString(alternateContentDescription.toString())
                    : smsContentDescription,
            shouldApplyColor, isEditable, entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription,
            thirdAction, thirdExtras, iconResourceId);
}