Example usage for android.view View getParent

List of usage examples for android.view View getParent

Introduction

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

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:com.android.photos.views.GalleryThumbnailView.java

/**
 * Obtain the view and add it to our list of children. The view can be made
 * fresh, converted from an unused view, or used as is if it was in the
 * recycle bin.//from  ww  w  .  ja v a  2 s .co m
 *
 * @param startPosition Logical position in the list to start from
 * @param x Left or right edge of the view to add
 * @param forward If true, align left edge to x and increase position.
 *                If false, align right edge to x and decrease position.
 * @return Number of views added
 */
private int makeAndAddColumn(int startPosition, int x, boolean forward) {
    int columnWidth = mLargeColumnWidth;
    int addViews = 0;
    for (int remaining = mLargeColumnUnitCount, i = 0; remaining > 0 && startPosition + i >= 0
            && startPosition + i < mItemCount; i += forward ? 1 : -1, addViews++) {
        if (mAdapter.getIntrinsicAspectRatio(startPosition + i) >= 1f) {
            // landscape
            remaining -= LAND_UNITS;
        } else {
            // portrait
            remaining -= PORT_UNITS;
            if (remaining < 0) {
                remaining += (mSmallColumnUnitCount - mLargeColumnUnitCount);
                columnWidth = mSmallColumnWidth;
            }
        }
    }
    int nextTop = 0;
    for (int i = 0; i < addViews; i++) {
        int position = startPosition + (forward ? i : -i);
        View child = obtainView(position, null);
        if (child.getParent() != this) {
            if (mInLayout) {
                addViewInLayout(child, forward ? -1 : 0, child.getLayoutParams());
            } else {
                addView(child, forward ? -1 : 0);
            }
        }
        int heightSize = (int) (.5f
                + (mAdapter.getIntrinsicAspectRatio(position) >= 1f ? columnWidth / ASPECT_RATIO
                        : columnWidth * ASPECT_RATIO));
        int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
        int widthSpec = MeasureSpec.makeMeasureSpec(columnWidth, MeasureSpec.EXACTLY);
        child.measure(widthSpec, heightSpec);
        int childLeft = forward ? x : x - columnWidth;
        child.layout(childLeft, nextTop, childLeft + columnWidth, nextTop + heightSize);
        nextTop += heightSize;
    }
    return addViews;
}

From source file:com.android.utils.ExploreByTouchHelper.java

/**
 * Computes whether the specified {@link Rect} intersects with the visible
 * portion of its parent {@link View}. Modifies {@code localRect} to contain
 * only the visible portion./*from w  ww . j  a  va  2  s  .c  o  m*/
 *
 * @param localRect A rectangle in local (parent) coordinates.
 * @return Whether the specified {@link Rect} is visible on the screen.
 */
private boolean intersectVisibleToUser(Rect localRect) {
    // Missing or empty bounds mean this view is not visible.
    if ((localRect == null) || localRect.isEmpty()) {
        return false;
    }

    // Attached to invisible window means this view is not visible.
    if (mHost.getWindowVisibility() != View.VISIBLE) {
        return false;
    }

    // An invisible predecessor or one with alpha zero means
    // that this view is not visible to the user.
    Object current = this;
    while (current instanceof View) {
        final View view = (View) current;
        // We have attach info so this view is attached and there is no
        // need to check whether we reach to ViewRootImpl on the way up.
        if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) {
            return false;
        }
        current = view.getParent();
    }

    // If no portion of the parent is visible, this view is not visible.
    if (!mHost.getLocalVisibleRect(mTempVisibleRect)) {
        return false;
    }

    // Check if the view intersects the visible portion of the parent.
    return localRect.intersect(mTempVisibleRect);
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

private boolean isDescendantClipped(View child) {
    mTempRect.set(0, 0, child.getWidth(), child.getHeight());
    offsetDescendantRectToMyCoords(child, mTempRect);
    View directChild;//from   w  w  w .ja  va 2s  .c  om
    if (child.getParent() == this) {
        directChild = child;
    } else {
        View v = child;
        ViewParent p = child.getParent();
        while (p != this) {
            v = (View) p;
            p = v.getParent();
        }
        directChild = v;
    }

    // ResolverDrawerLayout lays out vertically in child order;
    // the next view and forward is what to check against.
    int clipEdge = getHeight() - getPaddingBottom();
    final int childCount = getChildCount();
    for (int i = indexOfChild(directChild) + 1; i < childCount; i++) {
        final View nextChild = getChildAt(i);
        if (nextChild.getVisibility() == GONE) {
            continue;
        }
        clipEdge = Math.min(clipEdge, nextChild.getTop());
    }
    return mTempRect.bottom > clipEdge;
}

From source file:com.netease.hearttouch.htrefreshrecyclerview.base.HTBaseRecyclerView.java

private void initRefreshView() {
    if (mHTViewHolder == null)
        return;/*  w w w . j a v  a 2s  .  com*/
    View refreshView = mHTViewHolder.getRefreshView();
    if (refreshView != null) {
        if (refreshView.getParent() != null) {
            ((ViewGroup) refreshView.getParent()).removeView(refreshView);
        }
        int res = mHTViewHolder.getRefreshViewBackgroundResId();
        if (res != 0) {//?
            mRefreshContainerView.setBackgroundResource(res);
        } else {
            mRefreshContainerView.setBackgroundResource(android.R.color.transparent);
        }
        mRefreshContainerView.removeAllViews();
        setViewLayoutParams(refreshView);
        mRefreshContainerView.addView(refreshView);
        //            hideRefreshView(true);
    }
    setRefreshUIChangeListener(mHTViewHolder);
}

From source file:com.netease.hearttouch.htrefreshrecyclerview.base.HTBaseRecyclerView.java

private void initLoadMoreView() {
    if (mHTViewHolder == null)
        return;//  ww  w. j  a  v a 2s . c o m
    View loadMoreView = mHTViewHolder.getLoadMoreView();
    if (loadMoreView != null) {
        if (loadMoreView.getParent() != null) {
            ((ViewGroup) loadMoreView.getParent()).removeView(loadMoreView);
        }
        int res = mHTViewHolder.getLoadMoreViewBackgroundResId();
        if (res != 0) {//?
            mLoadMoreContainerView.setBackgroundResource(res);
        } else {
            mLoadMoreContainerView.setBackgroundResource(android.R.color.transparent);
        }
        mLoadMoreContainerView.removeAllViews();
        setViewLayoutParams(loadMoreView);
        mLoadMoreContainerView.addView(loadMoreView);
        hideLoadMoreView(true);
    }
    setLoadMoreUIChangeListener(mHTViewHolder);
}

From source file:com.google.blockly.android.AbstractBlocklyActivity.java

/**
 * Creates or loads the root content view (by default, {@link R.layout#drawers_and_action_bar})
 * for the Activity.  It is also responsible for assigning {@link #mActionBar} and
 * {@link #mDrawerLayout}, and adding the view returned by {@link #onCreateContentView}.
 *//*from   w  w w  .  j ava 2s  . co m*/
protected void onCreateActivityRootView() {
    setContentView(R.layout.drawers_and_action_bar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowTitleEnabled(true);

    // Create and attach content view into content container.  If content is a fragment, content
    // will be null here and the container will be populated during the FragmentTransaction.
    View content = onCreateContentView(R.id.content_container);
    if (content != null) {
        FrameLayout contentContainer = (FrameLayout) findViewById(R.id.content_container);
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        if (content.getParent() != contentContainer) {
            contentContainer.addView(content, lp);
        } else {
            content.setLayoutParams(lp);
        }
    }

    mNavigationDrawer = onCreateAppNavigationDrawer();
    if (mNavigationDrawer != null) {
        setupAppNaviagtionDrawer();
    }
}

From source file:com.skyousuke.ivtool.windows.MainWindow.java

private boolean hasParent(View view) {
    return view.getParent() != null;
}

From source file:com.cairoconfessions.MainActivity.java

public void follow(View view) {
    if (((TextView) view).getText().equals("Follow"))
        ((TextView) view).setText("Unfollow");
    else {//from  w  w w .  j  a  v a 2s . co m
        ((TextView) view).setText("Follow");
        if (mTitle.equals("Following"))
            ((LinearLayout) view.getParent().getParent().getParent()).setVisibility(View.GONE);
    }
}

From source file:com.cairoconfessions.MainActivity.java

public void expandItem(View view) {

    Intent mainIntent = new Intent(MainActivity.this, ExpandedConfessionActivity.class);
    mainIntent.putExtra("confession", ((TextView) view).getText().toString());
    mainIntent.putExtra("category",
            ((LinearLayout) view.getParent().getParent().getParent()).getContentDescription().toString());
    startActivity(mainIntent);//  ww  w.  j a v a2s  .c om

}

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

private static ViewGroup findSuitableParent(View view) {
    ViewGroup fallback = null;/*from w  w w. j av a2 s  . c  o  m*/
    do {
        if (view instanceof CoordinatorLayout) {
            // We've found a CoordinatorLayout, use it
            return (ViewGroup) view;
        } else if (view instanceof FrameLayout) {
            if (view.getId() == android.R.id.content) {
                // If we've hit the decor content view, then we didn't find a CoL in the
                // hierarchy, so use it.
                return (ViewGroup) view;
            } else {
                // It's not the content view but we'll use it as our fallback
                fallback = (ViewGroup) view;
            }
        }

        if (view != null) {
            // Else, we will loop and crawl up the view hierarchy and try to find a parent
            final ViewParent parent = view.getParent();
            view = parent instanceof View ? (View) parent : null;
        }
    } while (view != null);

    // If we reach here then we didn't find a CoL or a suitable content view so we'll fallback
    return fallback;
    //return (ViewGroup) view;
}