Example usage for android.view View getBottom

List of usage examples for android.view View getBottom

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getBottom() 

Source Link

Document

Bottom position of this view relative to its parent.

Usage

From source file:com.base.view.slidemenu.SlideMenu.java

protected final boolean canScrollVertically(View v, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();

        final int childCount = viewGroup.getChildCount();
        for (int index = 0; index < childCount; index++) {
            View child = viewGroup.getChildAt(index);
            final int left = child.getLeft();
            final int top = child.getTop();
            if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top
                    && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility()
                    && (ScrollDetectors.canScrollVertical(child, dy)
                            || canScrollVertically(child, dy, x + scrollX - left, y + scrollY - top))) {
                return true;
            }//from   w  ww.j  a  va  2  s  . co m
        }
    }

    return ViewCompat.canScrollVertically(v, -dy);
}

From source file:com.base.view.slidemenu.SlideMenu.java

/**
 * Detect whether the views inside content are slidable
 *//* ww w .j a v a  2s.co  m*/
protected final boolean canScrollHorizontally(View v, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup viewGroup = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();

        final int childCount = viewGroup.getChildCount();
        for (int index = 0; index < childCount; index++) {
            View child = viewGroup.getChildAt(index);
            final int left = child.getLeft();
            final int top = child.getTop();
            if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top
                    && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility()
                    && (ScrollDetectors.canScrollHorizontal(child, dx)
                            || canScrollHorizontally(child, dx, x + scrollX - left, y + scrollY - top))) {
                return true;
            }
        }
    }

    return ViewCompat.canScrollHorizontally(v, -dx);
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private void dumpChildren(String prefix) {
    int position = 0;
    for (MenuRowView view : mMenuRowViews) {
        View title = view.getChildAt(0);
        View contents = view.getChildAt(1);
        Log.d(TAG, prefix + " position=" + position++ + " rowView={visiblility=" + view.getVisibility()
                + ", alpha=" + view.getAlpha() + ", translationY=" + view.getTranslationY() + ", left="
                + view.getLeft() + ", top=" + view.getTop() + ", right=" + view.getRight() + ", bottom="
                + view.getBottom() + "}, title={visiblility=" + title.getVisibility() + ", alpha="
                + title.getAlpha() + ", translationY=" + title.getTranslationY() + ", left=" + title.getLeft()
                + ", top=" + title.getTop() + ", right=" + title.getRight() + ", bottom=" + title.getBottom()
                + "}, contents={visiblility=" + contents.getVisibility() + ", alpha=" + contents.getAlpha()
                + ", translationY=" + contents.getTranslationY() + ", left=" + contents.getLeft() + ", top="
                + contents.getTop() + ", right=" + contents.getRight() + ", bottom=" + contents.getBottom()
                + "}");
    }/*from   www .j  a  va2s.  c om*/
}

From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java

/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels/*ww w  .  j a  v  a  2s  . c  o  m*/
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight()
                    && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child,
                            true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
}

From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java

void updateObscuredViewVisibility() {
    if (getChildCount() == 0) {
        return;//from   w ww. j  a  v a2  s.c  om
    }
    final int leftBound = getPaddingLeft();
    final int rightBound = getWidth() - getPaddingRight();
    final int topBound = getPaddingTop();
    final int bottomBound = getHeight() - getPaddingBottom();
    final int left;
    final int right;
    final int top;
    final int bottom;
    if (mSlideableView != null && hasOpaqueBackground(mSlideableView)) {
        left = mSlideableView.getLeft();
        right = mSlideableView.getRight();
        top = mSlideableView.getTop();
        bottom = mSlideableView.getBottom();
    } else {
        left = right = top = bottom = 0;
    }
    View child = getChildAt(0);
    final int clampedChildLeft = Math.max(leftBound, child.getLeft());
    final int clampedChildTop = Math.max(topBound, child.getTop());
    final int clampedChildRight = Math.min(rightBound, child.getRight());
    final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
    final int vis;
    if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right
            && clampedChildBottom <= bottom) {
        vis = INVISIBLE;
    } else {
        vis = VISIBLE;
    }
    child.setVisibility(vis);
}

From source file:com.androzic.MapFragment.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            View root = getView();
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = root.findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = root.findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = root.findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (mapButtons.isShown()) {
                // Landscape mode
                if (v != null)
                    area.bottom = mapButtons.getTop();
                else
                    area.right = mapButtons.getLeft();
            }//from  ww w  .j  a  va2s. c om
            if (!area.isEmpty())
                map.updateViewArea(area);
            ViewTreeObserver ob;
            if (vto.isAlive())
                ob = vto;
            else
                ob = map.getViewTreeObserver();

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                ob.removeGlobalOnLayoutListener(this);
            } else {
                ob.removeOnGlobalLayoutListener(this);
            }
        }
    });
}

From source file:com.androidarchitecture.widgets.RecyclerViewSwipeToDeleteImpl.java

/**
 * We're gonna setup another ItemDecorator that will draw the red background in the empty space while the items are animating to their new positions
 * after an item is removed.//from   ww  w. j ava2 s . c  om
 */
private void setUpAnimationDecoratorHelper() {
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

        // we want to cache this and not allocate anything repeatedly in the onDraw method
        Drawable background;
        boolean initiated;

        private void init() {
            background = new ColorDrawable(ContextCompat.getColor(mContext, R.color.colorPrimary));
            initiated = true;
        }

        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {

            if (!initiated) {
                init();
            }

            // only if animation is in progress
            if (parent.getItemAnimator().isRunning()) {

                // some items might be animating down and some items might be animating up to close the gap left by the removed item
                // this is not exclusive, both movement can be happening at the same time
                // to reproduce this leave just enough items so the first one and the last one would be just a little off screen
                // then remove one from the middle

                // find first child with translationY > 0
                // and last one with translationY < 0
                // we're after a rect that is not covered in recycler-view views at this point in time
                View lastViewComingDown = null;
                View firstViewComingUp = null;

                // this is fixed
                int left = 0;
                int right = parent.getWidth();

                // this we need to find out
                int top = 0;
                int bottom = 0;

                // find relevant translating views
                int childCount = parent.getLayoutManager().getChildCount();
                for (int i = 0; i < childCount; i++) {
                    View child = parent.getLayoutManager().getChildAt(i);
                    if (child.getTranslationY() < 0) {
                        // view is coming down
                        lastViewComingDown = child;
                    } else if (child.getTranslationY() > 0) {
                        // view is coming up
                        if (firstViewComingUp == null) {
                            firstViewComingUp = child;
                        }
                    }
                }

                if (lastViewComingDown != null && firstViewComingUp != null) {
                    // views are coming down AND going up to fill the void
                    top = lastViewComingDown.getBottom() + (int) lastViewComingDown.getTranslationY();
                    bottom = firstViewComingUp.getTop() + (int) firstViewComingUp.getTranslationY();
                } else if (lastViewComingDown != null) {
                    // views are going down to fill the void
                    top = lastViewComingDown.getBottom() + (int) lastViewComingDown.getTranslationY();
                    bottom = lastViewComingDown.getBottom();
                } else if (firstViewComingUp != null) {
                    // views are coming up to fill the void
                    top = firstViewComingUp.getTop();
                    bottom = firstViewComingUp.getTop() + (int) firstViewComingUp.getTranslationY();
                }

                background.setBounds(left, top, right, bottom);
                background.draw(c);

            }
            super.onDraw(c, parent, state);
        }
    });
}

From source file:com.example.stickablelistview.StickListView.java

/**
 * Determine the Max X position. This is the farthest that the user can scroll the screen. Until the last adapter item has been
 * laid out it is impossible to calculate; once that has occurred this will perform the calculation, and if necessary force a
 * redraw and relayout of this view./*from  w w  w . j  a va  2s  .c om*/
 *
 * @return true if the maxx position was just determined
 */
private boolean determineMaxY() {
    // If the last view has been laid out, then we can determine the maximum x position
    if (isLastItemInAdapter(mBottomViewAdapterIndex)) {
        View bottomView = getBottomMostChild();

        if (bottomView != null) {
            int oldMaxY = mMaxY;

            // Determine the maximum x position
            mMaxY = mCurrentY + (bottomView.getBottom() - getPaddingTop()) - getRenderHeight();

            // Handle the case where the views do not fill at least 1 screen
            if (mMaxY < 0) {
                mMaxY = 0;
            }

            if (mMaxY != oldMaxY) {
                return true;
            }
        }
    }

    return false;
}

From source file:com.mycheez.adapter.DividerItemDecoration.java

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mDivider == null) {
        super.onDrawOver(c, parent, state);
        return;//from   w  ww.  j  ava 2 s . c om
    }

    // Initialization needed to avoid compiler warning
    int left = 0, right = 0, top = 0, bottom = 0, size;
    int orientation = mOrientation != -1 ? mOrientation : getOrientation(parent);
    int childCount = parent.getChildCount();

    if (orientation == LinearLayoutManager.VERTICAL) {
        size = mDivider.getIntrinsicHeight();
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
    } else { //horizontal
        size = mDivider.getIntrinsicWidth();
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
    }

    for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildPosition(child);
        // Hack for showing the divider only for the position where friends list ends
        // Actual code :
        // https://gist.github.com/zokipirlo/82336d89249e05bba5aa
        if (dividerLocation == position) {
            RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
            if (orientation == LinearLayoutManager.VERTICAL) {
                top = child.getTop() - params.topMargin - size;
                bottom = top + size;
            } else { //horizontal
                left = child.getLeft() - params.leftMargin;
                right = left + size;
            }
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
            break;
        }
    }

    // show last divider
    if (mShowLastDivider && childCount > 0) {
        View child = parent.getChildAt(childCount - 1);
        if (parent.getChildPosition(child) == (state.getItemCount() - 1)) {
            RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
            if (orientation == LinearLayoutManager.VERTICAL) {
                top = child.getBottom() + params.bottomMargin;
                bottom = top + size;
            } else { // horizontal
                left = child.getRight() + params.rightMargin;
                right = left + size;
            }
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }
}

From source file:com.irccloud.android.activity.UploadsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (ColorFormatter.file_uri_template != null)
        template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template);
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));/*w w  w .j a v a  2  s.c o  m*/
        cloud.recycle();
    }

    if (Build.VERSION.SDK_INT >= 14) {
        try {
            java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http");
            long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
            HttpResponseCache.install(httpCacheDir, httpCacheSize);
        } catch (IOException e) {
            Log.i("IRCCloud", "HTTP response cache installation failed:" + e);
        }
    }
    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        cid = savedInstanceState.getInt("cid");
        to = savedInstanceState.getString("to");
        msg = savedInstanceState.getString("msg");
        page = savedInstanceState.getInt("page");
        File[] files = (File[]) savedInstanceState.getSerializable("adapter");
        for (File f : files) {
            adapter.addFile(f);
        }
        adapter.notifyDataSetChanged();
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchFilesTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final File f = (File) adapter.getItem(i);

            AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this);
            builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
            final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null);
            final EditText messageinput = (EditText) v.findViewById(R.id.message);
            messageinput.setText(msg);
            final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);

            v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (messageinput.hasFocus()) {
                        v.post(new Runnable() {
                            @Override
                            public void run() {
                                v.scrollTo(0, v.getBottom());
                            }
                        });
                    }
                }
            });

            if (f.mime_type.startsWith("image/")) {
                try {
                    thumbnail.setImageBitmap(f.image);
                    thumbnail.setVisibility(View.VISIBLE);
                    thumbnail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class);
                            i.setData(Uri.parse(f.url));
                            startActivity(i);
                        }
                    });
                    thumbnail.setClickable(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                thumbnail.setVisibility(View.GONE);
            }

            ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata);
            v.findViewById(R.id.filename).setVisibility(View.GONE);
            v.findViewById(R.id.filename_heading).setVisibility(View.GONE);

            builder.setTitle("Send A File To " + to);
            builder.setView(v);
            builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String message = messageinput.getText().toString();
                    if (message.length() > 0)
                        message += " ";
                    message += f.url;

                    dialog.dismiss();
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK);
                    } else {
                        getParent().setResult(Activity.RESULT_OK);
                    }
                    finish();

                    NetworkConnection.getInstance().say(cid, to, message);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(UploadsActivity.this);
            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            d.show();
        }
    });
}