Java Code Examples for android.view.View.getWidth()

The following are Jave code examples for showing how to use getWidth() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Aurora   File: SwipeBackLayout.java   View Source Code Vote up 7 votes
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
    final int childWidth = releasedChild.getWidth();
    final int childHeight = releasedChild.getHeight();

    int left = 0, top = 0;
    if ((mTrackingEdge & EDGE_LEFT) != 0) {
        left = xvel > 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? childWidth
                + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE : 0;
    } else if ((mTrackingEdge & EDGE_RIGHT) != 0) {
        left = xvel < 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? -(childWidth
                + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE) : 0;
    } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) {
        top = yvel < 0 || yvel == 0 && mScrollPercent > mScrollThreshold ? -(childHeight
                + mShadowBottom.getIntrinsicHeight() + OVERSCROLL_DISTANCE) : 0;
    }

    mDragHelper.settleCapturedViewAt(left, top);
    invalidate();
}
 
Example 2
Project: superglue   File: DebugDrawerLayout.java   View Source Code Vote up 7 votes
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
  // Offset is how open the drawer is, therefore left/right values
  // are reversed from one another.
  final float offset = getDrawerViewOffset(releasedChild);
  final int childWidth = releasedChild.getWidth();

  int left;
  if (checkDrawerViewAbsoluteGravity(releasedChild, Gravity.LEFT)) {
    left = xvel > 0 || xvel == 0 && offset > 0.5f ? 0 : -childWidth;
  } else {
    final int width = getWidth();
    left = xvel < 0 || xvel == 0 && offset > 0.5f ? width - childWidth : width;
  }

  mDragger.settleCapturedViewAt(left, releasedChild.getTop());
  invalidate();
}
 
Example 3
Project: boohee_v5.6   File: TabLayout.java   View Source Code Vote up 7 votes
private void updateIndicatorPosition() {
    int right;
    int left;
    View selectedTitle = getChildAt(this.mSelectedPosition);
    if (selectedTitle == null || selectedTitle.getWidth() <= 0) {
        right = -1;
        left = -1;
    } else {
        left = selectedTitle.getLeft();
        right = selectedTitle.getRight();
        if (this.mSelectionOffset > 0.0f && this.mSelectedPosition < getChildCount() - 1) {
            View nextTitle = getChildAt(this.mSelectedPosition + 1);
            left = (int) ((this.mSelectionOffset * ((float) nextTitle.getLeft())) + ((1.0f - this.mSelectionOffset) * ((float) left)));
            right = (int) ((this.mSelectionOffset * ((float) nextTitle.getRight())) + ((1.0f - this.mSelectionOffset) * ((float) right)));
        }
    }
    setIndicatorPosition(left, right);
}
 
Example 4
Project: popomusic   File: MyItemDecoration.java   View Source Code Vote up 7 votes
public void drawHorizontal(Canvas c, RecyclerView parent) {

        final int childCount = parent.getChildCount();

        // 在每一个子控件的底部画线
        for (int i = 0; i < childCount; i++) {
            final View child = parent.getChildAt(i);

            final int left = child.getLeft() + child.getPaddingLeft();
            final int right = child.getWidth() + child.getLeft() - child.getPaddingRight();
            final int top = child.getBottom() - mDivider.getIntrinsicHeight() - child.getPaddingBottom();
            final int bottom = top + mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }
 
Example 5
Project: AOSP-Kayboard-7.1.2   File: EmojiPalettesView.java   View Source Code Vote up 7 votes
@Override
public boolean onTouch(final View v, final MotionEvent event) {
    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            onTouchDown(v);
            return true;
        case MotionEvent.ACTION_MOVE:
            final float x = event.getX();
            final float y = event.getY();
            if (x < 0.0f || v.getWidth() < x || y < 0.0f || v.getHeight() < y) {
                // Stop generating key events once the finger moves away from the view area.
                onTouchCanceled(v);
            }
            return true;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            onTouchUp(v);
            return true;
    }
    return false;
}
 
Example 6
Project: Android-Simple-MjpegViewer   File: MjpegViewThread.java   View Source Code Vote up 7 votes
public MjpegViewThread(SurfaceHolder surfaceHolder, View view){
    mSurfaceHolder = surfaceHolder;
    mRun = false;
    mCallback = null;
    dispWidth = view.getWidth();
    dispHeight = view.getHeight();
    prevdispWidth = dispWidth;
    prevdispHeight = dispHeight;
    destRect = new Rect(0,0,dispWidth,dispHeight);
    destSrc = null;
    displayMode = 1; // Default : SIZE_FIT_MODE
    prevdisplayMode = 1;

    bgColor = new Paint();
    bgColor.setStyle(Paint.Style.FILL);
    bgColor.setARGB(255, 0, 0, 0);
}
 
Example 7
Project: DailyStudy   File: ZoomOutPageTransformer.java   View Source Code Vote up 6 votes
@SuppressLint("NewApi")
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();

    Log.e("TAG", view + " , " + position + "");

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
    { // [-1,1]
        // Modify the default slide transition to shrink the page as well
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float vertMargin = pageHeight * (1 - scaleFactor) / 2;
        float horzMargin = pageWidth * (1 - scaleFactor) / 2;
        if (position < 0) {
            view.setTranslationX(horzMargin - vertMargin / 2);
        } else {
            view.setTranslationX(-horzMargin + vertMargin / 2);
        }

        // Scale the page down (between MIN_SCALE and 1)
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

        // Fade the page relative to its size.
        view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE)
                / (1 - MIN_SCALE) * (1 - MIN_ALPHA));

    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}
 
Example 8
Project: GitHub   File: TabPageIndicator.java   View Source Code Vote up 6 votes
private void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);
    }
    mTabSelector = new Runnable() {
        public void run() {
            final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;
            smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}
 
Example 9
Project: GeekZone   File: RotateUpTransformer.java   View Source Code Vote up 6 votes
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	view.setPivotX(width * 0.5f);
	view.setPivotY(0f);
	view.setTranslationX(0f);
	view.setRotation(rotation);
}
 
Example 10
Project: MNImageBrowser   File: RotateUpTransformer.java   View Source Code Vote up 6 votes
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	view.setPivotX(width * 0.5f);
	view.setPivotY(0f);
	view.setTranslationX(0f);
	view.setRotation(rotation);
}
 
Example 11
Project: Rey-MusicPlayer   File: ZoomOutPageTransformer.java   View Source Code Vote up 6 votes
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 1) { // [-1,1]
        // Modify the default slide transition to shrink the page as well
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float vertMargin = pageHeight * (1 - scaleFactor) / 2;
        float horzMargin = pageWidth * (1 - scaleFactor) / 2;
        if (position < 0) {
            view.setTranslationX(horzMargin - vertMargin / 2);
        } else {
            view.setTranslationX(-horzMargin + vertMargin / 2);
        }

        // Scale the page down (between MIN_SCALE and 1)
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

        // Fade the page relative to its size.
        view.setAlpha(MIN_ALPHA +
                (scaleFactor - MIN_SCALE) /
                (1 - MIN_SCALE) * (1 - MIN_ALPHA));

    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}
 
Example 12
Project: CodeCompilerApp   File: ViewUtils.java   View Source Code Vote up 6 votes
public static boolean isTouchPointInView(@NonNull View view, float x, float y) {
    final int[] coordinates = new int[3];
    view.getLocationInWindow(coordinates);
    int left = coordinates[0];
    int top = coordinates[1];
    return x >= left && x <= left + view.getWidth() &&
            y >= top && y <= top + view.getHeight();
}
 
Example 13
Project: FirebasePost   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public void onProfileClick(View v) {
    int[] startingLocation = new int[2];
    v.getLocationOnScreen(startingLocation);
    startingLocation[0] += v.getWidth() / 2;
    // ProfileActivity.startUserProfileFromLocation(startingLocation, this);
    overridePendingTransition(0, 0);
}
 
Example 14
Project: Huahui-Android   File: MorphTransition.java   View Source Code Vote up 6 votes
@Override
public void captureEndValues(TransitionValues transitionValues) {
    super.captureEndValues(transitionValues);
    final View view = transitionValues.view;
    if (view.getWidth() <= 0 || view.getHeight() <= 0) {
        return;
    }
    transitionValues.values.put(PROPERTY_COLOR, endColor);//ContextCompat.getColor(view.getContext(), R.color.dialog_background_color)
    transitionValues.values.put(PROPERTY_CORNER_RADIUS, endCornerRadius);
}
 
Example 15
Project: aos-MediaLib   File: Utils.java   View Source Code Vote up 6 votes
public static void setBackground(View v, Bitmap bm) {

        if (bm == null) {
            v.setBackgroundResource(0);
            return;
        }

        int vwidth = v.getWidth()/4;
        int vheight = v.getHeight()/4;
        int bwidth = bm.getWidth();
        int bheight = bm.getHeight();
        float scalex = (float) vwidth / bwidth;
        float scaley = (float) vheight / bheight;
        float scale = Math.max(scalex, scaley) * 1.3f;

        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
        Canvas c = new Canvas(bg);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        ColorMatrix greymatrix = new ColorMatrix();
        greymatrix.setSaturation(0);
        ColorMatrix darkmatrix = new ColorMatrix();
        darkmatrix.setScale(1f, 1f, 1f, .1f);
        greymatrix.postConcat(darkmatrix);
        ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
        paint.setColorFilter(filter);
        Matrix matrix = new Matrix();
        matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
        matrix.postRotate(10);
        matrix.postScale(scale, scale);
        matrix.postTranslate(vwidth/2, vheight/2);  // Move bitmap center to view center
        c.drawBitmap(bm, matrix, paint);
        v.setBackgroundDrawable(new BitmapDrawable(bg));
    }
 
Example 16
Project: AndroidBasicLibs   File: ViewUtils.java   View Source Code Vote up 6 votes
public static boolean isTouchInView(MotionEvent ev, View v) {
    int[] vLoc = new int[2];
    v.getLocationOnScreen(vLoc);
    float motionX = ev.getRawX();
    float motionY = ev.getRawY();
    return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth()) && motionY >= vLoc[1] && motionY <= (vLoc[1] + v.getHeight());
}
 
Example 17
Project: GitHub   File: RecyclerViewPager.java   View Source Code Vote up 6 votes
/***
 * adjust position before Touch event complete and fling action start.
 */
protected void adjustPositionX(int velocityX) {
    if (reverseLayout) velocityX *= -1;

    int childCount = getChildCount();
    if (childCount > 0) {
        int curPosition = ViewUtils.getCenterXChildPosition(this);
        int childWidth = getWidth() - getPaddingLeft() - getPaddingRight();
        int flingCount = getFlingCount(velocityX, childWidth);
        int targetPosition = curPosition + flingCount;
        if (mSinglePageFling) {
            flingCount = Math.max(-1, Math.min(1, flingCount));
            targetPosition = flingCount == 0 ? curPosition : mPositionOnTouchDown + flingCount;
        }
        targetPosition = Math.max(targetPosition, 0);
        targetPosition = Math.min(targetPosition, getItemCount() - 1);
        if (targetPosition == curPosition
                && (!mSinglePageFling || mPositionOnTouchDown == curPosition)) {
            View centerXChild = ViewUtils.getCenterXChild(this);
            if (centerXChild != null) {
                if (mTouchSpan > centerXChild.getWidth() * mTriggerOffset * mTriggerOffset && targetPosition != 0) {
                    if (!reverseLayout) targetPosition--;
                    else targetPosition++;
                } else if (mTouchSpan < centerXChild.getWidth() * -mTriggerOffset && targetPosition != getItemCount() - 1) {
                    if (!reverseLayout) targetPosition++;
                    else targetPosition--;
                }
            }
        }
        smoothScrollToPosition(safeTargetPosition(targetPosition, getItemCount()));
    }
}
 
Example 18
Project: FriendBook   File: ScreenUtils.java   View Source Code Vote up 6 votes
/**
 * 获取整个手机屏幕的大小(包括虚拟按钮)
 * 必须在onWindowFocus方法之后使用
 *
 * @param activity
 * @return
 */
public static int[] getScreenSize(AppCompatActivity activity) {
    int[] size = new int[2];
    View decorView = activity.getWindow().getDecorView();
    size[0] = decorView.getWidth();
    size[1] = decorView.getHeight();
    return size;
}
 
Example 19
Project: superglue   File: DebugDrawerLayout.java   View Source Code Vote up 6 votes
void moveDrawerToOffset(View drawerView, float slideOffset) {
  final float oldOffset = getDrawerViewOffset(drawerView);
  final int width = drawerView.getWidth();
  final int oldPos = (int) (width * oldOffset);
  final int newPos = (int) (width * slideOffset);
  final int dx = newPos - oldPos;

  drawerView.offsetLeftAndRight(
      checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
  setDrawerViewOffset(drawerView, slideOffset);
}
 
Example 20
Project: GitHub   File: RevealVisibilityTransition.java   View Source Code Vote up 5 votes
static double calculateMaxRadius(View view) {
    double widthSquared = view.getWidth() * view.getWidth();
    double heightSquared = view.getHeight() * view.getHeight();
    double radius = Math.sqrt(widthSquared + heightSquared) / 2;
    return radius;
}