@Override public void onChildDrawOver( Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; c.save(); if (dX > 0) { c.clipRect( itemView.getLeft(), itemView.getTop(), itemView.getLeft() + dX, itemView.getBottom()); c.translate(itemView.getLeft(), itemView.getTop()); } else { c.clipRect( itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom()); c.translate(itemView.getRight() + dX, itemView.getTop()); } mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive); c.restore(); } }
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { Bitmap bitmap = getChildDrawingCache(child); // (top,left) is the pixel position of the child inside the list final int top = child.getTop(); final int left = child.getLeft(); // center point of child final int childCenterY = child.getHeight() / 2; final int childCenterX = child.getWidth() / 2; // center of list final int parentCenterY = -child.getHeight() / 2; // center point of child relative to list final int absChildCenterY = child.getTop() + childCenterY; // distance of child center to the list center final int distanceY = parentCenterY - absChildCenterY; // radius of imaginary circle final int r = getHeight() * 2; prepareMatrix(mMatrix, distanceY, r); mMatrix.preTranslate(-childCenterX, -childCenterY); mMatrix.postTranslate(childCenterX, childCenterY); mMatrix.postTranslate(left, top); canvas.drawBitmap(bitmap, mMatrix, mPaint); return false; }
public void configureHeaderView(int groupPosition, int childPosition) { if (mHeaderView == null || mAdapter == null || ((ExpandableListAdapter) mAdapter).getGroupCount() == 0) { return; } int state = mAdapter.getTreeHeaderState(groupPosition, childPosition); switch (state) { case IphoneTreeHeaderAdapter.PINNED_HEADER_GONE: { mHeaderViewVisible = false; break; } case IphoneTreeHeaderAdapter.PINNED_HEADER_VISIBLE: { mAdapter.configureTreeHeader(mHeaderView, groupPosition, childPosition, MAX_ALPHA); if (mHeaderView.getTop() != 0) { mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight); } mHeaderViewVisible = true; break; } case IphoneTreeHeaderAdapter.PINNED_HEADER_PUSHED_UP: { View firstView = getChildAt(0); int bottom = firstView.getBottom(); // intitemHeight = firstView.getHeight(); int headerHeight = mHeaderView.getHeight(); int y; int alpha; if (bottom < headerHeight) { y = (bottom - headerHeight); alpha = MAX_ALPHA * (headerHeight + y) / headerHeight; } else { y = 0; alpha = MAX_ALPHA; } mAdapter.configureTreeHeader(mHeaderView, groupPosition, childPosition, alpha); if (mHeaderView.getTop() != y) { mHeaderView.layout(0, y, mHeaderViewWidth, mHeaderViewHeight + y); } mHeaderViewVisible = true; break; } } }
public void onClick(View v, int position, int countitem) { ImageView selectedShip = ((MapBuilder) context).getSelectedShip(); if (selectedShip != null) { ShipOnMap som = new ShipOnMap(); RelativeLayout fl = (RelativeLayout) v; RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(selectedShip.getWidth(), selectedShip.getHeight()); som.start.x = x; som.start.y = y - v.getTop(); som.time = (countitem - 1 - position) * 3 + 1; String[] shipinfo = ((String) selectedShip.getTag()).split(":"); som.type = shipinfo[0]; som.weapon = shipinfo[1]; params.leftMargin = x - (selectedShip.getWidth() / 2); params.topMargin = y - v.getTop() - (selectedShip.getHeight() / 2); ImageView iv = new ImageView(context); iv.setImageDrawable(selectedShip.getDrawable()); int h = fl.getHeight(); int w = fl.getWidth(); if (!ship.containsKey(position)) { ship.put(position, new LinkedList<ShipOnMap>()); } som.ship = iv.getDrawable(); som.param = params; List<ShipOnMap> lship = ship.get(position); lship.add(som); iv.setTag(position + "/" + (lship.size() - 1)); ((MapBuilder) context).registerForContextMenu(iv); fl.addView(iv, params); fl.getLayoutParams().height = h; fl.getLayoutParams().width = w; } }
public void hideMenu(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final int cx = (settingsMenuButton.getLeft() + settingsMenuButton.getRight()) / 2; final int cy = ((settingsMenuButton.getTop() + settingsMenuButton.getBottom()) / 2) - settingsMenu.getTop(); Log.i("", "Circle center " + cx + ", " + cy + " width " + bottomView.getWidth()); final Animator anim = ViewAnimationUtils.createCircularReveal(settingsMenu, cx, cy, bottomView.getWidth(), 0); anim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); settingsMenu.setVisibility(View.INVISIBLE); settingsMenuButton.setVisibility(View.VISIBLE); } }); anim.start(); } else { settingsMenuButton.setVisibility(View.VISIBLE); settingsMenu.setVisibility(View.INVISIBLE); } }
void getLayoutCache() { final RelativeLayout parent = (RelativeLayout) findViewById(R.id.parent); View view1 = (View) parent.findViewById(R.id.view1); View view2 = (View) parent.findViewById(R.id.view2); View view3 = (View) parent.findViewById(R.id.view3); View view4 = (View) parent.findViewById(R.id.view4); View view5 = (View) parent.findViewById(R.id.view5); View view12 = (View) parent.findViewById(R.id.view12); String firstColumn = view2.getLeft() + "," + view2.getRight(); layoutCache.put(firstColumn, new HashMap<String, Integer>()); String secondColumn = view1.getLeft() + "," + view1.getRight(); layoutCache.put(secondColumn, new HashMap<String, Integer>()); String thirdColumn = view4.getLeft() + "," + view4.getRight(); layoutCache.put(thirdColumn, new HashMap<String, Integer>()); String firstRow = view3.getTop() + "," + view3.getBottom(); layoutCache.get(firstColumn).put(firstRow, 1); layoutCache.get(secondColumn).put(firstRow, 2); layoutCache.get(thirdColumn).put(firstRow, 3); String secondRow = view5.getTop() + "," + view5.getBottom(); layoutCache.get(firstColumn).put(secondRow, 4); layoutCache.get(secondColumn).put(secondRow, 5); layoutCache.get(thirdColumn).put(secondRow, 6); String thirdRow = view12.getTop() + "," + view12.getBottom(); layoutCache.get(firstColumn).put(thirdRow, 7); layoutCache.get(secondColumn).put(thirdRow, 8); layoutCache.get(thirdColumn).put(thirdRow, 9); }
@Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_MOVE: mApplyResistance = true; if (mState == STATE_IDLE && getScrollY() <= mHeaderView.getTop()) { mState = STATE_READY; notifyStateChanged(); } else if (mState == STATE_READY && getScrollY() > mHeaderView.getTop()) { mState = STATE_IDLE; notifyStateChanged(); } return super.onTouchEvent(ev); case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: // We override this so we stop any flinging of the scroller. // Usually, an ACTION_UP event in a scroll view would result in some extra scrolling // because the user wants to fling through the scroller. However, in our case, we // want to handle all touch up events. // We also want to hide the refresh view. if (mState == STATE_READY) { showHeader(); refresh(); } else { hideRefreshView(); } return true; default: return super.onTouchEvent(ev); } }
protected void refreshHeader() { if (mHeaderView == null) { return; } int firstVisiblePos = getFirstVisiblePosition(); int pos = firstVisiblePos + 1; int firstVisibleGroupPos = getPackedPositionGroup(getExpandableListPosition(firstVisiblePos)); int group = getPackedPositionGroup(getExpandableListPosition(pos)); if (DEBUG) { Log.d(TAG, "refreshHeader firstVisibleGroupPos=" + firstVisibleGroupPos); } if (group == firstVisibleGroupPos + 1) { View view = getChildAt(1); if (view == null) { Log.w(TAG, "Warning : refreshHeader getChildAt(1)=null"); return; } if (view.getTop() <= mHeaderHeight) { int delta = mHeaderHeight - view.getTop(); mHeaderView.layout(0, -delta, mHeaderWidth, mHeaderHeight - delta); } else { // TODO : note it, when cause bug, remove it mHeaderView.layout(0, 0, mHeaderWidth, mHeaderHeight); } } else { mHeaderView.layout(0, 0, mHeaderWidth, mHeaderHeight); } if (mHeaderUpdateListener != null) { mHeaderUpdateListener.updatePinnedHeader(mHeaderView, firstVisibleGroupPos); } }
/** Remember enough information to restore the screen state when the data has changed. */ void rememberSyncState() { if (getChildCount() > 0) { mNeedSync = true; mSyncHeight = mLayoutHeight; if (mSelectedPosition >= 0) { // Sync the selection state View v = getChildAt(mSelectedPosition - mFirstPosition); mSyncRowId = mNextSelectedRowId; mSyncPosition = mNextSelectedPosition; if (v != null) { mSpecificTop = v.getTop(); } mSyncMode = SYNC_SELECTED_POSITION; } else { // Sync the based on the offset of the first view View v = getChildAt(0); T adapter = getAdapter(); if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) { mSyncRowId = adapter.getItemId(mFirstPosition); } else { mSyncRowId = NO_ID; } mSyncPosition = mFirstPosition; if (v != null) { mSpecificTop = v.getTop(); } mSyncMode = SYNC_FIRST_POSITION; } } }
protected void onScrollChanged(int i, int j, int k, int l) { super.onScrollChanged(i, j, k, l); if (mTrackedChild == null) { if (getChildCount() > 0) { mTrackedChild = getChildInTheMiddle(); mTrackedChildPrevTop = mTrackedChild.getTop(); mTrackedChildPrevPosition = getPositionForView(mTrackedChild); } return; } if (mTrackedChild.getParent() == this && getPositionForView(mTrackedChild) == mTrackedChildPrevPosition) { i = 1; } else { i = 0; } if (i != 0) { i = mTrackedChild.getTop(); if (mScrollDeltaListener != null) { j = mTrackedChildPrevTop; mScrollDeltaListener.onScroll(i - j); } mTrackedChildPrevTop = i; return; } else { mTrackedChild = null; return; } }
public void commOnTouchEvent(MotionEvent ev) { int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: y = ev.getY(); break; case MotionEvent.ACTION_UP: if (isNeedAnimation()) { animation(); } break; case MotionEvent.ACTION_MOVE: final float preY = y; float nowY = ev.getY(); int deltaY = (int) (preY - nowY) / size; y = nowY; if (isNeedMove()) { if (normal.isEmpty()) { normal.set(inner.getLeft(), inner.getTop(), inner.getRight(), inner.getBottom()); return; } int yy = inner.getTop() - deltaY; inner.layout(inner.getLeft(), yy, inner.getRight(), inner.getBottom() - deltaY); } break; default: break; } }
private void trySlideAttachmentView(final ViewWrapper viewWrapper) { if (!(viewWrapper.attachment instanceof MediaPickerMessagePartData)) { return; } final View view = viewWrapper.view; final int xOffset = viewWrapper.prevLeft - view.getLeft(); final int yOffset = viewWrapper.prevTop - view.getTop(); final float scaleX = viewWrapper.prevWidth / (float) view.getWidth(); final float scaleY = viewWrapper.prevHeight / (float) view.getHeight(); if (xOffset == 0 && yOffset == 0 && scaleX == 1 && scaleY == 1) { // Layout hasn't changed return; } final AnimationSet animationSet = new AnimationSet(true /* shareInterpolator */); animationSet.addAnimation(new TranslateAnimation(xOffset, 0, yOffset, 0)); animationSet.addAnimation(new ScaleAnimation(scaleX, 1, scaleY, 1)); animationSet.setDuration(UiUtils.MEDIAPICKER_TRANSITION_DURATION); animationSet.setInterpolator(UiUtils.DEFAULT_INTERPOLATOR); view.startAnimation(animationSet); view.invalidate(); viewWrapper.prevLeft = view.getLeft(); viewWrapper.prevTop = view.getTop(); viewWrapper.prevWidth = view.getWidth(); viewWrapper.prevHeight = view.getHeight(); }
private void drawDebugInfo(Canvas canvas, View child) { if (!debugDraw) { return; } Paint childPaint = this.createPaint(0xffffff00); Paint layoutPaint = this.createPaint(0xff00ff00); Paint newLinePaint = this.createPaint(0xffff0000); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.horizontalSpacing > 0) { float x = child.getRight(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y, x + lp.horizontalSpacing, y, childPaint); canvas.drawLine( x + lp.horizontalSpacing - 4.0f, y - 4.0f, x + lp.horizontalSpacing, y, childPaint); canvas.drawLine( x + lp.horizontalSpacing - 4.0f, y + 4.0f, x + lp.horizontalSpacing, y, childPaint); } else if (this.horizontalSpacing > 0) { float x = child.getRight(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y, x + this.horizontalSpacing, y, layoutPaint); canvas.drawLine( x + this.horizontalSpacing - 4.0f, y - 4.0f, x + this.horizontalSpacing, y, layoutPaint); canvas.drawLine( x + this.horizontalSpacing - 4.0f, y + 4.0f, x + this.horizontalSpacing, y, layoutPaint); } if (lp.verticalSpacing > 0) { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getBottom(); canvas.drawLine(x, y, x, y + lp.verticalSpacing, childPaint); canvas.drawLine( x - 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint); canvas.drawLine( x + 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint); } else if (this.verticalSpacing > 0) { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getBottom(); canvas.drawLine(x, y, x, y + this.verticalSpacing, layoutPaint); canvas.drawLine( x - 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint); canvas.drawLine( x + 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint); } if (lp.newLine) { if (orientation == HORIZONTAL) { float x = child.getLeft(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y - 6.0f, x, y + 6.0f, newLinePaint); } else { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getTop(); canvas.drawLine(x - 6.0f, y, x + 6.0f, y, newLinePaint); } } }
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView rv, RecyclerView.State state) { super.getItemOffsets(outRect, view, rv, state); debugLog("getItemOffsets"); debugLog("View top = " + view.getTop()); if (selectedDragItemPos != -1) { int itemPos = rv.getChildPosition(view); debugLog("itemPos =" + itemPos); if (!canDragOver(itemPos)) { return; } // Movement of finger float totalMovement = fingerY - fingerAnchorY; if (itemPos == selectedDragItemPos) { view.setVisibility(View.INVISIBLE); } else { // Make view visible incase invisible view.setVisibility(View.VISIBLE); // Find middle of the floatingItem float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2; // Moving down the list // These will auto-animate if the device continually sends touch motion events // if (totalMovment>0) { if ((itemPos > selectedDragItemPos) && (view.getTop() < floatMiddleY)) { float amountUp = (floatMiddleY - view.getTop()) / (float) view.getHeight(); // amountUp *= 0.5f; if (amountUp > 1) amountUp = 1; outRect.top = -(int) (floatingItemBounds.height() * amountUp); outRect.bottom = (int) (floatingItemBounds.height() * amountUp); } } // Moving up the list // else if (totalMovment < 0) { if ((itemPos < selectedDragItemPos) && (view.getBottom() > floatMiddleY)) { float amountDown = ((float) view.getBottom() - floatMiddleY) / (float) view.getHeight(); // amountDown *= 0.5f; if (amountDown > 1) amountDown = 1; outRect.top = (int) (floatingItemBounds.height() * amountDown); outRect.bottom = -(int) (floatingItemBounds.height() * amountDown); } } } } else { outRect.top = 0; outRect.bottom = 0; // Make view visible incase invisible view.setVisibility(View.VISIBLE); } }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { View rootView = getWindow().getDecorView(); if (rootView.getTop() != 0) { // We are animating the top view, need to compensate for that in motion events. ev.setLocation(ev.getX(), ev.getY() - rootView.getTop()); } return super.dispatchTouchEvent(ev); }
private Rect getScrollBounds(View v) { // There can be scroll amounts not yet accounted for in // onLayout, so add mXScroll and mYScroll to the current // positions when calculating the bounds. return getScrollBounds( v.getLeft() + mXScroll, v.getTop() + mYScroll, v.getLeft() + v.getMeasuredWidth() + mXScroll, v.getTop() + v.getMeasuredHeight() + mYScroll); }
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); final int x = (int) ev.getX(); final int y = (int) ev.getY(); // [shravan.mahankali] dynamically find the dragger object and let user drag the item // only if touched on dragger and not otherwise. if (action == MotionEvent.ACTION_DOWN) { int startPos = pointToPosition(x, y); if (startPos != INVALID_POSITION) { int mItemPosition = startPos - getFirstVisiblePosition(); View grabber = getChildAt(mItemPosition).findViewById(draggerId); int mDragPointY = y - grabber.getTop(); int[] grabberLocationOnScreen = new int[2]; grabber.getLocationOnScreen(grabberLocationOnScreen); if (x >= grabber.getLeft() && x <= grabber.getRight() && mDragPointY >= grabber.getTop() && mDragPointY <= grabberLocationOnScreen[1]) mDragMode = true; } } if (!mDragMode) return super.onTouchEvent(ev); switch (action) { case MotionEvent.ACTION_DOWN: mStartPosition = pointToPosition(x, y); if (mStartPosition != INVALID_POSITION) { int mItemPosition = mStartPosition - getFirstVisiblePosition(); mDragPointOffset = y - getChildAt(mItemPosition).getTop(); mDragPointOffset -= ((int) ev.getRawY()) - y; startDrag(mItemPosition, y); drag(0, y); // replace 0 with x if desired } break; case MotionEvent.ACTION_MOVE: drag(0, y); // replace 0 with x if desired break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: default: mDragMode = false; mEndPosition = pointToPosition(x, y); stopDrag(mStartPosition - getFirstVisiblePosition()); if (mDropListener != null && mStartPosition != INVALID_POSITION && mEndPosition != INVALID_POSITION) mDropListener.onDrop(mStartPosition, mEndPosition); break; } return true; }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); View localView1 = getChildAt(0); int column = getWidth() / localView1.getWidth(); int childCount = getChildCount(); Paint localPaint; localPaint = new Paint(); localPaint.setStyle(Paint.Style.STROKE); localPaint.setColor(getContext().getResources().getColor(R.color.grid_line)); for (int i = 0; i < childCount; i++) { View cellView = getChildAt(i); if ((i + 1) % column == 0) { canvas.drawLine( cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint); } else if ((i + 1) > (childCount - (childCount % column))) { canvas.drawLine( cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint); } else { canvas.drawLine( cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), localPaint); canvas.drawLine( cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), localPaint); } } if (childCount % column != 0) { for (int j = 0; j < (column - childCount % column); j++) { View lastView = getChildAt(childCount - 1); canvas.drawLine( lastView.getRight() + lastView.getWidth() * j, lastView.getTop(), lastView.getRight() + lastView.getWidth() * j, lastView.getBottom(), localPaint); } } }
private void updateHeader(int headerPosition) { // check if there is a new header should be sticky if (mHeaderPosition == null || mHeaderPosition != headerPosition) { mHeaderPosition = headerPosition; final long headerId = mAdapter.getHeaderId(headerPosition); if (mHeaderId == null || mHeaderId != headerId) { mHeaderId = headerId; final View header = mAdapter.getHeaderView(mHeaderPosition, mHeader, this); if (mHeader != header) { if (header == null) { throw new NullPointerException("header may not be null"); } swapHeader(header); } ensureHeaderHasCorrectLayoutParams(mHeader); measureHeader(mHeader); if (mOnStickyHeaderChangedListener != null) { mOnStickyHeaderChangedListener.onStickyHeaderChanged( this, mHeader, headerPosition, mHeaderId); } // Reset mHeaderOffset to null ensuring // that it will be set on the header and // not skipped for performance reasons. mHeaderOffset = null; } } int headerOffset = 0; // Calculate new header offset // Skip looking at the first view. it never matters because it always // results in a headerOffset = 0 int headerBottom = mHeader.getMeasuredHeight() + stickyHeaderTop(); for (int i = 0; i < mList.getChildCount(); i++) { final View child = mList.getChildAt(i); final boolean doesChildHaveHeader = child instanceof WrapperView && ((WrapperView) child).hasHeader(); final boolean isChildFooter = mList.containsFooterView(child); if (child.getTop() >= stickyHeaderTop() && (doesChildHaveHeader || isChildFooter)) { headerOffset = Math.min(child.getTop() - headerBottom, 0); break; } } setHeaderOffet(headerOffset); if (!mIsDrawingListUnderStickyHeader) { mList.setTopClippingLength(mHeader.getMeasuredHeight() + mHeaderOffset); } updateHeaderVisibilities(); }
public void commOnTouchEvent(MotionEvent ev) { int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: y = ev.getY(); break; case MotionEvent.ACTION_UP: if (isNeedAnimation()) { animation(); } // 加入额外代码 if (mAutoScrollViewPager != null) { mAutoScrollViewPager.startAutoScroll(); } y = DEFAULT_POSITION; break; /** * 排除第一次移动计算,因为第一次无法得知y左边,在MotionEvent.ACTION_DOWN中获取不到, * 因为此时是MyScrollView的Tocuh时间传递到了ListView的孩子item上面。所以从第二次开始计算 * 然而我们也要进行初始化,就是第一次移动的时候让滑动距离归零,之后记录准确了就正常执行 */ case MotionEvent.ACTION_MOVE: float preY = y; float nowY = ev.getY(); if (isDefaultPosition(y)) { preY = nowY; } int deltaY = (int) (preY - nowY); scrollBy(0, deltaY); y = nowY; // 当滚动到最上或者最下时就不会再滚动,这时移动布局 if (isNeedMove()) { if (normal.isEmpty()) { // 保存正常的布局位置 normal.set(inner.getLeft(), inner.getTop(), inner.getRight(), inner.getBottom()); } // 移动布局 inner.layout( inner.getLeft(), inner.getTop() - deltaY / 2, inner.getRight(), inner.getBottom() - deltaY / 2); } break; default: break; } }
protected Rect getRelativePosition(View child) { View t = child; Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0); while (t.getParent() != null && t != getRootView()) { t = (View) t.getParent(); if (t == this) break; r.left += t.getLeft(); r.top += t.getTop(); } r.right = r.left + child.getMeasuredWidth(); r.bottom = r.top + child.getMeasuredHeight(); return r; }
@Override public void applyTransformation(float interpolatedTime, Transformation t) { int targetTop = 0; if (mFrom != mOriginalOffsetTop) { targetTop = (mFrom + (int) ((mOriginalOffsetTop - mFrom) * interpolatedTime)); } int offset = targetTop - mTarget.getTop(); final int currentTop = mTarget.getTop(); if (offset + currentTop < 0) { offset = 0 - currentTop; } setTargetOffsetTopAndBottom(offset); }
private static void updateForView(final RFBClient client, View view) { view.setDrawingCacheEnabled(true); // view.destroyDrawingCache(); // view.buildLayer(); // Bitmap bm = Bitmap.createBitmap( view.getMeasuredWidth(), view.getMeasuredHeight(), // Bitmap.Config.ARGB_8888); // Canvas c = new Canvas(bm); // view.invalidate(); // view.forceLayout(); // view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height); // view.draw(c); // // view.getDrawingCache(); Bitmap cache = view.getDrawingCache(); // Canvas renderC = new Canvas(cache); // view.destroyDrawingCache(); // view.layout(0, 0, cache.getWidth(), cache.getHeight()); // view.draw(renderC); // view.buildDrawingCache(false); int[] location = new int[2]; view.getLocationOnScreen(location); int[] pixels = new int[cache.getWidth() * cache.getHeight()]; cache.getPixels( pixels, 0, cache.getWidth(), view.getLeft(), view.getTop(), cache.getWidth(), cache.getHeight()); Rect rect = Rect.encode( client.getPreferredEncoding(), pixels, client.getPixelFormat(), cache.getWidth(), view.getLeft(), view.getTop(), cache.getWidth(), cache.getHeight()); rect.transform(location[0], location[1]); Rect[] rects = {rect}; try { client.writeFrameBufferUpdate(rects); } catch (IOException e) { Log.e("RemoteDisplay", "error while sending update rect", e); } }
public int getTop() { // find smallest value. int top = Integer.MAX_VALUE; int childCount = getChildCount(); for (int index = 0; index < childCount; ++index) { View v = getChildAt(index); if (v.getLeft() != mColumnLeft && isFixedView(v) == false) continue; top = top > v.getTop() ? v.getTop() : top; } if (top == Integer.MAX_VALUE) return mSynchedTop; // no child for this column. just return // saved sync top.. return top; }
/** * By overriding dispatchDraw, we can draw the cells that disappear during the expansion process. * When the cell expands, some items below or above the expanding cell may be moved off screen and * are thus no longer children of the ListView's layout. By storing a reference to these views * prior to the layout, and guaranteeing that these cells do not get recycled, the cells can be * drawn directly onto the canvas during the animation process. After the animation completes, the * references to the extra views can then be discarded. */ @Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mViewsToDraw.size() == 0) { return; } for (View v : mViewsToDraw) { canvas.translate(0, v.getTop()); v.draw(canvas); canvas.translate(0, -v.getTop()); } }
/** 监听ListView滑动 */ @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); // 获得ImageView的父控件 View header = (View) mImageView.getParent(); if (header.getTop() < 0 && mImageView.getHeight() > mImageViewHeight) { // 减小ImageView的高度 -- 不能超过图片最原始的高度 mImageView.getLayoutParams().height = Math.max(mImageView.getHeight() + header.getTop(), mImageViewHeight); // ImageView所在的容器的高度也要变化:getTop--->0 header.layout(header.getLeft(), 0, header.getRight(), header.getHeight()); mImageView.requestLayout(); } }
public void configureHeaderView(int position) { if (mHeaderView == null) { return; } int state = mAdapter.getPinnedHeaderState(position); switch (state) { case PinnedHeaderAdapter.PINNED_HEADER_GONE: { mHeaderViewVisible = false; break; } case PinnedHeaderAdapter.PINNED_HEADER_VISIBLE: { mAdapter.configurePinnedHeader(mHeaderView, position, MAX_ALPHA); if (mHeaderView.getTop() != 0) { mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight); } mHeaderViewVisible = true; break; } case PinnedHeaderAdapter.PINNED_HEADER_PUSHED_UP: { View firstView = getChildAt(0); if (firstView != null) { int bottom = firstView.getBottom(); int itemHeight = firstView.getHeight(); int headerHeight = mHeaderView.getHeight(); int y; int alpha; if (bottom < headerHeight) { y = (bottom - headerHeight); alpha = MAX_ALPHA * (headerHeight + y) / headerHeight; } else { y = 0; alpha = MAX_ALPHA; } mAdapter.configurePinnedHeader(mHeaderView, position, alpha); if (mHeaderView.getTop() != y) { mHeaderView.layout(0, y, mHeaderViewWidth, mHeaderViewHeight + y); } mHeaderViewVisible = true; } break; } } }
/** @return Calculates the position to which the ListView should be scrolled. */ public int getScrollToPosition() { int childCount = getChildCount(); if (childCount == 0) { return -1; } if (childCount == 1) { return 0; } int firstPos = getFirstVisiblePosition(); View firstChild = getChildAt(0); // If the first child is scrolled past at least half, // scroll to the next item. Else, scroll back to the first child. int top = firstChild.getTop(); int height = firstChild.getHeight(); boolean halfScrolled = Math.abs(top) >= (height / 2); int position = firstPos; if (halfScrolled) { position++; } // Sanity check. if (position >= mMonthAdapter.getCount()) { position = mMonthAdapter.getCount() - 1; } return position; }
private void blur(Bitmap bg, View view) { long startMs = System.currentTimeMillis(); float radius = 20; Bitmap overlay = Bitmap.createBitmap( view.getMeasuredWidth() / scaleFactor, view.getMeasuredHeight() / scaleFactor, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor); // scale参数为float类型 canvas.scale(1.0f / scaleFactor, 1.0f / scaleFactor); // 开启双缓冲 Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bg, 0, 0, paint); // Bitmap result = blurBitmap(overlay, 2); Bitmap result = blurBitmapStack(overlay, 2); view.setBackground(new BitmapDrawable(result)); long endMs = System.currentTimeMillis(); String time = (endMs - startMs) + "ms"; Toast.makeText(this, time, Toast.LENGTH_SHORT).show(); }
private Bitmap makeBitmapMask(final View view) { if (view != null) { Drawable d = view.getBackground(); float scaleFactor = 0.5f; int width = (int) (getMeasuredWidth() * scaleFactor); int height = (int) (getMeasuredHeight() * scaleFactor); if (d != null && width > 0 && height > 0) { d.setBounds( (int) (view.getLeft() * scaleFactor), (int) (view.getTop() * scaleFactor), (int) (view.getRight() * scaleFactor), (int) (view.getBottom() * scaleFactor)); Bitmap mask = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mask); d.draw(canvas); return mask; } else { log( "Can't create a mask with height 0 or width 0. Or the layout has no children and is wrap content"); return null; } } else { log("No bitmap mask loaded, view will NOT be masked !"); } return null; }