Java Code Examples for android.view.ViewTreeObserver.OnGlobalLayoutListener

The following are top voted examples for showing how to use android.view.ViewTreeObserver.OnGlobalLayoutListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ChromeLikeTabSwitcher   File: TabletTabSwitcherLayout.java   View source code 8 votes vote down vote up
/**
 * 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);
            }
        }

    };
}
 
Example 2
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 7 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 3
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 7 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 4
Project: GitHub   File: VLayoutActivity.java   View source code 6 votes vote down vote up
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();
            }
        }
    });
}
 
Example 5
Project: GitHub   File: VLayoutActivity.java   View source code 6 votes vote down vote up
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();
            }
        }
    });
}
 
Example 6
Project: airgram   File: PagerSlidingTabStrip.java   View source code 6 votes vote down vote up
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);
        }
    });
}
 
Example 7
Project: vlayout   File: VLayoutActivity.java   View source code 6 votes vote down vote up
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();
            }
        }
    });
}
 
Example 8
Project: letv   File: RegisterActivity.java   View source code 6 votes vote down vote up
@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);
        }
    });
}
 
Example 9
Project: jackknife   File: HorizontalTabBar.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example 10
Project: ChromeLikeTabSwitcher   File: AbstractTabSwitcherLayout.java   View source code 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 11
Project: ChromeLikeTabSwitcher   File: TabletTabSwitcherLayout.java   View source code 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 12
Project: ChromeLikeTabSwitcher   File: TabletTabSwitcherLayout.java   View source code 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 13
Project: ChromeLikeTabSwitcher   File: TabletTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
            }
        }

    };
}
 
Example 14
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 15
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 16
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 17
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   View source code 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();
            }
        }

    };
}
 
Example 18
Project: PlusGram   File: PagerSlidingTabStrip.java   View source code 6 votes vote down vote up
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);
        }
    });
}
 
Example 19
Project: RefreshWithAppBarLayout   File: PullToRefreshBase.java   View source code 6 votes vote down vote up
/**
 * 初始化
 *
 * @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);
        }
    });
}
 
Example 20
Project: FlickLauncher   File: CropView.java   View source code 6 votes vote down vote up
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();
}
 
Example 21
Project: ticket-view   File: TicketView.java   View source code 6 votes vote down vote up
@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);
            }
        });
    }
}
 
Example 22
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 23
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 24
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 25
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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);
        }

    };
}
 
Example 26
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 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 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();
            }
        }

    };
}
 
Example 27
Project: NeoTerm   File: PhoneTabSwitcherLayout.java   View source code 6 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example 28
Project: AndroidUtilCode   File: KeyboardUtils.java   View source code 6 votes vote down vote up
/**
 * 注册软键盘改变监听器
 *
 * @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;
                }
            }
        }
    });
}
 
Example 29
Project: solved-hacking-problem   File: bj.java   View source code 6 votes vote down vote up
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));
        }
    }
}
 
Example 30
Project: solved-hacking-problem   File: bj.java   View source code 6 votes vote down vote up
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));
        }
    }
}
 
Example 31
Project: SimplOS   File: CropView.java   View source code 6 votes vote down vote up
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();
}
 
Example 32
Project: enjoychat   File: XListView.java   View source code 6 votes vote down vote up
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);
				}
			});
}
 
Example 33
Project: XPPLE_IM   File: XListView.java   View source code 6 votes vote down vote up
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);
				}
			});
}
 
Example 34
Project: Trebuchet   File: CropView.java   View source code 6 votes vote down vote up
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();
}
 
Example 35
Project: zone-sdk   File: MeasureUtils.java   View source code 6 votes vote down vote up
/**
 * <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;
            }
        }
    });
}
 
Example 36
Project: ItHome   File: XListView.java   View source code 6 votes vote down vote up
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);
        }
    });
}
 
Example 37
Project: QQ   File: XListView.java   View source code 6 votes vote down vote up
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);
				}
			});
}
 
Example 38
Project: Mobile-Office   File: PreviewAdapter.java   View source code 6 votes vote down vote up
@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;
}
 
Example 39
Project: Mobile-Office   File: MeetingApprFragment.java   View source code 6 votes vote down vote up
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);
				}
			});
}
 
Example 40
Project: Mobile-Office   File: WaitMeApprFragment.java   View source code 6 votes vote down vote up
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);
				}
			});
}