List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java
@Override public int getBaseline() { View child = null; if (getChildCount() > 0) { child = getChildAt(0);/*www . j a va 2s . c om*/ } else if (mAdapter != null && mAdapter.getCount() > 0) { child = makeAndAddView(0); mRecycler.put(0, child); removeAllViewsInLayout(); } if (child != null) { final int childBaseline = child.getBaseline(); return childBaseline >= 0 ? child.getTop() + childBaseline : -1; } else { return -1; } }
From source file:com.crazymin2.retailstore.ui.BaseActivity.java
protected void enableActionBarAutoHide(final ListView listView) { initActionBarAutoHide();// w w w .ja v a2 s . c o m listView.setOnScrollListener(new AbsListView.OnScrollListener() { /** The heights of all items. */ private Map<Integer, Integer> heights = new HashMap<Integer, Integer>(); private int lastCurrentScrollY = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // Get the first visible item's view. View firstVisibleItemView = view.getChildAt(0); if (firstVisibleItemView == null) { return; } // Save the height of the visible item. heights.put(firstVisibleItem, firstVisibleItemView.getHeight()); // Calculate the height of all previous (hidden) items. int previousItemsHeight = 0; for (int i = 0; i < firstVisibleItem; i++) { previousItemsHeight += heights.get(i) != null ? heights.get(i) : 0; } int currentScrollY = previousItemsHeight - firstVisibleItemView.getTop() + view.getPaddingTop(); onMainContentScrolled(currentScrollY, currentScrollY - lastCurrentScrollY); lastCurrentScrollY = currentScrollY; } }); }
From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java
/** * Updates the scrollbar.//from w w w .j a v a2s. c o m * * @param newSongList The updated list of songs for the playlist. * @param listPlayingID The current playing playlist id. */ protected void updateScrollbar(final ArrayList newSongList, final int listPlayingID) { mActivity.runOnUiThread(new Runnable() { /** * This is a helper method to workaround shortcomings of the fast scroll API. * * @param scrollbarStyle The {@code View} scrollbar style. * @param isAlwaysVisible The visibility of the scrollbar. */ private void refreshFastScrollStyle(final int scrollbarStyle, final boolean isAlwaysVisible) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mList.setFastScrollAlwaysVisible(isAlwaysVisible); mList.setScrollBarStyle(scrollbarStyle); } else { mList.setScrollBarStyle(scrollbarStyle); mList.setFastScrollAlwaysVisible(isAlwaysVisible); } } @Override public void run() { final int firstVisibleElementIndex = mList.getFirstVisiblePosition(); final View firstVisibleItem = mList.getChildAt(0); final int firstVisiblePosition; final ArrayAdapter songs = new QueueAdapter(mActivity, R.layout.playlist_queue_item, newSongList); if (firstVisibleItem != null) { firstVisiblePosition = firstVisibleItem.getTop(); } else { firstVisiblePosition = 0; } setListAdapter(songs); mSongList = newSongList; songs.notifyDataSetChanged(); /** * Note : Setting the scrollbar style before setting the fast scroll state is very * important pre-KitKat, because of a bug. It is also very important post-KitKat * because it needs the opposite order or it won't show the FastScroll. * * This is so stupid I don't even .... argh. */ if (newSongList.size() >= MIN_SONGS_BEFORE_FASTSCROLL) { refreshFastScrollStyle(View.SCROLLBARS_INSIDE_INSET, true); } else { refreshFastScrollStyle(View.SCROLLBARS_INSIDE_OVERLAY, false); } if (mActionMode != null) { mActionMode.finish(); } // Restore the scroll bar position if (firstVisibleElementIndex == 0 || firstVisiblePosition == 0) { /** * Only scroll if there is a valid song to scroll to. 0 is a valid song but * does not require scroll anyway. Also, only scroll if it's the first update. * You don't want your playlist to scroll itself while you are looking at other * stuff. */ if (listPlayingID > 0 && getView() != null) { setSelection(listPlayingID); } } else { mList.setSelectionFromTop(firstVisibleElementIndex, firstVisiblePosition); } } }); }
From source file:com.aretha.slidemenu.SlideMenu.java
protected final boolean canScroll(View v, int dx, int x, int y) { if (null == mScrollDetector) { return false; }//from ww w . j a va 2 s . co m if (v instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int childCount = viewGroup.getChildCount(); for (int index = 0; index < childCount; index++) { View child = viewGroup.getChildAt(index); final int left = child.getLeft(); final int top = child.getTop(); if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top && y + scrollY < child.getBottom() && (mScrollDetector.isScrollable(child, dx, x + scrollX - left, y + scrollY - top) || canScroll(child, dx, x + scrollX - left, y + scrollY - top))) { return true; } } } return ViewCompat.canScrollHorizontally(v, -dx); }
From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java
private void scrollTo(final View view) { final Rect scrollBounds = new Rect(); scrollContainer.getHitRect(scrollBounds); scrollBounds.set(scrollBounds.left, scrollBounds.top, scrollBounds.right, scrollBounds.bottom - 200); view.getLocalVisibleRect(scrollBounds); if (scrollBounds.height() >= view.getHeight()) { return; // no scroll need }/*from w w w . j ava 2s. c om*/ // Determine where to set the scroll-to to by measuring the distance from the top of the scroll view // to the control to focus on by summing the "top" position of each view in the hierarchy. int yDistanceToControlsView = 0; View parentView = (View) view.getParent(); while (true) { if (parentView.equals(scrollContainer)) { break; } yDistanceToControlsView += parentView.getTop(); parentView = (View) parentView.getParent(); } // Compute the final position value for the top and bottom of the control in the scroll view. final int topInScrollView = yDistanceToControlsView + view.getTop(); final int bottomInScrollView = yDistanceToControlsView + view.getBottom(); // Post the scroll action to happen on the scrollView with the UI thread. scrollContainer.post(new Runnable() { @Override public void run() { int height = view.getHeight(); scrollContainer.smoothScrollTo(0, topInScrollView); //((topInScrollView + bottomInScrollView) / 2) - height); view.requestFocus(); } }); }
From source file:com.example.administrator.common.widget.swipeback.SwipeBackLayout.java
private void drawScrim(Canvas canvas, View child) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int alpha = (int) (baseAlpha * mScrimOpacity); final int color = alpha << 24 | (mScrimColor & 0xffffff); if ((mTrackingEdge & EDGE_LEFT) != 0) { canvas.clipRect(0, 0, child.getLeft(), getHeight()); } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { canvas.clipRect(child.getRight(), 0, getRight(), getHeight()); } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight()); } else if ((mTrackingEdge & EDGE_TOP) != 0) { canvas.clipRect(0, child.getTop(), 0, getHeight()); }/*from w ww. j ava 2 s . co m*/ canvas.drawColor(color); }
From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RecyclerViewSwipeManager.java
private boolean handleActionDown(RecyclerView rv, MotionEvent e) { final RecyclerView.Adapter adapter = rv.getAdapter(); final RecyclerView.ViewHolder holder = CustomRecyclerViewUtils.findChildViewHolderUnderWithTranslation(rv, e.getX(), e.getY());//from www. jav a 2s. c o m if (!(holder instanceof SwipeableItemViewHolder)) { return false; } final int itemPosition = CustomRecyclerViewUtils.getSynchronizedPosition(holder); // verify the touched item is valid state if (!(itemPosition >= 0 && itemPosition < adapter.getItemCount())) { return false; } if (holder.getItemId() != adapter.getItemId(itemPosition)) { return false; } final int touchX = (int) (e.getX() + 0.5f); final int touchY = (int) (e.getY() + 0.5f); final View view = holder.itemView; final int translateX = (int) (ViewCompat.getTranslationX(view) + 0.5f); final int translateY = (int) (ViewCompat.getTranslationY(view) + 0.5f); final int viewX = touchX - (view.getLeft() + translateX); final int viewY = touchY - (view.getTop() + translateY); final int reactionType = mAdapter.getSwipeReactionType(holder, itemPosition, viewX, viewY); if (reactionType == 0) { return false; } mInitialTouchX = touchX; mInitialTouchY = touchY; mCheckingTouchSlop = holder.getItemId(); mSwipingItemReactionType = reactionType; if ((reactionType & REACTION_START_SWIPE_ON_LONG_PRESS) != 0) { mHandler.startLongPressDetection(e, mLongPressTimeout); } return true; }
From source file:android.support.v7.widget.DropDownListView.java
private void setPressedItem(View child, int position, float x, float y) { mDrawsInPressedState = true;//from w w w . j a va2s . com // Ordering is essential. First, update the container's pressed state. if (Build.VERSION.SDK_INT >= 21) { drawableHotspotChanged(x, y); } if (!isPressed()) { setPressed(true); } // Next, run layout to stabilize child positions. layoutChildren(); // Manage the pressed view based on motion position. This allows us to // play nicely with actual touch and scroll events. if (mMotionPosition != INVALID_POSITION) { final View motionView = getChildAt(mMotionPosition - getFirstVisiblePosition()); if (motionView != null && motionView != child && motionView.isPressed()) { motionView.setPressed(false); } } mMotionPosition = position; // Offset for child coordinates. final float childX = x - child.getLeft(); final float childY = y - child.getTop(); if (Build.VERSION.SDK_INT >= 21) { child.drawableHotspotChanged(childX, childY); } if (!child.isPressed()) { child.setPressed(true); } // Ensure that keyboard focus starts from the last touched position. positionSelectorLikeTouchCompat(position, child, x, y); // This needs some explanation. We need to disable the selector for this next call // due to the way that ListViewCompat works. Otherwise both ListView and ListViewCompat // will draw the selector and bad things happen. setSelectorEnabled(false); // Refresh the drawable state to reflect the new pressed state, // which will also update the selector state. refreshDrawableState(); }
From source file:com.app.blockydemo.ui.adapter.BrickAdapter.java
private int calculateItemPositionAndTouchPointY(View view) { return dragAndDropListView.pointToPosition(view.getLeft(), view.getTop()); }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Calculates the position the item should have when it is dropped. * * @return The new position for the item *//*from w w w . j av a2s. c o m*/ public int calculateNewPosition() { int itemsOnScreen = recyclerView.getLayoutManager().getChildCount(); updateFloatingItemCenter(); int before = 0; int pos = 0; int after = Integer.MAX_VALUE; for (int screenPosition = 0; screenPosition < itemsOnScreen; screenPosition++) { //Grabs the view at screenPosition View view = recyclerView.getLayoutManager().getChildAt(screenPosition); if (view.getVisibility() != View.VISIBLE) { continue; } //Makes sure we don't compare to itself int itemPos = recyclerView.getChildAdapterPosition(view); if (itemPos == selectedDragItemPosition) { continue; } //Performs the Vertical position calculations if (orientation == LayoutOrientation.VERTICAL) { float viewMiddleY = view.getTop() + (view.getHeight() / 2); if (floatingItemCenter.y > viewMiddleY && itemPos > before) { before = itemPos; pos = screenPosition; } else if (floatingItemCenter.y <= viewMiddleY && itemPos < after) { after = itemPos; pos = screenPosition; } } //Performs the Horizontal position calculations if (orientation == LayoutOrientation.HORIZONTAL) { float viewMiddleX = view.getLeft() + (view.getWidth() / 2); if (floatingItemCenter.x > viewMiddleX && itemPos > before) { before = itemPos; pos = screenPosition; } else if (floatingItemCenter.x <= viewMiddleX && itemPos < after) { after = itemPos; pos = screenPosition; } } } int newPosition; if (after != Integer.MAX_VALUE) { if (after < selectedDragItemPosition) { newPosition = after; updateNewViewStart(pos, true); } else { newPosition = after - 1; updateNewViewStart(pos - 1, false); } } else { if (before < selectedDragItemPosition) { before++; pos++; } newPosition = before; updateNewViewStart(pos, false); } return newPosition; }