List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:com.dm.xz.views.PinnedSectionListView.java
/** Makes sure we have an actual pinned shadow for given position. */ void ensureShadowForPosition(int sectionPosition, int firstVisibleItem, int visibleItemCount) { if (visibleItemCount < 2) { // no need for creating shadow at all, we have a single visible item destroyPinnedShadow();/*from w w w .ja va 2s. co m*/ return; } if (mPinnedSection != null && mPinnedSection.position != sectionPosition) { // invalidate shadow, if required destroyPinnedShadow(); } if (mPinnedSection == null) { // create shadow, if empty createPinnedShadow(sectionPosition); } // align shadow according to next section position, if needed int nextPosition = sectionPosition + 1; if (nextPosition < getCount()) { int nextSectionPosition = findFirstVisibleSectionPosition(nextPosition, visibleItemCount - (nextPosition - firstVisibleItem)); if (nextSectionPosition > -1) { View nextSectionView = getChildAt(nextSectionPosition - firstVisibleItem); final int bottom = mPinnedSection.view.getBottom() + getPaddingTop(); mSectionsDistanceY = nextSectionView.getTop() - bottom; if (mSectionsDistanceY < 0) { // next section overlaps pinned shadow, move it up mTranslateY = mSectionsDistanceY; } else { // next section does not overlap with pinned, stick to top mTranslateY = 0; } } else { // no other sections are visible, stick to top mTranslateY = 0; mSectionsDistanceY = Integer.MAX_VALUE; } } }
From source file:com.androidarchitecture.widgets.RecyclerViewSwipeToDeleteImpl.java
/** * This is the standard support library way of implementing "swipe to delete" feature. You can do custom drawing in onChildDraw method * but whatever you draw will disappear once the swipe is over, and while the items are animating to their new position the recycler view * background will be visible. That is rarely an desired effect. *//* w w w .j av a 2s . c om*/ private void setUpItemTouchHelper() { ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { // we want to cache these and not allocate anything repeatedly in the onChildDraw method Drawable background; Drawable xMark; int xMarkMargin; boolean initiated; private void init() { background = new ColorDrawable(ContextCompat.getColor(mContext, R.color.colorPrimary)); xMark = ContextCompat.getDrawable(mContext, R.drawable.ic_cancel_black_24dp); xMark.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); xMarkMargin = (int) mContext.getResources().getDimension(R.dimen.activity_margin); initiated = true; } // not important, we don't want drag & drop @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { return super.getSwipeDirs(recyclerView, viewHolder); } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { int swipedPosition = viewHolder.getAdapterPosition(); mListener.removeItem(swipedPosition); } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { View itemView = viewHolder.itemView; // not sure why, but this method get's called for viewHolder that are already swiped away if (viewHolder.getAdapterPosition() == -1) { // not interested in those return; } if (!initiated) { init(); } // draw red background background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom()); background.draw(c); // draw x mark int itemHeight = itemView.getBottom() - itemView.getTop(); int intrinsicWidth = xMark.getIntrinsicWidth(); int intrinsicHeight = xMark.getIntrinsicWidth(); int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth; int xMarkRight = itemView.getRight() - xMarkMargin; int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; int xMarkBottom = xMarkTop + intrinsicHeight; xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); xMark.draw(c); super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }; ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); mItemTouchHelper.attachToRecyclerView(mRecyclerView); }
From source file:com.android.music.AlbumBrowserActivity.java
@Override public void onDestroy() { ListView lv = getListView();//www . j a v a2 s . c om if (lv != null) { mLastListPosCourse = lv.getFirstVisiblePosition(); View cv = lv.getChildAt(0); if (cv != null) { mLastListPosFine = cv.getTop(); } } MusicUtils.unbindFromService(mToken); // If we have an adapter and didn't send it off to another activity yet, we should // close its cursor, which we do by assigning a null cursor to it. Doing this // instead of closing the cursor directly keeps the framework from accessing // the closed cursor later. if (!mAdapterSent && mAdapter != null) { mAdapter.changeCursor(null); } // Because we pass the adapter to the next activity, we need to make // sure it doesn't keep a reference to this activity. We can do this // by clearing its DatasetObservers, which setListAdapter(null) does. setListAdapter(null); mAdapter = null; unregisterReceiver(mScanListener); super.onDestroy(); }
From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.MyExpandableDraggableSwipeableItemAdapter.java
@Override public boolean onCheckGroupCanStartDrag(MyGroupViewHolder holder, int groupPosition, int x, int y) { // x, y --- relative from the itemView's top-left final View containerView = holder.mContainer; final View dragHandleView = holder.mDragHandle; final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f); final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f); return ViewUtil.hitTest(dragHandleView, x - offsetX, y - offsetY); }
From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.MyExpandableDraggableSwipeableItemAdapter.java
@Override public boolean onCheckChildCanStartDrag(MyChildViewHolder holder, int groupPosition, int childPosition, int x, int y) {//from www .java 2s . c om // x, y --- relative from the itemView's top-left final View containerView = holder.mContainer; final View dragHandleView = holder.mDragHandle; final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f); final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f); return ViewUtil.hitTest(dragHandleView, x - offsetX, y - offsetY); }
From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.expandable.MyExpandableDraggableSwipeableItemAdapter.java
@Override public boolean onCheckCanExpandOrCollapseGroup(MyGroupViewHolder holder, int groupPosition, int x, int y, boolean expand) { // check the item is *not* pinned if (mProvider.getGroupItem(groupPosition).isPinnedToSwipeLeft()) { // return false to raise View.OnClickListener#onClick() event return false; }/*from ww w .ja v a2 s. c om*/ // check is enabled if (!(holder.itemView.isEnabled() && holder.itemView.isClickable())) { return false; } final View containerView = holder.mContainer; final View dragHandleView = holder.mDragHandle; final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f); final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f); return !ViewUtil.hitTest(dragHandleView, x - offsetX, y - offsetY); }
From source file:com.scigames.registration.LoginActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { View v = getCurrentFocus();/*w ww . j a v a 2s . c o m*/ Log.d(TAG, "CLICK DETECTED"); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION ); // v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); // Window win = this.getWindow(); // in Activity's onCreate() for instance // win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); boolean ret = super.dispatchTouchEvent(event); if (v instanceof EditText) { View w = getCurrentFocus(); int scrcoords[] = new int[2]; w.getLocationOnScreen(scrcoords); float x = event.getRawX() + w.getLeft() - scrcoords[0]; float y = event.getRawY() + w.getTop() - scrcoords[1]; Log.d("Activity", "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect " + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords " + scrcoords[0] + "," + scrcoords[1]); if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0); } } return ret; }
From source file:com.android.music.ArtistAlbumBrowserFragment.java
@Override public void onDestroy() { // TODO Auto-generated method stub //ExpandableListView lv = getExpandableListView(); if (lv != null) { mLastListPosCourse = lv.getFirstVisiblePosition(); View cv = lv.getChildAt(0); if (cv != null) { mLastListPosFine = cv.getTop(); }/* w w w .j av a 2 s . c om*/ } MusicUtils.unbindFromService(mToken); // If we have an adapter and didn't send it off to another activity yet, we should // close its cursor, which we do by assigning a null cursor to it. Doing this // instead of closing the cursor directly keeps the framework from accessing // the closed cursor later. if (!mAdapterSent && mAdapter != null) { mAdapter.changeCursor(null); } // Because we pass the adapter to the next activity, we need to make // sure it doesn't keep a reference to this activity. We can do this // by clearing its DatasetObservers, which setListAdapter(null) does. //lv.setAdapter(null); mAdapter = null; getActivity().unregisterReceiver(mScanListener); lv.setAdapter(mAdapter); super.onDestroy(); }
From source file:android.widget.PinnedHeaderListView.java
@Override protected void dispatchDraw(final Canvas canvas) { final long currentTime = mAnimating ? System.currentTimeMillis() : 0; int top = 0;//w ww .jav a 2 s. c o m final int right = 0; int bottom = getBottom(); boolean hasVisibleHeaders = false; for (int i = 0; i < mSize; i++) { final PinnedHeader header = mHeaders[i]; if (header.visible) { hasVisibleHeaders = true; if (header.state == BOTTOM && header.y < bottom) bottom = header.y; else if (header.state == TOP || header.state == FADING) { final int newTop = header.y + header.height; if (newTop > top) top = newTop; } } } if (hasVisibleHeaders) canvas.save(); super.dispatchDraw(canvas); if (hasVisibleHeaders) { canvas.restore(); // If the first item is visible and if it has a positive top that is greater than the // first header's assigned y-value, use that for the first header's y value. This way, // the header inherits any padding applied to the list view. if (mSize > 0 && getFirstVisiblePosition() == 0) { final View firstChild = getChildAt(0); final PinnedHeader firstHeader = mHeaders[0]; if (firstHeader != null) { final int firstHeaderTop = firstChild != null ? firstChild.getTop() : 0; firstHeader.y = Math.max(firstHeader.y, firstHeaderTop); } } // First draw top headers, then the bottom ones to handle the Z axis correctly for (int i = mSize; --i >= 0;) { final PinnedHeader header = mHeaders[i]; if (header.visible && (header.state == TOP || header.state == FADING)) drawHeader(canvas, header, currentTime); } for (int i = 0; i < mSize; i++) { final PinnedHeader header = mHeaders[i]; if (header.visible && header.state == BOTTOM) drawHeader(canvas, header, currentTime); } } invalidateIfAnimating(); }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Generates the Bitmap that will be used to represent the view being dragged across the screen * * @param view The view to create the drag bitmap from * @return The bitmap representing the drag view */// w ww . j a va2 s .co m private BitmapDrawable createDragBitmap(View view) { floatingItemStartingBounds = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); floatingItemBounds = new Rect(floatingItemStartingBounds); Bitmap bitmap = Bitmap.createBitmap(floatingItemStartingBounds.width(), floatingItemStartingBounds.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); BitmapDrawable retDrawable = new BitmapDrawable(view.getResources(), bitmap); retDrawable.setBounds(floatingItemBounds); return retDrawable; }