Java Code Examples for android.view.ViewTreeObserver.OnGlobalLayoutListener#onGlobalLayout()

The following examples show how to use android.view.ViewTreeObserver.OnGlobalLayoutListener#onGlobalLayout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the view, which is used to visualize a specific item.
 *
 * @param item
 *         The item, whose view should be inflated, as an instance of the class {@link
 *         AbstractItem}. The item may not be null
 * @param listener
 *         The layout listener, which should be notified, when the view has been inflated, as an
 *         instance of the type {@link OnGlobalLayoutListener} or null, if no listener should be
 *         notified
 * @param params
 *         An array, which contains optional parameters, which should be passed to the view
 *         recycler, which is used to inflate the view, as an {@link Integer} array or null, if
 *         no optional parameters should be used
 */
protected final void inflateView(@NonNull final AbstractItem item,
                                 @Nullable final OnGlobalLayoutListener listener,
                                 @NonNull final Integer... params) {
    Pair<View, Boolean> pair = getTabViewRecycler().inflate(item, params);

    if (listener != null) {
        boolean inflated = pair.second;

        if (inflated) {
            View view = pair.first;
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
 
Example 2
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the content, which is associated with a specific tab.
 *
 * @param tab
 *         The tab, whose content should be inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @param listener
 *         The layout listener, which should be notified, when the view has been inflated, as an
 *         instance of the type {@link OnGlobalLayoutListener} or null, if no listener should be
 *         notified
 */
private void inflateContent(@NonNull final Tab tab,
                            @Nullable final OnGlobalLayoutListener listener) {
    Pair<View, Boolean> pair = contentViewRecycler.inflate(tab);
    View view = pair.first;

    if (listener != null) {
        boolean inflated = pair.second;

        if (inflated) {
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
 
Example 3
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of an
 * item, once its view has been inflated.
 *
 * @param item
 *         The item, whose view should be adapted, as an instance of the class {@link
 *         AbstractItem}. The item may not be null
 * @param dragging
 *         True, if the item is currently being dragged, false otherwise
 * @param layoutListener
 *         The layout lister, which should be notified, when the created listener is invoked, as
 *         an instance of the type {@link OnGlobalLayoutListener} or null, if no listener should
 *         be notified
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createInflateViewLayoutListener(@NonNull final AbstractItem item,
                                                               final boolean dragging,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            updateView(item, dragging);

            if (layoutListener != null) {
                layoutListener.onGlobalLayout();
            }
        }

    };
}
 
Example 4
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, whose view should be adapted, as an instance
 *         of the class {@link AbstractItem}. The item may not be null
 * @param dragging
 *         True, if the item is currently being dragged, false otherwise
 * @param layoutListener
 *         The layout lister, which should be notified, when the created listener is invoked, as
 *         an instance of the type {@link OnGlobalLayoutListener} or null, if no listener should
 *         be notified
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createInflateViewLayoutListener(@NonNull final AbstractItem item,
                                                               final boolean dragging,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            adaptViewSize(item);
            updateView(item, dragging);

            if (layoutListener != null) {
                layoutListener.onGlobalLayout();
            }
        }

    };
}