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:net.osmand.plus.views.controls.DynamicListView.java

/**
 * Returns the most inner view that contains the xy coordinate.
 *
 * @param v This method gets called recursively. The initial call should be the root view.
 * @param x The X location to be tested.
 * @param y The Y location to be tested.
 * @return Returns the most inner view that contains the XY coordinate or null if no view could be found.
 *///ww  w  .  j  a v  a 2  s  . c o  m
private View findViewAtPositionWithDragIconTag(View v, int x, int y) {
    View vXY = null;

    if (v instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) v;

        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View c = viewGroup.getChildAt(i);

            int loc[] = new int[2];
            c.getLocationOnScreen(loc);

            if ((x >= loc[0] && (x <= (loc[0] + c.getWidth())))
                    && (y >= loc[1] && (y <= (loc[1] + c.getHeight())))) {
                vXY = c;
                View viewAtPosition = findViewAtPositionWithDragIconTag(c, x, y);

                if ((viewAtPosition != null) && (viewAtPosition.getTag() != null)
                        && viewAtPosition.getTag() instanceof DragIcon) {
                    vXY = viewAtPosition;
                    break;
                }
            }
        }
    }

    return vXY;
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void refreshAnnotationNumber(ViewGroup viewGroup) {
    if (viewGroup != null) {
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof TextAnnotationView) {
                TextView textView = (((TextAnnotationView) child).getAnnotationNumberView());
                String newAnnotationNumber = Integer
                        .toString(Integer.valueOf(textView.getText().toString()) - 1);
                if (Integer.valueOf(newAnnotationNumber) != 0) {
                    textView.setText(newAnnotationNumber);
                }// w w  w.j a v a 2 s .  c  o m
            }
        }
    }
}

From source file:net.openwatch.acluaz.fragment.FormFragment.java

public JSONObject toJson(ViewGroup container, JSONObject json) {
    String TAG = "FormFragment-ToJSON";
    if (container == null) {
        Log.e(TAG, "null container passed to toJson");
        return new JSONObject();
    }//  ww  w. j  a  v a 2  s.c om

    if (json == null)
        json = new JSONObject();
    View view;
    for (int x = 0; x < container.getChildCount(); x++) {
        view = container.getChildAt(x);

        if (EditText.class.isInstance(view)) {
            if (view.getTag() != null) {
                if (((EditText) view).getText().toString().compareTo("") == 0)
                    continue; // skip blank input
                try {
                    Log.i(TAG, "Mapping: " + view.getTag().toString() + " value: "
                            + ((EditText) view).getText().toString());
                    if (view.getTag().toString().compareTo(getString(R.string.zipcode_tag)) == 0)
                        json.put(view.getTag().toString(),
                                Integer.parseInt(((EditText) view).getText().toString()));
                    else
                        json.put(view.getTag().toString(), ((EditText) view).getText().toString());
                } catch (JSONException e) {
                    Log.e(TAG, "Error jsonifying text input");
                    e.printStackTrace();
                }

            }
        } else if (CompoundButton.class.isAssignableFrom(view.getClass())) {
            if (view.getTag() != null) {
                // if location toggle, bundle location
                if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) != null) {
                    if (((CompoundButton) view).isChecked()) {
                        try {
                            json.put(getString(R.string.device_lat),
                                    ((Location) view.getTag(R.id.view_tag)).getLatitude());
                            json.put(getString(R.string.device_lon),
                                    ((Location) view.getTag(R.id.view_tag)).getLongitude());
                        } catch (JSONException e) {
                            Log.e(TAG, "Error jsonifying toggle input");
                            e.printStackTrace();
                        }
                    }
                } else if (((String) view.getTag()).compareTo(getString(R.string.device_location_tag)) == 0
                        && view.getTag(R.id.view_tag) == null) {
                    // no location tagged, get last known
                    LocationManager lm = (LocationManager) container.getContext()
                            .getSystemService(Context.LOCATION_SERVICE);
                    Location last = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    try {
                        json.put(getString(R.string.device_lat), last.getLatitude());
                        json.put(getString(R.string.device_lon), last.getLongitude());
                    } catch (JSONException e) {
                        Log.e(TAG, "Error jsonifying last location");
                        e.printStackTrace();
                    } catch (NullPointerException e2) {
                        Log.e(TAG, "No current or historical location info on this device");
                    }
                }

            }
        }

        // combine date and time fields into a single datetime
        if (json.has(getString(R.string.date_tag)) && json.has(getString(R.string.time_tag))) {
            Log.i(TAG, "found date and time tag, let's smush 'em");
            try {
                //TESTING
                //String datetime = combineDateAndTime(json.getString(getString(R.string.date_tag)), json.getString(getString(R.string.time_tag)));
                //Log.i(TAG,"datetime: " + datetime);
                json.put(getString(R.string.date_tag),
                        combineDateAndTime(json.getString(getString(R.string.date_tag)),
                                json.getString(getString(R.string.time_tag))));
                Log.i(TAG, json.toString());
                //json.remove(getString(R.string.date_tag));
                json.remove(getString(R.string.time_tag));
            } catch (JSONException e) {
                Log.e(TAG, "Error creating json datetime field from date and time");
                e.printStackTrace();
            }
        }

    }
    Log.i(TAG, "toJson: " + json.toString());
    return json;

}

From source file:net.sf.aria2.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean offerUpNav;

    // at some point after API 11 framework begins to throw, when you use old style..
    if (Build.VERSION.SDK_INT < HONEYCOMB) {
        initLegacyPrefs();//from w w w  . j ava 2s  . c  o  m
        offerUpNav = false;
    } else
        offerUpNav = isOfferingUpNav();

    final LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.activity_prefs, null);

    // transplant content view children (created for us by framework)
    final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    final int contentChildrenCount = root.getChildCount();
    final List<View> childViews = new ArrayList<>(contentChildrenCount);

    for (int i = 0; i < contentChildrenCount; ++i)
        childViews.add(root.getChildAt(i));

    root.removeAllViews();

    for (View childView : childViews)
        toolbarContainer.addView(childView);

    root.addView(toolbarContainer);

    // initialize toolbar
    final Toolbar toolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);
    toolbar.setTitle(getTitle());

    if (offerUpNav) {
        toolbar.setLogo(null);
        toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        toolbar.setNavigationOnClickListener(v -> goUp());
    } else {
        toolbar.setNavigationIcon(null);
        toolbar.setLogo(R.drawable.aria2_logo);
    }
}

From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java

/**
 * Returns user ids from the SectionView
 *
 * @param userIdsView//from   www.  ja  va 2 s .  com
 * @return
 */
private ArrayList<String> getUserIds(SectionView userIdsView) throws PgpGeneralException {
    ArrayList<String> userIds = new ArrayList<String>();

    ViewGroup userIdEditors = userIdsView.getEditors();

    boolean gotMainUserId = false;
    for (int i = 0; i < userIdEditors.getChildCount(); ++i) {
        UserIdEditor editor = (UserIdEditor) userIdEditors.getChildAt(i);
        String userId;
        userId = editor.getValue();

        if (editor.isMainUserId()) {
            userIds.add(0, userId);
            gotMainUserId = true;
        } else {
            userIds.add(userId);
        }
    }

    if (userIds.size() == 0) {
        throw new PgpGeneralException(getString(R.string.error_key_needs_a_user_id));
    }

    if (!gotMainUserId) {
        throw new PgpGeneralException(getString(R.string.error_main_user_id_must_not_be_empty));
    }

    return userIds;
}

From source file:com.gome.haoyuangong.views.SwipeRefreshLayout.java

private void disableSubControls(View view) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View v = viewGroup.getChildAt(i);
            if (v instanceof ViewGroup) {
                if (v instanceof Spinner) {
                    v.setPressed(false);
                } else if (v instanceof ListView) {
                    removeListTapCallback((ListView) v);
                } else {
                    removeViewTapCallback(v);
                    disableSubControls((ViewGroup) v);
                }/*  w w  w.  j  a  v a 2 s. c o m*/
            } else {
                removeViewTapCallback(v);
            }
        }
    } else {
        removeViewTapCallback(view);
    }
}

From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java

private void updateLinksTab(Cursor cursor) {
    ViewGroup container = (ViewGroup) mRootView.findViewById(R.id.links_container);

    // Remove all views but the 'empty' view
    int childCount = container.getChildCount();
    if (childCount > 1) {
        container.removeViews(1, childCount - 1);
    }/*from w  w  w  .j a  v  a  2s  .c om*/

    LayoutInflater inflater = getLayoutInflater(null);

    boolean hasLinks = false;
    for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) {
        final String url = cursor.getString(SessionsQuery.LINKS_INDICES[i]);
        if (!TextUtils.isEmpty(url)) {
            hasLinks = true;
            ViewGroup linkContainer = (ViewGroup) inflater.inflate(R.layout.list_item_session_link, container,
                    false);
            ((TextView) linkContainer.findViewById(R.id.link_text)).setText(SessionsQuery.LINKS_TITLES[i]);
            final int linkTitleIndex = i;
            linkContainer.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    fireLinkEvent(SessionsQuery.LINKS_TITLES[linkTitleIndex]);
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    startActivity(intent);

                }
            });

            container.addView(linkContainer);

            // Create separator
            View separatorView = new ImageView(getActivity());
            separatorView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            separatorView.setBackgroundResource(android.R.drawable.divider_horizontal_bright);
            container.addView(separatorView);
        }
    }

    container.findViewById(R.id.empty_links).setVisibility(hasLinks ? View.GONE : View.VISIBLE);
}

From source file:android.support.design.widget.BottomSheetBehavior.java

private View findScrollingChild(View view) {
    if (view instanceof NestedScrollingChild) {
        return view;
    }/*from   ww w . java2 s  . com*/
    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.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  w ww.  j  a  v a2s.com*/
        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:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void hideAllControlItems(ViewGroup viewGroup) {
    // Hide all control items
    if (viewGroup != null) {
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof StickerAnnotationView) {
                ((StickerAnnotationView) child).setControlItemsHidden(true);
            } else if (child instanceof TextAnnotationView) {
                ((TextAnnotationView) child).setControlItemsHidden(true);
            }//from  www .  j a  v a2  s .  c  o  m
        }
    }
}