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

The following examples show how to use android.view.ViewGroup#getWidth() . These examples are extracted from open source projects. 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 Project: PreviewSeekBar   File: PreviewDelegate.java    License: 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 2
Source Project: KUtils   File: SlideInLeftAnimator.java    License: 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 3
Source Project: scene   File: Slide.java    License: 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 4
Source Project: imsdk-android   File: StickerModel.java    License: 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 5
Source Project: scene   File: Slide.java    License: 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 6
Source Project: KUtils   File: SlideOutRightAnimator.java    License: 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 7
Source Project: litho   File: IncrementalMountUtils.java    License: 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 8
Source Project: KUtils   File: SlideInRightAnimator.java    License: 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 9
@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 10
Source Project: imsdk-android   File: StickerModel.java    License: 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 11
Source Project: WeiXinRecordedDemo   File: TouchView.java    License: 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 12
@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 Project: GracefulMovies   File: BaseActivity.java    License: 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 14
Source Project: video-player   File: VideoView.java    License: 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 15
Source Project: android_9.0.0_r45   File: Slide.java    License: 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 Project: react-native-android-vitamio   File: VideoView.java    License: 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 17
Source Project: android_9.0.0_r45   File: Slide.java    License: 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
@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
@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 20
Source Project: AndroidMuPDF   File: PageAdapter.java    License: 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;
}