List of usage examples for android.view View getTop
@ViewDebug.CapturedViewProperty public final int getTop()
From source file:com.ebaonet.lawyer.ui.weight.DraggableGridViewPager.java
private void animateDragged() { if (mLastDragged >= 0) { final View v = getChildAt(mLastDragged); final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); r.inset(-r.width() / 20, -r.height() / 20); v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY)); v.layout(r.left, r.top, r.right, r.bottom); AnimationSet animSet = new AnimationSet(true); ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2); scale.setDuration(ANIMATION_DURATION); AlphaAnimation alpha = new AlphaAnimation(1, .8f); alpha.setDuration(ANIMATION_DURATION); animSet.addAnimation(scale);/* w w w. j a v a 2s . c o m*/ animSet.addAnimation(alpha); animSet.setFillEnabled(true); animSet.setFillAfter(true); v.clearAnimation(); v.startAnimation(animSet); } }
From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java
/** * Resets all the appropriate fields to a default state while also animating * the hover cell back to its correct location. */// w ww. ja v a 2s . c om private void touchEventsEnded() { final View mobileView = getViewForID(mMobileItemId); if (mCellIsMobile || mIsWaitingForScrollFinish) { mCellIsMobile = false; mIsWaitingForScrollFinish = false; mIsMobileScrolling = false; mActivePointerId = INVALID_POINTER_ID; // If the autoscroller has not completed scrolling, we need to wait for it to // finish in order to determine the final location of where the hover cell // should be animated to. if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) { mIsWaitingForScrollFinish = true; return; } mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop()); ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator, mHoverCellCurrentBounds); hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { invalidate(); } }); hoverViewAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { setEnabled(false); } @Override public void onAnimationEnd(Animator animation) { mAboveItemId = INVALID_ID; mMobileItemId = INVALID_ID; mBelowItemId = INVALID_ID; mobileView.setVisibility(VISIBLE); mHoverCell = null; setEnabled(true); invalidate(); } }); hoverViewAnimator.start(); } else { touchEventsCancelled(); } }
From source file:com.base.view.slidemenu.SlideMenu.java
protected final boolean canScrollVertically(View v, int dy, int x, int y) { 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() && View.VISIBLE == child.getVisibility() && (ScrollDetectors.canScrollVertical(child, dy) || canScrollVertically(child, dy, x + scrollX - left, y + scrollY - top))) { return true; }// w w w . j ava2 s.c o m } } return ViewCompat.canScrollVertically(v, -dy); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.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).//from ww w. ja v a2s . com * @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--) { 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.base.view.slidemenu.SlideMenu.java
/** * Detect whether the views inside content are slidable *///ww w . j ava2s .c o m protected final boolean canScrollHorizontally(View v, int dx, int x, int y) { 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() && View.VISIBLE == child.getVisibility() && (ScrollDetectors.canScrollHorizontal(child, dx) || canScrollHorizontally(child, dx, x + scrollX - left, y + scrollY - top))) { return true; } } } return ViewCompat.canScrollHorizontally(v, -dx); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
void updateObscuredViewVisibility() { if (getChildCount() == 0) { return;/*from w w w . java2 s . co m*/ } final int leftBound = getPaddingLeft(); final int rightBound = getWidth() - getPaddingRight(); final int topBound = getPaddingTop(); final int bottomBound = getHeight() - getPaddingBottom(); final int left; final int right; final int top; final int bottom; if (mSlideableView != null && hasOpaqueBackground(mSlideableView)) { left = mSlideableView.getLeft(); right = mSlideableView.getRight(); top = mSlideableView.getTop(); bottom = mSlideableView.getBottom(); } else { left = right = top = bottom = 0; } View child = getChildAt(0); final int clampedChildLeft = Math.max(leftBound, child.getLeft()); final int clampedChildTop = Math.max(topBound, child.getTop()); final int clampedChildRight = Math.min(rightBound, child.getRight()); final int clampedChildBottom = Math.min(bottomBound, child.getBottom()); final int vis; if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right && clampedChildBottom <= bottom) { vis = INVISIBLE; } else { vis = VISIBLE; } child.setVisibility(vis); }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateCommit(JSONArray commitJ) { if (findViewById(R.id.commit_list) == null) return;/* w ww. j a va 2 s.co m*/ commitList = (ListView) findViewById(R.id.commit_list); myCommitments = new ArrayList<JSONObject>(); ArrayList<JSONObject> commitArray = new ArrayList<JSONObject>(); for (int i = 0; i < commitJ.length(); i++) { try { JSONObject commit = commitJ.getJSONObject(i); if (commit.getString("type").equals("repeat")) { JSONObject usersJ = commit.getJSONObject("users"); for (int j = 0; j < usersJ.names().length(); j++) { if (usersJ.names().get(j).equals(username)) { myCommitments.add(commit); } } } if (openCommitments.size() == i) { openCommitments.add(false); commit.put("open", false); } else commit.put("open", openCommitments.get(i)); commitArray.add(commit); } catch (JSONException e) { e.printStackTrace(); } } // save index and top position int index = commitList.getFirstVisiblePosition(); View v = commitList.getChildAt(0); int top = (v == null) ? 0 : v.getTop(); AdapterCommit adapter = new AdapterCommit(this, R.layout.list_item_commit, commitArray, username); commitList.setAdapter(adapter); // restore index and position commitList.setSelectionFromTop(index, top); }
From source file:android.support.designox.widget.CollapsingToolbarLayout.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); // Update the collapsed bounds by getting it's transformed bounds. This needs to be done // before the children are offset below if (mCollapsingTitleEnabled && mDummyView != null) { // We only draw the title if the dummy view is being displayed (Toolbar removes // views if there is no space) mDrawCollapsingTitle = ViewCompat.isAttachedToWindow(mDummyView) && mDummyView.getVisibility() == VISIBLE; if (mDrawCollapsingTitle) { int bottomOffset = 0; if (mToolbarDirectChild != null && mToolbarDirectChild != this) { final LayoutParams lp = (LayoutParams) mToolbarDirectChild.getLayoutParams(); bottomOffset = lp.bottomMargin; }/*ww w . j av a 2 s .c o m*/ ViewGroupUtils.getDescendantRect(this, mDummyView, mTmpRect); mCollapsingTextHelper.setCollapsedBounds(mTmpRect.left, bottom - mTmpRect.height() - bottomOffset, mTmpRect.right, bottom - bottomOffset); final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // Update the expanded bounds mCollapsingTextHelper.setExpandedBounds(isRtl ? mExpandedMarginEnd : mExpandedMarginStart, mTmpRect.bottom + mExpandedMarginTop, right - left - (isRtl ? mExpandedMarginStart : mExpandedMarginEnd), bottom - top - mExpandedMarginBottom); // Now recalculate using the new bounds mCollapsingTextHelper.recalculate(); } } // Update our child view offset helpers for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); if (mLastInsets != null && !ViewCompat.getFitsSystemWindows(child)) { final int insetTop = mLastInsets.getSystemWindowInsetTop(); if (child.getTop() < insetTop) { // If the child isn't set to fit system windows but is drawing within the inset // offset it down ViewCompat.offsetTopAndBottom(child, insetTop); } } getViewOffsetHelper(child).onViewLayout(); } // Finally, set our minimum height to enable proper AppBarLayout collapsing if (mToolbar != null) { if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) { // If we do not currently have a title, try and grab it from the Toolbar mCollapsingTextHelper.setText(mToolbar.getTitle()); } if (mToolbarDirectChild == null || mToolbarDirectChild == this) { setMinimumHeight(getHeightWithMargins(mToolbar)); } else { setMinimumHeight(getHeightWithMargins(mToolbarDirectChild)); } } }
From source file:com.example.customview.DynamicListView.java
/** * Resets all the appropriate fields to a default state while also animating * the hover cell back to its correct location. *///from w w w . j a v a 2 s . c o m private void touchEventsEnded() { final View mobileView = getViewForID(mMobileItemId); if (mCellIsMobile || mIsWaitingForScrollFinish) { mCellIsMobile = false; mIsWaitingForScrollFinish = false; mIsMobileScrolling = false; mActivePointerId = INVALID_POINTER_ID; // If the autoscroller has not completed scrolling, we need to wait for it to // finish in order to determine the final location of where the hover cell // should be animated to. if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) { mIsWaitingForScrollFinish = true; return; } mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop()); ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator, mHoverCellCurrentBounds); hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { invalidate(); } }); hoverViewAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { setEnabled(false); } @Override public void onAnimationEnd(Animator animation) { mAboveItemId = INVALID_ID; mMobileItemId = INVALID_ID; mBelowItemId = INVALID_ID; mobileView.setVisibility(VISIBLE); mHoverCell = null; setEnabled(true); invalidate(); } }); hoverViewAnimator.start(); } else { touchEventsCancelled(); } }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateChat(JSONArray chats, boolean admin) { if (findViewById(R.id.chat_list) == null) return;/* ww w . j av a 2 s . c om*/ chatList = (ListView) findViewById(R.id.chat_list); int newChatNo = 0; int latestChatTime = 0; ArrayList<JSONObject> chatArray = new ArrayList<JSONObject>(); if (chats.length() < lastChatArray.size()) { // prepend old chats for (int i = chats.length(); i < lastChatArray.size(); i++) { chatArray.add(lastChatArray.get(i)); } } for (int i = 0; i < chats.length(); i++) { try { JSONObject chat = chats.getJSONObject(i); latestChatTime = Integer.parseInt(chat.getString("time")); if (latestChatTime > lastChatTime) newChatNo++; chatArray.add(chat); } catch (JSONException e) { e.printStackTrace(); } } lastChatArray = chatArray; if (latestChatTime < lastChatTime) newChatNo = -1; if (admin) chatList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { String cid = (String) view.findViewById(R.id.message).getTag(); ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); doSubmit("delchat_" + cid, nvp, true); return true; } }); // save index and top position int index = chatList.getFirstVisiblePosition(); View v = chatList.getChildAt(0); int top = (v == null) ? 0 : v.getTop(); AdapterChat adapter = new AdapterChat(this, R.layout.list_item_chat, chatArray); chatList.setAdapter(adapter); // restore index and position if (doChatScroll) { chatList.setSelection(adapter.getCount() - 1); doChatScroll = false; } else chatList.setSelectionFromTop(index, top); if (newChatNo > 0) { if (currentPosition != 1 && lastChatTime > 0) { final MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.tick); mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { mp.release(); } }); mp.start(); newChats = true; ActionBar actionBar = getSupportActionBar(); if (actionBar.getTabAt(1) != null) actionBar.getTabAt(1).setText( Html.fromHtml(getString(R.string.title_section2).toUpperCase(Locale.getDefault()) + " (" + newChatNo + ")")); } } lastChatTime = latestChatTime; }