List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
private ViewGroup createSubDecor() { TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme); if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar_ox)) { a.recycle();/*from w w w.j a v a2s. co m*/ throw new IllegalStateException( "You need to use a Theme.AppCompat theme (or descendant) with this activity."); } if (a.getBoolean(R.styleable.AppCompatTheme_windowNoTitle_ox, false)) { requestWindowFeature(Window.FEATURE_NO_TITLE); } else if (a.getBoolean(R.styleable.AppCompatTheme_windowActionBar_ox, false)) { // Don't allow an action bar if there is no title. requestWindowFeature(FEATURE_SUPPORT_ACTION_BAR); } if (a.getBoolean(R.styleable.AppCompatTheme_windowActionBarOverlay_ox, false)) { requestWindowFeature(FEATURE_SUPPORT_ACTION_BAR_OVERLAY); } if (a.getBoolean(R.styleable.AppCompatTheme_windowActionModeOverlay_ox, false)) { requestWindowFeature(FEATURE_ACTION_MODE_OVERLAY); } mIsFloating = a.getBoolean(R.styleable.AppCompatTheme_android_windowIsFloating, false); a.recycle(); final LayoutInflater inflater = LayoutInflater.from(mContext); ViewGroup subDecor = null; if (!mWindowNoTitle) { if (mIsFloating) { // If we're floating, inflate the dialog title decor subDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null); // Floating windows can never have an action bar, reset the flags mHasActionBar = mOverlayActionBar = false; } else if (mHasActionBar) { /** * 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_ox, 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 subDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar, null); mDecorContentParent = (DecorContentParent) subDecor.findViewById(R.id.decor_content_parent); mDecorContentParent.setWindowCallback(getWindowCallback()); /** * Propagate features to DecorContentParent */ if (mOverlayActionBar) { mDecorContentParent.initFeature(FEATURE_SUPPORT_ACTION_BAR_OVERLAY); } if (mFeatureProgress) { mDecorContentParent.initFeature(Window.FEATURE_PROGRESS); } if (mFeatureIndeterminateProgress) { mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } } else { if (mOverlayActionMode) { subDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null); } else { subDecor = (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(subDecor, 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) subDecor) .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() { @Override public void onFitSystemWindows(Rect insets) { insets.top = updateStatusGuard(insets.top); } }); } } if (subDecor == null) { throw new IllegalArgumentException("AppCompat does not support the current theme features: { " + "windowActionBar: " + mHasActionBar + ", windowActionBarOverlay: " + mOverlayActionBar + ", android:windowIsFloating: " + mIsFloating + ", windowActionModeOverlay: " + mOverlayActionMode + ", windowNoTitle: " + mWindowNoTitle + " }"); } if (mDecorContentParent == null) { mTitleView = (TextView) subDecor.findViewById(R.id.title); } // Make the decor optionally fit system windows, like the window's decor ViewUtils.makeOptionalFitsSystemWindows(subDecor); final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content); final ContentFrameLayout abcContent = (ContentFrameLayout) subDecor .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(subDecor); // 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) { decorContent.setForeground(null); } abcContent.setAttachListener(new ContentFrameLayout.OnAttachListener() { @Override public void onAttachedFromWindow() { } @Override public void onDetachedFromWindow() { dismissPopups(); } }); return subDecor; }
From source file:beichen.douban.ui.view.LazyViewPager.java
/** * Tests scrollability within child views of v given a delta of dx. * //from w w w. ja va2s . c om * @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. */ 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:com.bowen.hannengclub.view.LazyViewPager.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v/*from w w w . jav a 2 s . co m*/ * 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--) { // : 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:com.android.leanlauncher.Workspace.java
void removeItemsByPackageName(final ArrayList<String> packages, final UserHandleCompat user) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);//from w w w . j a va2 s . co m // Filter out all the ItemInfos that this is going to affect final HashSet<ItemInfo> infos = new HashSet<ItemInfo>(); final HashSet<ComponentName> cns = new HashSet<ComponentName>(); ViewGroup layout = mWorkspace.getShortcutsAndWidgets(); int childCount = layout.getChildCount(); for (int i = 0; i < childCount; ++i) { View view = layout.getChildAt(i); infos.add((ItemInfo) view.getTag()); } LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { @Override public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { if (packageNames.contains(cn.getPackageName()) && info.user.equals(user)) { cns.add(cn); return true; } return false; } }; LauncherModel.filterItemInfos(infos, filter); // Remove the affected components removeItemsByComponentName(cns, user); }
From source file:com.android.leanlauncher.Workspace.java
/** * Removes items that match the item info specified. When applications are removed * as a part of an update, this is called to ensure that other widgets and application * shortcuts are not removed.//from ww w .jav a 2s .co m */ void removeItemsByComponentName(final HashSet<ComponentName> componentNames, final UserHandleCompat user) { final ViewGroup layout = mWorkspace.getShortcutsAndWidgets(); final ArrayMap<ItemInfo, View> children = new ArrayMap<>(); for (int j = 0; j < layout.getChildCount(); j++) { final View view = layout.getChildAt(j); children.put((ItemInfo) view.getTag(), view); } final ArrayList<View> childrenToRemove = new ArrayList<View>(); LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { @Override public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) { if (componentNames.contains(cn) && info.user.equals(user)) { childrenToRemove.add(children.get(info)); return true; } return false; } }; LauncherModel.filterItemInfos(children.keySet(), filter); // Remove all the other children for (View child : childrenToRemove) { // Note: We can not remove the view directly from CellLayoutChildren as this // does not re-mark the spaces as unoccupied. mWorkspace.removeViewInLayout(child); if (child instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) child); } } if (childrenToRemove.size() > 0) { layout.requestLayout(); layout.invalidate(); } }
From source file:javalibrary.android.ui.VerticalViewPager.java
protected boolean canScrolls(View v, boolean checkV, int dy, 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() && canScrolls(child, true, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; }// w ww . ja v a2s .co m } } return checkV && ViewCompat.canScrollVertically(v, -dy); // return checkV && ViewCompat.canScrollHorizontally(v, -dx); }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
/** * Tests scrollability within child views of v given a delta of dy. * * @param v View to test for vertical scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). * @param dy Delta scrolled in pixels/*w ww.j av a2 s .com*/ * @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 dy, 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } /* end of if */ } /* end of for */ } /* end of if */ return checkV && ViewCompat.canScrollVertically(v, -dy); }
From source file:com.plusot.senselib.SenseMain.java
private void toggleLarge(View view) { int id = view.getId() - SenseMain.VIEW_ID_BASE; if (id < 0 || id > 7) return;//from ww w. j av a 2 s .co m large[id] ^= true; for (View tempView : valueViews) { if (view != tempView && tempView != null) { if (large[id]) tempView.setVisibility(View.GONE); else tempView.setVisibility(View.VISIBLE); } } for (ViewGroup vg : vgs) { if (vg.getChildAt(0) == view || vg.getChildAt(1) == view) { } else { if (large[id]) { vg.setVisibility(View.GONE); } else if (vg.getChildCount() > 0) { vg.setVisibility(View.VISIBLE); } } } }
From source file:com.example.view.VerticalViewPager.java
/** * Tests scrollability within child views of v given a delta of dy. * // w w w. jav a 2s . co m * @param v * View to test for vertical scrollability * @param checkV * Whether the view v passed should itself be checked for * scrollability (true), or just its children (false). * @param dy * 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 dy, 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } /* end of if */ } /* end of for */ } /* end of if */ return checkV && ViewCompat.canScrollVertically(v, -dy); }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
/** * Recursively enable/disable all the views contained in a ViewGroup and * it's descendants.// w w w . jav a 2s . c o m * * @param enable when true views will be disable * @param vg a ViewGroup that will be modified */ private void disableEnableControls(boolean enable, ViewGroup vg) { for (int i = 0; i < vg.getChildCount(); i++) { View child = vg.getChildAt(i); if (child instanceof ViewGroup) { disableEnableControls(enable, (ViewGroup) child); } else { if (child != null) { child.setEnabled(enable); } else { Log.w(OTPApp.TAG, "Not possible to fully perform process to disable all controls"); } } } }