Search in sources :

Example 26 with ViewTreeObserver

use of android.view.ViewTreeObserver in project android-extendedactionbar by Takhion.

the class ExtendedActionBarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    final Resources res = getResources();
    final boolean isKitkat = Build.VERSION.SDK_INT >= 19;
    // replace window background to reduce overdraw
    final Window window = getWindow();
    final ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
    final View content = contentView.getChildAt(0);
    final Drawable extendedWindowBackground = window.getDecorView().getBackground();
    final Drawable windowBackground = !isKitkat ? extendedWindowBackground : getWindowBackgroundLayer(extendedWindowBackground, R.id.window_background, "window_background");
    window.setBackgroundDrawable(null);
    setBackground(content, windowBackground);
    // add statusbar background
    if (isKitkat) {
        // check if translucent bars are enabled
        final int config_enableTranslucentDecor_id = res.getIdentifier("config_enableTranslucentDecor", "bool", "android");
        if (config_enableTranslucentDecor_id > 0 && res.getBoolean(config_enableTranslucentDecor_id)) {
            // get ActionBar container
            final View actionBarContainer = findViewById("action_bar_container", "android");
            if (actionBarContainer != null) {
                // add layout listener (can't get margin before layout)
                //noinspection ConstantConditions
                actionBarContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                    @SuppressWarnings("ConstantConditions")
                    @Override
                    public void onGlobalLayout() {
                        // remove layout listener
                        final ViewTreeObserver vto = actionBarContainer.getViewTreeObserver();
                        if (Build.VERSION.SDK_INT < 16)
                            vto.removeGlobalOnLayoutListener(this);
                        else
                            vto.removeOnGlobalLayoutListener(this);
                        // create and add statusbar background view
                        final Drawable statusBarBackground = getWindowBackgroundLayer(extendedWindowBackground, R.id.statusbar_background, "statusbar_background");
                        final int statusBarHeight = ((ViewGroup.MarginLayoutParams) actionBarContainer.getLayoutParams()).topMargin;
                        final View statusBarView = new View(ExtendedActionBarActivity.this);
                        setBackground(statusBarView, statusBarBackground);
                        final FrameLayout.LayoutParams statusBarBackground_lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight, Gravity.TOP | Gravity.FILL_HORIZONTAL);
                        contentView.addView(statusBarView, 0, statusBarBackground_lp);
                        // shift content under actionbar
                        final ViewGroup.MarginLayoutParams content_lp = (ViewGroup.MarginLayoutParams) content.getLayoutParams();
                        content_lp.topMargin = getActionBar().getHeight() + statusBarHeight;
                        content.setLayoutParams(content_lp);
                    }
                });
            }
        }
    }
}
Also used : Window(android.view.Window) ViewGroup(android.view.ViewGroup) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) View(android.view.View) FrameLayout(android.widget.FrameLayout) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver)

Example 27 with ViewTreeObserver

use of android.view.ViewTreeObserver in project ElasticDownload by Tibolte.

the class ElasticDownloadView method onFinishInflate.

/**
     * MARK: Overrides
     */
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mIntroView = (IntroView) findViewById(R.id.intro_view);
    mIntroView.setListener(this);
    mProgressDownloadView = (ProgressDownloadView) findViewById(R.id.progress_download_view);
    ViewTreeObserver vto = mProgressDownloadView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                mProgressDownloadView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                mProgressDownloadView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            mIntroView.getLayoutParams().width = mProgressDownloadView.getWidth();
            mIntroView.getLayoutParams().height = mProgressDownloadView.getHeight();
            mProgressDownloadView.setBackgroundColor(mBackgroundColor);
        }
    });
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 28 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Fairphone by Kwamecorp.

the class LauncherTransitionable method showAppsCustomizeHelper.

/**
	 * Things to test when changing the following seven functions. - Home from
	 * workspace - from center screen - from other screens - Home from all apps
	 * - from center screen - from other screens - Back from all apps - from
	 * center screen - from other screens - Launch app from workspace and quit -
	 * with back - with home - Launch app from all apps and quit - with back -
	 * with home - Go to a screen that's not the default, then all apps, and
	 * launch and app, and go back - with back -with home - On workspace, long
	 * press power and go back - with back - with home - On all apps, long press
	 * power and go back - with back - with home - On workspace, power off - On
	 * all apps, power off - Launch an app and turn off the screen while in that
	 * app - Go back with home key - Go back with back key TODO: make this not
	 * go to workspace - From all apps - From workspace - Enter and exit car
	 * mode (becuase it causes an extra configuration changed) - From all apps -
	 * From the center workspace - From another workspace
	 */
/**
	 * Zoom the camera out from the workspace to reveal 'toView'. Assumes that
	 * the view to show is anchored at either the very top or very bottom of the
	 * screen.
	 */
private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
    if (mStateAnimation != null) {
        mStateAnimation.cancel();
        mStateAnimation = null;
    }
    final Resources res = getResources();
    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
    final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
    setPivotsForZoom(toView, scale);
    // Shrink workspaces away if going to AppsCustomize from workspace
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
    if (animated) {
        toView.setScaleX(scale);
        toView.setScaleY(scale);
        final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
        scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration).setInterpolator(new Workspace.ZoomOutInterpolator());
        toView.setVisibility(View.VISIBLE);
        toView.setAlpha(0f);
        final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(toView, "alpha", 0f, 1f).setDuration(fadeDuration);
        alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
        alphaAnim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (animation == null) {
                    throw new RuntimeException("animation is null");
                }
                float t = (Float) animation.getAnimatedValue();
                dispatchOnLauncherTransitionStep(fromView, t);
                dispatchOnLauncherTransitionStep(toView, t);
            }
        });
        // toView should appear right at the end of the workspace shrink
        // animation
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        mStateAnimation.play(scaleAnim).after(startDelay);
        mStateAnimation.play(alphaAnim).after(startDelay);
        mStateAnimation.addListener(new AnimatorListenerAdapter() {

            boolean animationCancelled = false;

            @Override
            public void onAnimationStart(Animator animation) {
                updateWallpaperVisibility(true);
                // Prepare the position
                toView.setTranslationX(0.0f);
                toView.setTranslationY(0.0f);
                toView.setVisibility(View.VISIBLE);
                toView.bringToFront();
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);
                if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
                    // Hide the workspace scrollbar
                    mWorkspace.hideScrollingIndicator(true);
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(false);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                animationCancelled = true;
            }
        });
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }
        boolean delayAnim = false;
        final ViewTreeObserver observer;
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        // yet, delay the animation until we get a layout pass
        if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) {
            observer = mWorkspace.getViewTreeObserver();
            delayAnim = true;
        } else {
            observer = null;
        }
        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {

            public void run() {
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                setPivotsForZoom(toView, scale);
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);
                toView.post(new Runnable() {

                    public void run() {
                        // we waited for a layout/draw pass
                        if (mStateAnimation != stateAnimation)
                            return;
                        mStateAnimation.start();
                    }
                });
            }
        };
        if (delayAnim) {
            final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {

                public void onGlobalLayout() {
                    toView.post(startAnimRunnable);
                    observer.removeOnGlobalLayoutListener(this);
                }
            };
            observer.addOnGlobalLayoutListener(delayedStart);
        } else {
            startAnimRunnable.run();
        }
    } else {
        toView.setTranslationX(0.0f);
        toView.setTranslationY(0.0f);
        toView.setScaleX(1.0f);
        toView.setScaleY(1.0f);
        toView.setVisibility(View.VISIBLE);
        toView.bringToFront();
        if (!springLoaded && !LauncherApplication.isScreenLarge()) {
            // Hide the workspace scrollbar
            mWorkspace.hideScrollingIndicator(true);
        }
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionStart(fromView, animated, false);
        dispatchOnLauncherTransitionEnd(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        dispatchOnLauncherTransitionStart(toView, animated, false);
        dispatchOnLauncherTransitionEnd(toView, animated, false);
        updateWallpaperVisibility(false);
    }
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) AnimatorSet(android.animation.AnimatorSet) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Resources(android.content.res.Resources) ViewTreeObserver(android.view.ViewTreeObserver)

Example 29 with ViewTreeObserver

use of android.view.ViewTreeObserver in project ImageryHeader by YukiMatsumura.

the class ImageryHeaderFragment method setupCustomScrolling.

private void setupCustomScrolling(View rootView) {
    scrollView = (ObservableScrollView) rootView.findViewById(R.id.scroll_view);
    scrollView.addCallbacks(this);
    ViewTreeObserver vto = scrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(globalLayoutListener);
    }
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 30 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Klyph by jonathangerbaud.

the class AbsHListView method onDetachedFromWindow.

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    // Dismiss the popup in case onSaveInstanceState() was not invoked
    // Detach any view left in the scrap heap
    mRecycler.clear();
    final ViewTreeObserver treeObserver = getViewTreeObserver();
    treeObserver.removeOnTouchModeChangeListener(this);
    if (mAdapter != null && mDataSetObserver != null) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
        mDataSetObserver = null;
    }
    if (mFlingRunnable != null) {
        removeCallbacks(mFlingRunnable);
    }
    if (mPositionScroller != null) {
        mPositionScroller.stop();
    }
    if (mClearScrollingCache != null) {
        removeCallbacks(mClearScrollingCache);
    }
    if (mPerformClick != null) {
        removeCallbacks(mPerformClick);
    }
    if (mTouchModeReset != null) {
        removeCallbacks(mTouchModeReset);
        mTouchModeReset = null;
    }
    mIsAttached = false;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)222 View (android.view.View)56 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)15 ViewGroup (android.view.ViewGroup)14 SuppressLint (android.annotation.SuppressLint)12 AdapterView (android.widget.AdapterView)12 TypedArray (android.content.res.TypedArray)7 Test (org.junit.Test)7 RectF (android.graphics.RectF)6 DisplayMetrics (android.util.DisplayMetrics)6 ViewParent (android.view.ViewParent)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 Resources (android.content.res.Resources)5 ValueAnimator (android.animation.ValueAnimator)4 TargetApi (android.annotation.TargetApi)4 Paint (android.graphics.Paint)4 Point (android.graphics.Point)4