Example usage for android.support.v4.os TraceCompat endSection

List of usage examples for android.support.v4.os TraceCompat endSection

Introduction

In this page you can find the example usage for android.support.v4.os TraceCompat endSection.

Prototype

public static void endSection() 

Source Link

Document

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

Usage

From source file:nl.sebastiaanschool.contact.app.MainActivity.java

private void initializeApplicationServices() {
    TraceCompat.beginSection("Initialize services");
    try {/*  w ww.jav a2  s . co  m*/
        JodaTimeAndroid.init(this);
        BackendInterface.init(this);
        analytics = FirebaseWrapper.init(this);
        DownloadManagerInterface.init(this);
        PushNotificationManager.init(this, BackendInterface.getInstance().getNotificationApi());
        IntentFilter filter = PushNotificationManager.createTimelineUpdateBroadcastFilter();
        LocalBroadcastManager.getInstance(this).registerReceiver(localBroadcastReceiver, filter);
    } finally {
        TraceCompat.endSection();
    }
}

From source file:com.ferdi2005.secondgram.support.widget.GapWorker.java

private void prefetchInnerRecyclerViewWithDeadline(@Nullable RecyclerView innerView, long deadlineNs) {
    if (innerView == null) {
        return;/*  ww w  .  j a v  a2  s .  c  o m*/
    }

    if (innerView.mDataSetHasChangedAfterLayout && innerView.mChildHelper.getUnfilteredChildCount() != 0) {
        // RecyclerView has new data, but old attached views. Clear everything, so that
        // we can prefetch without partially stale data.
        innerView.removeAndRecycleViews();
    }

    // do nested prefetch!
    final LayoutPrefetchRegistryImpl innerPrefetchRegistry = innerView.mPrefetchRegistry;
    innerPrefetchRegistry.collectPrefetchPositionsFromView(innerView, true);

    if (innerPrefetchRegistry.mCount != 0) {
        try {
            TraceCompat.beginSection(RecyclerView.TRACE_NESTED_PREFETCH_TAG);
            innerView.mState.prepareForNestedPrefetch(innerView.mAdapter);
            for (int i = 0; i < innerPrefetchRegistry.mCount * 2; i += 2) {
                // Note that we ignore immediate flag for inner items because
                // we have lower confidence they're needed next frame.
                final int innerPosition = innerPrefetchRegistry.mPrefetchArray[i];
                prefetchPositionWithDeadline(innerView, innerPosition, deadlineNs);
            }
        } finally {
            TraceCompat.endSection();
        }
    }
}

From source file:com.ferdi2005.secondgram.support.widget.GapWorker.java

@Override
public void run() {
    try {/*from   w ww  . j  a  v  a2 s  . co  m*/
        TraceCompat.beginSection(RecyclerView.TRACE_PREFETCH_TAG);

        if (mRecyclerViews.isEmpty()) {
            // abort - no work to do
            return;
        }

        // Query last vsync so we can predict next one. Note that drawing time not yet
        // valid in animation/input callbacks, so query it here to be safe.
        long lastFrameVsyncNs = TimeUnit.MILLISECONDS.toNanos(mRecyclerViews.get(0).getDrawingTime());
        if (lastFrameVsyncNs == 0) {
            // abort - couldn't get last vsync for estimating next
            return;
        }

        // TODO: consider rebasing deadline if frame was already dropped due to long UI work.
        // Next frame will still wait for VSYNC, so we can still use the gap if it exists.
        long nextFrameNs = lastFrameVsyncNs + mFrameIntervalNs;

        prefetch(nextFrameNs);

        // TODO: consider rescheduling self, if there's more work to do
    } finally {
        mPostTimeNs = 0;
        TraceCompat.endSection();
    }
}

From source file:com.lee.lib.support.v7.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p>/*from   w  w w .  j  av a  2 s.c  om*/
 * It also reports any unused scroll request to the related EdgeEffect.
 *
 * @param x The amount of horizontal scroll request
 * @param y The amount of vertical scroll request
 * @param ev The originating MotionEvent, or null if not from a touch event.
 *
 * @return Whether any scroll was consumed in either direction.
 */
boolean scrollByInternal(int x, int y, MotionEvent ev) {
    int unconsumedX = 0, unconsumedY = 0;
    int consumedX = 0, consumedY = 0;

    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        onEnterLayoutOrScroll();
        TraceCompat.beginSection(TRACE_SCROLL_TAG);
        if (x != 0) {
            consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            unconsumedX = x - consumedX;
        }
        if (y != 0) {
            consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            unconsumedY = y - consumedY;
        }
        TraceCompat.endSection();
        if (supportsChangeAnimations()) {
            // Fix up shadow views used by changing animations
            int count = mChildHelper.getChildCount();
            for (int i = 0; i < count; i++) {
                View view = mChildHelper.getChildAt(i);
                ViewHolder holder = getChildViewHolder(view);
                if (holder != null && holder.mShadowingHolder != null) {
                    ViewHolder shadowingHolder = holder.mShadowingHolder;
                    View shadowingView = shadowingHolder != null ? shadowingHolder.itemView : null;
                    if (shadowingView != null) {
                        int left = view.getLeft();
                        int top = view.getTop();
                        if (left != shadowingView.getLeft() || top != shadowingView.getTop()) {
                            shadowingView.layout(left, top, left + shadowingView.getWidth(),
                                    top + shadowingView.getHeight());
                        }
                    }
                }
            }
        }
        onExitLayoutOrScroll();
        resumeRequestLayout(false);
    }
    if (!mItemDecorations.isEmpty()) {
        invalidate();
    }

    if (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
        // Update the last touch co-ords, taking any scroll offset into account
        mLastTouchX -= mScrollOffset[0];
        mLastTouchY -= mScrollOffset[1];
        if (ev != null) {
            ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
        }
        mNestedOffsets[0] += mScrollOffset[0];
        mNestedOffsets[1] += mScrollOffset[1];
    } else if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        if (ev != null) {
            pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
        }
        considerReleasingGlowsOnScroll(x, y);
    }
    if (consumedX != 0 || consumedY != 0) {
        dispatchOnScrolled(consumedX, consumedY);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
    return consumedX != 0 || consumedY != 0;
}

From source file:cn.ismartv.recyclerview.widget.RecyclerView.java

/**
 * Helper method reflect data changes to the state.
 * <p>/* www  .j  a  v  a2s  .co m*/
 * Adapter changes during a scroll may trigger a crash because scroll assumes no data change
 * but data actually changed.
 * <p>
 * This method consumes all deferred changes to avoid that case.
 */
private void consumePendingUpdateOperations() {
    if (!mFirstLayoutComplete) {
        // a layout request will happen, we should not do layout here.
        return;
    }
    if (mDataSetHasChangedAfterLayout) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
        return;
    }
    if (!mAdapterHelper.hasPendingUpdates()) {
        return;
    }

    // if it is only an item change (no add-remove-notifyDataSetChanged) we can check if any
    // of the visible items is affected and if not, just ignore the change.
    if (mAdapterHelper.hasAnyUpdateTypes(UpdateOp.UPDATE)
            && !mAdapterHelper.hasAnyUpdateTypes(UpdateOp.ADD | UpdateOp.REMOVE | UpdateOp.MOVE)) {
        TraceCompat.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG);
        eatRequestLayout();
        mAdapterHelper.preProcess();
        if (!mLayoutRequestEaten) {
            if (hasUpdatedView()) {
                dispatchLayout();
            } else {
                // no need to layout, clean state
                mAdapterHelper.consumePostponedUpdates();
            }
        }
        resumeRequestLayout(true);
        TraceCompat.endSection();
    } else if (mAdapterHelper.hasPendingUpdates()) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
    }
}

From source file:ir.besteveryeverapp.telegram.support.widget.RecyclerView.java

/**
 * Helper method reflect data changes to the state.
 * <p>/* w w  w. ja  v a2 s .co  m*/
 * Adapter changes during a scroll may trigger a crash because scroll assumes no data change
 * but data actually changed.
 * <p>
 * This method consumes all deferred changes to avoid that case.
 */
private void consumePendingUpdateOperations() {
    if (!mFirstLayoutComplete) {
        // a layout request will happen, we should not do layout here.
        return;
    }
    if (mDataSetHasChangedAfterLayout) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
        return;
    }
    if (!mAdapterHelper.hasPendingUpdates()) {
        return;
    }

    // if it is only an item change (no add-remove-notifyDataSetChanged) we can check if any
    // of the visible items is affected and if not, just ignore the change.
    if (mAdapterHelper.hasAnyUpdateTypes(AdapterHelper.UpdateOp.UPDATE) && !mAdapterHelper.hasAnyUpdateTypes(
            AdapterHelper.UpdateOp.ADD | AdapterHelper.UpdateOp.REMOVE | AdapterHelper.UpdateOp.MOVE)) {
        TraceCompat.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG);
        eatRequestLayout();
        mAdapterHelper.preProcess();
        if (!mLayoutRequestEaten) {
            if (hasUpdatedView()) {
                dispatchLayout();
            } else {
                // no need to layout, clean state
                mAdapterHelper.consumePostponedUpdates();
            }
        }
        resumeRequestLayout(true);
        TraceCompat.endSection();
    } else if (mAdapterHelper.hasPendingUpdates()) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
    }
}

From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java

/**
 * Helper method reflect data changes to the state.
 * <p>/*from   w  w w  .j  av a2 s .  co  m*/
 * Adapter changes during a scroll may trigger a crash because scroll assumes no data change
 * but data actually changed.
 * <p>
 * This method consumes all deferred changes to avoid that case.
 */
private void consumePendingUpdateOperations() {
    if (!mFirstLayoutComplete || mDataSetHasChangedAfterLayout) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
        return;
    }
    if (!mAdapterHelper.hasPendingUpdates()) {
        return;
    }

    // if it is only an item change (no add-remove-notifyDataSetChanged) we can check if any
    // of the visible items is affected and if not, just ignore the change.
    if (mAdapterHelper.hasAnyUpdateTypes(UpdateOp.UPDATE)
            && !mAdapterHelper.hasAnyUpdateTypes(UpdateOp.ADD | UpdateOp.REMOVE | UpdateOp.MOVE)) {
        TraceCompat.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG);
        eatRequestLayout();
        mAdapterHelper.preProcess();
        if (!mLayoutRequestEaten) {
            if (hasUpdatedView()) {
                dispatchLayout();
            } else {
                // no need to layout, clean state
                mAdapterHelper.consumePostponedUpdates();
            }
        }
        resumeRequestLayout(true);
        TraceCompat.endSection();
    } else if (mAdapterHelper.hasPendingUpdates()) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
    }
}

From source file:android.support.v71.widget.RecyclerView.java

/**
 * Helper method reflect data changes to the state.
 * <p/>/*www  .j a  v a  2  s  .c o  m*/
 * Adapter changes during a scroll may trigger a crash because scroll assumes no data change
 * but data actually changed.
 * <p/>
 * This method consumes all deferred changes to avoid that case.
 */
private void consumePendingUpdateOperations() {
    if (!mFirstLayoutComplete) {
        // ? ???
        // a layout request will happen, we should not do layout here.
        return;
    }

    if (mDataSetHasChangedAfterLayout) {
        // ??
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        //   
        dispatchLayout();
        // ??
        TraceCompat.endSection();
        return;
    }
    if (!mAdapterHelper.hasPendingUpdates()) {
        return;
    }

    // if it is only an item change (no add-remove-notifyDataSetChanged) we can check if any
    // of the visible items is affected and if not, just ignore the change.
    if (mAdapterHelper.hasAnyUpdateTypes(AdapterHelper.UpdateOp.UPDATE) && !mAdapterHelper.hasAnyUpdateTypes(
            AdapterHelper.UpdateOp.ADD | AdapterHelper.UpdateOp.REMOVE | AdapterHelper.UpdateOp.MOVE)) {
        TraceCompat.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG);
        eatRequestLayout();
        mAdapterHelper.preProcess();
        if (!mLayoutRequestEaten) {
            if (hasUpdatedView()) {
                dispatchLayout();
            } else {
                // no need to layout, clean state
                mAdapterHelper.consumePostponedUpdates();
            }
        }
        resumeRequestLayout(true);
        TraceCompat.endSection();
    } else if (mAdapterHelper.hasPendingUpdates()) {
        TraceCompat.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG);
        dispatchLayout();
        TraceCompat.endSection();
    }
}

From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p>//from w  w w  .j  av a2s .c  om
 * It also reports any unused scroll request to the related EdgeEffect.
 *
 * @param x The amount of horizontal scroll request
 * @param y The amount of vertical scroll request
 * @param ev The originating MotionEvent, or null if not from a touch event.
 *
 * @return Whether any scroll was consumed in either direction.
 */
boolean scrollByInternal(int x, int y, MotionEvent ev) {
    int unconsumedX = 0, unconsumedY = 0;
    int consumedX = 0, consumedY = 0;

    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        onEnterLayoutOrScroll();
        TraceCompat.beginSection(TRACE_SCROLL_TAG);
        if (x != 0) {
            consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            unconsumedX = x - consumedX;
        }
        if (y != 0) {
            consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            unconsumedY = y - consumedY;
        }
        TraceCompat.endSection();
        repositionShadowingViews();
        onExitLayoutOrScroll();
        resumeRequestLayout(false);
    }
    if (!mItemDecorations.isEmpty()) {
        invalidate();
    }

    if (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
        // Update the last touch co-ords, taking any scroll offset into account
        mLastTouchX -= mScrollOffset[0];
        mLastTouchY -= mScrollOffset[1];
        if (ev != null) {
            ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
        }
        mNestedOffsets[0] += mScrollOffset[0];
        mNestedOffsets[1] += mScrollOffset[1];
    } else if (getOverScrollMode() != View.OVER_SCROLL_NEVER) {
        if (ev != null) {
            pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
        }
        considerReleasingGlowsOnScroll(x, y);
    }
    if (consumedX != 0 || consumedY != 0) {
        dispatchOnScrolled(consumedX, consumedY);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
    return consumedX != 0 || consumedY != 0;
}

From source file:android.support.v71.widget.RecyclerView.java

/**
 * Does not perform bounds checking. Used by internal methods that have already validated input.
 * <p/>/*  w  w w . j  ava  2s . c o  m*/
 * It also reports any unused scroll request to the related EdgeEffect.
 *
 * @param x  The amount of horizontal scroll request
 * @param y  The amount of vertical scroll request
 * @param ev The originating MotionEvent, or null if not from a touch event.
 * @return Whether any scroll was consumed in either direction.
 */
boolean scrollByInternal(int x, int y, MotionEvent ev) {
    int unconsumedX = 0, unconsumedY = 0;
    int consumedX = 0, consumedY = 0;

    consumePendingUpdateOperations();
    if (mAdapter != null) {
        eatRequestLayout();
        onEnterLayoutOrScroll();
        TraceCompat.beginSection(TRACE_SCROLL_TAG);
        if (x != 0) {
            consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
            unconsumedX = x - consumedX;
        }
        if (y != 0) {
            consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
            unconsumedY = y - consumedY;
        }
        TraceCompat.endSection();
        repositionShadowingViews();
        onExitLayoutOrScroll();
        resumeRequestLayout(false);
    }
    if (!mItemDecorations.isEmpty()) {
        invalidate();
    }

    if (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
        // Update the last touch co-ords, taking any scroll offset into account
        mLastTouchX -= mScrollOffset[0];
        mLastTouchY -= mScrollOffset[1];
        if (ev != null) {
            ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
        }
        mNestedOffsets[0] += mScrollOffset[0];
        mNestedOffsets[1] += mScrollOffset[1];
    } else if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        if (ev != null) {
            pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
        }
        considerReleasingGlowsOnScroll(x, y);
    }
    if (consumedX != 0 || consumedY != 0) {
        dispatchOnScrolled(consumedX, consumedY);
    }
    if (!awakenScrollBars()) {
        invalidate();
    }
    return consumedX != 0 || consumedY != 0;
}