List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:com.cairoconfessions.MainActivity.java
public void addLocation(View view) { TextView newView = new TextView(this); AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation)); String newLoc = addLoc.getText().toString(); ViewGroup locList = ((ViewGroup) findViewById(R.id.locations)); boolean notFound = true; for (int i = 0; i < locList.getChildCount(); i++) { if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString())) notFound = false;//from www.ja v a2s .co m break; } if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) { newView.setText(newLoc); newView.setClickable(true); newView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { addItem(view); } }); float scale = getResources().getDisplayMetrics().density; newView.setGravity(17); newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); newView.setBackgroundResource(R.drawable.city2); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) (150 * scale)); lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale)); newView.setLayoutParams(lp); locList.addView(newView, 0); addLoc.setText(""); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0); addLoc.setCursorVisible(false); } else { Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show(); } }
From source file:com.google.samples.apps.iosched.ui.widget.CollectionView.java
private View createGroupView(RowComputeResult rowInfo, View view, ViewGroup parent) { ViewGroup groupView; if (view != null && view instanceof ViewGroup) { groupView = (ViewGroup) view;// w ww . j av a 2 s .com // If there are more children in the recycled view we remove the extra ones. if (groupView.getChildAt(0) instanceof LinearLayout) { LinearLayout groupViewContent = (LinearLayout) groupView.getChildAt(0); if (groupViewContent.getChildCount() > rowInfo.group.getRowCount()) { groupViewContent.removeViews(rowInfo.group.getRowCount(), groupViewContent.getChildCount() - rowInfo.group.getRowCount()); } } // Use the defined callbacks if the user has chosen to by implementing a // CardsCollectionViewCallbacks. } else if (mCallbacks instanceof CollectionViewCallbacks.GroupCollectionViewCallbacks) { groupView = ((CollectionViewCallbacks.GroupCollectionViewCallbacks) mCallbacks) .newCollectionGroupView(getContext(), rowInfo.groupId, rowInfo.group, parent); // This should never happened but if it does we'll display an EmptyView. } else { LOGE(TAG, "Tried to create a group view but the callback is not an instance of " + "GroupCollectionViewCallbacks"); return new EmptyView(getContext()); } LinearLayout groupViewContent; if (groupView.getChildAt(0) instanceof LinearLayout) { groupViewContent = (LinearLayout) groupView.getChildAt(0); } else { groupViewContent = new LinearLayout(getContext()); groupViewContent.setOrientation(LinearLayout.VERTICAL); LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); groupViewContent.setLayoutParams(LLParams); groupView.addView(groupViewContent); } disableCustomGroupView(); for (int i = 0; i < rowInfo.group.getRowCount(); i++) { View itemView; try { itemView = getRowView(rowInfo.groupOffset + i, groupViewContent.getChildAt(i), groupViewContent); } catch (Exception e) { // Recycling failed (maybe the items were not compatible) so we start again without // recycling. itemView = getRowView(rowInfo.groupOffset + i, null, groupViewContent); } if (itemView != groupViewContent.getChildAt(i)) { if (groupViewContent.getChildCount() > i) { groupViewContent.removeViewAt(i); } groupViewContent.addView(itemView, i); } } enableCustomGroupView(); return groupView; }
From source file:com.razza.apps.iosched.ui.widget.CollectionView.java
private View createGroupView(RowComputeResult rowInfo, View view, ViewGroup parent) { ViewGroup groupView; if (view != null && view instanceof ViewGroup) { groupView = (ViewGroup) view;/* w w w .ja va 2 s . co m*/ // If there are more children in the recycled view we remove the extra ones. if (groupView.getChildAt(0) instanceof LinearLayout) { LinearLayout groupViewContent = (LinearLayout) groupView.getChildAt(0); if (groupViewContent.getChildCount() > rowInfo.group.getRowCount()) { groupViewContent.removeViews(rowInfo.group.getRowCount(), groupViewContent.getChildCount() - rowInfo.group.getRowCount()); } } // Use the defined callbacks if the user has chosen to by implementing a // CardsCollectionViewCallbacks. } else if (mCallbacks instanceof CollectionViewCallbacks.GroupCollectionViewCallbacks) { groupView = ((CollectionViewCallbacks.GroupCollectionViewCallbacks) mCallbacks) .newCollectionGroupView(getContext(), rowInfo.groupId, rowInfo.group, parent); // This should never happened but if it does we'll display an EmptyView. } else { LogUtils.LOGE(TAG, "Tried to create a group view but the callback is not an instance of " + "GroupCollectionViewCallbacks"); return new EmptyView(getContext()); } LinearLayout groupViewContent; if (groupView.getChildAt(0) instanceof LinearLayout) { groupViewContent = (LinearLayout) groupView.getChildAt(0); } else { groupViewContent = new LinearLayout(getContext()); groupViewContent.setOrientation(LinearLayout.VERTICAL); LayoutParams LLParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); groupViewContent.setLayoutParams(LLParams); groupView.addView(groupViewContent); } disableCustomGroupView(); for (int i = 0; i < rowInfo.group.getRowCount(); i++) { View itemView; try { itemView = getRowView(rowInfo.groupOffset + i, groupViewContent.getChildAt(i), groupViewContent); } catch (Exception e) { // Recycling failed (maybe the items were not compatible) so we start again without // recycling. itemView = getRowView(rowInfo.groupOffset + i, null, groupViewContent); } if (itemView != groupViewContent.getChildAt(i)) { if (groupViewContent.getChildCount() > i) { groupViewContent.removeViewAt(i); } groupViewContent.addView(itemView, i); } } enableCustomGroupView(); return groupView; }
From source file:gr.plushost.prototypeapp.widgets.LabelView.java
private boolean replaceLayout(View target) { if (getParent() != null || target == null || target.getParent() == null || _labelViewContainerID != -1) { return false; }/*from ww w . ja va 2s. co m*/ ViewGroup parentContainer = (ViewGroup) target.getParent(); if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { int groupIndex = parentContainer.indexOfChild(target); _labelViewContainerID = generateViewId(); // relativeLayout need copy rule if (target.getParent() instanceof RelativeLayout) { for (int i = 0; i < parentContainer.getChildCount(); i++) { if (i == groupIndex) { continue; } View view = parentContainer.getChildAt(i); RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams(); for (int j = 0; j < para.getRules().length; j++) { if (para.getRules()[j] == target.getId()) { para.getRules()[j] = _labelViewContainerID; } } view.setLayoutParams(para); } } parentContainer.removeView(target); // new dummy layout FrameLayout labelViewContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams targetLayoutParam = target.getLayoutParams(); labelViewContainer.setLayoutParams(targetLayoutParam); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // add target and label in dummy layout labelViewContainer.addView(target); labelViewContainer.addView(this); labelViewContainer.setId(_labelViewContainerID); // add dummy layout in parent container parentContainer.addView(labelViewContainer, groupIndex, targetLayoutParam); } return true; }
From source file:android.support.design.widget.BottomSheetBehavior.java
private View findScrollingChild(View view) { if (view instanceof NestedScrollingChild) { return view; }//w w w . j a v a 2s. c o m if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0, count = group.getChildCount(); i < count; i++) { View scrollingChild = findScrollingChild(group.getChildAt(i)); if (scrollingChild != null) { return scrollingChild; } } } return null; }
From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!allowWidthFull) return;//from w w w . j a v a2 s .c om ViewGroup tabsLayout = getTabsLayout(); if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth()) return; if (tabsLayout.getChildCount() <= 0) return; if (tabViews == null) { tabViews = new ArrayList<View>(); } else { tabViews.clear(); } for (int w = 0; w < tabsLayout.getChildCount(); w++) { tabViews.add(tabsLayout.getChildAt(w)); } adjustChildWidthWithParent(tabViews, getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java
@VisibleForTesting View findScrollingChild(View view) { if (ViewCompat.isNestedScrollingEnabled(view)) { return view; }//ww w. j av a 2s .c o m if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0, count = group.getChildCount(); i < count; i++) { View scrollingChild = findScrollingChild(group.getChildAt(i)); if (scrollingChild != null) { return scrollingChild; } } } return null; }
From source file:com.cicada.startup.common.ui.view.indicator.ViewPagerIndicator.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!allowWidthFull) { return;// w w w . j a va2 s . co m } setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + slidingBlockHeight); ViewGroup tabsLayout = getTabsLayout(); if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth()) return; if (tabsLayout.getChildCount() <= 0) return; if (tabViews == null) { tabViews = new ArrayList<View>(); } else { tabViews.clear(); } for (int w = 0; w < tabsLayout.getChildCount(); w++) { tabViews.add(tabsLayout.getChildAt(w)); } adjustChildWidthWithParent(tabViews, getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
From source file:com.mfh.litecashier.ui.widget.TopSlidingTabStrip.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (!allowWidthFull) return;//from ww w. j a va 2 s . c o m ViewGroup tabsLayout = getTabsLayout(); if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth()) return; if (tabsLayout.getChildCount() <= 0) return; if (tabViews == null) { tabViews = new ArrayList<>(); } else { tabViews.clear(); } for (int w = 0; w < tabsLayout.getChildCount(); w++) { tabViews.add(tabsLayout.getChildAt(w)); } adjustChildWidthWithParent(tabViews, getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java
private HashMap<Integer, String> processStickerAnnotations(ViewGroup viewGroup) { HashMap<Integer, String> allStickerAnnotations = new HashMap<>(); if (viewGroup != null) { for (int i = 0; i < viewGroup.getChildCount(); ++i) { View child = viewGroup.getChildAt(i); if (child instanceof StickerAnnotationImageView) { StickerAnnotationImageView stickerAnnotationImageView = (StickerAnnotationImageView) child; int annotationImageResource = stickerAnnotationImageView.getImageResourceId(); float getX = child.getX(); float getY = child.getY(); int width = child.getWidth(); int height = child.getHeight(); float rotation = child.getRotation(); String value = annotationImageResource + Utils.SEPARATOR + getX + Utils.SEPARATOR + getY + Utils.SEPARATOR + width + Utils.SEPARATOR + height + Utils.SEPARATOR + rotation; allStickerAnnotations.put(i, value); }/*from ww w .j a va2 s . c o m*/ } } return allStickerAnnotations; }