List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:com.cairoconfessions.MainActivity.java
public void addItem(View view) { // Instantiate a new "row" view. final ViewGroup mFilter = (ViewGroup) findViewById(R.id.filter_cat); final ViewGroup mFilterLoc = (ViewGroup) findViewById(R.id.filter_loc); final ViewGroup mFilterMain = (ViewGroup) findViewById(R.id.filter_main); final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); final ViewGroup newViewLoc = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null);/* w w w . j av a 2s .c o m*/ final ViewGroup newViewMain = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null); ArrayList<View> presentView = new ArrayList<View>(); mFilter.findViewsWithText(presentView, ((TextView) view).getText(), 1); if (presentView.size() == 0) { final String filterName = ((TextView) view).getText().toString(); switch (((LinearLayout) view.getParent()).getId()) { case R.id.cat_filter_list: Categories.add(filterName); break; case R.id.locations: Cities.add(filterName); break; } if (filterName.equals("Love")) { newView.getChildAt(0).setBackgroundResource(R.color.love); newViewLoc.getChildAt(0).setBackgroundResource(R.color.love); newViewMain.getChildAt(0).setBackgroundResource(R.color.love); } if (filterName.equals("Pain")) { newView.getChildAt(0).setBackgroundResource(R.color.pain); newViewLoc.getChildAt(0).setBackgroundResource(R.color.pain); newViewMain.getChildAt(0).setBackgroundResource(R.color.pain); } if (filterName.equals("Guilt")) { newView.getChildAt(0).setBackgroundResource(R.color.guilt); newViewLoc.getChildAt(0).setBackgroundResource(R.color.guilt); newViewMain.getChildAt(0).setBackgroundResource(R.color.guilt); } if (filterName.equals("Fantasy")) { newView.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewLoc.getChildAt(0).setBackgroundResource(R.color.fantasy); newViewMain.getChildAt(0).setBackgroundResource(R.color.fantasy); } if (filterName.equals("Dream")) { newView.getChildAt(0).setBackgroundResource(R.color.dream); newViewLoc.getChildAt(0).setBackgroundResource(R.color.dream); newViewMain.getChildAt(0).setBackgroundResource(R.color.dream); } ((TextView) newView.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewLoc.findViewById(android.R.id.text1)).setText(filterName); ((TextView) newViewMain.findViewById(android.R.id.text1)).setText(filterName); // Set a click listener for the "X" button in the row that will // remove the row. newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilter.removeView(newView); mFilterLoc.removeView(newViewLoc); mFilterMain.removeView(newViewMain); if (mFilter.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewLoc.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterLoc.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); newViewMain.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mFilterLoc.removeView(newViewLoc); mFilter.removeView(newView); mFilterMain.removeView(newViewMain); if (mFilterMain.getChildCount() == 0) { findViewById(R.id.content_loc).setVisibility(View.GONE); findViewById(R.id.content_cat).setVisibility(View.GONE); findViewById(R.id.content_main).setVisibility(View.GONE); } if (Categories.contains(filterName)) while (Categories.remove(filterName)) ; if (Cities.contains(filterName)) while (Cities.remove(filterName)) ; updateFilters(); } }); // Because mFilter has android:animateLayoutChanges set to true, // adding this view is automatically animated. // mFilterCat.addView(newViewCat); mFilter.addView(newView, 0); mFilterLoc.addView(newViewLoc, 0); mFilterMain.addView(newViewMain, 0); findViewById(R.id.content_loc).setVisibility(View.VISIBLE); findViewById(R.id.content_cat).setVisibility(View.VISIBLE); findViewById(R.id.content_main).setVisibility(View.VISIBLE); updateFilters(); Toast.makeText(this, filterName + " filter added!", Toast.LENGTH_LONG).show(); } else Toast.makeText(this, "Already added!", Toast.LENGTH_LONG).show(); }
From source file:android.support.transition.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 ww. ja v a 2s. c om*/ */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } boolean isListViewItem = false; if (view.getParent() instanceof ListView) { isListViewItem = true; } if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) { // ignore listview children unless we can track them with stable IDs return; } int id = View.NO_ID; long itemId = View.NO_ID; if (!isListViewItem) { id = view.getId(); } else { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); itemId = listview.getItemIdAtPosition(position); ViewCompat.setHasTransientState(view, true); } 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; } } } TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } if (start) { if (!isListViewItem) { mStartValues.viewValues.put(view, values); if (id >= 0) { mStartValues.idValues.put((int) id, values); } } else { mStartValues.itemIdValues.put(itemId, values); } } else { if (!isListViewItem) { mEndValues.viewValues.put(view, values); if (id >= 0) { mEndValues.idValues.put((int) id, values); } } else { mEndValues.itemIdValues.put(itemId, 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 && view != 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.givewaygames.transition.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.j av a 2 s .co m*/ */ private void captureHierarchy(View view, boolean start) { if (view == null) { return; } boolean isListViewItem = false; if (view.getParent() instanceof ListView) { isListViewItem = true; } if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) { // ignore listview children unless we can track them with stable IDs return; } int id = View.NO_ID; long itemId = View.NO_ID; if (!isListViewItem) { id = view.getId(); } else { ListView listview = (ListView) view.getParent(); int position = listview.getPositionForView(view); itemId = listview.getItemIdAtPosition(position); view.setHasTransientState(true); } 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; } } } TransitionValues values = new TransitionValues(); values.view = view; if (start) { captureStartValues(values); } else { captureEndValues(values); } if (start) { if (!isListViewItem) { mStartValues.viewValues.put(view, values); if (id >= 0) { mStartValues.idValues.put((int) id, values); } } else { mStartValues.itemIdValues.put(itemId, values); } } else { if (!isListViewItem) { mEndValues.viewValues.put(view, values); if (id >= 0) { mEndValues.idValues.put((int) id, values); } } else { mEndValues.itemIdValues.put(itemId, 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 && view != 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.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
private boolean isDrawerViewOrChild(View child) { if (child == mDrawerView) return true; if (mDrawerView instanceof ViewGroup) { ViewGroup parent = (ViewGroup) mDrawerView; int count = parent.getChildCount(); for (int i = 0; i < count; i++) { if (parent.getChildAt(i) == child) return true; }// www .j a va2 s . co m } return false; }
From source file:com.lansun.qmyo.view.ViewDragHelper.java
/** * Tests scrollability within child views of v given a delta of dx. * // w w w .j a v a2 s. com * @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 along the X axis * @param dy * Delta scrolled in pixels along the Y axis * @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 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--) { // 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, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }
From source file:com.todoroo.astrid.adapter.TaskAdapter.java
/** Creates a new view for use in the list view */ @Override//from ww w . j a v a 2s . co m public View newView(Context context, Cursor cursor, ViewGroup parent) { ViewGroup view = (ViewGroup) inflater.inflate(R.layout.task_adapter_row_simple, parent, false); // create view holder ViewHolder viewHolder = new ViewHolder(); viewHolder.task = new Task(); viewHolder.rowBody = (ViewGroup) view.findViewById(R.id.rowBody); viewHolder.nameView = (TextView) view.findViewById(R.id.title); viewHolder.completeBox = (CheckableImageView) view.findViewById(R.id.completeBox); viewHolder.dueDate = (TextView) view.findViewById(R.id.due_date); viewHolder.tagBlock = (TextView) view.findViewById(R.id.tag_block); viewHolder.taskActionContainer = view.findViewById(R.id.taskActionContainer); viewHolder.taskActionIcon = (ImageView) view.findViewById(R.id.taskActionIcon); boolean showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false); if (showFullTaskTitle) { viewHolder.nameView.setMaxLines(Integer.MAX_VALUE); viewHolder.nameView.setSingleLine(false); viewHolder.nameView.setEllipsize(null); } view.setTag(viewHolder); for (int i = 0; i < view.getChildCount(); i++) { view.getChildAt(i).setTag(viewHolder); } // add UI component listeners addListeners(view); return view; }
From source file:android.support.v7.preference.Preference.java
/** * Makes sure the view (and any children) get the enabled state changed. *///from w w w. ja v a 2 s . c om private void setEnabledStateOnViews(View v, boolean enabled) { v.setEnabled(enabled); if (v instanceof ViewGroup) { final ViewGroup vg = (ViewGroup) v; for (int i = vg.getChildCount() - 1; i >= 0; i--) { setEnabledStateOnViews(vg.getChildAt(i), enabled); } } }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
View findTopChildUnder(View view, int x, int y) { if (view instanceof ViewGroup) { ViewGroup parent = (ViewGroup) view; final int childCount = parent.getChildCount(); for (int i = childCount - 1; i >= 0; i--) { final View child = parent.getChildAt(i); if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { return child; }/*w w w . j av a2 s. c om*/ } } return null; }
From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java
private void rebuildNotifications() { final long now = SystemClock.elapsedRealtime(); ViewGroup container = mIconsContainer; final int childCount = container.getChildCount(); // Count the number of non-notification fragments // such as unlock or music controls fragments. int start = 0; for (int i = 0; i < childCount; i++) { View child = container.getChildAt(i); Widget fragment = findWidgetByIcon(child); if (fragment instanceof NotifyWidget) { // Those fragments are placed at the begin of layout // so no reason to continue searching. break; } else {// w w w. j a v a 2 s .co m start++; } } final ArrayList<OpenNotification> list = NotificationPresenter.getInstance().getList(); final int notifyCount = list.size(); final boolean[] notifyUsed = new boolean[notifyCount]; final boolean[] childUsed = new boolean[childCount]; for (int i = start; i < childCount; i++) { View child = container.getChildAt(i); NotifyWidget widget = (NotifyWidget) findWidgetByIcon(child); OpenNotification target = widget.getNotification(); for (int j = 0; j < notifyCount; j++) { OpenNotification n = list.get(j); if (NotificationUtils.hasIdenticalIds(target, n)) { notifyUsed[j] = true; childUsed[i] = true; if (target != n) { widget.setNotification(n); } break; } } } // Re-use free views and remove redundant views. boolean removeAllAfter = false; for (int a = start, j = 0, offset = 0; a < childCount; a++) { if (childUsed[a]) continue; final int i = a + offset; View child = container.getChildAt(i); removing_all_next_views: { if (!removeAllAfter) { for (; j < notifyCount; j++) { if (notifyUsed[j]) continue; assert child != null; notifyUsed[j] = true; NotifyWidget nw = (NotifyWidget) findWidgetByIcon(child); nw.setNotification(list.get(j)); break removing_all_next_views; } } removeAllAfter = true; internalReleaseWidget(child); // Remove widget's icon. container.removeViewAt(i); offset--; } } assert getActivity() != null; LayoutInflater inflater = getActivity().getLayoutInflater(); final int iconSize = getConfig().getIconSizePx(); for (int i = 0; i < notifyCount; i++) { if (notifyUsed[i]) continue; NotifyWidget nw = new NotifyWidget(this, this); if (isResumed()) nw.start(); View iconView = nw.createIconView(inflater, container); ViewUtils.setSize(iconView, iconSize); container.addView(iconView); nw.setNotification(list.get(i)); mWidgetsMap.put(iconView, nw); } // ///////////////////// // ~~ UPDATE HASH MAP ~~ // ///////////////////// HashMap<String, SceneCompat> map = (HashMap<String, SceneCompat>) mScenesMap.clone(); mScenesMap.clear(); for (Widget fragment : mWidgetsMap.values()) { String type = fragment.getClass().getName(); SceneCompat scene = map.get(type); if (scene != null) { fragment.createView(null, null, scene.getView()); } else { ViewGroup sceneView = fragment.createView(inflater, mSceneContainer, null); if (sceneView != null) { scene = new SceneCompat(mSceneContainer, sceneView); map.put(type, scene); } } if (scene != null) { mScenesMap.put(type, scene); } } if (DEBUG) { long delta = SystemClock.elapsedRealtime() - now; Log.d(TAG, "Fragment list updated in " + delta + "ms."); } // Do not animate divider's visibility change on // pause/resume, cause it _somehow_ confuses people. boolean animate = !mResuming; updateDividerVisibility(animate); }
From source file:com.chauthai.swipereveallayout.ViewDragHelper.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 along the X axis * @param dy Delta scrolled in pixels along the Y axis * @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 ww w. j a v a 2 s. c om protected boolean canScroll(View v, boolean checkV, int dx, 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, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }