Search in sources :

Example 31 with OnGlobalLayoutListener

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

the class RoundCornerProgressBar 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);
    layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
    padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
    layoutBackground.setPadding(padding, padding, padding, padding);
    if (!isBackgroundColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
        setBackgroundColor(color);
    }
    ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            int height = 0;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                backgroundWidth = layoutBackground.getMeasuredWidth();
                height = layoutBackground.getMeasuredHeight();
            } else {
                backgroundWidth = layoutBackground.getWidth();
                height = layoutBackground.getHeight();
            }
            backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
            LayoutParams params = (LayoutParams) layoutBackground.getLayoutParams();
            params.height = backgroundHeight;
            layoutBackground.setLayoutParams(params);
            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 = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
    }
    if (!isProgressSetBeforeDraw) {
        progress = (int) 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)

Example 32 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 33 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 34 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 35 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project FadingActionBar by ManuelPeinado.

the class FadingActionBarHelperBase method createView.

public final View createView(LayoutInflater inflater) {
    //
    // Prepare everything
    mInflater = inflater;
    if (mContentView == null) {
        mContentView = inflater.inflate(mContentLayoutResId, null);
    }
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(mHeaderLayoutResId, null, false);
    }
    //
    // See if we are in a ListView, WebView or ScrollView scenario
    ListView listView = (ListView) mContentView.findViewById(android.R.id.list);
    View root;
    if (listView != null) {
        root = createListView(listView);
    } else if (mContentView instanceof ObservableWebViewWithHeader) {
        root = createWebView();
    } else {
        root = createScrollView();
    }
    if (mHeaderOverlayView == null && mHeaderOverlayLayoutResId != 0) {
        mHeaderOverlayView = inflater.inflate(mHeaderOverlayLayoutResId, mMarginView, false);
    }
    if (mHeaderOverlayView != null) {
        mMarginView.addView(mHeaderOverlayView);
    }
    // Use measured height here as an estimate of the header height, later on after the layout is complete 
    // we'll use the actual height
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
    mHeaderView.measure(widthMeasureSpec, heightMeasureSpec);
    updateHeaderHeight(mHeaderView.getMeasuredHeight());
    root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            int headerHeight = mHeaderContainer.getHeight();
            if (!mFirstGlobalLayoutPerformed && headerHeight != 0) {
                updateHeaderHeight(headerHeight);
                mFirstGlobalLayoutPerformed = true;
            }
        }
    });
    return root;
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) AbsListView(android.widget.AbsListView) ObservableScrollView(com.manuelpeinado.fadingactionbar.view.ObservableScrollView) View(android.view.View) ListView(android.widget.ListView) ObservableWebViewWithHeader(com.manuelpeinado.fadingactionbar.view.ObservableWebViewWithHeader)

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