Example usage for android.view View getHeight

List of usage examples for android.view View getHeight

Introduction

In this page you can find the example usage for android.view View getHeight.

Prototype

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

Source Link

Document

Return the height of your view.

Usage

From source file:com.aidy.launcher3.support.views.bottomdrawer.BottomDrawerLayout.java

/**
 * Open the specified drawer view by animating it into view.
 * /*from   ww  w .  ja  v  a2s . c o  m*/
 * @param drawerView
 *            Drawer view to open
 */
public void openDrawer(View drawerView) {
    Log.i(TAG, "openDrawer() --view");
    if (!isDrawerView(drawerView)) {
        throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer");
    }
    Log.i(TAG, "openDrawer() -- mFirstLayout = " + mFirstLayout);
    if (mFirstLayout) {
        final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams();
        lp.onScreen = 1.f;
        lp.knownOpen = true;
    } else {
        if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.BOTTOM)) {
            mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(),
                    getHeight() - drawerView.getHeight());
        }
    }
    invalidate();
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animations);

    mGridView = (MyGridView) findViewById(R.id.gv_photo_grid);
    PhotoGridAdapter mAdapter = new PhotoGridAdapter(this);
    pictures = mBitmapUtils.loadPhotos(getResources());
    mAdapter.updateData(pictures);//from w  w w . j a  v a2s.  co  m
    mGridView.setAdapter(mAdapter);

    // the image for pop up animation effect
    mImage = (ClippingImageView) findViewById(R.id.iv_animation);
    mImage.setVisibility(View.GONE);

    // set the background color in the fullscreen
    mTopLevelLayout = (RelativeLayout) findViewById(R.id.rl_fullscreen_bg);
    mBackground = new ColorDrawable(Color.BLACK);
    mBackground.setAlpha(0);
    mTopLevelLayout.setBackground(mBackground);

    mPager = (ClickableViewPager) findViewById(R.id.pager);
    mPager.setVisibility(View.GONE);

    // enable/disable touch event
    mGridView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (mIsInFullscreen) {
                // returning true means that this event has been consumed
                // in fullscreen the grid view is not responding any finger interaction
                return true;
            }
            return false;
        }
    });

    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            mIsInFullscreen = true;
            // set the animating image to the clicked item
            Drawable drawable = ((ImageView) view).getDrawable();
            mImage.setImageDrawable(drawable);
            mImage.setVisibility(View.VISIBLE);

            // reset image translation
            mImage.setTranslationX(0);
            mImage.setTranslationY(0);

            // reset pager's adapter every time a view in Grid view is clicked
            mPager.setAdapter(new PhotoViewAdapter(MainActivity.this, pictures));
            mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    // the GirdView should follow the Pager
                    mGridView.smoothScrollToPosition(mPager.getCurrentItem());
                }
            });
            mPager.setCurrentItem(position, false);

            final float drawableWidth = drawable.getIntrinsicWidth();
            final float drawableHeight = drawable.getIntrinsicHeight();
            // calculate the clicked view's location and width/height
            final float heightWidthRatio = drawableHeight / drawableWidth;
            final int thumbnailWidth = view.getWidth();
            final int thumbnailHeight = view.getHeight();

            int[] viewLocation = new int[2];
            int[] gridViewLocation = new int[2];
            view.getLocationOnScreen(viewLocation);
            mGridView.getLocationOnScreen(gridViewLocation);
            final int thumbnailX = viewLocation[0] + thumbnailWidth / 2;
            final int thumbnailY = viewLocation[1] + thumbnailHeight / 2;
            final int fullscreenX = gridViewLocation[0] + mGridView.getWidth() / 2;
            final int fullscreenY = gridViewLocation[1] + mGridView.getHeight() / 2;

            Log.d(TAG, "viewLocation=" + viewLocation[0] + ", " + viewLocation[1] + "\ngridViewLocation="
                    + gridViewLocation[0] + ", " + gridViewLocation[1]);
            Log.d(TAG, "thumbnailX=" + thumbnailX + ", thumbnailY=" + thumbnailY + "\nfullscreenX="
                    + fullscreenX + ", fullscreenY=" + fullscreenY);

            // for image transform, we need 3 arguments to transform properly:
            // deltaX and deltaY - the translation of the image
            // scale value - the resize value
            // clip ratio - the reveal part of the image

            // figure out where the thumbnail and full size versions are, relative
            // to the screen and each other
            mXDelta = thumbnailX - fullscreenX;
            mYDelta = thumbnailY - fullscreenY;

            // Scale factors to make the large version the same size as the thumbnail
            if (heightWidthRatio < 1) {
                mImageScale = (float) thumbnailHeight / mImage.getLayoutParams().height;
            } else {
                mImageScale = (float) thumbnailWidth / mImage.getLayoutParams().width;
            }

            // clip ratio
            if (heightWidthRatio < 1) {
                // if the original picture is in landscape
                clipRatio = 1 - heightWidthRatio;
            } else {
                // if the original picture is in portrait
                clipRatio = 1 - 1 / heightWidthRatio;
            }

            Log.d(TAG, "*************************Enter Animation*************************");
            Log.d(TAG, "(mXDelta, mTopDelta)=(" + mXDelta + ", " + mYDelta + ")\nmImageScale=" + mImageScale
                    + "\nclipRatio=" + clipRatio);

            runEnterAnimation();
        }
    });
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    Log.i(TAG, "drawChild()");
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();
    int clipTop = 0, clipBottom = getHeight();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                Log.i(TAG, "drawChild() -- 0");
                continue;
            }// w  w  w  . j a  va 2 s  .com
            switch (getDrawerViewAbsoluteGravity(v)) {
            case Gravity.LEFT:
                Log.i(TAG, "drawChild() -- 1");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                    final int vright = v.getRight();
                    if (vright > clipLeft)
                        clipLeft = vright;
                }
                break;
            case Gravity.RIGHT:
                Log.i(TAG, "drawChild() -- 2");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.RIGHT)) {
                    final int vleft = v.getLeft();
                    if (vleft < clipRight)
                        clipRight = vleft;
                }
                break;
            case Gravity.TOP:
                Log.i(TAG, "drawChild() -- 3");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                    final int vbottom = v.getBottom();
                    if (vbottom > clipTop) {
                        clipTop = vbottom;
                    }
                }
                break;
            case Gravity.BOTTOM:
                Log.i(TAG, "drawChild() -- 4");
                if (checkDrawerViewAbsoluteGravity(v, Gravity.BOTTOM)) {
                    final int vtop = v.getTop();
                    if (vtop < clipBottom) {
                        clipBottom = vtop;
                    }
                }
                break;
            default:
                Log.i(TAG, "drawChild() -- 5");
                final int vtop = v.getTop();
                if (vtop < clipBottom) {
                    clipBottom = vtop;
                }
                break;
            }
        }
        canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        Log.i(TAG, "drawChild() -- drawingContent");
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);
        canvas.drawRect(clipLeft, clipTop, clipRight, clipBottom, mScrimPaint);
    } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
        Log.i(TAG, "drawChild() -- LEFT");
        final int shadowWidth = mShadowLeft.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeft.setAlpha((int) (0xff * alpha));
        mShadowLeft.draw(canvas);
    } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
        Log.i(TAG, "drawChild() -- Gravity.RIGHT");
        final int shadowWidth = mShadowRight.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
        Log.i(TAG, "drawChild() -- Gravity.TOP");
        final int shadowHeight = mShadowTop.getIntrinsicHeight();
        final int childBottom = child.getBottom();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight);
        mShadowTop.setAlpha((int) (0xff * alpha));
        mShadowTop.draw(canvas);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        Log.i(TAG, "drawChild() -- Gravity.BOTTOM");
        final int shadowHeight = mShadowBottom.getIntrinsicWidth();
        final int childTop = child.getTop();
        final int showing = getHeight() - childTop;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop);
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    }
    return result;
}

From source file:com.appunite.list.GridView.java

@Override
protected int computeVerticalScrollExtent() {
    final int count = getChildCount();
    if (count > 0) {
        final int numColumns = mNumColumns;
        final int rowCount = (count + numColumns - 1) / numColumns;

        int extent = rowCount * 100;

        View view = getChildAt(0);
        final int top = view.getTop();
        int height = view.getHeight();
        if (height > 0) {
            extent += (top * 100) / height;
        }/*  w ww  . j a  v  a 2 s  .co  m*/

        view = getChildAt(count - 1);
        final int bottom = view.getBottom();
        height = view.getHeight();
        if (height > 0) {
            extent -= ((bottom - getHeight()) * 100) / height;
        }

        return extent;
    }
    return 0;
}

From source file:com.appunite.list.GridView.java

@Override
protected int computeVerticalScrollOffset() {
    if (mFirstPosition >= 0 && getChildCount() > 0) {
        final View view = getChildAt(0);
        final int top = view.getTop();
        int height = view.getHeight();
        if (height > 0) {
            final int numColumns = mNumColumns;
            final int rowCount = (mItemCount + numColumns - 1) / numColumns;
            // In case of stackFromBottom the calculation of whichRow needs
            // to take into account that counting from the top the first row
            // might not be entirely filled.
            final int oddItemsOnFirstRow = isStackFromBottom() ? ((rowCount * numColumns) - mItemCount) : 0;
            final int whichRow = (mFirstPosition + oddItemsOnFirstRow) / numColumns;
            final int scrollY = getScrollY();
            return Math.max(whichRow * 100 - (top * 100) / height
                    + (int) ((float) scrollY / getHeight() * rowCount * 100), 0);
        }/*from   w ww .  j av  a 2 s.  com*/
    }
    return 0;
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

public int getPreferredVerticalOffset(int position) {
    buildDropDown();//from w  w w.  ja  v a 2s. c  o m

    final View anchor = getAnchorView();
    final AbstractXpListPopupWindow popup = this;

    final Context context = anchor.getContext();

    // Shadow is emulated below Lollipop, we have to account for that.
    final int backgroundPaddingTop = getBackgroundTopPadding();

    // Center selected item over anchor view.
    if (position < 0)
        position = 0;
    final int viewHeight = anchor.getHeight();
    final int dropDownListViewPaddingTop = mDropDownList.getPaddingTop();
    final int selectedItemHeight = popup.measureItem(position);
    final int beforeSelectedItemHeight = popup.measureItemsUpTo(position + 1);

    final int viewHeightAdjustedHalf = (viewHeight - anchor.getPaddingTop() - anchor.getPaddingBottom()) / 2
            + anchor.getPaddingBottom();

    final int offset;
    if (selectedItemHeight >= 0 && beforeSelectedItemHeight >= 0) {
        offset = -(beforeSelectedItemHeight + (viewHeightAdjustedHalf - selectedItemHeight / 2)
                + dropDownListViewPaddingTop + backgroundPaddingTop);
    } else {
        final int height = Util.resolveDimensionPixelSize(context, R.attr.dropdownListPreferredItemHeight, 0);
        offset = -(height * (position + 1) + (viewHeightAdjustedHalf - height / 2) + dropDownListViewPaddingTop
                + backgroundPaddingTop);
    }
    return offset;
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

void moveDrawerToOffset(View drawerView, float slideOffset) {
    Log.i(TAG, "BottomDrawerLayout -- moveDrawerToOffset() -- slideOffset = " + slideOffset);
    final int absGravity = getDrawerViewAbsoluteGravity(drawerView);
    final float oldOffset = getDrawerViewOffset(drawerView);
    final int width = drawerView.getWidth();
    final int height = drawerView.getHeight();
    final int xoldPos = (int) (width * oldOffset);
    final int xnewPos = (int) (width * slideOffset);
    final int yoldPos = (int) (height * oldOffset);
    final int ynewPos = (int) (height * slideOffset);
    int dx = xnewPos - xoldPos;
    int dy = ynewPos - yoldPos;

    if (absGravity == Gravity.LEFT || absGravity == Gravity.RIGHT) {
        drawerView.offsetLeftAndRight(checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
    }/*from   ww  w  .j  a  v  a  2s  . co m*/
    if (absGravity == Gravity.TOP || absGravity == Gravity.BOTTOM) {
        drawerView.offsetTopAndBottom(checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP) ? dy : -dy);
    }
    setDrawerViewOffset(drawerView, slideOffset);
}

From source file:com.androzic.vnspeech.MapFragment.java

@SuppressLint("ClickableViewAccessibility")
@Override/*  ww w  . j  a v  a2 s. c om*/
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        zoom100X = (int) event.getRawX();
        zoom100Y = (int) event.getRawY();
        zoomHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                zoom100X = 0;
                zoom100Y = 0;
            }
        }, 2000);
        break;
    case MotionEvent.ACTION_UP:
        int dx = Math.abs((int) event.getRawX() - zoom100X);
        int dy = (int) event.getRawY() - zoom100Y;
        int h = v.getHeight();
        int w = v.getWidth() >> 1;
        if (dy > h * 0.8 && dy < h * 2 && dx < w) {
            wait(new Waitable() {
                @Override
                public void waitFor() {
                    application.setZoom(1.);
                }
            });
            zoom100X = 0;
            zoom100Y = 0;
        }
        break;
    }
    return false;
}

From source file:com.android.dialer.widget.OverlappingPaneLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP);

    final int height = b - t;
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int paddingLeft = getPaddingLeft();

    final int childCount = getChildCount();
    int yStart = paddingTop;
    int nextYStart = yStart;

    if (mFirstLayout) {
        mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f;
    }/*  w  ww  .j  a v  a  2  s.  c o  m*/

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int childHeight = child.getMeasuredHeight();

        if (lp.slideable) {
            final int margin = lp.topMargin + lp.bottomMargin;
            final int range = Math.min(nextYStart, height - paddingBottom - mOverhangSize) - yStart - margin;
            mSlideRange = range;
            final int lpMargin = lp.topMargin;
            final int pos = (int) (range * mSlideOffset);
            yStart += pos + lpMargin;
            updateSlideOffset(pos);
        } else {
            yStart = nextYStart;
        }

        final int childTop = yStart;
        final int childBottom = childTop + childHeight;
        final int childLeft = paddingLeft;
        final int childRight = childLeft + child.getMeasuredWidth();

        child.layout(childLeft, childTop, childRight, childBottom);

        nextYStart += child.getHeight();
    }

    if (mFirstLayout) {
        updateObscuredViewsVisibility(mSlideableView);
    }

    mFirstLayout = false;
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * @param out Margins relative to left, top, right and bottom of the window.
 *///from  www.  java  2  s .  c o m
private void getBoundsInWindow(Rect out) {
    final View bounds = mDropDownBoundsView;
    if (bounds != null) {
        bounds.getWindowVisibleDisplayFrame(mTempRect);
        final int windowTop = mTempRect.top;
        final int windowRight = mTempRect.right;
        final int windowLeft = mTempRect.left;
        final int windowBottom = mTempRect.bottom;

        bounds.getLocationInWindow(mTempLocation);
        final int boundsTop = mTempLocation[1];
        final int boundsLeft = mTempLocation[0];

        final int boundsHeight = bounds.getHeight();
        final int boundsWidth = bounds.getWidth();

        out.top = boundsTop - windowTop;
        out.left = boundsLeft - windowLeft;
        out.bottom = windowBottom - (boundsTop + boundsHeight);
        out.right = windowRight - (boundsLeft + boundsWidth);
        return;
    }

    out.set(0, 0, 0, 0);
}