Example usage for android.view ViewGroup getChildCount

List of usage examples for android.view ViewGroup getChildCount

Introduction

In this page you can find the example usage for android.view ViewGroup getChildCount.

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:com.android.launcher3.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 v  a2 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>();
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (CellLayout layoutParent : cellLayouts) {
        ViewGroup layout = layoutParent.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:self.philbrown.droidQuery.$.java

/**
 * Loops through all the sibling views of the first view in the current selection, and wraps 
 * each in a droidQuery object. When invoked, the given function will receive two parameters:
 * <ol>//from w w  w  .  j  a v a  2 s .c om
 * <li>the droidQuery for the view
 * <li>the child index of the sibling
 * </ol>
 * @param function receives the droidQuery for the view, and the index for arg1
 */
public $ siblings(Function function) {
    ViewParent parent = view(0).getParent();
    if (parent != null && parent instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) parent;
        for (int i = 0; i < group.getChildCount(); i++) {
            function.invoke($.with(group.getChildAt(i)), i);
        }
    }
    return this;
}

From source file:com.upchannel.launcher3.Workspace.java

void removeItemsByComponentName(final HashSet<ComponentName> componentNames, final UserHandleCompat user) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>();
        for (int j = 0; j < layout.getChildCount(); j++) {
            final View view = layout.getChildAt(j);
            children.put((ItemInfo) view.getTag(), view);
        }/*from   w w  w .ja v a  2 s .  co  m*/

        final ArrayList<View> childrenToRemove = new ArrayList<View>();
        final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfo, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
                if (parent instanceof FolderInfo) {
                    if (componentNames.contains(cn) && info.user.equals(user)) {
                        FolderInfo folder = (FolderInfo) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    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 apps from their folders
        for (FolderInfo folder : folderAppsToRemove.keySet()) {
            ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }

        // 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.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.android.launcher3.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.//w  w  w  . ja  v  a 2s  .c  om
 */
void removeItemsByComponentName(final HashSet<ComponentName> componentNames, final UserHandleCompat user) {
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (final CellLayout layoutParent : cellLayouts) {
        final ViewGroup layout = layoutParent.getShortcutsAndWidgets();

        final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>();
        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>();
        final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = new HashMap<FolderInfo, ArrayList<ShortcutInfo>>();
        LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
            @Override
            public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
                if (parent instanceof FolderInfo) {
                    if (componentNames.contains(cn) && info.user.equals(user)) {
                        FolderInfo folder = (FolderInfo) parent;
                        ArrayList<ShortcutInfo> appsToRemove;
                        if (folderAppsToRemove.containsKey(folder)) {
                            appsToRemove = folderAppsToRemove.get(folder);
                        } else {
                            appsToRemove = new ArrayList<ShortcutInfo>();
                            folderAppsToRemove.put(folder, appsToRemove);
                        }
                        appsToRemove.add((ShortcutInfo) info);
                        return true;
                    }
                } else {
                    if (componentNames.contains(cn) && info.user.equals(user)) {
                        childrenToRemove.add(children.get(info));
                        return true;
                    }
                }
                return false;
            }
        };
        LauncherModel.filterItemInfos(children.keySet(), filter);

        /*SPRD: bug410501 coverity 105605 problem, Inefficient Map Iterator, 2015-3-3. @{
        // Remove all the apps from their folders
        for (FolderInfo folder : folderAppsToRemove.keySet()) {
        ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder);
        for (ShortcutInfo info : appsToRemove) {
            folder.remove(info);
        }
        }*/
        Iterator iter = folderAppsToRemove.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<FolderInfo, ArrayList<ShortcutInfo>> entry = (Map.Entry<FolderInfo, ArrayList<ShortcutInfo>>) iter
                    .next();
            FolderInfo folder = entry.getKey();
            ArrayList<ShortcutInfo> appsToRemove = entry.getValue();
            for (ShortcutInfo info : appsToRemove) {
                folder.remove(info);
            }
        }
        /*SPRD: bug410501 coverity 105605 problem, Inefficient Map Iterator, 2015-3-3. @{*/

        // 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.
            layoutParent.removeViewInLayout(child);
            if (child instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) child);
            }
        }

        if (childrenToRemove.size() > 0) {
            layout.requestLayout();
            layout.invalidate();
        }
    }

    // Strip all the empty screens
    stripEmptyScreens();
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void dismissPreview(final View v) {
    final PopupWindow window = (PopupWindow) v.getTag(R.id.TAG_PREVIEW);
    if (window != null) {
        hideDesktop(false);//from  ww  w. j  a va2s.  co m
        window.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @SuppressWarnings("unchecked")
            public void onDismiss() {
                ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
                int count = group.getChildCount();
                for (int i = 0; i < count; i++) {
                    ((ImageView) group.getChildAt(i)).setImageDrawable(null);
                }
                ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
                for (Bitmap bitmap : bitmaps)
                    bitmap.recycle();

                v.setTag(R.id.workspace, null);
                v.setTag(R.id.icon, null);
                window.setOnDismissListener(null);
            }
        });
        window.dismiss();
        showingPreviews = false;
        mWorkspace.unlock();
        mWorkspace.invalidate();
        mDesktopLocked = false;
    }
    v.setTag(R.id.TAG_PREVIEW, null);
}

From source file:android.app.Activity.java

private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) {
    writer.print(prefix);//from w w  w .  j a  v a 2 s . c  om
    if (view == null) {
        writer.println("null");
        return;
    }
    writer.println(view.toString());
    if (!(view instanceof ViewGroup)) {
        return;
    }
    ViewGroup grp = (ViewGroup) view;
    final int N = grp.getChildCount();
    if (N <= 0) {
        return;
    }
    prefix = prefix + "  ";
    for (int i = 0; i < N; i++) {
        dumpViewHierarchy(prefix, writer, grp.getChildAt(i));
    }
}

From source file:org.telegram.ui.ArticleViewer.java

private ImageReceiver getImageReceiverFromListView(ViewGroup listView, TLRPC.PageBlock pageBlock,
        int[] coords) {
    int count = listView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view instanceof BlockPhotoCell) {
            BlockPhotoCell cell = (BlockPhotoCell) view;
            if (cell.currentBlock == pageBlock) {
                view.getLocationInWindow(coords);
                return cell.imageView;
            }//  w  w w.j av a  2  s . com
        } else if (view instanceof BlockVideoCell) {
            BlockVideoCell cell = (BlockVideoCell) view;
            if (cell.currentBlock == pageBlock) {
                view.getLocationInWindow(coords);
                return cell.imageView;
            }
        } else if (view instanceof BlockCollageCell) {
            ImageReceiver imageReceiver = getImageReceiverFromListView(((BlockCollageCell) view).innerListView,
                    pageBlock, coords);
            if (imageReceiver != null) {
                return imageReceiver;
            }
        } else if (view instanceof BlockSlideshowCell) {
            ImageReceiver imageReceiver = getImageReceiverFromListView(
                    ((BlockSlideshowCell) view).innerListView, pageBlock, coords);
            if (imageReceiver != null) {
                return imageReceiver;
            }
        }
    }
    return null;
}

From source file:jmri.enginedriver.throttle.java

void set_function_labels_and_listeners_for_view(int whichThrottle) {
    // Log.d("Engine_Driver","starting set_function_labels_and_listeners_for_view");

    //        // implemented in derived class, but called from this class

    if (fbs != null) { // if it is null it probably because the Throttle Screen Type does not have Functions Buttons
        if (fbs[0] != null) {
            ViewGroup tv; // group
            ViewGroup r; // row
            function_button_touch_listener fbtl;
            Button b; // button
            int k = 0; // button count
            LinkedHashMap<Integer, String> function_labels_temp;
            LinkedHashMap<Integer, Button> functionButtonMap = new LinkedHashMap<>();

            tv = fbs[whichThrottle];//from w  w w .j ava2 s. com

            // note: we make a copy of function_labels_x because TA might change it
            // while we are using it (causing issues during button update below)
            function_labels_temp = mainapp.function_labels_default;
            if (!prefAlwaysUseDefaultFunctionLabels) { //avoid npe
                if (mainapp.function_labels != null && mainapp.function_labels[whichThrottle] != null
                        && mainapp.function_labels[whichThrottle].size() > 0) {
                    function_labels_temp = new LinkedHashMap<>(mainapp.function_labels[whichThrottle]);
                } else {
                    if (mainapp.consists != null) { //avoid npe maybe
                        if (mainapp.consists[whichThrottle] != null
                                && !mainapp.consists[whichThrottle].isLeadFromRoster()) {
                            function_labels_temp = mainapp.function_labels_default;
                        } else {
                            function_labels_temp = mainapp.function_labels_default_for_roster;
                        }
                    }
                }
            }

            // put values in array for indexing in next step
            // to do this
            ArrayList<Integer> aList = new ArrayList<>(function_labels_temp.keySet());

            if (tv != null) {
                for (int i = 0; i < tv.getChildCount(); i++) {
                    r = (ViewGroup) tv.getChildAt(i);
                    for (int j = 0; j < r.getChildCount(); j++) {
                        b = (Button) r.getChildAt(j);
                        if (k < function_labels_temp.size()) {
                            Integer func = aList.get(k);
                            functionButtonMap.put(func, b); // save function to button
                            // mapping
                            String bt = function_labels_temp.get(func);
                            fbtl = new function_button_touch_listener(func, whichThrottle, bt);
                            b.setOnTouchListener(fbtl);
                            //                                if ((mainapp.getCurrentTheme().equals(THEME_DEFAULT))) {
                            //                                    bt = bt + "        ";  // pad with spaces, and limit to 7 characters
                            //                                    b.setText(bt.substring(0, 7));
                            //                                } else {
                            bt = bt + "                      "; // pad with spaces, and limit to 20 characters
                            b.setText(bt.trim());
                            //                                }
                            b.setVisibility(View.VISIBLE);
                            b.setEnabled(false); // start out with everything disabled
                        } else {
                            b.setVisibility(View.GONE);
                        }
                        k++;
                    }
                }
            }

            // update the function-to-button map for the current throttle
            functionMaps[whichThrottle] = functionButtonMap;
        }
    }
}

From source file:com.ferdi2005.secondgram.support.widget.RecyclerView.java

/**
 * Utility method for finding an internal RecyclerView, if present
 *//*from w  w w .j av a 2  s .  c o m*/
@Nullable
static RecyclerView findNestedRecyclerView(@NonNull View view) {
    if (!(view instanceof ViewGroup)) {
        return null;
    }
    if (view instanceof RecyclerView) {
        return (RecyclerView) view;
    }
    final ViewGroup parent = (ViewGroup) view;
    final int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView descendant = findNestedRecyclerView(child);
        if (descendant != null) {
            return descendant;
        }
    }
    return null;
}