List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * Close the specified drawer view by animating it into view. * /*from w w w .j a va 2 s .c o m*/ * @param drawerView * Drawer view to close */ public void closeDrawer(View drawerView) { if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } if (mFirstLayout) { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; lp.knownOpen = false; } else { switch (getDrawerViewAbsoluteGravity(drawerView)) { case Gravity.LEFT: if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) mLeftDragger.smoothSlideViewTo(drawerView, -drawerView.getWidth(), drawerView.getTop()); break; case Gravity.RIGHT: if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) mRightDragger.smoothSlideViewTo(drawerView, getWidth(), drawerView.getTop()); break; case Gravity.TOP: if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP)) mTopDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), -drawerView.getHeight()); break; case Gravity.BOTTOM: if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.BOTTOM)) mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), getHeight()); break; default: mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), getHeight()); break; } } invalidate(); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition2() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;/* w w w .jav a 2 s .c o m*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_CLASS, PositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = t1.getTop(); View t2 = v.findViewById(R.id.t2); int t2align = t2.getTop() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition3() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;/* w w w . jav a 2s . c om*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_VIEWTYPE_CLASS, ViewTypePositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = t1.getTop(); View t2 = v.findViewById(R.id.t2); int t2align = t2.getBottom() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testMultipleScrollPosition1() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.relative_layout); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 300;/*from w ww . j av a 2 s . c o m*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_VIEWTYPEPROVIDER_CLASS, TwoViewTypesProvider.class.getName()); // Set ItemAlignment for each ViewHolder and view type, ViewHolder should // override the view type settings. intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_CLASS, PositionItemAlignmentFacetProviderForRelativeLayout1.class.getName()); intent.putExtra(GridActivity.EXTRA_ITEMALIGNMENTPROVIDER_VIEWTYPE_CLASS, ViewTypePositionItemAlignmentFacetProviderForRelativeLayout2.class.getName()); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); assertEquals("First view is aligned with padding top", mGridView.getPaddingTop(), mGridView.getChildAt(0).getTop()); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); final View v = mGridView.getChildAt(0); View t1 = v.findViewById(R.id.t1); int t1align = (t1.getTop() + t1.getBottom()) / 2; View t2 = v.findViewById(R.id.t2); int t2align = t2.getBottom() - 10; assertEquals("Expected alignment for 2nd textview", mGridView.getPaddingTop() - (t2align - t1align), v.getTop()); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testExtraLayoutSpace() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 1000); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); initActivity(intent);/*from w ww .j a v a 2s . co m*/ final int windowSize = mGridView.getHeight(); final int extraLayoutSize = windowSize; int itemLength = mActivity.mItemLengths[0]; mOrientation = BaseGridView.VERTICAL; mNumRows = 1; // add extra layout space runTestOnUiThread(new Runnable() { public void run() { mGridView.setExtraLayoutSpace(extraLayoutSize); } }); Thread.sleep(50); View v; v = mGridView.getChildAt(mGridView.getChildCount() - 1); assertTrue(v.getTop() < windowSize + extraLayoutSize); assertTrue(v.getBottom() >= windowSize + extraLayoutSize - mGridView.getVerticalMargin()); mGridView.setSelectedPositionSmooth(150); waitForScrollIdle(mVerifyLayout); v = mGridView.getChildAt(0); assertTrue(v.getBottom() > -extraLayoutSize); assertTrue(v.getTop() <= -extraLayoutSize + mGridView.getVerticalMargin()); // clear extra layout space runTestOnUiThread(new Runnable() { public void run() { mGridView.setExtraLayoutSpace(0); verifyMargin(); } }); Thread.sleep(50); v = mGridView.getChildAt(mGridView.getChildCount() - 1); assertTrue(v.getTop() < windowSize); assertTrue(v.getBottom() >= windowSize - mGridView.getVerticalMargin()); }
From source file:com.ad.view.staggeredgridview.StaggeredGridView.java
/** * Important: this method will leave offscreen views attached if they are * required to maintain the invariant that child view with index i is always * the view corresponding to position mFirstPosition + i. *///from w w w .j a v a 2 s . co m private void recycleOffscreenViews() { final int height = getHeight(); final int clearAbove = -mItemMargin; final int clearBelow = height + mItemMargin; for (int i = getChildCount() - 1; i >= 0; i--) { final View child = getChildAt(i); if (child.getTop() <= clearBelow) { // There may be other offscreen views, but we need to maintain // the invariant documented above. break; } if (mInLayout) { removeViewsInLayout(i, 1); } else { removeViewAt(i); } mRecycler.addScrap(child); } while (getChildCount() > 0) { final View child = getChildAt(0); if (child.getBottom() >= clearAbove) { // There may be other offscreen views, but we need to maintain // the invariant documented above. break; } if (mInLayout) { removeViewsInLayout(0, 1); } else { removeViewAt(0); } mRecycler.addScrap(child); mFirstPosition++; } final int childCount = getChildCount(); if (childCount > 0) { // Repair the top and bottom column boundaries from the views we // still have Arrays.fill(mItemTops, Integer.MAX_VALUE); Arrays.fill(mItemBottoms, Integer.MIN_VALUE); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int top = child.getTop() - mItemMargin; final int bottom = child.getBottom(); final LayoutRecord rec = mLayoutRecords.get(mFirstPosition + i); final int colEnd = lp.column + Math.min(mColCount, lp.span); for (int col = lp.column; col < colEnd; col++) { final int colTop = top - rec.getMarginAbove(col - lp.column); final int colBottom = bottom + rec.getMarginBelow(col - lp.column); if (colTop < mItemTops[col]) { mItemTops[col] = colTop; } if (colBottom > mItemBottoms[col]) { mItemBottoms[col] = colBottom; } } } for (int col = 0; col < mColCount; col++) { if (mItemTops[col] == Integer.MAX_VALUE) { // If one was untouched, both were. mItemTops[col] = 0; mItemBottoms[col] = 0; } } } }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
/** * Pagekeypad?//from w w w .j av a2s . co m * @param direction ? * @return handled */ public boolean arrowScroll(int direction) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null; boolean handled = false; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction); if (nextFocused != null && nextFocused != currentFocused) { if (direction == View.FOCUS_UP) { // If there is nothing to the left, or this is causing us to // jump to the down, then what we really want to do is page up. if (currentFocused != null && nextFocused.getTop() >= currentFocused.getTop()) { handled = pageUp(); } else { handled = nextFocused.requestFocus(); } /* end of if */ } else if (direction == View.FOCUS_DOWN) { // If there is nothing to the right, or this is causing us to // jump to the left, then what we really want to do is page right. if (currentFocused != null && nextFocused.getTop() <= currentFocused.getTop()) { handled = pageDown(); } else { handled = nextFocused.requestFocus(); } /* end of if */ } /* end of if */ } else if (direction == FOCUS_UP || direction == FOCUS_BACKWARD) { // Trying to move left and nothing there; try to page. handled = pageUp(); } else if (direction == FOCUS_DOWN || direction == FOCUS_FORWARD) { // Trying to move right and nothing there; try to page. handled = pageDown(); } /* end of if */ if (handled) { playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); } /* end of if */ return handled; }
From source file:chan.android.app.bitwise.util.StaggeredGridView.java
final void offsetChildren(int offset) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); child.layout(child.getLeft(), child.getTop() + offset, child.getRight(), child.getBottom() + offset); }/*from ww w. j a v a 2s.c o m*/ final int colCount = mColCount; for (int i = 0; i < colCount; i++) { mItemTops[i] += offset; mItemBottoms[i] += offset; } }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
/** * Group and sort children by their position on each row (HORIZONTAL) or column(VERTICAL). *//*from w ww. j ava 2 s . c o m*/ protected View[][] sortByRows() { final HashMap<Integer, ArrayList<View>> rows = new HashMap<Integer, ArrayList<View>>(); ArrayList<Integer> rowLocations = new ArrayList(); for (int i = 0; i < mGridView.getChildCount(); i++) { View v = mGridView.getChildAt(i); int rowLocation; if (mOrientation == BaseGridView.HORIZONTAL) { rowLocation = v.getTop(); } else { rowLocation = mGridView.getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_RTL ? v.getRight() : v.getLeft(); } ArrayList<View> views = rows.get(rowLocation); if (views == null) { views = new ArrayList<View>(); rows.put(rowLocation, views); rowLocations.add(rowLocation); } views.add(v); } Object[] sortedLocations = rowLocations.toArray(); Arrays.sort(sortedLocations); if (mNumRows != rows.size()) { assertEquals("Dump Views by rows " + rows, mNumRows, rows.size()); } View[][] sorted = new View[rows.size()][]; for (int i = 0; i < rowLocations.size(); i++) { Integer rowLocation = rowLocations.get(i); ArrayList<View> arr = rows.get(rowLocation); View[] views = arr.toArray(new View[arr.size()]); Arrays.sort(views, mRowSortComparator); sorted[i] = views; } return sorted; }