List of usage examples for android.view ViewGroup getChildCount
public int getChildCount()
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.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//from w ww .j av a2 s. c o m * @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.tjych.swip.vertical.DirectionalViewPager.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/* ww w .j av a2 s. c o m*/ * @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--) { // 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); }
From source file:com.minoon.stackviewpagersample.StackViewPager.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/* ww w. ja va 2 s.c om*/ * @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; // [Changed] // final int scrollX = v.getScrollX(); final int scrollX = (int) v.getTranslationX(); 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.telerik.examples.primitives.ExampleViewPagerBase.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 * @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 . ja v a 2s . c o m protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scroll = getScroll(v); final int invertedScroll = getInvertedScroll(v); 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 + scroll >= getStart(child) && x + scroll < getEnd(child) && y + invertedScroll >= getInvertedStart(child) && y + invertedScroll < getInvertedEnd(child) && canScroll(child, true, dx, x + scroll - getStart(child), y + invertedScroll - getInvertedStart(child))) { return true; } } } return checkV && getCanScroll(v, -dx); }
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.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/*from w ww. j av a2s.c o m*/ * @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; } } } boolean canScroll = false; if (isOrientationHorizontal()) { canScroll = ViewCompat.canScrollHorizontally(v, -dx); } else { canScroll = ViewCompat.canScrollVertically(v, -dx); } return checkV && canScroll; }
From source file:com.viewpagerindicator.MyDirectionalViewPager.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 dposition 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. *//*w w w . j ava2 s . co m*/ protected boolean canScroll(View v, boolean checkV, int dposition, 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, dposition, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } if (mOrientation == HORIZONTAL) { return checkV && ViewCompat.canScrollHorizontally(v, -dposition); } else { return checkV && ViewCompat.canScrollVertically(v, -dposition); } }
From source file:com.guide.ViewPager.java
/** * Tests scrollability within child views of v given a delta of dx. * //from w w w. j ava2 s. co m * @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; } } } boolean canScroll = false; if (isOrientationHorizontal()) { canScroll = ViewCompat.canScrollHorizontally(v, -dx); } else { canScroll = ViewCompat.canScrollVertically(v, -dx); } return checkV && canScroll; }
From source file:android.improving.utils.views.cardsview.OrientedViewPager.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 delta 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. *///from w w w . j av a2s. c o m protected boolean canScroll(View v, boolean checkV, int delta, 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 (mOrientation == Orientation.VERTICAL) { if (y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && canScroll(child, true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } else { if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, delta, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } } return checkV && ViewCompat.canScrollVertically(v, -delta); }
From source file:dev.dworks.libs.widget.ViewPager.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 d Delta scrolled in pixels/*from ww w.j a va 2 s . c o m*/ * @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 d, 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, d, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } boolean canScroll; if (mOrientation == HORIZONTAL) { canScroll = checkV && ViewCompat.canScrollHorizontally(v, -d); } else { canScroll = checkV && ViewCompat.canScrollVertically(v, -d); } return canScroll; }
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);//from w ww . ja va 2 s . co 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(); }