Example usage for android.view ViewGroup getHeight

List of usage examples for android.view ViewGroup getHeight

Introduction

In this page you can find the example usage for android.view ViewGroup getHeight.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java

private Animator getAlertAnimator(final View source, final int titleResId, final String infoText,
        final String accessibilityText, final int revealColor, final int backgroundColor) {
    final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//from   www .  jav a2s  . c  o  m
    containerView.addView(revealView);

    // TODO: Fade out source icon over the reveal (like LOLLIPOP version).

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS);
    revealAnimator.setInterpolator(REVEAL_INTERPOLATOR);
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            mAlertView.setVisibility(View.VISIBLE);
            mAlertTitleView.setText(titleResId);

            if (infoText != null) {
                mAlertInfoView.setText(infoText);
                mAlertInfoView.setVisibility(View.VISIBLE);
            }
            mContentView.setVisibility(View.GONE);

            getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor));
        }
    });

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet alertAnimator = new AnimatorSet();
    alertAnimator.play(revealAnimator).before(fadeAnimator);
    alertAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (Build.VERSION.SDK_INT >= 16) {
                mAlertView.announceForAccessibility(accessibilityText);
            }

            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.java

public void show() {
    verifyDismissed();/*  ww w .j a v a2 s .  co m*/
    final ViewGroup rootView = (ViewGroup) mAnchorView.getRootView();

    createOverlay(rootView);

    mContentLayout.getViewTreeObserver().addOnGlobalLayoutListener(mLocationLayoutListener);

    rootView.post(new Runnable() {
        @Override
        public void run() {
            mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, rootView.getWidth(),
                    rootView.getHeight());
        }
    });
}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private Animator getRevealAnimator(View source, int revealColor) {
    final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from  w ww  . java2 s.co m*/
    containerView.addView(revealView);

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f));

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
    animatorSet.playSequentially(revealAnimator, fadeAnimator);

    return revealAnimator;
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

private void updateFocalCentrePosition() {
    updateClipBounds();// w  w  w. j  a v  a2s  .c  o  m
    if (mTargetView != null) {
        final int[] viewPosition = new int[2];
        mView.getLocationInWindow(viewPosition);
        final int[] targetPosition = new int[2];
        mTargetView.getLocationInWindow(targetPosition);

        mView.mCentreLeft = mBaseLeft + targetPosition[0] - viewPosition[0] + (mTargetView.getWidth() / 2);
        mView.mCentreTop = mBaseTop + targetPosition[1] - viewPosition[1] + (mTargetView.getHeight() / 2);
    } else {
        mView.mCentreLeft = mBaseLeft;
        mView.mCentreTop = mBaseTop;
    }

    final ViewGroup parent = getParentView();
    mTextPositionAbove = mView.mCentreTop > parent.getHeight() / 2;
    mTextPositionRight = mView.mCentreLeft > parent.getWidth() / 2;

    updateTextPositioning();
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert/*from www  .  j  ava2 s. com*/
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

void updateFocalCentrePosition() {
    updateClipBounds();// ww  w.  j  a va  2s .  c  om
    if (mTargetView != null) {
        final int[] viewPosition = new int[2];
        mView.getLocationInWindow(viewPosition);
        final int[] targetPosition = new int[2];
        mTargetView.getLocationInWindow(targetPosition);

        mView.mCentreLeft = mBaseLeft + targetPosition[0] - viewPosition[0] + (mTargetView.getWidth() / 2);
        mView.mCentreTop = mBaseTop + targetPosition[1] - viewPosition[1] + (mTargetView.getHeight() / 2);
    } else {
        mView.mCentreLeft = mBaseLeft;
        mView.mCentreTop = mBaseTop;
    }

    final ViewGroup parent = getParentView();
    mTextPositionAbove = mView.mCentreTop > parent.getHeight() / 2;
    mTextPositionRight = mView.mCentreLeft > parent.getWidth() / 2;

    updateTextPositioning();
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@SuppressWarnings("NewApi")
private android.animation.Animator animateRevealColorFromCoordinates(ViewGroup viewRoot, @ColorRes int color,
        int x, int y) {
    float finalRadius = (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight());

    android.animation.Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, x, y, 0, finalRadius);
    viewRoot.setBackgroundColor(ContextCompat.getColor(this, color));
    anim.setDuration(getResources().getInteger(R.integer.anim_duration_long));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.start();/*from  w ww . ja v  a 2  s. com*/
    return anim;
}

From source file:Main.java

private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer,
        final int targtetHeight) {

    setHeight(view, 0);// w ww  . j av a 2 s  . com
    view.setVisibility(View.VISIBLE);
    final Animation animation = new Animation() {

        private final Rect rect = new Rect();
        private final Rect parentVisibleRect = new Rect();

        ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;

        private final Runnable checkViewRunnable = new Runnable() {
            @Override
            public void run() {
                checkForViewInsideVisibleArea();
            }
        };

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            setHeight(view, neededHeight);

            final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();

            if (globalLayoutListener == null) {
                globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {

                        if (globalLayoutListener == null) {
                            removeGlobalLayoutListener(viewTreeObserver, this);
                        }

                        checkForViewInsideVisibleArea();
                    }
                };

                viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener);
            }

            if (globalLayoutListener != null && interpolatedTime == 1) {
                runInUIThread(checkViewRunnable);
                globalLayoutListener = null;
            }

            view.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }

        private void checkForViewInsideVisibleArea() {

            if (rootContainer.indexOfChild(parentView) == -1) {
                return;
            }

            parentVisibleRect.left = 0;
            parentVisibleRect.top = 0;
            parentVisibleRect.right = parentView.getWidth();
            parentVisibleRect.bottom = parentView.getHeight();

            rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect);

            if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) {

                rect.left = parentView.getLeft();
                rect.top = parentView.getTop();
                rect.right = parentView.getRight();
                rect.bottom = parentView.getBottom();

                parentView.requestRectangleOnScreen(rect, true);
            }
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    view.startAnimation(animation);
}

From source file:com.dk.view.FolderDrawerLayout.java

private boolean createCache() {
    ViewGroup left = (ViewGroup) findDrawerWithGravity(Gravity.LEFT);

    if (left.getChildCount() > 0 && !(left.getChildAt(0) instanceof MeshImageView)) {
        mDrawingCache = drawViewToBitmap(mDrawingCache, left, left.getWidth(), left.getHeight(), 1,
                new BitmapDrawable());

        if (mCoreCalc == null)
            mCoreCalc = new CoreCalc(left.getWidth(), left.getHeight());
        return true;
    } else {//from w w  w  .  j  ava 2s  .  c o m
        return false;
    }

}

From source file:com.android.incallui.CallCardFragment.java

@Override
public void animateForNewOutgoingCall() {
    final ViewGroup parent = (ViewGroup) mPrimaryCallCardContainer.getParent();

    final ViewTreeObserver observer = getView().getViewTreeObserver();

    mIsAnimating = true;//  ww w .  j a v a 2 s.c  om

    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ViewTreeObserver observer = getView().getViewTreeObserver();
            if (!observer.isAlive()) {
                return;
            }
            observer.removeOnGlobalLayoutListener(this);

            final LayoutIgnoringListener listener = new LayoutIgnoringListener();
            mPrimaryCallCardContainer.addOnLayoutChangeListener(listener);

            // Prepare the state of views before the slide animation
            final int originalHeight = mPrimaryCallCardContainer.getHeight();
            mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, originalHeight);
            mPrimaryCallCardContainer.setBottom(parent.getHeight());

            // Set up FAB.
            mFloatingActionButtonContainer.setVisibility(View.GONE);
            mFloatingActionButtonController.setScreenWidth(parent.getWidth());

            mCallButtonsContainer.setAlpha(0);
            mCallStateLabel.setAlpha(0);
            mPrimaryName.setAlpha(0);
            mCallTypeLabel.setAlpha(0);
            mCallNumberAndLabel.setAlpha(0);

            assignTranslateAnimation(mCallStateLabel, 1);
            assignTranslateAnimation(mCallStateIcon, 1);
            assignTranslateAnimation(mPrimaryName, 2);
            assignTranslateAnimation(mCallNumberAndLabel, 3);
            assignTranslateAnimation(mCallTypeLabel, 4);
            assignTranslateAnimation(mCallButtonsContainer, 5);

            final Animator animator = getShrinkAnimator(parent.getHeight(), originalHeight);

            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mPrimaryCallCardContainer.setTag(R.id.view_tag_callcard_actual_height, null);
                    setViewStatePostAnimation(listener);
                    mIsAnimating = false;
                    InCallPresenter.getInstance().onShrinkAnimationComplete();
                }
            });
            animator.start();
        }
    });
}