Example usage for android.view ViewParent getParent

List of usage examples for android.view ViewParent getParent

Introduction

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

Prototype

public ViewParent getParent();

Source Link

Document

Returns the parent if it exists, or null.

Usage

From source file:Main.java

public static boolean isShown(View mContentLayout) {
    if (!mContentLayout.isShown())
        return false;
    ViewParent parent = mContentLayout.getParent();
    do {//from   ww w. j  a  v a 2  s .co  m
        if (parent instanceof View && !((View) parent).isShown())
            return false;
        else
            System.out.println(parent.getClass());

    } while ((parent = parent.getParent()) != null);
    return true;
}

From source file:Main.java

public static void requestLayoutParent(View view, boolean isAll) {
    ViewParent parent = view.getParent();
    while (parent != null && parent instanceof View) {
        if (!parent.isLayoutRequested()) {
            parent.requestLayout();//  w  ww  .  j  a v  a  2  s .  co m
            if (!isAll) {
                break;
            }
        }
        parent = parent.getParent();
    }
}

From source file:cn.bingoogolapple.refreshlayout.util.BGARefreshScrollingUtil.java

public static BGAStickyNavLayout getStickyNavLayout(View view) {
    ViewParent viewParent = view.getParent();
    while (viewParent != null) {
        if (viewParent instanceof BGAStickyNavLayout) {
            return (BGAStickyNavLayout) viewParent;
        }/*from  ww  w .j  ava 2s.  co m*/
        viewParent = viewParent.getParent();
    }
    return null;
}

From source file:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java

public static boolean getIgnored(AccessibilityNodeInfoCompat node, View view) {
    int important = ViewCompat.getImportantForAccessibility(view);
    if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO
            || important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
        return true;
    }//from   ww w .j av  a2  s  . c o  m

    // Go all the way up the tree to make sure no parent has hidden its descendants
    ViewParent parent = view.getParent();
    while (parent instanceof View) {
        if (ViewCompat.getImportantForAccessibility(
                (View) parent) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
            return true;
        }
        parent = parent.getParent();
    }

    if (!node.isVisibleToUser()) {
        return true;
    }

    if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
        if (node.getChildCount() <= 0) {
            // Leaves that are accessibility focusable are never ignored, even if they don't have a
            // speakable description
            return false;
        } else if (AccessibilityUtil.isSpeakingNode(node, view)) {
            // Node is focusable and has something to speak
            return false;
        }

        // Node is focusable and has nothing to speak
        return true;
    }

    // If this node has no focusable ancestors, but it still has text,
    // then it should receive focus from navigation and be read aloud.
    if (!AccessibilityUtil.hasFocusableAncestor(node, view) && AccessibilityUtil.hasText(node)) {
        return false;
    }

    return true;
}

From source file:com.facebook.stetho.inspector.elements.android.AccessibilityNodeInfoWrapper.java

public static String getIgnoredReasons(AccessibilityNodeInfoCompat node, View view) {
    int important = ViewCompat.getImportantForAccessibility(view);

    if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO) {
        return "View has importantForAccessibility set to 'NO'.";
    }//from  ww w .  java  2  s  .  c  o  m

    if (important == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
        return "View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
    }

    ViewParent parent = view.getParent();
    while (parent instanceof View) {
        if (ViewCompat.getImportantForAccessibility(
                (View) parent) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
            return "An ancestor View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
        }
        parent = parent.getParent();
    }

    if (!node.isVisibleToUser()) {
        return "View is not visible.";
    }

    if (AccessibilityUtil.isAccessibilityFocusable(node, view)) {
        return "View is actionable, but has no description.";
    }

    if (AccessibilityUtil.hasText(node)) {
        return "View is not actionable, and an ancestor View has co-opted its description.";
    }

    return "View is not actionable and has no description.";
}

From source file:com.google.android.apps.common.testing.accessibility.framework.ViewAccessibilityUtils.java

/**
 * @see View#isImportantForAccessibility()
 *///from   w w  w.j  a  v  a 2  s .c  o  m
public static boolean isImportantForAccessibility(View view) {
    if (view == null) {
        return false;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return view.isImportantForAccessibility();
    } else {
        // On earlier APIs, we must piece together accessibility importance from the available
        // properties. We return false incorrectly for some cases where unretrievable listeners
        // prevent us from determining importance.

        // If the developer marked the view as explicitly not important, it isn't.
        int mode = view.getImportantForAccessibility();
        if ((mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO)
                || (mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)) {
            return false;
        }

        // No parent view can be hiding us. (APIs 19 to 21)
        ViewParent parent = view.getParent();
        while (parent instanceof View) {
            if (((View) parent)
                    .getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
                return false;
            }
            parent = parent.getParent();
        }

        // Interrogate the view's other properties to determine importance.
        return (mode == View.IMPORTANT_FOR_ACCESSIBILITY_YES) || isActionableForAccessibility(view)
                || hasListenersForAccessibility(view) || (view.getAccessibilityNodeProvider() != null)
                || (ViewCompat.getAccessibilityLiveRegion(view) != ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE);
    }
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static Fragment getFocusedFragment(FragmentActivity activity) {
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus == null) {
        return null;
    }/* w ww  .j a va2  s.  co  m*/
    ViewParent currentFocusParent = currentFocus.getParent();
    if (currentFocusParent == null) {
        return null;
    }
    List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();
    for (Fragment f : fragments) {
        if (f == null) {
            continue;
        }
        ViewParent v = currentFocusParent;
        View fragmentView = f.getView();
        while (v != null) {
            if (v == fragmentView) {
                return f;
            }
            v = v.getParent();
        }
    }

    return null;
}

From source file:im.neon.util.VectorUtils.java

/**
 * Set the call avatar in an imageView.//from ww  w .j a  va  2 s.  c o  m
 *
 * @param context   the context
 * @param session   the session
 * @param imageView the image view
 * @param room      the room
 */
public static void loadCallAvatar(Context context, MXSession session, ImageView imageView, Room room) {
    // sanity check
    if ((null != room) && (null != session) && (null != imageView) && session.isAlive()) {
        // reset the imageView tag
        imageView.setTag(null);

        String callAvatarUrl = room.getCallAvatarUrl();
        String roomId = room.getRoomId();
        String displayName = VectorUtils.getRoomDisplayName(context, session, room);
        int pixelsSide = imageView.getLayoutParams().width;

        // when size < 0, it means that the render graph must compute it
        // so, we search the valid parent view with valid size
        if (pixelsSide < 0) {
            ViewParent parent = imageView.getParent();

            while ((pixelsSide < 0) && (null != parent)) {
                if (parent instanceof View) {
                    View parentAsView = (View) parent;
                    pixelsSide = parentAsView.getLayoutParams().width;
                }
                parent = parent.getParent();
            }
        }

        // if the avatar is already cached, use it
        if (session.getMediasCache().isAvatarThumbnailCached(callAvatarUrl,
                context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) {
            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView,
                    callAvatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size));
        } else {
            Bitmap bitmap = null;

            if (pixelsSide > 0) {
                // get the avatar bitmap.
                bitmap = VectorUtils.createAvatar(VectorUtils.getAvatarColor(roomId),
                        getInitialLetter(displayName), pixelsSide);
            }

            // until the dedicated avatar is loaded.
            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView,
                    callAvatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size),
                    bitmap);
        }
    }
}

From source file:com.customviewcollection.nestedscroll.NestedScrollingChildHelper.java

/**
 * View(?ViewView?)//from  ww w.  j  a  v  a2 s  . co  m
 * ???ViewonStartNestedScroll  onNestedScrollAccepted
 *
 * @param axes ????
 * @return true ViewView?
 */
public boolean startNestedScroll(int axes) {
    if (hasNestedScrollingParent()) {
        // Already in progress
        return true;
    }
    if (isNestedScrollingEnabled()) {
        ViewParent p = mView.getParent();
        View child = mView;
        while (p != null) {
            if (ViewParentCompat.onStartNestedScroll(p, child, mView, axes)) {
                mNestedScrollingParent = p;
                ViewParentCompat.onNestedScrollAccepted(p, child, mView, axes);
                return true;
            }
            if (p instanceof View) {
                child = (View) p;
            }
            p = p.getParent();
        }
    }
    return false;
}

From source file:com.android.launcher3.BubbleTextView.java

void setStayPressed(boolean stayPressed) {
    mStayPressed = stayPressed;//from www. java2 s.  c o  m
    if (!stayPressed) {
        HolographicOutlineHelper.obtain(getContext()).recycleShadowBitmap(mPressedBackground);
        mPressedBackground = null;
    } else {
        if (mPressedBackground == null) {
            mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
        }
    }

    // Only show the shadow effect when persistent pressed state is set.
    ViewParent parent = getParent();
    if (parent != null && parent.getParent() instanceof BubbleTextShadowHandler) {
        ((BubbleTextShadowHandler) parent.getParent()).setPressedIcon(this, mPressedBackground);
    }

    updateIconState();
}