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

The following are Jave code examples for showing how to use getHeight() 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: react-native-webgl-view-shot   File: RNWebGLTextureView.java   View Source Code Vote up 7 votes
private Bitmap captureView (View view) {
    int w = view.getWidth();
    int h = view.getHeight();
    if (w <= 0 || h <= 0) {
        throw new RuntimeException("Impossible to snapshot the view: view is invalid");
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Bitmap childBitmapBuffer;
    Canvas c = new Canvas(bitmap);
    view.draw(c);
    List<View> childrenList = getAllChildren(view);
    for (View child : childrenList) {
        if(child instanceof TextureView) {
            ((TextureView) child).setOpaque(false);
            childBitmapBuffer = ((TextureView) child).getBitmap(child.getWidth(), child.getHeight());
            c.drawBitmap(childBitmapBuffer, child.getLeft() + ((ViewGroup)child.getParent()).getLeft() +  child.getPaddingLeft(), child.getTop() + ((ViewGroup)child.getParent()).getTop() + child.getPaddingTop(), null);
        }
    }
    if (bitmap == null) {
        throw new RuntimeException("Impossible to snapshot the view");
    }
    return bitmap;
}
 
Example 2
Project: publicProject   File: BaseActivtiy.java   View Source Code Vote up 7 votes
/**
 * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时则不能隐藏
 *
 * @param v
 * @param event
 * @return
 */
private boolean isShouldHideKeyboard(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l = {0, 0};
        v.getLocationInWindow(l);
        int left = l[0],
                top = l[1],
                bottom = top + v.getHeight(),
                right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // 点击EditText的事件,忽略它。
            return false;
        } else {
            return true;
        }
    }
    // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditText上,和用户用轨迹球选择其他的焦点
    return false;
}
 
Example 3
Project: PlusGram   File: PasscodeView.java   View Source Code Vote up 7 votes
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    View rootView = getRootView();
    int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView);
    getWindowVisibleDisplayFrame(rect);
    keyboardHeight = usableViewHeight - (rect.bottom - rect.top);

    if (UserConfig.passcodeType == 1 && (AndroidUtilities.isTablet() || getContext().getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)) {
        int t = 0;
        if (passwordFrameLayout.getTag() != null) {
            t = (Integer) passwordFrameLayout.getTag();
        }
        LayoutParams layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
        layoutParams.topMargin = t + layoutParams.height - keyboardHeight / 2 - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
        passwordFrameLayout.setLayoutParams(layoutParams);
    }

    super.onLayout(changed, left, top, right, bottom);
}
 
Example 4
Project: publicProject   File: BaseTitleActivity.java   View Source Code Vote up 7 votes
/**
 * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时则不能隐藏
 *
 * @param v
 * @param event
 * @return
 */
private boolean isShouldHideKeyboard(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l = {0, 0};
        v.getLocationInWindow(l);
        int left = l[0],
                top = l[1],
                bottom = top + v.getHeight(),
                right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right
                && event.getY() > top && event.getY() < bottom) {
            // 点击EditText的事件,忽略它。
            return false;
        } else {
            return true;
        }
    }
    // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditText上,和用户用轨迹球选择其他的焦点
    return false;
}
 
Example 5
Project: JD-Test   File: BottomNavBarFabBehaviour.java   View Source Code Vote up 7 votes
private float[] getFabTranslationYForBottomNavigationBar(CoordinatorLayout parent,
                                                         FloatingActionButton fab) {
    float minOffset = 0;
    float viewHeight = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof BottomNavigationBar) {
            viewHeight = view.getHeight();
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - viewHeight);
        }
    }
    float[] returnValues = {minOffset, viewHeight};

    return returnValues;
}
 
Example 6
Project: ultrasonic   File: DragSortController.java   View Source Code Vote up 6 votes
public int viewIdHitPosition(MotionEvent ev, int id) {
    final int x = (int) ev.getX();
    final int y = (int) ev.getY();

    int touchPos = mDslv.pointToPosition(x, y); // includes headers/footers

    final int numHeaders = mDslv.getHeaderViewsCount();
    final int numFooters = mDslv.getFooterViewsCount();
    final int count = mDslv.getCount();

    // Log.d("mobeta", "touch down on position " + itemnum);
    // We're only interested if the touch was on an
    // item that's not a header or footer.
    if (touchPos != AdapterView.INVALID_POSITION && touchPos >= numHeaders
            && touchPos < (count - numFooters)) {
        final View item = mDslv.getChildAt(touchPos - mDslv.getFirstVisiblePosition());
        final int rawX = (int) ev.getRawX();
        final int rawY = (int) ev.getRawY();

        View dragBox = id == 0 ? item : (View) item.findViewById(id);
        if (dragBox != null) {
            dragBox.getLocationOnScreen(mTempLoc);

            if (rawX > mTempLoc[0] && rawY > mTempLoc[1] &&
                    rawX < mTempLoc[0] + dragBox.getWidth() &&
                    rawY < mTempLoc[1] + dragBox.getHeight()) {

                mItemX = item.getLeft();
                mItemY = item.getTop();

                return touchPos;
            }
        }
    }

    return MISS;
}
 
Example 7
Project: browser   File: SwipeListViewTouchListener.java   View Source Code Vote up 6 votes
/**
 * Unselected choice state in item
 */
protected int dismiss(int position) {
    int start = swipeListView.getFirstVisiblePosition();
    int end = swipeListView.getLastVisiblePosition();
    View view = swipeListView.getChildAt(position - start);
    ++dismissAnimationRefCount;
    if (position >= start && position <= end) {
        performDismiss(view, position, false);
        return view.getHeight();
    } else {
        pendingDismisses.add(new PendingDismissData(position, null));
        return 0;
    }
}
 
Example 8
Project: youkes_browser   File: SwipeListViewTouchListener.java   View Source Code Vote up 6 votes
/**
 * Unselected choice state in item
 */
protected int dismiss(int position) {
    int start = swipeListView.getFirstVisiblePosition();
    int end = swipeListView.getLastVisiblePosition();
    View view = swipeListView.getChildAt(position - start);
    ++dismissAnimationRefCount;
    if (position >= start && position <= end) {
        performDismiss(view, position, false);
        return view.getHeight();
    } else {
        pendingDismisses.add(new PendingDismissData(position, null));
        return 0;
    }
}
 
Example 9
Project: ExpectAnim   File: PositionAnimExpectationCenterBetweenViews.java   View Source Code Vote up 6 votes
@Override
public Float getCalculatedValueY(View viewToMove) {
    if (vertical) {
        final int centerYView1 = (int) (view1.getTop() + view1.getHeight() / 2f);
        final int centerYView2 = (int) (view2.getTop() + view2.getHeight() / 2f);

        return (centerYView1 + centerYView2) / 2f - viewToMove.getHeight() / 2f;
    }
    return null;
}
 
Example 10
Project: showroom-android   File: OuterItem.java   View Source Code Vote up 6 votes
private float computeRatio(RecyclerView recyclerView) {
    final View child0 = recyclerView.getChildAt(0);
    final int pos = recyclerView.getChildAdapterPosition(child0);
    if (pos != 0) {
        return 0;
    }

    final int height = child0.getHeight();
    final float y = Math.max(0, child0.getY());
    return y / height;
}
 
Example 11
Project: boohee_v5.6   File: AnimationBuilder.java   View Source Code Vote up 6 votes
public AnimationBuilder standUp() {
    for (View view : this.views) {
        float x = (float) ((((view.getWidth() - view.getPaddingLeft()) - view.getPaddingRight
                ()) / 2) + view.getPaddingLeft());
        float y = (float) (view.getHeight() - view.getPaddingBottom());
        pivotX(x, x, x, x, x);
        pivotY(y, y, y, y, y);
        rotationX(55.0f, -30.0f, 15.0f, -15.0f, 0.0f);
    }
    return this;
}
 
Example 12
Project: QMUI_Android   File: QMUIAnimationListView.java   View Source Code Vote up 6 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mOpenChangeDisappearAnimation && mChangeDisappearAnimator != null &&
            mChangeDisappearAnimator.isStarted() && mDetachViewsMap.size() > 0 && mIsAnimating) {
        for (int i = 0; i < mDetachViewsMap.size(); i++) {
            long id = mDetachViewsMap.keyAt(i);
            View view = mDetachViewsMap.valueAt(i);
            int newPos = getPositionForId(id);
            int top, offset = (int) (mChangeDisappearPlayTime / mOffsetDurationUnit);
            if (newPos < getFirstVisiblePosition()) {
                top = mTopMap.get(id) - offset;
                if (top < -view.getHeight()) {
                    continue;
                }
            } else {
                top = mTopMap.get(id) + offset;
                if (top > getHeight()) {
                    continue;
                }
            }
            view.layout(0, top, view.getWidth(), top + view.getHeight());
            view.setAlpha(1f - mChangeDisappearPlayTime * 1f / getChangeDisappearDuration());
            // 不能直接调用view.draw(canvas), 在listview上由于缓存会冲突
            drawChild(canvas, view, getDrawingTime());
        }
    }
}
 
Example 13
Project: RxEasyHttp   File: AppTools.java   View Source Code Vote up 6 votes
/**
 * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时没必要隐藏
 *
 * @param v
 * @param event
 * @return
 */
public static boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l = {0, 0};
        v.getLocationInWindow(l);
        int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left
                + v.getWidth();
        return !(event.getX() > left && event.getX() < right
                && event.getY() > top && event.getY() < bottom);
    }
    // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditView上,和用户用轨迹球选择其他的焦点  
    return false;
}
 
Example 14
Project: Hotspot-master-devp   File: BitmapCommonUtils.java   View Source Code Vote up 6 votes
/**
 * @param view				图形类控件
 * @param maxImageWidth		图片宽
 * @param maxImageHeight	图片高
 * @return	如果maxImageWidth和maxImageWidth大于0,此BitmapSize已配置,直接返回。
 * 			否则,根据所传控件设置BitmapSize,并返回该对象
 * 
 */
public static BitmapSize optimizeMaxSizeByView(View view, int maxImageWidth, int maxImageHeight) {
    int width = maxImageWidth;
    int height = maxImageHeight;

    if (width > 0 && height > 0) {
        return new BitmapSize(width, height);
    }

    final ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params != null) {
        if (params.width > 0) {
            width = params.width;
        } else if (params.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
            width = view.getWidth();
        }

        if (params.height > 0) {
            height = params.height;
        } else if (params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
            height = view.getHeight();
        }
    }

    if (width <= 0) width = getFieldValue(view, "mMaxWidth");
    if (height <= 0) height = getFieldValue(view, "mMaxHeight");

    BitmapSize screenSize = getScreenSize(view.getContext());
    if (width <= 0) width = screenSize.getWidth();
    if (height <= 0) height = screenSize.getHeight();

    return new BitmapSize(width, height);
}
 
Example 15
Project: PageScrollView   File: TestPageTransformer.java   View Source Code Vote up 6 votes
public void transformPage(View view, float position, boolean horizontal) {
    int pageSize = horizontal ? view.getWidth() : view.getHeight();
    if (position < -1) { // [-Infinity,-1)way off-screen to the left
        view.setAlpha(MIN_ALPHA);
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
    } else if (position <= 1) { // [-1,1]
        float percent = 1 - Math.abs(position);
        float scale = MIN_SCALE + (1 - MIN_SCALE) * percent;
        if (mAdjustTranslate) {
            float horizontalMargin = pageSize * (1 - scale) / 2;
            if (position > 0) {
                if (horizontal) {
                    view.setTranslationX(horizontalMargin);
                } else {
                    view.setTranslationY(horizontalMargin);
                }
            } else {
                if (horizontal) {
                    view.setTranslationX(-horizontalMargin);
                } else {
                    view.setTranslationY(-horizontalMargin);
                }
            }
        }
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(MIN_ALPHA + (1 - MIN_ALPHA) * percent);
    } else { // (1,+Infinity]page is way off-screen to the right.
        view.setAlpha(MIN_ALPHA);
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
    }
}
 
Example 16
Project: HandyGridView   File: HandyGridView.java   View Source Code Vote up 6 votes
private void getBasicValues(int firstVisibleItem) {
    View firstChild = getChildAt(0);
    mFirstLeft = getListPaddingLeft();
    mFirstTop = firstChild.getTop();
    mColumnWidth = firstChild.getWidth();
    mRowHeight = firstChild.getHeight();
    int rowLine = firstVisibleItem / mColumnsNum;
    mScrollY = mFirstTop - rowLine * (mVerticalSpacing + mRowHeight);
}
 
Example 17
Project: BoardView   File: BoardView.java   View Source Code Vote up 6 votes
private Bitmap getBitmapFromView(View v, float scale){
    double radians = 0.0523599f;
    double s = Math.abs(Math.sin(radians));
    double c = Math.abs(Math.cos(radians));
    int width = (int)(v.getHeight()*s + v.getWidth()*c);
    int height = (int)(v.getWidth()*s + v.getHeight()*c);
    Bitmap bitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.scale(scale,scale);
    v.draw(canvas);
    return bitmap;
}
 
Example 18
Project: ShadowImageView   File: ShadowImageView.java   View Source Code Vote up 5 votes
@Override
protected void dispatchDraw(Canvas canvas) {

    if (mInvalidat) {

        mInvalidat = false;

        View view = getChildAt(0);

        Paint shadowPaint = new Paint();

        shadowPaint.setColor(Color.WHITE);
        shadowPaint.setStyle(Paint.Style.FILL);
        shadowPaint.setAntiAlias(true);

        int radius = view.getHeight() / 12 > 40 ? 40 : view.getHeight() / 12;
        int shadowDimen = view.getHeight() / 16 > 28 ? 28 : view.getHeight() / 16;

        Bitmap bitmap;
        int rgb;

        if (((ImageView) view).getDrawable() instanceof ColorDrawable) {
            rgb = ((ColorDrawable) ((ImageView) view).getDrawable()).getColor();
            shadowPaint.setShadowLayer(40, 0, 28, getDarkerColor(rgb));
        } else if (((ImageView) view).getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) ((ImageView) view).getDrawable()).getBitmap();
            Palette.Swatch mSwatch = Palette.from(bitmap).generate().getDominantSwatch();

            if (null != mSwatch) {
                rgb = mSwatch.getRgb();
            } else {
                rgb = Color.parseColor("#8D8D8D");
            }

            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
            Bitmap bitmapT = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 4 * 3,
                    bitmap.getWidth(), bitmap.getHeight() / 4);

            if (null != Palette.from(bitmapT).generate().getDominantSwatch()) {
                rgb = Palette.from(bitmapT).generate().getDominantSwatch().getRgb();
                shadowPaint.setShadowLayer(radius, 0, shadowDimen, rgb);
            }
        } else {
            rgb = Color.parseColor("#8D8D8D");
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
        }

        if (this.shadowColor != -147483648) {
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, this.shadowColor);
        }

        RectF rectF = new RectF(view.getX() + (view.getWidth() / 20), view.getY(), view.getX() + view.getWidth() - (view.getWidth() / 20), view.getY() + view.getHeight() - ((view.getHeight() / 40)));

        canvas.drawRoundRect(rectF, shadowRound, shadowRound, shadowPaint);

        canvas.save();
    }
    super.dispatchDraw(canvas);
}
 
Example 19
Project: VideoCRE   File: MediaLayout.java   View Source Code Vote up 5 votes
@Override
public int clampViewPositionVertical(final View child, final int top, final int dy) {
    int topBound = getPaddingTop();
    int bottomBound = getHeight() - getPaddingBottom() - child.getHeight();
    return Math.min(Math.max(top, topBound), bottomBound);
}
 
Example 20
Project: MaterialFabSpeedDial   File: FabSpeedDial.java   View Source Code Vote up 5 votes
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FabSpeedDial child, View dependency) {
    float diff = dependency.getTranslationY() - dependency.getHeight();
    child.setTranslationY(diff);
    return false;
}