Example usage for android.os Trace beginSection

List of usage examples for android.os Trace beginSection

Introduction

In this page you can find the example usage for android.os Trace beginSection.

Prototype

public static void beginSection(String sectionName) 

Source Link

Document

Writes a trace message to indicate that a given section of code has begun.

Usage

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

private void startInteractionLoaders(Cp2DataCardModel cp2DataCardModel) {
    final Map<String, List<DataItem>> dataItemsMap = cp2DataCardModel.dataItemsMap;
    final List<DataItem> phoneDataItems = dataItemsMap.get(Phone.CONTENT_ITEM_TYPE);
    if (phoneDataItems != null && phoneDataItems.size() == 1) {
        mOnlyOnePhoneNumber = true;//from  w ww . j  a v  a  2 s . c  om
    }
    String[] phoneNumbers = null;
    if (phoneDataItems != null) {
        phoneNumbers = new String[phoneDataItems.size()];
        for (int i = 0; i < phoneDataItems.size(); ++i) {
            phoneNumbers[i] = ((PhoneDataItem) phoneDataItems.get(i)).getNumber();
        }
    }
    final Bundle phonesExtraBundle = new Bundle();
    phonesExtraBundle.putStringArray(KEY_LOADER_EXTRA_PHONES, phoneNumbers);

    Trace.beginSection("start sms loader");
    getLoaderManager().initLoader(LOADER_SMS_ID, phonesExtraBundle, mLoaderInteractionsCallbacks);
    Trace.endSection();

    Trace.beginSection("start call log loader");
    getLoaderManager().initLoader(LOADER_CALL_LOG_ID, phonesExtraBundle, mLoaderInteractionsCallbacks);
    Trace.endSection();

    Trace.beginSection("start calendar loader");
    final List<DataItem> emailDataItems = dataItemsMap.get(Email.CONTENT_ITEM_TYPE);
    if (emailDataItems != null && emailDataItems.size() == 1) {
        mOnlyOneEmail = true;
    }
    String[] emailAddresses = null;
    if (emailDataItems != null) {
        emailAddresses = new String[emailDataItems.size()];
        for (int i = 0; i < emailDataItems.size(); ++i) {
            emailAddresses[i] = ((EmailDataItem) emailDataItems.get(i)).getAddress();
        }
    }
    final Bundle emailsExtraBundle = new Bundle();
    emailsExtraBundle.putStringArray(KEY_LOADER_EXTRA_EMAILS, emailAddresses);
    getLoaderManager().initLoader(LOADER_CALENDAR_ID, emailsExtraBundle, mLoaderInteractionsCallbacks);
    Trace.endSection();
}

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

private void populateContactAndAboutCard(Cp2DataCardModel cp2DataCardModel, boolean shouldAddPhoneticName) {
    mCachedCp2DataCardModel = cp2DataCardModel;
    if (mHasIntentLaunched || cp2DataCardModel == null) {
        return;/*  w  w w .  ja  v  a2s  .  c o m*/
    }
    Trace.beginSection("bind contact card");

    final List<List<Entry>> contactCardEntries = cp2DataCardModel.contactCardEntries;
    final List<List<Entry>> aboutCardEntries = cp2DataCardModel.aboutCardEntries;
    final String customAboutCardName = cp2DataCardModel.customAboutCardName;

    if (contactCardEntries.size() > 0) {
        final boolean firstEntriesArePrioritizedMimeType = !TextUtils.isEmpty(mExtraPrioritizedMimeType)
                && mCachedCp2DataCardModel.dataItemsMap.containsKey(mExtraPrioritizedMimeType)
                && mCachedCp2DataCardModel.dataItemsMap.get(mExtraPrioritizedMimeType).size() != 0;
        mContactCard.initialize(contactCardEntries,
                /* numInitialVisibleEntries = */ MIN_NUM_CONTACT_ENTRIES_SHOWN,
                /* isExpanded = */ mContactCard.isExpanded(), /* isAlwaysExpanded = */ false,
                mExpandingEntryCardViewListener, mScroller, firstEntriesArePrioritizedMimeType);
        mContactCard.setVisibility(View.VISIBLE);
    } else {
        mContactCard.setVisibility(View.GONE);
    }
    Trace.endSection();

    Trace.beginSection("bind about card");
    // Phonetic name is not a data item, so the entry needs to be created separately
    // But if mCachedCp2DataCardModel is passed to this method (e.g. returning from editor
    // without saving any changes), then it should include phoneticName and the phoneticName
    // shouldn't be changed. If this is the case, we shouldn't add it again. b/27459294
    final String phoneticName = mContactData.getPhoneticName();
    if (shouldAddPhoneticName && !TextUtils.isEmpty(phoneticName)) {
        Entry phoneticEntry = new Entry(/* viewId = */ -1, /* icon = */ null,
                getResources().getString(R.string.name_phonetic), phoneticName, /* subHeaderIcon = */ null,
                /* text = */ null, /* textIcon = */ null, /* primaryContentDescription = */ null,
                /* intent = */ null, /* alternateIcon = */ null, /* alternateIntent = */ null,
                /* alternateContentDescription = */ null, /* shouldApplyColor = */ false,
                /* isEditable = */ false,
                /* EntryContextMenuInfo = */ new EntryContextMenuInfo(phoneticName,
                        getResources().getString(R.string.name_phonetic), /* mimeType = */ null, /* id = */ -1,
                        /* isPrimary = */ false),
                /* thirdIcon = */ null, /* thirdIntent = */ null, /* thirdContentDescription = */ null,
                /* thirdAction = */ Entry.ACTION_NONE, /* thirdExtras = */ null, /* iconResourceId = */ 0);
        List<Entry> phoneticList = new ArrayList<>();
        phoneticList.add(phoneticEntry);
        // Phonetic name comes after nickname. Check to see if the first entry type is nickname
        if (aboutCardEntries.size() > 0 && aboutCardEntries.get(0).get(0).getHeader()
                .equals(getResources().getString(R.string.header_nickname_entry))) {
            aboutCardEntries.add(1, phoneticList);
        } else {
            aboutCardEntries.add(0, phoneticList);
        }
    }

    if (!TextUtils.isEmpty(customAboutCardName)) {
        mAboutCard.setTitle(customAboutCardName);
    }

    mAboutCard.initialize(aboutCardEntries, /* numInitialVisibleEntries = */ 1, /* isExpanded = */ true,
            /* isAlwaysExpanded = */ true, mExpandingEntryCardViewListener, mScroller);

    if (contactCardEntries.size() == 0 && aboutCardEntries.size() == 0) {
        initializeNoContactDetailCard();
    } else {
        mNoContactDetailsCard.setVisibility(View.GONE);
    }

    // If the Recent card is already initialized (all recent data is loaded), show the About
    // card if it has entries. Otherwise About card visibility will be set in bindRecentData()
    if (isAllRecentDataLoaded() && aboutCardEntries.size() > 0) {
        mAboutCard.setVisibility(View.VISIBLE);
    }
    Trace.endSection();
}

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

/**
 * Builds the {@link DataItem}s Map out of the Contact.
 * @param data The contact to build the data from.
 * @return A pair containing a list of data items sorted within mimetype and sorted
 *  amongst mimetype. The map goes from mimetype string to the sorted list of data items within
 *  mimetype//from  w  w w. j a  v  a 2 s .  c o  m
 */
private Cp2DataCardModel generateDataModelFromContact(Contact data) {
    Trace.beginSection("Build data items map");

    final Map<String, List<DataItem>> dataItemsMap = new HashMap<>();

    final ResolveCache cache = ResolveCache.getInstance(this);
    for (RawContact rawContact : data.getRawContacts()) {
        for (DataItem dataItem : rawContact.getDataItems()) {
            dataItem.setRawContactId(rawContact.getId());

            final String mimeType = dataItem.getMimeType();
            if (mimeType == null)
                continue;

            final AccountType accountType = rawContact.getAccountType(this);
            final DataKind dataKind = AccountTypeManager.getInstance(this).getKindOrFallback(accountType,
                    mimeType);
            if (dataKind == null)
                continue;

            dataItem.setDataKind(dataKind);

            final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, dataKind));

            if (isMimeExcluded(mimeType) || !hasData)
                continue;

            List<DataItem> dataItemListByType = dataItemsMap.get(mimeType);
            if (dataItemListByType == null) {
                dataItemListByType = new ArrayList<>();
                dataItemsMap.put(mimeType, dataItemListByType);
            }
            dataItemListByType.add(dataItem);
        }
    }
    Trace.endSection();

    Trace.beginSection("sort within mimetypes");
    /*
     * Sorting is a multi part step. The end result is to a have a sorted list of the most
     * used data items, one per mimetype. Then, within each mimetype, the list of data items
     * for that type is also sorted, based off of {super primary, primary, times used} in that
     * order.
     */
    final List<List<DataItem>> dataItemsList = new ArrayList<>();
    for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) {
        // Remove duplicate data items
        Collapser.collapseList(mimeTypeDataItems, this);
        // Sort within mimetype
        Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator);
        // Add to the list of data item lists
        dataItemsList.add(mimeTypeDataItems);
    }
    Trace.endSection();

    Trace.beginSection("sort amongst mimetypes");
    // Sort amongst mimetypes to bubble up the top data items for the contact card
    Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator);
    Trace.endSection();

    Trace.beginSection("cp2 data items to entries");

    final List<List<Entry>> contactCardEntries = new ArrayList<>();
    final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap);
    final MutableString aboutCardName = new MutableString();

    for (int i = 0; i < dataItemsList.size(); ++i) {
        final List<DataItem> dataItemsByMimeType = dataItemsList.get(i);
        final DataItem topDataItem = dataItemsByMimeType.get(0);
        if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) {
            // About card mimetypes are built in buildAboutCardEntries, skip here
            continue;
        } else {
            List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), aboutCardName);
            if (contactEntries.size() > 0) {
                contactCardEntries.add(contactEntries);
            }
        }
    }

    Trace.endSection();

    final Cp2DataCardModel dataModel = new Cp2DataCardModel();
    dataModel.customAboutCardName = aboutCardName.value;
    dataModel.aboutCardEntries = aboutCardEntries;
    dataModel.contactCardEntries = contactCardEntries;
    dataModel.dataItemsMap = dataItemsMap;
    return dataModel;
}

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

private void bindRecentData() {
    final List<ContactInteraction> allInteractions = new ArrayList<>();
    final List<List<Entry>> interactionsWrapper = new ArrayList<>();

    // Serialize mRecentLoaderResults into a single list. This should be done on the main
    // thread to avoid races against mRecentLoaderResults edits.
    for (List<ContactInteraction> loaderInteractions : mRecentLoaderResults.values()) {
        allInteractions.addAll(loaderInteractions);
    }/*from   ww w . j av a 2  s  . c  o m*/

    mRecentDataTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Trace.beginSection("sort recent loader results");

            // Sort the interactions by most recent
            Collections.sort(allInteractions, new Comparator<ContactInteraction>() {
                @Override
                public int compare(ContactInteraction a, ContactInteraction b) {
                    if (a == null && b == null) {
                        return 0;
                    }
                    if (a == null) {
                        return 1;
                    }
                    if (b == null) {
                        return -1;
                    }
                    if (a.getInteractionDate() > b.getInteractionDate()) {
                        return -1;
                    }
                    if (a.getInteractionDate() == b.getInteractionDate()) {
                        return 0;
                    }
                    return 1;
                }
            });

            Trace.endSection();
            Trace.beginSection("contactInteractionsToEntries");

            // Wrap each interaction in its own list so that an icon is displayed for each entry
            for (Entry contactInteraction : contactInteractionsToEntries(allInteractions)) {
                List<Entry> entryListWrapper = new ArrayList<>(1);
                entryListWrapper.add(contactInteraction);
                interactionsWrapper.add(entryListWrapper);
            }

            Trace.endSection();
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            Trace.beginSection("initialize recents card");

            if (allInteractions.size() > 0) {
                mRecentCard.initialize(interactionsWrapper,
                        /* numInitialVisibleEntries = */ MIN_NUM_COLLAPSED_RECENT_ENTRIES_SHOWN,
                        /* isExpanded = */ mRecentCard.isExpanded(), /* isAlwaysExpanded = */ false,
                        mExpandingEntryCardViewListener, mScroller);
                mRecentCard.setVisibility(View.VISIBLE);
            }

            Trace.endSection();

            // About card is initialized along with the contact card, but since it appears after
            // the recent card in the UI, we hold off until making it visible until the recent
            // card is also ready to avoid stuttering.
            if (mAboutCard.shouldShow()) {
                mAboutCard.setVisibility(View.VISIBLE);
            } else {
                mAboutCard.setVisibility(View.GONE);
            }
            mRecentDataTask = null;
        }
    };
    mRecentDataTask.execute();
}

From source file:com.android.launcher3.Launcher.java

/**
 * Refreshes the shortcuts shown on the workspace.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*from   ww  w .java2  s  .c  om*/
public void startBinding() {
    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.beginSection("Starting page bind");
    }
    setWorkspaceLoading(true);

    // Clear the workspace because it's going to be rebound
    mWorkspace.clearDropTargets();
    mWorkspace.removeAllWorkspaceScreens();

    mWidgetsToAdvance.clear();
    if (mHotseat != null) {
        mHotseat.resetLayout();
    }
    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.endSection();
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Callback saying that there aren't any more items to bind.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*from w w  w . j  a va2s  . c o m*/
public void finishBindingItems() {
    Runnable r = new Runnable() {
        public void run() {
            finishBindingItems();
        }
    };
    if (waitUntilResume(r)) {
        return;
    }
    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.beginSection("Page bind completed");
    }
    if (mSavedState != null) {
        if (!mWorkspace.hasFocus()) {
            mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
        }

        mSavedState = null;
    }

    mWorkspace.restoreInstanceStateForRemainingPages();

    setWorkspaceLoading(false);

    if (mPendingActivityResult != null) {
        handleActivityResult(mPendingActivityResult.requestCode, mPendingActivityResult.resultCode,
                mPendingActivityResult.data);
        mPendingActivityResult = null;
    }

    InstallShortcutReceiver.disableAndFlushInstallQueue(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.finishBindingItems(false);
    }
    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.endSection();
    }
}