Java Code Examples for android.view.ViewGroup#getWidth()

The following examples show how to use android.view.ViewGroup#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StickerModel.java    From imsdk-android with MIT License 5 votes vote down vote up
public void addTextSticker(final Context cxt, final FragmentManager fragmentManager, String text, ViewGroup rootgroup) {

        if (textStickers.size() > 0 && !textStickers.get(textStickers.size() - 1).isChecked) {
            textStickers.get(textStickers.size() - 1).delete();
        }
        final TextSticker sticker = new TextSticker(cxt, text, rootgroup.getWidth() / 2, rootgroup.getHeight() / 2);
        sticker.setOnStickerClickListener(new OnStickerClickListener() {
            @Override
            public void onDelete() {
                textStickers.remove(sticker);
            }

            @Override
            public void onEditor() {
                EditFragment.show(fragmentManager, sticker);
            }

            @Override
            public void onTop() {
                textStickers.remove(sticker);
                textStickers.add(sticker);
            }

            @Override
            public void onUsing() {
                if (currTextSticker != null && currTextSticker != sticker) {
                    currTextSticker.setUsing(false);
                    currTextSticker = sticker;
                }
            }
        });
        if (currBitmapSticker != null) {
            currBitmapSticker.setUsing(false);
        }
        rootgroup.addView(sticker);
        currTextSticker = sticker;
        textStickers.add(sticker);
    }
 
Example 2
Source File: DontPressWithParentCheckBox.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    ViewParent vp = getParent();
    if (vp instanceof ViewGroup && getVisibility() == View.VISIBLE) {
        ViewGroup vg = (ViewGroup) vp;
        Rect bounds = new Rect(vg.getWidth() - w - 2 * mTouchAddition, 0, vg.getWidth(), h);
        TouchDelegate delegate = new TouchDelegate(bounds, this);
        vg.setTouchDelegate(delegate);

    }
}
 
Example 3
Source File: SlideInRightAnimator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup)target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0, 1),
            ObjectAnimator.ofFloat(target,"translationX",distance,0)
    );
}
 
Example 4
Source File: Slide.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public float getGoneX(ViewGroup sceneRoot, View view, float fraction) {
    final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    final float x;
    if (isRtl) {
        x = view.getTranslationX() - sceneRoot.getWidth() * fraction;
    } else {
        x = view.getTranslationX() + sceneRoot.getWidth() * fraction;
    }
    return x;
}
 
Example 5
Source File: VideoView.java    From react-native-android-vitamio with MIT License 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    </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;
}
 
Example 6
Source File: Slide.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public float getGoneX(ViewGroup sceneRoot, View view, float fraction) {
    final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    final float x;
    if (isRtl) {
        x = view.getTranslationX() + sceneRoot.getWidth() * fraction;
    } else {
        x = view.getTranslationX() - sceneRoot.getWidth() * fraction;
    }
    return x;
}
 
Example 7
Source File: VideoView.java    From video-player with MIT License 5 votes vote down vote up
/**
 * Set the display options
 *
 * @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;
 }
 
Example 8
Source File: BaseActivity.java    From GracefulMovies with Apache License 2.0 5 votes vote down vote up
/**
 * 带水波动画的Activity跳转
 */
@SuppressLint("NewApi")
protected void navigateWithRippleCompat(final Activity activity, final Intent intent,
                                        final View triggerView, @ColorRes int color) {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptionsCompat option = ActivityOptionsCompat.makeClipRevealAnimation(triggerView, 0, 0,
                triggerView.getMeasuredWidth(), triggerView.getMeasuredHeight());
        ActivityCompat.startActivity(activity, intent, option.toBundle());

        return;
    }

    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(activity);
    view.setImageResource(color);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);
    int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(500);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            activity.startActivity(intent);
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            decorView.postDelayed(() -> decorView.removeView(view), 500);
        }
    });
    anim.start();
}
 
Example 9
Source File: SlideInRightAnimator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup)target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0, 1),
            ObjectAnimator.ofFloat(target,"translationX",distance,0)
    );
}
 
Example 10
Source File: TouchView.java    From WeiXinRecordedDemo with MIT License 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    if(minWidth == 0){
        whRatio = getWidth()*1f/getHeight();
        minWidth = getWidth()/2;
        ViewGroup parent = (ViewGroup) getParent();
        maxWidth = parent.getWidth();
        minHeight = getHeight()/2;
        maxHeight = (int) (maxWidth / whRatio);
    }
}
 
Example 11
Source File: SlideOutRightAnimator.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup) target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 1, 0),
            ObjectAnimator.ofFloat(target, "translationX", 0, distance)
    );
}
 
Example 12
Source File: SlideInRightAnimator.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup) target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0, 1),
            ObjectAnimator.ofFloat(target, "translationX", distance, 0)
    );
}
 
Example 13
Source File: IncrementalMountUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Performs incremental mount on the children views of the given ViewGroup.
 *
 * @param scrollingViewParent ViewGroup container of views that will be incrementally mounted.
 */
public static void performIncrementalMount(ViewGroup scrollingViewParent) {
  assertMainThread();

  final int viewGroupWidth = scrollingViewParent.getWidth();
  final int viewGroupHeight = scrollingViewParent.getHeight();
  for (int i = 0; i < scrollingViewParent.getChildCount(); i++) {
    maybePerformIncrementalMountOnView(
        viewGroupWidth, viewGroupHeight, scrollingViewParent.getChildAt(i));
  }
}
 
Example 14
Source File: SlideOutRightAnimator.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup) target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 1, 0),
            ObjectAnimator.ofFloat(target, "translationX", 0, distance)
    );
}
 
Example 15
Source File: Slide.java    From scene with Apache License 2.0 5 votes vote down vote up
@Override
public float getGoneX(ViewGroup sceneRoot, View view, float fraction) {
    final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    final float x;
    if (isRtl) {
        x = view.getTranslationX() - sceneRoot.getWidth() * fraction;
    } else {
        x = view.getTranslationX() + sceneRoot.getWidth() * fraction;
    }
    return x;
}
 
Example 16
Source File: StickerModel.java    From imsdk-android with MIT License 5 votes vote down vote up
public void addBitmapSticker(Context cxt, String imagePath, int imageResourceId, ViewGroup rootgroup) {

        if (bitmapStickers.size() > 0 && !bitmapStickers.get(bitmapStickers.size() - 1).isChecked) {
            bitmapStickers.get(bitmapStickers.size() - 1).delete();
        }
        final BitmapSticker sticker = new BitmapSticker(cxt, imagePath, imageResourceId, rootgroup.getWidth() / 2, rootgroup.getHeight() / 2);
        sticker.setOnStickerClickListener(new OnStickerClickListener() {
            @Override
            public void onDelete() {
                bitmapStickers.remove(sticker);
            }

            @Override
            public void onEditor() {

            }

            @Override
            public void onTop() {
                bitmapStickers.remove(sticker);
                bitmapStickers.add(sticker);
            }

            @Override
            public void onUsing() {
                if (currBitmapSticker != null && currBitmapSticker != sticker) {
                    currBitmapSticker.setUsing(false);
                    currBitmapSticker = sticker;
                }
            }
        });
        if (currBitmapSticker != null) {
            currBitmapSticker.setUsing(false);
        }
        rootgroup.addView(sticker);
        currBitmapSticker = sticker;
        bitmapStickers.add(sticker);
    }
 
Example 17
Source File: Slide.java    From scene with Apache License 2.0 5 votes vote down vote up
@Override
public float getGoneX(ViewGroup sceneRoot, View view, float fraction) {
    final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    final float x;
    if (isRtl) {
        x = view.getTranslationX() + sceneRoot.getWidth() * fraction;
    } else {
        x = view.getTranslationX() - sceneRoot.getWidth() * fraction;
    }
    return x;
}
 
Example 18
Source File: SlideInLeftAnimator.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(View target) {
    ViewGroup parent = (ViewGroup) target.getParent();
    int distance = parent.getWidth() - target.getLeft();
    getAnimatorAgent().playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0, 1),
            ObjectAnimator.ofFloat(target, "translationX", -distance, 0)
    );
}
 
Example 19
Source File: PreviewDelegate.java    From PreviewSeekBar with Apache License 2.0 5 votes vote down vote up
/**
 * Get the x position for the preview view. This method takes into account padding
 * that'll make the frame not move until the scrub position exceeds
 * at least half of the frame's width.
 */
private int updatePreviewX(int progress, int max) {
    if (max == 0) {
        return 0;
    }

    final ViewGroup parent = (ViewGroup) previewView.getParent();
    final ViewGroup.MarginLayoutParams layoutParams
            = (ViewGroup.MarginLayoutParams) previewView.getLayoutParams();

    float offset = (float) progress / max;

    int minimumX = previewView.getLeft();
    int maximumX = parent.getWidth()
            - parent.getPaddingRight()
            - layoutParams.rightMargin;

    float previewPadding = previewBar.getThumbOffset();
    float previewLeftX = ((View) previewBar).getLeft();
    float previewRightX = ((View) previewBar).getRight();
    float previewSeekBarStartX = previewLeftX + previewPadding;
    float previewSeekBarEndX = previewRightX - previewPadding;

    float currentX = previewSeekBarStartX
            + (previewSeekBarEndX - previewSeekBarStartX) * offset;

    float startX = currentX - previewView.getWidth() / 2f;
    float endX = startX + previewView.getWidth();

    // Clamp the moves
    if (startX >= minimumX && endX <= maximumX) {
        return (int) startX;
    } else if (startX < minimumX) {
        return minimumX;
    } else {
        return maximumX - previewView.getWidth();
    }
}
 
Example 20
Source File: PageAdapter.java    From AndroidMuPDF with Apache License 2.0 4 votes vote down vote up
public View getView(final int position, View convertView, ViewGroup parent) {
	final PageView pageView;
	if (convertView == null) {
		if (mSharedHqBm == null || mSharedHqBm.getWidth() != parent.getWidth() || mSharedHqBm.getHeight() != parent.getHeight())
			mSharedHqBm = Bitmap.createBitmap(parent.getWidth(), parent.getHeight(), Bitmap.Config.ARGB_8888);

		pageView = new PageView(mContext, mCore, new Point(parent.getWidth(), parent.getHeight()), mSharedHqBm);
	} else {
		pageView = (PageView) convertView;
	}

	PointF pageSize = mPageSizes.get(position);
	if (pageSize != null) {
		// We already know the page size. Set it up
		// immediately
		pageView.setPage(position, pageSize);
	} else {
		// Page size as yet unknown. Blank it for now, and
		// start a background task to find the size
		pageView.blank(position);
		AsyncTask<Void,Void,PointF> sizingTask = new AsyncTask<Void,Void,PointF>() {
			@Override
			protected PointF doInBackground(Void... arg0) {
				return mCore.getPageSize(position);
			}

			@Override
			protected void onPostExecute(PointF result) {
				super.onPostExecute(result);
				// We now know the page size
				mPageSizes.put(position, result);
				// Check that this view hasn't been reused for
				// another page since we started
				if (pageView.getPage() == position)
					pageView.setPage(position, result);
			}
		};

		sizingTask.execute((Void)null);
	}
	return pageView;
}