List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:com.miuhouse.yourcompany.student.view.widget.LazyViewPager.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v/* www. j av a2 s.com*/ * 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 * @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--) { // This will not work for transformed views in Honeycomb+ 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:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.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).//ww w . j av a2 s . c o m * @param dx Delta scrolled in pixels * @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--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ 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:me.bemind.sidemenu.SideMenu.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/*from ww w .j a va2s. c om*/ * @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--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ 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; } } } /* special case ViewPagers, which don't properly implement the scrolling interface */ return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || draggedChild || ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx))); //return checkV && ViewCompat.canScrollHorizontally(v, (isLayoutRtlSupport() ? dx : -dx)); }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private void ensureSubDecor() { if (!mSubDecorInstalled) { final LayoutInflater inflater = LayoutInflater.from(mContext); if (!mWindowNoTitle) { if (mIsFloating) { // If we're floating, inflate the dialog title decor mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null); } else if (mHasActionBar) { /**//from www. ja v a 2 s. co m * This needs some explanation. As we can not use the android:theme attribute * pre-L, we emulate it by manually creating a LayoutInflater using a * ContextThemeWrapper pointing to actionBarTheme. */ TypedValue outValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true); Context themedContext; if (outValue.resourceId != 0) { themedContext = new ContextThemeWrapper(mContext, outValue.resourceId); } else { themedContext = mContext; } // Now inflate the view using the themed context and set it as the content view mSubDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar, null); mDecorContentParent = (DecorContentParent) mSubDecor.findViewById(R.id.decor_content_parent); mDecorContentParent.setWindowCallback(getWindowCallback()); /** * Propagate features to DecorContentParent */ if (mOverlayActionBar) { mDecorContentParent.initFeature(FEATURE_ACTION_BAR_OVERLAY); } if (mFeatureProgress) { mDecorContentParent.initFeature(Window.FEATURE_PROGRESS); } if (mFeatureIndeterminateProgress) { mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } } else { if (mOverlayActionMode) { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null); } else { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null); } if (Build.VERSION.SDK_INT >= 21) { // If we're running on L or above, we can rely on ViewCompat's // setOnApplyWindowInsetsListener ViewCompat.setOnApplyWindowInsetsListener(mSubDecor, new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { final int top = insets.getSystemWindowInsetTop(); final int newTop = updateStatusGuard(top); if (top != newTop) { insets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), newTop, insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); } // Now apply the insets on our view return ViewCompat.onApplyWindowInsets(v, insets); } }); } else { // Else, we need to use our own FitWindowsViewGroup handling ((FitWindowsViewGroup) mSubDecor) .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() { @Override public void onFitSystemWindows(Rect insets) { insets.top = updateStatusGuard(insets.top); } }); } } if (mSubDecor == null) { throw new IllegalArgumentException("AppCompat does not support the current theme features"); } if (mDecorContentParent == null) { mTitleView = (TextView) mSubDecor.findViewById(R.id.title); } // Make the decor optionally fit system windows, like the window's decor ViewUtils.makeOptionalFitsSystemWindows(mSubDecor); final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content); final ViewGroup abcContent = (ViewGroup) mSubDecor.findViewById(R.id.action_bar_activity_content); // There might be Views already added to the Window's content view so we need to // migrate them to our content view while (decorContent.getChildCount() > 0) { final View child = decorContent.getChildAt(0); decorContent.removeViewAt(0); abcContent.addView(child); } // Now set the Window's content view with the decor mWindow.setContentView(mSubDecor); // Change our content FrameLayout to use the android.R.id.content id. // Useful for fragments. decorContent.setId(View.NO_ID); abcContent.setId(android.R.id.content); // The decorContent may have a foreground drawable set (windowContentOverlay). // Remove this as we handle it ourselves if (decorContent instanceof FrameLayout) { ((FrameLayout) decorContent).setForeground(null); } // If a title was set before we installed the decor, propogate it now CharSequence title = getTitle(); if (!TextUtils.isEmpty(title)) { onTitleChanged(title); } applyFixedSizeWindow(); onSubDecorInstalled(mSubDecor); mSubDecorInstalled = true; // Invalidate if the panel menu hasn't been created before this. // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu // being called in the middle of onCreate or similar. // A pending invalidation will typically be resolved before the posted message // would run normally in order to satisfy instance state restoration. PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); if (!isDestroyed() && (st == null || st.menu == null)) { invalidatePanelMenu(FEATURE_ACTION_BAR); } } }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.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 * @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. *///w w w . ja va 2 s. c o m 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--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ 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, (isLayoutRtlSupport() ? dx : -dx)); }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Open the drawer view by animating it into view. *///from w w w. j a v a 2s . c om public void openDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); mStartedOpen = false; if (hasWindowFocus()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart(); } else { left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerOpening(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; dispatchOnDrawerOpened(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); View focusable = drawerView.getChildAt(0); if (focusable != null) { focusable.requestFocus(); } invalidate(); }
From source file:com.juick.android.MainActivity.java
private static void restyleViewGroup(ViewGroup view, ColorsTheme.ColorTheme colorTheme, boolean pressed, boolean selected, boolean dontBackground) { ViewGroup parent = view; if (parent.getId() == R.id.navigation_panel) return;/*from www . ja v a 2 s. co m*/ int childCount = parent.getChildCount(); int background = colorTheme.getBackground(pressed); int foreground = colorTheme.getForeground(pressed); if (selected) { background = calculatePressedBackground(background, foreground); } if (!dontBackground) { boolean skipDraw = false; if ((view instanceof LinearLayout || view instanceof FrameLayout || view instanceof RelativeLayout)) { Context context = view.getContext(); if (context instanceof MainActivity || context instanceof MessagesActivity || context instanceof ThreadActivity) { // no unneeded background in given scrolling activities skipDraw = true; if (view.getBackground() != null) { // but enable for layouts that with color skipDraw = false; } if (!skipDraw && view.getClass().getName().toLowerCase().contains("decorview")) { // given activities manage themselves skipDraw = true; } } } if (!skipDraw) parent.setBackgroundColor(background); } if (view instanceof ListView) dontBackground = true; for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); restyleChildrenOrWidget(child, dontBackground); } }
From source file:com.chenglong.muscle.ui.LazyViewPager.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 * @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. *///from w ww. j a va 2 s . c o m 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--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ 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:android.transitions.everywhere.Transition.java
/** * Recursive method which captures values for an entire view hierarchy, * starting at some root view. Transitions without targetIDs will use this * method to capture values for all possible views. * * @param view The view for which to capture values. Children of this View * will also be captured, recursively down to the leaf nodes. * @param start true if values are being captured in the start scene, false * otherwise./* www . ja v a 2 s .c o m*/ */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } int id = view.getId(); if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) { return; } if (mTargetExcludes != null && mTargetExcludes.contains(view)) { return; } if (mTargetTypeExcludes != null && view != null) { int numTypes = mTargetTypeExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeExcludes.get(i).isInstance(view)) { return; } } } if (view.getParent() instanceof ViewGroup) { TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } values.targetedTransitions.add(this); capturePropagationValues(values); if (start) { addViewValues(mStartValues, view, values); } else { addViewValues(mEndValues, view, values); } } if (view instanceof ViewGroup) { // Don't traverse child hierarchy if there are any child-excludes on this view if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) { return; } if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) { return; } if (mTargetTypeChildExcludes != null) { int numTypes = mTargetTypeChildExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeChildExcludes.get(i).isInstance(view)) { return; } } } ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); ++i) { captureHierarchy(parent.getChildAt(i), start); } } }
From source file:com.transitionseverywhere.Transition.java
/** * Recursive method which captures values for an entire view hierarchy, * starting at some root view. Transitions without targetIDs will use this * method to capture values for all possible views. * * @param view The view for which to capture values. Children of this View * will also be captured, recursively down to the leaf nodes. * @param start true if values are being captured in the start scene, false * otherwise./*from w w w.java 2s . c o m*/ */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } int id = view.getId(); if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) { return; } if (mTargetExcludes != null && mTargetExcludes.contains(view)) { return; } if (mTargetTypeExcludes != null) { int numTypes = mTargetTypeExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeExcludes.get(i).isInstance(view)) { return; } } } if (view.getParent() instanceof ViewGroup) { TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } values.targetedTransitions.add(this); capturePropagationValues(values); if (start) { addViewValues(mStartValues, view, values); } else { addViewValues(mEndValues, view, values); } } if (view instanceof ViewGroup) { // Don't traverse child hierarchy if there are any child-excludes on this view if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) { return; } if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) { return; } if (mTargetTypeChildExcludes != null) { int numTypes = mTargetTypeChildExcludes.size(); for (int i = 0; i < numTypes; ++i) { if (mTargetTypeChildExcludes.get(i).isInstance(view)) { return; } } } ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); ++i) { captureHierarchy(parent.getChildAt(i), start); } } }