Java Code Examples for android.view.ViewGroup#setDrawingCacheEnabled()
The following examples show how to use
android.view.ViewGroup#setDrawingCacheEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragListView.java From DongWeather with Apache License 2.0 | 5 votes |
/** * 获取触点所在条目的位置 * 获取选中条目的图片 * 事件的拦截机制 * * @param ev * @return */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { //识别动作 switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: //获取触点的坐标 int x = (int) ev.getX(); int y = (int) ev.getY(); //这样就可以计算我按到哪个条目上了 mStartPosition = mEndPosition = pointToPosition(x, y); //判断触点是否在logo的区域 ViewGroup itemView = (ViewGroup) getChildAt(mStartPosition - getFirstVisiblePosition()); //记录手指在条目中的相对Y坐标 dragPoint = y - itemView.getTop(); //ListView在屏幕中的Y坐标 dragOffset = (int) (ev.getRawY() - y); //拖动的图标 View dragger = itemView.findViewById(R.id.guide_shape_im); //有修改 //判断触点是否在logo区域 if (dragger != null && x < dragger.getRight() + 10) { //定义ListView的滚动条目 //上 upScroll = getHeight() / 3; //下 downScroll = getHeight() * 2 / 3; //获取选中的图片/截图 itemView.setDrawingCacheEnabled(true); //获取截图 Bitmap bitMap = itemView.getDrawingCache(); //图片滚动 startDrag(bitMap, y); } break; } //还会传递事件到子View return false; }
Example 2
Source File: AllAngleExpandableButton.java From AllAngleExpandableButton with Apache License 2.0 | 5 votes |
private boolean showBlur() { if (!blurBackground) { return false; } //set invisible to avoid be blurred that resulting in show the blurred button edge when expanded, //must be called before do blur setVisibility(INVISIBLE); final ViewGroup root = (ViewGroup) getRootView(); root.setDrawingCacheEnabled(true); Bitmap bitmap = root.getDrawingCache(); checkBlurRadius(); blur.setParams(new Blur.Callback() { @Override public void onBlurred(Bitmap blurredBitmap) { blurImageView.setImageBitmap(blurredBitmap); root.setDrawingCacheEnabled(false); root.addView(blurImageView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); blurAnimator = ObjectAnimator.ofFloat(blurImageView, "alpha", 0.0f, 1.0f).setDuration(expandAnimDuration); if (blurListener != null) { blurAnimator.removeListener(blurListener); } blurAnimator.start(); root.addView(maskView); maskAttached = true; maskView.reset(); maskView.initButtonRect(); maskView.onClickMainButton(); } }, getContext(), bitmap, blurRadius); blur.execute(); return true; }
Example 3
Source File: FoldableLayout.java From FoldableLayout with Apache License 2.0 | 5 votes |
private Bitmap computeBitmap(ViewGroup viewGroup) { Bitmap bitmap; Rect rect = new Rect(); viewGroup.getWindowVisibleDisplayFrame(rect); viewGroup.destroyDrawingCache(); viewGroup.setDrawingCacheEnabled(true); viewGroup.buildDrawingCache(true); bitmap = viewGroup.getDrawingCache(true); /** * After rotation, the DecorView has no height and no width. Therefore * .getDrawingCache() return null. That's why we have to force measure and layout. */ if (bitmap == null) { viewGroup.measure( MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mCoverHeight * 2, MeasureSpec.EXACTLY) ); viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(), viewGroup.getMeasuredHeight()); viewGroup.destroyDrawingCache(); viewGroup.setDrawingCacheEnabled(true); viewGroup.buildDrawingCache(true); bitmap = viewGroup.getDrawingCache(true); } if (bitmap == null) { return Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); } else { return bitmap.copy(Bitmap.Config.ARGB_8888, false); } }
Example 4
Source File: DragnDropListView.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if ((mDragListener != null || mDropListener != null) && ev.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) ev.getX(); int y = (int) ev.getY(); int itemnum = pointToPosition(x, y); if (itemnum != AdapterView.INVALID_POSITION) { ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition()); Log.d("DnD view", "Start dragging at " + (itemnum - getFirstVisiblePosition()) + " for "+ itemnum + " # "+ getFirstVisiblePosition()); mDragPoint = y - item.getTop(); mCoordOffset = ((int) ev.getRawY()) - y; View dragger = item.findViewById(grabberId); if(dragger == null || dragger.getVisibility() == View.GONE) { return super.onInterceptTouchEvent(ev); } Rect r = mTempRect; r.left=dragger.getLeft(); r.right=dragger.getRight(); r.top=dragger.getTop(); r.bottom=dragger.getBottom(); if ((r.left<x) && (x<r.right)) { item.setDrawingCacheEnabled(true); // Create a copy of the drawing cache so that it does // not get recycled // by the framework when the list tries to clean up // memory Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache()); startDragging(bitmap, y); mDragPos = itemnum; mFirstDragPos = mDragPos; mHeight = getHeight(); int touchSlop = mTouchSlop; mUpperBound = Math.min(y - touchSlop, mHeight / 3); mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3); item.setDrawingCacheEnabled(false); return false; } mDragView = null; } } return super.onInterceptTouchEvent(ev); }
Example 5
Source File: TouchInterceptor.java From GravityBox with Apache License 2.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (mDragListener != null || mDropListener != null) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: int x = (int) ev.getX(); int y = (int) ev.getY(); int itemnum = pointToPosition(x, y); if (itemnum == AdapterView.INVALID_POSITION) { break; } ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition()); mDragPoint = y - item.getTop(); mCoordOffset = ((int) ev.getRawY()) - y; View dragger = item.findViewById(R.id.grabber); Rect r = mTempRect; dragger.getDrawingRect(r); if (shouldStartDragging(x, r.width())) { // Fix x position while dragging int[] itemPos = new int[2]; item.getLocationOnScreen(itemPos); item.setDrawingCacheEnabled(true); // Create a copy of the drawing cache so that it does // not get recycled // by the framework when the list tries to clean up // memory Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache()); startDragging(bitmap, itemPos[0], y); mDragPos = itemnum; mFirstDragPos = mDragPos; mHeight = getHeight(); int touchSlop = mTouchSlop; mUpperBound = Math.min(y - touchSlop, mHeight / 3); mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3); return false; } stopDragging(); break; } } return super.onInterceptTouchEvent(ev); }