Search in sources :

Example 26 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project PagerSlidingTabStrip by astuetz.

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 27 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Launcher3 by chislon.

the class WallpaperPickerActivity method initializeScrollForRtl.

private void initializeScrollForRtl() {
    final HorizontalScrollView scroll = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);
    if (scroll.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        final ViewTreeObserver observer = scroll.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            public void onGlobalLayout() {
                LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
                scroll.scrollTo(masterWallpaperList.getWidth(), 0);
                scroll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) HorizontalScrollView(android.widget.HorizontalScrollView) ViewTreeObserver(android.view.ViewTreeObserver) LinearLayout(android.widget.LinearLayout)

Example 28 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Launcher3 by chislon.

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 29 with OnGlobalLayoutListener

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

the class FlowerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mConverView = LayoutInflater.from(getActivity()).inflate(R.layout.switch_animation_view_fragment, null);
    mConverView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            new SwitchAnimationUtil().startAnimation(mConverView, Constant.mType);
        }
    });
    return mConverView;
}
Also used : SwitchAnimationUtil(com.marshalchen.common.uimodule.smoothswitch.SwitchAnimationUtil) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener)

Example 30 with OnGlobalLayoutListener

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

the class IconRoundCornerProgressBar method setup.

@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
    int color;
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    radius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
    radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
    padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
    imageIcon = (ImageView) findViewById(R.id.round_corner_progress_icon);
    imageIcon.setScaleType(ScaleType.CENTER_CROP);
    if (!isIconSetBeforeDraw) {
        int iconResource = (int) typedArray.getResourceId(R.styleable.RoundCornerProgress_rcp_iconSrc, R.drawable.round_corner_progress_icon);
        imageIcon.setImageResource(iconResource);
    }
    iconSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iconSize, metrics);
    iconSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_iconSize, iconSize);
    imageIcon.setLayoutParams(new LayoutParams(iconSize, iconSize));
    layoutHeader = (LinearLayout) findViewById(R.id.round_corner_progress_header);
    iconPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iconPadding, metrics);
    iconPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_iconPadding, iconPadding);
    layoutHeader.setPadding(iconPadding, iconPadding, iconPadding, iconPadding);
    if (!isHeaderColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_headerColor, headerColor);
        setHeaderColor(color);
    }
    ViewTreeObserver observer = layoutHeader.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            layoutHeader.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                headerWidth = layoutHeader.getMeasuredWidth();
            } else {
                headerWidth = layoutHeader.getWidth();
            }
            if (backgroundWidth > 0)
                setProgress(progress);
        }
    });
    layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
    layoutBackground.setPadding(padding, padding, padding, padding);
    if (!isBackgroundColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
        setBackgroundColor(color);
    }
    observer = layoutBackground.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                backgroundWidth = layoutBackground.getMeasuredWidth();
            } else {
                backgroundWidth = layoutBackground.getWidth();
            }
            if (headerWidth > 0)
                setProgress(progress);
        }
    });
    layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
    if (!isProgressColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
        setProgressColor(color);
    }
    if (!isMaxProgressSetBeforeDraw) {
        max = typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
    }
    if (!isProgressSetBeforeDraw) {
        progress = typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
    }
    typedArray.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) DisplayMetrics(android.util.DisplayMetrics) ViewTreeObserver(android.view.ViewTreeObserver) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

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