Example usage for android.view ViewGroup getWidth

List of usage examples for android.view ViewGroup getWidth

Introduction

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

Prototype

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

Source Link

Document

Return the width of your view.

Usage

From source file:Main.java

public static void startActivity(final Activity thisActivity, final Intent intent, final View triggerView,
        int colorOrImageRes, final long durationMills) {
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth();
    final int cy = location[1] + triggerView.getHeight() + (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, thisActivity.getResources().getDisplayMetrics());
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);/*from w  w  w . j a  v a 2 s. com*/
    final int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            thisActivity.startActivity(intent);
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    });
    anim.start();
}

From source file:Main.java

/**
 *
 * @param act/*from ww w.  ja v  a 2  s.  co m*/
 * @return
 */
public static RelativeLayout getContainerView(Activity act) {
    // create a new relative layout
    RelativeLayout rl = new RelativeLayout(act);

    // fint the root view of the activity
    ViewGroup fl = (ViewGroup) act.findViewById(android.R.id.content);
    fl = (ViewGroup) fl.getChildAt(0);
    Log.d("DEBUG", "w: " + fl.getWidth() + "h: " + fl.getHeight());

    // Params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
    //        new FrameLayout.LayoutParams(-1, -1);
    // add to the root view of the activity
    fl.addView(rl, params);

    return rl;
}

From source file:com.facebook.litho.utils.IncrementalMountUtils.java

/**
 * Performs incremental mount on the children views of the given ViewGroup.
 * @param scrollingViewParent ViewGroup container of views that will be incrementally mounted.
 * @param force whether the incremental mount should always take place, or only if
 * {@link ComponentsConfiguration.isIncrementalMountOnOffsetOrTranslationChangeEnabled} returns
 * false.//from   ww w  .j a  v a 2  s  . co  m
 */
public static void performIncrementalMount(ViewGroup scrollingViewParent, boolean force) {
    assertMainThread();

    if (!force && ComponentsConfiguration.isIncrementalMountOnOffsetOrTranslationChangeEnabled) {
        return;
    }

    final int viewGroupWidth = scrollingViewParent.getWidth();
    final int viewGroupHeight = scrollingViewParent.getHeight();
    for (int i = 0; i < scrollingViewParent.getChildCount(); i++) {
        maybePerformIncrementalMountOnView(viewGroupWidth, viewGroupHeight, scrollingViewParent.getChildAt(i));
    }
}

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

private int getMaxDistance(ViewGroup sceneRoot) {
    switch (mSide) {
    case Gravity.LEFT:
    case Gravity.RIGHT:
    case Gravity.START:
    case Gravity.END:
        return sceneRoot.getWidth();
    default:/*w w w.  j a  va  2s. c  om*/
        return sceneRoot.getHeight();
    }
}

From source file:com.tompee.funtablayout.BubbleTabAdapter.java

private LinearLayout.LayoutParams createLayoutParamsForTabs(ViewGroup parent) {
    LinearLayout.LayoutParams params;/* ww w  .  j av a  2s .c o m*/
    int width;
    if (getItemCount() > getTabVisibleCount()) {
        width = parent.getWidth() / getTabVisibleCount();
    } else {
        width = parent.getWidth() / getItemCount();
    }
    params = new LinearLayout.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT);
    return params;
}

From source file:com.tompee.funtablayout.SimpleTabAdapter.java

private RecyclerView.LayoutParams createLayoutParamsForTabs(ViewGroup parent) {
    RecyclerView.LayoutParams params;//from   w ww.  j a v a2  s  .com
    int width;
    if (getItemCount() > getTabVisibleCount()) {
        width = parent.getWidth() / getTabVisibleCount();
    } else {
        width = parent.getWidth() / getItemCount();
    }
    params = new RecyclerView.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT);
    return params;
}

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 ww  w . j av a  2 s  .  co 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:de.mrapp.android.bottomsheet.view.DraggableView.java

/**
 * Returns, whether a touch event at a specific position targets a view, which can be scrolled
 * up./*w w w .java2 s.  co m*/
 *
 * @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//ww  w  .j a  v a2  s .c  o 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:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
    final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance()
            .getCurrent().mShouldShowUiToAcceptTypedWord;
    final int stripWidth = addToDictionaryStrip.getWidth();
    final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2;

    final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save);
    wordView.setTextColor(mColorTypedWord);
    final int wordWidth = (int) (width * mCenterSuggestionWeight);
    final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint());
    final float wordScaleX = wordView.getTextScaleX();
    wordView.setText(wordToSave);/*from  www .j  av  a 2 s  . c  om*/
    wordView.setTextScaleX(wordScaleX);
    setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
    final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
    wordView.setVisibility(wordVisibility);
    addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);

    final Resources res = addToDictionaryStrip.getResources();
    final CharSequence hintText;
    final int hintWidth;
    final float hintWeight;
    final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary);
    if (shouldShowUiToAcceptTypedWord) {
        hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
        hintWidth = width;
        hintWeight = 1.0f;
        hintView.setGravity(Gravity.CENTER);
    } else {
        final boolean isRtlLanguage = (ViewCompat
                .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL);
        final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
        final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale);
        final CharSequence hint = res.getText(R.string.hint_add_to_dictionary);
        hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow);
        hintWidth = width - wordWidth;
        hintWeight = 1.0f - mCenterSuggestionWeight;
        hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    }
    hintView.setTextColor(mColorAutoCorrect);
    final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
    hintView.setText(hintText);
    hintView.setTextScaleX(hintScaleX);
    setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}