Search in sources :

Example 46 with ViewTreeObserver

use of android.view.ViewTreeObserver in project KJFrameForAndroid by kymjs.

the class KJDragGridView method onSwapItem.

/**
     * 交换item,并且控制item之间的显示与隐藏效果
     * 
     * @param moveX
     * @param moveY
     */
private void onSwapItem(int moveX, int moveY) {
    // 获取我们手指移动到的那个item的position
    final int tempPosition = pointToPosition(moveX, moveY);
    if (tempPosition != mDragPosition && tempPosition != AdapterView.INVALID_POSITION && mAnimationEnd) {
        mDragAdapter.reorderItems(mDragPosition, tempPosition);
        mDragAdapter.setHideItem(tempPosition);
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);
                animateReorder(mDragPosition, tempPosition);
                mDragPosition = tempPosition;
                return true;
            }
        });
    }
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver) OnPreDrawListener(android.view.ViewTreeObserver.OnPreDrawListener)

Example 47 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Crouton by keyboardsurfer.

the class Manager method addCroutonToView.

/**
   * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
   *
   * @param crouton
   *     The {@link Crouton} that should be added.
   */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }
    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup if it has been supplied
        if (null != crouton.getViewGroup()) {
            final ViewGroup croutonViewGroup = crouton.getViewGroup();
            if (shouldAddViewWithoutPosition(croutonViewGroup)) {
                croutonViewGroup.addView(croutonView, params);
            } else {
                croutonViewGroup.addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);
            handleActionBarOverlay((ViewGroup.MarginLayoutParams) params, activity);
            activity.addContentView(croutonView, params);
        }
    }
    // This is needed so the animation can use the measured with/height
    croutonView.requestLayout();
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
                if (crouton.getInAnimation() != null) {
                    croutonView.startAnimation(crouton.getInAnimation());
                    announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                    if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                        sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration());
                    }
                }
            }
        });
    }
}
Also used : ViewGroup(android.view.ViewGroup) Activity(android.app.Activity) View(android.view.View) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 48 with ViewTreeObserver

use of android.view.ViewTreeObserver in project superCleanMaster by joyoyao.

the class TextRoundCornerProgressBar method setup.

@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
    int color;
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
    autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_autoTextChange, false);
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
    radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_backgroundRadius, radius);
    textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
    textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressSize, textSize);
    textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_textProgressColor, textColor));
    text = typedArray.getString(R.styleable.RoundCornerProgress_textProgress);
    text = (text == null) ? "" : text;
    textViewValue.setText(text);
    textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressPadding, textPadding);
    textViewValue.setPadding(textPadding, 0, textPadding, 0);
    textUnit = typedArray.getString(R.styleable.RoundCornerProgress_textProgressUnit);
    textUnit = (textUnit == null) ? "" : textUnit;
    textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_textProgressWidth, textWidth);
    layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_backgroundPadding, padding);
    layoutBackground.setPadding(padding, padding, padding, padding);
    if (!isBackgroundColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_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() - textWidth;
                height = layoutBackground.getMeasuredHeight();
            } else {
                backgroundWidth = layoutBackground.getWidth() - textWidth;
                height = layoutBackground.getHeight();
            }
            backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
            params.width = backgroundWidth;
            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_progressColor, progressColor);
        setProgressColor(color);
    }
    if (!isMaxProgressSetBeforeDraw) {
        max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_max, 0);
    }
    if (!isProgressSetBeforeDraw) {
        progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_progress1, 0);
    }
    typedArray.recycle();
}
Also used : ViewGroup(android.view.ViewGroup) 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 49 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 50 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)

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)13 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 Activity (android.app.Activity)4 Paint (android.graphics.Paint)4