Java 类android.view.ViewTreeObserver.OnGlobalLayoutListener 实例源码

项目:ChromeLikeTabSwitcher    文件:TabletTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @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 createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(neighbor.getTab());

            if (view != null) {
                float position;

                if (dragDistance > 0) {
                    position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
                } else {
                    position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
                }

                view.setX(position);
            }
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to show a tab as the currently selected
 * one, once it view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which has been added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createAddSelectedTabLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, item,
                    getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE));
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
                    getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, item, DragState.NONE));
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 1);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 1);
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to start a reveal animation to add a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param revealAnimation
 *         The reveal animation, which should be started, as an instance of the class {@link
 *         RevealAnimation}. The reveal animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createRevealLayoutListener(@NonNull final AbstractItem item,
                                                          @NonNull final RevealAnimation revealAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();
            float x = revealAnimation.getX();
            float y = revealAnimation.getY() + tabTitleContainerHeight;
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.X_AXIS, item, x);
            getArithmetics().setPivot(Axis.Y_AXIS, item, y);
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 0);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 0);
            animateReveal(item, revealAnimation);
        }

    };
}
项目:GitHub    文件:VLayoutActivity.java   
public void setListenerToRootView() {
    final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
                if (isOpened == false) {
                    //Do two things, make the view top visible and the editText smaller
                }
                isOpened = true;
            } else if (isOpened == true) {
                isOpened = false;
                final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    });
}
项目:GitHub    文件:VLayoutActivity.java   
public void setListenerToRootView() {
    final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
                if (isOpened == false) {
                    //Do two things, make the view top visible and the editText smaller
                }
                isOpened = true;
            } else if (isOpened == true) {
                isOpened = false;
                final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    });
}
项目:airgram    文件:PagerSlidingTabStrip.java   
public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++) {
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
项目:vlayout    文件:VLayoutActivity.java   
public void setListenerToRootView() {
    final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
                if (isOpened == false) {
                    //Do two things, make the view top visible and the editText smaller
                }
                isOpened = true;
            } else if (isOpened == true) {
                isOpened = false;
                final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    });
}
项目:letv    文件:RegisterActivity.java   
@SuppressLint({"NewApi"})
private void changeViewPageHight() {
    final int w = MeasureSpec.makeMeasureSpec(0, 0);
    final int h = MeasureSpec.makeMeasureSpec(0, 0);
    this.mRegisterViewPager.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(this) {
        final /* synthetic */ RegisterActivity this$0;

        public void onGlobalLayout() {
            if (VERSION.SDK_INT >= 16) {
                this.this$0.mRegisterViewPager.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                this.this$0.mRegisterViewPager.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            View view = this.this$0.mRegisterViewPager.getChildAt(this.this$0.mRegisterViewPager.getCurrentItem());
            view.measure(w, h);
            LayoutParams params = new LayoutParams(-1, -2);
            params.height = view.getMeasuredHeight();
            this.this$0.mRegisterViewPager.setLayoutParams(params);
        }
    });
}
项目:jackknife    文件:HorizontalTabBar.java   
/**
 * You can invoke the method if you need to rearrange.
 */
public void notifyDataSetChanged() {
    mTabCount = mTabTitles.size();
    mTabContainer.removeAllViews();
    if (mTabTitles != null && mTabTitles.size() > 0) {
        for (int i = 0; i < mTabTitles.size(); i++) {
            addTextTab(i, mTabTitles.get(i));
        }
    }
    refreshTabs();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        public void onGlobalLayout() {
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
            scrollToChild(mPosition, 0);
        }
    });
}
项目:ChromeLikeTabSwitcher    文件:AbstractTabSwitcherLayout.java   
/**
 * 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();
        }
    }
}
项目:ChromeLikeTabSwitcher    文件:TabletTabSwitcherLayout.java   
/**
 * 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();
        }
    }
}
项目:ChromeLikeTabSwitcher    文件:TabletTabSwitcherLayout.java   
/**
 * 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();
            }
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:TabletTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to position the content of a tab, after
 * it has been inflated.
 *
 * @param tab
 *         The tab, whose content has been inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createContentLayoutListener(@NonNull final Tab tab) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(tab);

            if (view != null) {
                view.setX(0);
            }
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to start a peek animation to add a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param peekAnimation
 *         The peek animation, which should be started, as an instance of the class {@link
 *         PeekAnimation}. The peek animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
private OnGlobalLayoutListener createPeekLayoutListener(@NonNull final AbstractItem item,
                                                        @NonNull final PeekAnimation peekAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            float peekPosition =
                    getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false) * 0.66f;
            animatePeek(item, duration, interpolator, peekPosition, peekAnimation);
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @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 createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            float position;

            if (dragDistance > 0) {
                position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
            } else {
                position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
            }

            getArithmetics().setPosition(Axis.X_AXIS, neighbor, position);
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to adapt the bottom margin 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
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
private OnGlobalLayoutListener createBottomMarginLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();

            if (tabViewBottomMargin == -1) {
                tabViewBottomMargin = calculateBottomMargin(item);
            }

            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            layoutParams.bottomMargin = tabViewBottomMargin;
            view.setLayoutParams(layoutParams);
        }

    };
}
项目:ChromeLikeTabSwitcher    文件:PhoneTabSwitcherLayout.java   
/**
 * 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();
            }
        }

    };
}
项目:PlusGram    文件:PagerSlidingTabStrip.java   
public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++) {
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < 16) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
项目:RefreshWithAppBarLayout    文件:PullToRefreshBase.java   
/**
 * 初始化
 *
 * @param context context
 */
private void init(Context context, AttributeSet attrs) {
    setOrientation(LinearLayout.VERTICAL);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mHeaderLayout = createHeaderLoadingLayout(context, attrs);
    mFooterLayout = createFooterLoadingLayout(context, attrs);
    mRefreshableView = createRefreshableView(context, attrs);

    if (null == mRefreshableView) {
        throw new NullPointerException("Refreshable view can not be null.");
    }

    addRefreshableView(context, mRefreshableView);
    addHeaderAndFooter(context);

    // 得到Header的高度,这个高度需要用这种方式得到,在onLayout方法里面得到的高度始终是0
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            refreshLoadingViewsSize();
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}
项目:FlickLauncher    文件:CropView.java   
public void moveToLeft() {
    if (getWidth() == 0 || getHeight() == 0) {
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                moveToLeft();
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    final RectF edges = mTempEdges;
    getEdgesHelper(edges);
    final float scale = mRenderer.scale;
    mCenterX += Math.ceil(edges.left / scale);
    updateCenter();
}
项目:ticket-view    文件:TicketView.java   
@Override protected void onFinishInflate() {
    super.onFinishInflate();
    if (anchorViewId != NO_VALUE) {
        final View anchorView = findViewById(anchorViewId);

        getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override public void onGlobalLayout() {
                if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
                    getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
                setAnchor(anchorView);
            }
        });
    }
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to show a tab as the currently selected
 * one, once it view has been inflated.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which has been added, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createAddSelectedTabLayoutListener(
        @NonNull final TabItem tabItem) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = tabItem.getView();
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, view,
                    getArithmetics().getPivot(Axis.DRAGGING_AXIS, view, DragState.NONE));
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, view,
                    getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, view, DragState.NONE));
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, view, 1);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, view, 1);
        }

    };
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to start a reveal animation to add a tab,
 * once its view has been inflated.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be added, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param revealAnimation
 *         The reveal animation, which should be started, as an instance of the class {@link
 *         RevealAnimation}. The reveal animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createRevealLayoutListener(@NonNull final TabItem tabItem,
                                                          @NonNull final RevealAnimation revealAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = tabItem.getView();
            float x = revealAnimation.getX();
            float y = revealAnimation.getY() + tabTitleContainerHeight;
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.X_AXIS, view, x);
            getArithmetics().setPivot(Axis.Y_AXIS, view, y);
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, view, 0);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, view, 0);
            animateReveal(tabItem, revealAnimation);
        }

    };
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to start a peek animation to add a tab,
 * once its view has been inflated.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be added, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param peekAnimation
 *         The peek animation, which should be started, as an instance of the class {@link
 *         PeekAnimation}. The peek animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
private OnGlobalLayoutListener createPeekLayoutListener(@NonNull final TabItem tabItem,
                                                        @NonNull final PeekAnimation peekAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            float peekPosition =
                    getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false) * 0.66f;
            animatePeek(tabItem, duration, interpolator, peekPosition, peekAnimation);
        }

    };
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to adapt the bottom margin of a tab, once
 * its view has been inflated.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, whose view should be adapted, as an
 *         instance of the class {@link TabItem}. The tab item may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
private OnGlobalLayoutListener createBottomMarginLayoutListener(
        @NonNull final TabItem tabItem) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = tabItem.getView();

            if (tabViewBottomMargin == -1) {
                tabViewBottomMargin = calculateBottomMargin(view);
            }

            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            layoutParams.bottomMargin = tabViewBottomMargin;
            view.setLayoutParams(layoutParams);
        }

    };
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of a tab,
 * once its view has been inflated.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, whose view should be adapted, as an
 *         instance of the class {@link TabItem}. The tab item may not be null
 * @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 TabItem tabItem,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            adaptViewSize(tabItem);
            updateView(tabItem);

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

    };
}
项目:NeoTerm    文件:PhoneTabSwitcherLayout.java   
/**
 * Inflates the view, which is used to visualize a specific tab.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, whose view should be inflated, as an
 *         instance of the class {@link TabItem}. The tab 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 array of the type {@link Integer}.
 *         The array may not be null
 */
private void inflateView(@NonNull final TabItem tabItem,
                         @Nullable final OnGlobalLayoutListener listener,
                         @NonNull final Integer... params) {
    Pair<View, Boolean> pair = viewRecycler.inflate(tabItem, params);

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

        if (inflated) {
            View view = pair.first;
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
项目:AndroidUtilCode    文件:KeyboardUtils.java   
/**
 * 注册软键盘改变监听器
 *
 * @param activity activity
 * @param listener listener
 */
public static void registerSoftInputChangedListener(final Activity activity,
                                                    final OnSoftInputChangedListener listener) {
    final View contentView = activity.findViewById(android.R.id.content);
    sContentViewInvisibleHeightPre = getContentViewInvisibleHeight(activity);
    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (listener != null) {
                int height = getContentViewInvisibleHeight(activity);
                if (sContentViewInvisibleHeightPre != height) {
                    listener.onSoftInputChanged(height);
                    sContentViewInvisibleHeightPre = height;
                }
            }
        }
    });
}
项目:solved-hacking-problem    文件:bj.java   
public void m2592c() {
    boolean k = m2581k();
    m2591b();
    m2576g(2);
    super.m2567c();
    m2583m().setChoiceMode(1);
    m2578h(this.f1401a.getSelectedItemPosition());
    if (!k) {
        ViewTreeObserver viewTreeObserver = this.f1401a.getViewTreeObserver();
        if (viewTreeObserver != null) {
            OnGlobalLayoutListener blVar = new bl(this);
            viewTreeObserver.addOnGlobalLayoutListener(blVar);
            m2564a(new bm(this, blVar));
        }
    }
}
项目:solved-hacking-problem    文件:bj.java   
public void m2592c() {
    boolean k = m2581k();
    m2591b();
    m2576g(2);
    super.m2567c();
    m2583m().setChoiceMode(1);
    m2578h(this.f1401a.getSelectedItemPosition());
    if (!k) {
        ViewTreeObserver viewTreeObserver = this.f1401a.getViewTreeObserver();
        if (viewTreeObserver != null) {
            OnGlobalLayoutListener blVar = new bl(this);
            viewTreeObserver.addOnGlobalLayoutListener(blVar);
            m2564a(new bm(this, blVar));
        }
    }
}
项目:SimplOS    文件:CropView.java   
public void moveToLeft() {
    if (getWidth() == 0 || getHeight() == 0) {
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                public void onGlobalLayout() {
                    moveToLeft();
                    getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
    }
    final RectF edges = mTempEdges;
    getEdgesHelper(edges);
    final float scale = mRenderer.scale;
    mCenterX += Math.ceil(edges.left / scale);
    updateCenter();
}
项目:enjoychat    文件:XListView.java   
private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XListView need the scroll event, and it will dispatch the event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);

    m_context = context;
    // init header view
    mHeaderView = new XListViewHeader(context);
    mHeaderViewContent = (RelativeLayout) mHeaderView
            .findViewById(R.id.xlistview_header_content);
    addHeaderView(mHeaderView);

    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {
                @SuppressWarnings("deprecation")
                @Override
                public void onGlobalLayout() {
                    mHeaderViewHeight = mHeaderViewContent.getHeight();
                    getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            });
}
项目:XPPLE_IM    文件:XListView.java   
private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XListView need the scroll event, and it will dispatch the event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);

    m_context = context;
    // init header view
    mHeaderView = new XListViewHeader(context);
    mHeaderViewContent = (RelativeLayout) mHeaderView
            .findViewById(R.id.xlistview_header_content);
    addHeaderView(mHeaderView);

    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {
                @SuppressWarnings("deprecation")
                @Override
                public void onGlobalLayout() {
                    mHeaderViewHeight = mHeaderViewContent.getHeight();
                    getViewTreeObserver()
                            .removeGlobalOnLayoutListener(this);
                }
            });
}
项目:Trebuchet    文件:CropView.java   
public void moveToLeft() {
    if (getWidth() == 0 || getHeight() == 0) {
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                public void onGlobalLayout() {
                    moveToLeft();
                    getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
    }
    final RectF edges = mTempEdges;
    getEdgesHelper(edges);
    final float scale = mRenderer.scale;
    mCenterX += Math.ceil(edges.left / scale);
    updateCenter();
}
项目:zone-sdk    文件:MeasureUtils.java   
/**
 * <br>调用时机:可见性 或者 布局状态改变的时候 如果view背景换了 那么一定invalited那么布局状态一定改变了
 * <br>Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes
 *
 * @param v
 * @param gs 枚举表示 测量后是否移除此监听 目的是:为了防止被多次调用 (用完就移除     除非特殊一直想监听)
 */
public static void measure(final View v, final ListenerState gs, final OnMeasureListener oml) {
    ViewTreeObserver vto = v.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            int height = v.getMeasuredHeight();
            int width = v.getMeasuredWidth();
            if (oml != null) {
                oml.measureResult(v, width, height);
            }
            switch (gs) {
                case MEASURE_REMOVE:
                    v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    break;
                case MEASURE_CONTINUE:
                    break;
                default:
                    break;
            }
        }
    });
}
项目:ItHome    文件:XListView.java   
private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XListView need the scroll event, and it will dispatch the event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);

    // init header view
    mHeaderView = new XListViewHeader(context);
    mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
    mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
    addHeaderView(mHeaderView);

    // init footer view
    mFooterView = new XListViewFooter(context);

    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mHeaderViewHeight = mHeaderViewContent.getHeight();
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}
项目:QQ    文件:XListView.java   
private void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XListView need the scroll event, and it will dispatch the event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);

    m_context = context;
    // init header view
    mHeaderView = new XListViewHeader(context);
    mHeaderViewContent = (RelativeLayout) mHeaderView
            .findViewById(R.id.xlistview_header_content);
    addHeaderView(mHeaderView);

    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {
                @SuppressWarnings("deprecation")
                @Override
                public void onGlobalLayout() {
                    mHeaderViewHeight = mHeaderViewContent.getHeight();
                    getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            });
}
项目:Mobile-Office    文件:PreviewAdapter.java   
@Override
public Object instantiateItem(ViewGroup container, final int position) {
    final ImageView iv = new ImageView(mContext);
    iv.setScaleType(ScaleType.CENTER_INSIDE);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    iv.setLayoutParams(params);
    iv.setImageResource(R.drawable.bg_default_pic);
    iv.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            iv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            int width = iv.getWidth();
            int height = iv.getHeight();
            ImageLoader.getInstance().loadImageFormDisk(iv, mData.get(position), R.drawable.bg_default_pic, width, height);
        }
    });
    container.addView(iv);
    return iv;
}
项目:Mobile-Office    文件:MeetingApprFragment.java   
private void initiScrollBar() {
    mScrollBarContainer.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

                @SuppressWarnings("deprecation")
                @Override
                public void onGlobalLayout() {
                    int width = mScrollBarContainer.getWidth();
                    scrollBarWidth = width;
                    RelativeLayout.LayoutParams lp = (LayoutParams) mScrollBar
                            .getLayoutParams();
                    lp.width = width / 2;
                    mScrollBar.setLayoutParams(lp);
                    initViewAnimation();
                    mScrollBarContainer.getViewTreeObserver()
                            .removeGlobalOnLayoutListener(this);
                }
            });
}
项目:Mobile-Office    文件:WaitMeApprFragment.java   
private void initiScrollBar() {
    scrollBarContainer.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    int width = scrollBarContainer.getWidth();
                    scrollBarWidth = width;
                    RelativeLayout.LayoutParams lp = (LayoutParams) scrollBar
                            .getLayoutParams();
                    lp.width = width / 2;
                    scrollBar.setLayoutParams(lp);
                    initViewAnimation();
                    scrollBarContainer.getViewTreeObserver()
                            .removeGlobalOnLayoutListener(this);
                }
            });
}