Search in sources :

Example 46 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project UltimateAndroid by cymcsg.

the class PagerSlidingTabStrip method notifyDataSetChanged.

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));
        } else {
            addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 47 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by AOSPA.

the class CropView method moveToLeft.

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();
}
Also used : RectF(android.graphics.RectF) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ViewTreeObserver(android.view.ViewTreeObserver)

Example 48 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project SuperToasts by JohnPersano.

the class TabStrip method notifyDataSetChanged.

private 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));
        } else {
            addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 49 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by crdroidandroid.

the class CropView method moveToLeft.

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();
}
Also used : RectF(android.graphics.RectF) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ViewTreeObserver(android.view.ViewTreeObserver)

Example 50 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by crdroidandroid.

the class Spinner method onRestoreInstanceState.

@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());
    if (ss.showDropdown) {
        ViewTreeObserver vto = getViewTreeObserver();
        if (vto != null) {
            final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (!mPopup.isShowing()) {
                        mPopup.show(getTextDirection(), getTextAlignment());
                    }
                    final ViewTreeObserver vto = getViewTreeObserver();
                    if (vto != null) {
                        vto.removeOnGlobalLayoutListener(this);
                    }
                }
            };
            vto.addOnGlobalLayoutListener(listener);
        }
    }
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)51 ViewTreeObserver (android.view.ViewTreeObserver)25 SuppressLint (android.annotation.SuppressLint)18 View (android.view.View)13 Paint (android.graphics.Paint)12 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)8 TypedArray (android.content.res.TypedArray)7 DisplayMetrics (android.util.DisplayMetrics)7 RectF (android.graphics.RectF)6 TextView (android.widget.TextView)6 AbsListView (android.widget.AbsListView)4 ListView (android.widget.ListView)4 Scroller (android.widget.Scroller)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 AnimatorSet (android.animation.AnimatorSet)3 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)3 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)3 AppWidgetHostView (android.appwidget.AppWidgetHostView)3