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.vuze.android.remote.activity.LoginActivity.java

@SuppressWarnings("deprecation")
private void setBackgroundGradient() {

    ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout);
    assert mainLayout != null;
    int h = mainLayout.getHeight();
    int w = mainLayout.getWidth();
    View viewCenterOn = findViewById(R.id.login_frog_logo);
    assert viewCenterOn != null;

    RectShape shape = new RectShape();
    ShapeDrawable mDrawable = new ShapeDrawable(shape);
    int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1);
    int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2);

    RadialGradient shader;//from  www .  jav a2s  .  c  o m
    if (w > h) {
        int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2);
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        int remaining = w - left;
        shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f },
                Shader.TileMode.CLAMP);
    } else {
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP);
    }
    mDrawable.setBounds(0, 0, w, h);
    mDrawable.getPaint().setShader(shader);
    mDrawable.getPaint().setDither(true);
    mDrawable.getPaint().setAntiAlias(true);
    mDrawable.setDither(true);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mainLayout.setAnimationCacheEnabled(false);

    mainLayout.setBackgroundDrawable(mDrawable);
}

From source file:is.hello.go99.example.view.InfoTooltipView.java

/**
 * Shows the tooltip above a given view within a given parent view.
 *
 * @param parent    The parent view to attach the tooltip to.
 * @param aboveView The view to display the tooltip above.
 * @param onDismissListener A functor to call if the tooltip is dismissed without user intervention.
 *//*from w  ww.  j  ava2 s.c om*/
public void showAboveView(final @NonNull ViewGroup parent, final @NonNull View aboveView,
        final @NonNull OnDismissListener onDismissListener) {
    text.setVisibility(INVISIBLE);
    parent.addView(this, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    final Resources resources = getResources();
    final int overlap = resources.getDimensionPixelSize(R.dimen.view_info_tooltip_overlap);

    final LayoutParams layoutParams = (LayoutParams) text.getLayoutParams();
    layoutParams.bottomMargin = (parent.getHeight() - aboveView.getTop()) - overlap;
    layoutParams.leftMargin = aboveView.getLeft();
    text.requestLayout();
    post(new Runnable() {
        @Override
        public void run() {
            animateInText(onDismissListener);
        }
    });
}

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

/**
 * Anim the alert and the main view accordingly
 *
 * @param alertView         View Resources to animate
 * @param mainView          ViewGroup resources
 * @param configuration     describes all device configuration information
 * @param translationYAlert Move alert panel to be displayed
 * @param translationYMain  Move main windows screen
 * @param animIn            true animate panel to be displayed else animate panel to hide
 * @return Animated views/*from   w  ww  . ja v  a2  s  . c o m*/
 */
private static ViewPropertyAnimator animViews(View alertView, final ViewGroup mainView,
        final Configuration configuration, int translationYAlert, int translationYMain, final boolean animIn) {
    long duration = animIn ? DURATION_IN : DURATION_OUT;
    ViewPropertyAnimator viewPropertyAnimator = null;

    if (configuration.isWithAnim()) {
        viewPropertyAnimator = alertView.animate().translationY(translationYAlert).setDuration(duration);

        if (configuration.isShiftContent()) {
            final View viewToResize = mainView.getChildAt(0);

            // Resizing the view after the animation only alert is not on screen otherwise keep size
            viewToResize.animate().translationY(translationYMain).setDuration(duration)
                    .setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            resizeViewHeight(viewToResize, configuration.getHeight(), !animIn,
                                    mainView.getHeight());
                        }
                    });
        }
    } else {
        alertView.setTranslationY(translationYAlert);

        if (configuration.isShiftContent()) {
            final View viewToResize = mainView.getChildAt(0);
            viewToResize.setTranslationY(translationYMain);

            // Resizing the view
            resizeViewHeight(viewToResize, configuration.getHeight(), !animIn, mainView.getHeight());
        }
    }

    return viewPropertyAnimator;
}

From source file:net.naonedbus.card.impl.HoraireCard.java

private int getTextViewCount(final ViewGroup parent) {
    final TextView textView = (TextView) mLayoutInflater.inflate(R.layout.card_horaire_text, parent, false);
    final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00);
    final int padding = getContext().getResources().getDimensionPixelSize(R.dimen.padding_medium);
    textView.setText(FormatUtils.formatTimeAmPm(getContext(), mTimeFormat.format(noon.toDate())));

    final int specY = MeasureSpec.makeMeasureSpec(parent.getHeight(), MeasureSpec.UNSPECIFIED);
    final int specX = MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.UNSPECIFIED);
    textView.measure(specX, specY);/*from   ww  w  .  j  a  va 2s.c  o m*/

    return (parent.getWidth() - padding) / textView.getMeasuredWidth();
}

From source file:de.mrapp.android.bottomsheet.view.DraggableView.java

/**
 * Returns, whether a touch event at a specific position targets a view, which can be scrolled
 * up.//from  w w w .j a  v  a  2 s .  com
 *
 * @param x
 *         The horizontal position of the touch event in pixels as a {@link Float} value
 * @param y
 *         The vertical position of the touch event in pixels as a {@link Float} value
 * @param viewGroup
 *         The view group, which should be used to search for scrollable child views, as an
 *         instance of the class {@link ViewGroup}. The view group may not be null
 * @return True, if the touch event targets a view, which can be scrolled up, false otherwise
 */
private boolean isScrollUpEvent(final float x, final float y, @NonNull final ViewGroup viewGroup) {
    int location[] = new int[2];
    viewGroup.getLocationOnScreen(location);

    if (x >= location[0] && x <= location[0] + viewGroup.getWidth() && y >= location[1]
            && y <= location[1] + viewGroup.getHeight()) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View view = viewGroup.getChildAt(i);

            if (ViewCompat.canScrollVertically(view, -1)) {
                return true;
            } else if (view instanceof ViewGroup) {
                return isScrollUpEvent(x, y, (ViewGroup) view);
            }
        }
    }

    return false;
}

From source file:com.ll.myapplication.vitamio.widget.VideoView.java

/**
   * Set the display options//from  ww w .j a va  2 s . co m
   *
   * @param layout      <ul>
   *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
   *                    <li>{@link #VIDEO_LAYOUT_SCALE}
   *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
   *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
   *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
   *                    </ul>
   * @param aspectRatio video aspect ratio, will audo detect if 0.
   */
  public void setVideoLayout(int layout, float aspectRatio) {
      LayoutParams lp = getLayoutParams();
      Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
      int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
      float windowRatio = windowWidth / (float) windowHeight;
      float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
      mSurfaceHeight = mVideoHeight;
      mSurfaceWidth = mVideoWidth;
      if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
          lp.width = (int) (mSurfaceHeight * videoRatio);
          lp.height = mSurfaceHeight;
      } else if (layout == VIDEO_LAYOUT_ZOOM) {
          lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
          lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
      } else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
          ViewGroup parent = (ViewGroup) getParent();
          float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
          lp.width = (parentRatio < videoRatio) ? parent.getWidth()
                  : Math.round(((float) parent.getHeight()) * videoRatio);
          lp.height = (parentRatio > videoRatio) ? parent.getHeight()
                  : Math.round(((float) parent.getWidth()) / videoRatio);
      } else {
          boolean full = layout == VIDEO_LAYOUT_STRETCH;
          lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
          lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
      }
      setLayoutParams(lp);
      getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
      Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight,
              mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight,
              windowRatio);
      mVideoLayout = layout;
      mAspectRatio = aspectRatio;
  }

From source file:org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*// w  w w  .  ja va 2  s.c  o  m
       * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid,
            container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
       * Adjust the layout of the gridview to a square.
     *
     * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use
                * a hard coded value of 8 dip.
                *
                * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step
                * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value?
                */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid unnecessary updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:com.android.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  .ja v  a  2  s  .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) {
            mAlertView.announceForAccessibility(accessibilityText);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            }, ALERT_DISMISS_DELAY_MILLIS);
        }
    });

    return alertAnimator;
}

From source file:android.support.transition.SidePropagation.java

@Override
public long getStartDelay(ViewGroup sceneRoot, Transition transition, TransitionValues startValues,
        TransitionValues endValues) {//from  ww  w  .  j  a v a 2s  .c o  m
    if (startValues == null && endValues == null) {
        return 0;
    }
    int directionMultiplier = 1;
    Rect epicenter = transition.getEpicenter();
    TransitionValues positionValues;
    if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) {
        positionValues = startValues;
        directionMultiplier = -1;
    } else {
        positionValues = endValues;
    }

    int viewCenterX = getViewX(positionValues);
    int viewCenterY = getViewY(positionValues);

    int[] loc = new int[2];
    sceneRoot.getLocationOnScreen(loc);
    int left = loc[0] + Math.round(sceneRoot.getTranslationX());
    int top = loc[1] + Math.round(sceneRoot.getTranslationY());
    int right = left + sceneRoot.getWidth();
    int bottom = top + sceneRoot.getHeight();

    int epicenterX;
    int epicenterY;
    if (epicenter != null) {
        epicenterX = epicenter.centerX();
        epicenterY = epicenter.centerY();
    } else {
        epicenterX = (left + right) / 2;
        epicenterY = (top + bottom) / 2;
    }

    float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right,
            bottom);
    float maxDistance = getMaxDistance(sceneRoot);
    float distanceFraction = distance / maxDistance;

    long duration = transition.getDuration();
    if (duration < 0) {
        duration = 300;
    }

    return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction);
}

From source file:ti.org.dmfs.android.colorpicker.PaletteFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    /*//from  ww w.j ava 2 s  .c o  m
     * TODO: build the layout programmatically to get rid of the resources,
     * so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater
            .inflate(RHelper.getLayout("org_dmfs_colorpickerdialog_palette_grid"), container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
     * Adjust the layout of the gridview to a square.
     * 
     * Inspired by Bill Lahti, see
     * http://blahti.wordpress.com/2012/07/23/three
     * -variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                 * TODO: getHorizontalSpacing() has been introduced
                 * in SDK level 16. We need to find a way to get get
                 * the actual spacing. Until then we use a hard
                 * coded value of 8 dip.
                 * 
                 * One way would be to use a dimension in the
                 * layout. That would allow us to resolve the
                 * dimension here. However, that would be one step
                 * away from a library without resource
                 * dependencies. Maybe there is an Android dimension
                 * resource with a reasonable value?
                 */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the
                    // entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the
            // entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid
            // unnecessary
            // updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}