Example usage for android.view ViewTreeObserver addOnGlobalLayoutListener

List of usage examples for android.view ViewTreeObserver addOnGlobalLayoutListener

Introduction

In this page you can find the example usage for android.view ViewTreeObserver addOnGlobalLayoutListener.

Prototype

public void addOnGlobalLayoutListener(OnGlobalLayoutListener listener) 

Source Link

Document

Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes

Usage

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void setupQueryBar() {

    mSearchInput.setTextColor(mSearchInputTextColor);
    mSearchInput.setHintTextColor(mSearchInputHintColor);

    if (!isInEditMode() && mHostActivity != null) {
        mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }// w  w  w.  j  ava 2  s  . co  m

    ViewTreeObserver vto = mQuerySection.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Util.removeGlobalLayoutObserver(mQuerySection, this);

            inflateOverflowMenu(mMenuId);
        }
    });

    mMenuView.setMenuCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {

            if (mActionMenuItemListener != null) {
                mActionMenuItemListener.onActionMenuItemSelected(item);
            }

            //todo check if we should care about this return or not
            return false;
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {
        }

    });

    mMenuView.setOnVisibleWidthChanged(new MenuView.OnVisibleWidthChangedListener() {
        @Override
        public void onItemsMenuVisibleWidthChanged(int newVisibleWidth) {
            handleOnVisibleMenuItemsWidthChanged(newVisibleWidth);
        }
    });

    mMenuView.setActionIconColor(mActionMenuItemColor);
    mMenuView.setOverflowColor(mOverflowIconColor);

    mClearButton.setVisibility(View.INVISIBLE);
    mClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchInput.setText("");
            if (mOnClearSearchActionListener != null) {
                mOnClearSearchActionListener.onClearSearchClicked();
            }
        }
    });

    mSearchInput.addTextChangedListener(new TextWatcherAdapter() {

        public void onTextChanged(final CharSequence s, int start, int before, int count) {
            //todo investigate why this is called twice when pressing back on the keyboard

            if (mSkipTextChangeEvent || !mIsFocused) {
                mSkipTextChangeEvent = false;
            } else {
                if (mSearchInput.getText().toString().length() != 0
                        && mClearButton.getVisibility() == View.INVISIBLE) {
                    mClearButton.setAlpha(0.0f);
                    mClearButton.setVisibility(View.VISIBLE);
                    ViewCompat.animate(mClearButton).alpha(1.0f).setDuration(CLEAR_BTN_FADE_ANIM_DURATION)
                            .start();
                } else if (mSearchInput.getText().toString().length() == 0) {
                    mClearButton.setVisibility(View.INVISIBLE);
                }

                if (mQueryListener != null && mIsFocused
                        && !mOldQuery.equals(mSearchInput.getText().toString())) {
                    mQueryListener.onSearchTextChanged(mOldQuery, mSearchInput.getText().toString());
                }

            }

            mOldQuery = mSearchInput.getText().toString();
        }

    });

    mSearchInput.setOnFocusChangeListener(new TextView.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            if (mSkipQueryFocusChangeEvent) {
                mSkipQueryFocusChangeEvent = false;
            } else if (hasFocus != mIsFocused) {
                setSearchFocusedInternal(hasFocus);
            }
        }
    });

    mSearchInput.setOnKeyboardDismissedListener(new SearchInputView.OnKeyboardDismissedListener() {
        @Override
        public void onKeyboardDismissed() {
            if (mCloseSearchOnSofteKeyboardDismiss) {
                setSearchFocusedInternal(false);
            }
        }
    });

    mSearchInput.setOnSearchKeyListener(new SearchInputView.OnKeyboardSearchKeyClickListener() {
        @Override
        public void onSearchKeyClicked() {
            if (mSearchListener != null) {
                mSearchListener.onSearchAction(getQuery());
            }
            mSkipTextChangeEvent = true;
            mSkipTextChangeEvent = true;
            if (mIsTitleSet) {
                setSearchBarTitle(getQuery());
            } else {
                setSearchText(getQuery());
            }
            setSearchFocusedInternal(false);
        }
    });

    mLeftAction.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (isSearchBarFocused()) {
                setSearchFocusedInternal(false);
            } else {
                switch (mLeftActionMode) {
                case LEFT_ACTION_MODE_SHOW_HAMBURGER:
                    toggleLeftMenu();
                    break;
                case LEFT_ACTION_MODE_SHOW_SEARCH:
                    setSearchFocusedInternal(true);
                    break;
                case LEFT_ACTION_MODE_SHOW_HOME:
                    if (mOnHomeActionClickListener != null) {
                        mOnHomeActionClickListener.onHomeClicked();
                    }
                    break;
                case LEFT_ACTION_MODE_NO_LEFT_ACTION:
                    //do nothing
                    break;
                }
            }

        }
    });

    refreshLeftIcon();
}

From source file:com.androzic.MapActivity.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (!area.isEmpty())
                map.updateViewArea(area);
            if (vto.isAlive()) {
                vto.removeGlobalOnLayoutListener(this);
            } else {
                final ViewTreeObserver vto1 = map.getViewTreeObserver();
                vto1.removeGlobalOnLayoutListener(this);
            }/*from   w w w. java  2  s  .  co  m*/
        }
    });
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*  ww  w  .  j  av  a  2  s.c  om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View mainView = inflater.inflate(R.layout.main, container, false);

    if (mainView != null) {
        ViewTreeObserver vto = mainView.getViewTreeObserver();

        if (vto != null) {
            vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                @Override
                public void onGlobalLayout() {
                    MainFragment.removeOnGlobalLayoutListener(mainView, this);
                    int locationTbEndLocation[] = new int[2];
                    mTbEndLocation.getLocationInWindow(locationTbEndLocation);
                    int locationItinerarySelectionSpinner[] = new int[2];
                    mItinerarySelectionSpinner.getLocationInWindow(locationItinerarySelectionSpinner);
                    int locationBtnHandle[] = new int[2];
                    mBtnHandle.getLocationInWindow(locationBtnHandle);
                    DisplayMetrics metrics = MainFragment.this.getResources().getDisplayMetrics();
                    int windowHeight = metrics.heightPixels;
                    int paddingMargin = MainFragment.this.getResources()
                            .getInteger(R.integer.map_padding_margin);
                    if (mMap != null) {
                        mMap.setPadding(locationBtnHandle[0] + mBtnHandle.getWidth() / 2 + paddingMargin,
                                locationTbEndLocation[1] + mTbEndLocation.getHeight() / 2 + paddingMargin, 0,
                                windowHeight - locationItinerarySelectionSpinner[1] + paddingMargin);
                    }
                }
            });
        } else {
            Log.w(OTPApp.TAG, "Not possible to obtain exact element's positions on screen, some other"
                    + "elements can be misplaced");
        }

        mTbStartLocation = (EditText) mainView.findViewById(R.id.tbStartLocation);
        mTbEndLocation = (EditText) mainView.findViewById(R.id.tbEndLocation);

        mBtnPlanTrip = (ImageButton) mainView.findViewById(R.id.btnPlanTrip);
        mDdlOptimization = (ListView) mainView.findViewById(R.id.spinOptimization);
        mDdlTravelMode = (ListView) mainView.findViewById(R.id.spinTravelMode);

        mBikeTriangleParameters = new RangeSeekBar<Double>(OTPApp.BIKE_PARAMETERS_MIN_VALUE,
                OTPApp.BIKE_PARAMETERS_MAX_VALUE, this.getActivity().getApplicationContext(), R.color.sysRed,
                R.color.sysGreen, R.color.sysBlue, R.drawable.seek_thumb_normal, R.drawable.seek_thumb_pressed);

        // add RangeSeekBar to pre-defined layout
        mBikeTriangleParametersLayout = (ViewGroup) mainView.findViewById(R.id.bikeParametersLayout);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, R.id.bikeParametersTags);

        mBikeTriangleParametersLayout.addView(mBikeTriangleParameters, params);

        mBtnMyLocation = (ImageButton) mainView.findViewById(R.id.btnMyLocation);

        mBtnDateDialog = (ImageButton) mainView.findViewById(R.id.btnDateDialog);

        mBtnDisplayDirection = (ImageButton) mainView.findViewById(R.id.btnDisplayDirection);

        mNavigationDrawerLeftPane = (ViewGroup) mainView.findViewById(R.id.navigationDrawerLeftPane);
        mPanelDisplayDirection = mainView.findViewById(R.id.panelDisplayDirection);

        mBtnHandle = (ImageButton) mainView.findViewById(R.id.btnHandle);
        mDrawerLayout = (DrawerLayout) mainView.findViewById(R.id.drawerLayout);

        mTbStartLocation.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        mTbEndLocation.setImeOptions(EditorInfo.IME_ACTION_DONE);
        mTbEndLocation.requestFocus();

        mItinerarySelectionSpinner = (Spinner) mainView.findViewById(R.id.itinerarySelection);

        Log.v(OTPApp.TAG, "finish onStart()");

        if (Build.VERSION.SDK_INT > 11) {
            LayoutTransition l = new LayoutTransition();
            ViewGroup mainButtons = (ViewGroup) mainView.findViewById(R.id.content_frame);
            mainButtons.setLayoutTransition(l);
        }

        return mainView;
    } else {
        Log.e(OTPApp.TAG, "Not possible to obtain main view, UI won't be correctly created");
        return null;
    }
}

From source file:org.mozilla.gecko.BrowserApp.java

private void showTabs(final TabsPanel.Panel panel) {
    if (Tabs.getInstance().getDisplayCount() == 0)
        return;/*from   www .j a v  a2 s .  co m*/

    if (ensureTabsPanelExists()) {
        // If we've just inflated the tabs panel, only show it once the current
        // layout pass is done to avoid displayed temporary UI states during
        // relayout.
        ViewTreeObserver vto = mTabsPanel.getViewTreeObserver();
        if (vto.isAlive()) {
            vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    mTabsPanel.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    showTabs(panel);
                }
            });
        }
    } else {
        if (mDoorHangerPopup != null) {
            mDoorHangerPopup.disable();
        }
        mTabsPanel.show(panel);

        // Hide potentially visible "find in page" bar (Bug 1177338)
        mFindInPageBar.hide();
    }
}

From source file:com.android.soma.Launcher.java

private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
        final AppsCustomizePagedView.ContentType contentType) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);/*from  w  w  w  . j  a va  2  s  .c o  m*/
        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 (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
        // Set the content type for the all apps space
        mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
    }

    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 = LauncherAnimUtils.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() {
            @Override
            public void onAnimationStart(Animator animation) {
                // 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);

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(false);
                }
            }
        });

        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

        boolean delayAnim = false;

        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);

        // If any of the objects being animated haven't been measured/laid out
        // yet, delay the animation until we get a layout pass
        if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0)
                || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) {
            delayAnim = true;
        }

        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {
            public void run() {
                // Check that mStateAnimation hasn't changed while
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                setPivotsForZoom(toView, scale);
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);
                LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
            }
        };
        if (delayAnim) {
            final ViewTreeObserver observer = toView.getViewTreeObserver();
            observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                public void onGlobalLayout() {
                    startAnimRunnable.run();
                    toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
        } 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 && !LauncherAppState.getInstance().isScreenLarge()) {
            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionStart(fromView, animated, false);
        dispatchOnLauncherTransitionEnd(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        dispatchOnLauncherTransitionStart(toView, animated, false);
        dispatchOnLauncherTransitionEnd(toView, animated, false);
    }
}

From source file:vapor.view.VaporView.java

private final void __center(final boolean centerX, final boolean centerY) {
    View p = (View) parent();

    if (p == null) {
        Log.w("center()", "Cannot center View with no parent");
        return;/*  w ww. j av  a2  s .com*/
    }

    int pH = p.getHeight();
    int pW = p.getWidth();

    // if these are both 0 we suspect the layout has not completed yet
    if (pH == 0 && pW == 0) {
        // in this case we register a callback for when the layout has
        // completed

        final VaporView<T, self> self = this;
        ViewTreeObserver vto = self.treeObserver();

        // NOTE: DO NOT USE hook.VIEW_READY for this as it won't be called
        // if
        // client is using standard Android Activities
        vto.addOnGlobalLayoutListener(new $$layout() {

            @Override
            public void onGlobalLayout() {
                View p = (View) parent();
                if (centerY)
                    y((p.getHeight() / 2) - (height() / 2));
                if (centerX)
                    x((p.getWidth() / 2) - (width() / 2));

                self.treeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    } else {
        if (centerY)
            y((pH / 2) - (this.height() / 2));
        if (centerX)
            x((pW / 2) - (this.width() / 2));
    }

}

From source file:com.android.launcher2.Launcher.java

/**
 * 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.//from w ww.j  ava 2s.  c o  m
 */
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);
                    hideDockDivider();
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(false);
                }

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(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);

        // If any of the objects being animated haven't been measured/laid out
        // 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() {
                // Check that mStateAnimation hasn't changed while
                // 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() {
                        // Check that mStateAnimation hasn't changed while
                        // 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);
                    ViewTreeObserverCompat.removeOnGlobalLayoutListener(observer, 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);
            hideDockDivider();

            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        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);
    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

/**
 * 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.//from  www.j a va 2 s.  c  om
 */
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);
                    hideDockDivider();
                }
                if (!animationCancelled) {
                    updateWallpaperVisibility(false);
                }

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(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);

        // If any of the objects being animated haven't been measured/laid out
        // 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() {
                // Check that mStateAnimation hasn't changed while
                // 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() {
                        // Check that mStateAnimation hasn't changed while
                        // 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);
            hideDockDivider();

            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        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);
    }
}

From source file:com.example.libwidgettv.bak.AbsListView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    final ViewTreeObserver treeObserver = getViewTreeObserver();
    treeObserver.addOnTouchModeChangeListener(this);
    if (mTextFilterEnabled && mPopup != null && !mGlobalLayoutListenerAddedFilter) {
        treeObserver.addOnGlobalLayoutListener(this);
    }/*from  w w  w. j  av  a 2 s.co  m*/

    if (mAdapter != null && mDataSetObserver == null) {
        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        // Data may have changed while we were detached. Refresh.
        mDataChanged = true;
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
    }
    mIsAttached = true;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    final ViewTreeObserver treeObserver = getViewTreeObserver();
    treeObserver.addOnTouchModeChangeListener(this);
    if (mTextFilterEnabled && mPopup != null && !mGlobalLayoutListenerAddedFilter) {
        treeObserver.addOnGlobalLayoutListener(this);
    }//from  www .j  a  v  a  2  s.co  m

    if (mAdapter != null && mDataSetObserver == null) {
        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        // Data may have changed while we were detached. Refresh.
        mDataChanged = true;
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
    }
}