public static int[] getRelativeLocation(View reference, View view) { reference.getLocationInWindow(sLocation); int referenceX = sLocation[0]; int referenceY = sLocation[1]; view.getLocationInWindow(sLocation); sLocation[0] -= referenceX; sLocation[1] -= referenceY; return sLocation; }
public static Point translateLocationWithOther(View view, View target) { Point location = new Point(); int[] viewLocation = new int[2]; int[] targetLocation = new int[2]; view.getLocationInWindow(viewLocation); target.getLocationInWindow(targetLocation); location.set(viewLocation[0] - targetLocation[0], viewLocation[1] - targetLocation[1]); return location; }
/** * Positions the popup window on screen. When the popup window is too tall to fit under the * anchor, a parent scroll view is seeked and scrolled up to reclaim space. If scrolling is not * possible or not enough, the popup window gets moved on top of the anchor. * * <p>The height must have been set on the layout parameters prior to calling this method. * * @param anchor the view on which the popup window must be anchored * @param p the layout parameters used to display the drop down * @return true if the popup is translated upwards to fit on screen */ private boolean findDropDownPosition( View anchor, WindowManager.LayoutParams p, int xoff, int yoff) { anchor.getLocationInWindow(mDrawingLocation); p.x = mDrawingLocation[0] + xoff; p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; boolean onTop = false; p.gravity = Gravity.LEFT | Gravity.TOP; anchor.getLocationOnScreen(mScreenLocation); final Rect displayFrame = new Rect(); anchor.getWindowVisibleDisplayFrame(displayFrame); final View root = anchor.getRootView(); if (mScreenLocation[1] + anchor.getMeasuredHeight() + yoff + mPopupHeight > displayFrame.bottom || p.x + mPopupWidth - root.getWidth() > 0) { // if the drop down disappears at the bottom of the screen. we try to // scroll a parent scrollview or move the drop down back up on top of // the edit box int scrollX = anchor.getScrollX(); int scrollY = anchor.getScrollY(); Rect r = new Rect( scrollX, scrollY, scrollX + mPopupWidth, scrollY + mPopupHeight + anchor.getMeasuredHeight()); anchor.requestRectangleOnScreen(r, true); // now we re-evaluate the space available, and decide from that // whether the pop-up will go above or below the anchor. anchor.getLocationInWindow(mDrawingLocation); p.x = mDrawingLocation[0] + xoff; p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; // determine whether there is more space above or below the anchor anchor.getLocationOnScreen(mScreenLocation); onTop = (displayFrame.bottom - mScreenLocation[1] - anchor.getMeasuredHeight() - yoff) < (mScreenLocation[1] - yoff - displayFrame.top); if (onTop) { p.gravity = Gravity.LEFT | Gravity.BOTTOM; p.y = root.getHeight() - mDrawingLocation[1] - yoff; } else { p.y = mDrawingLocation[1] + anchor.getMeasuredHeight() + yoff; } } p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL; return onTop; }
@Override public void onClick(View view, int position, long id) { // TODO Auto-generated method stub MyFile myFile = mData.get(position); File file = new File(myFile.getPath()); if (file.isDirectory()) { // 如果是文件夹节点,则进入下一层,并初始化数据 initFileData(myFile.getPath()); } else { // Toast.makeText(MainActivity.this, "阅读器待开发", Toast.LENGTH_SHORT).show(); LayoutInflater layoutInflater = LayoutInflater.from(this); View v = layoutInflater.inflate(R.layout.popup_item, null); PopupWindow pw = new PopupWindow(v, LayoutParams.MATCH_PARENT, 400, true); pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.local_popup_bg)); TextView tv_fileName = (TextView) v.findViewById(R.id.tv_fileName); tv_fileName.setText(myFile.getName()); TextView tv_filePath = (TextView) v.findViewById(R.id.tv_filePath); tv_filePath.setText(myFile.getPath()); TextView tv_modifyTime = (TextView) v.findViewById(R.id.tv_modifyTime); tv_modifyTime.setText(myFile.getModifyTime()); // 获得Item在屏蔽上的坐标位置 int[] location = new int[2]; view.getLocationInWindow(location); int windowWidth = FunctionHelper.getWindowWidth(this); pw.showAtLocation( view, Gravity.TOP | Gravity.LEFT, location[0] + windowWidth / 8, location[1] - 100); } }
public void onClick(View view) { StickerFragment.a(a, (StickerObj) view.getTag()); StickerFragment.a(a, null); if (StickerFragment.a(a) != null) { if (StickerFragment.b(a).equals(de.a)) { int ai[] = new int[2]; view.getLocationInWindow(ai); StickerFragment.a( a, ai, Pair.create(Integer.valueOf(view.getWidth()), Integer.valueOf(view.getHeight())), StickerFragment.a(a)); return; } if (StickerFragment.c(a) != null) { StickerFragment.c(a).a(StickerFragment.d(a)); } view = (f) StickerFragment.e(a).getAdapter(); if (view != null) { view.a(StickerFragment.e(a).getCurrentItem(), StickerFragment.a(a)); } if (StickerFragment.c(a) != null) { StickerFragment.c(a).a(StickerFragment.a(a)); return; } } }
// This method is not thread-safe. public static boolean pointInView(float x, float y, View v) { v.getLocationInWindow(sLocation); return x >= sLocation[0] && x < (sLocation[0] + v.getWidth()) && y >= sLocation[1] && y < (sLocation[1] + v.getHeight()); }
public void hideToFromView() { if (vFrom != null) { AlphaAnimation animAlpha = new AlphaAnimation(1, 0); animAlpha.setDuration(AnimationDuration); vMask.startAnimation(animAlpha); int x = 0; int y = (screenHeight - statusBarHeight - screenWidth) / 2 + statusBarHeight; int[] location = new int[2]; vFrom.getLocationInWindow(location); int toX = location[0]; int toY = location[1]; float scale = (float) vFrom.getWidth() / (float) UIUtil.getScreenWidth(); ScaleAnimation animScale = new ScaleAnimation(1, scale, 1, scale); animScale.setDuration(AnimationDuration); TranslateAnimation animTrans = new TranslateAnimation(0, toX - x, 0, toY - y); animTrans.setDuration(AnimationDuration); AnimationSet animSet = new AnimationSet(true); animSet.addAnimation(animScale); animSet.addAnimation(animTrans); flImages.startAnimation(animSet); postDelayed( new Runnable() { @Override public void run() { setVisibility(View.GONE); } }, AnimationDuration); } else { setVisibility(View.GONE); } }
public static int[] getCenterDeltaInScreenSpace(View v0, View v1, int[] delta) { v0.getLocationInWindow(sLoc0); v1.getLocationInWindow(sLoc1); sLoc0[0] += (v0.getMeasuredWidth() * v0.getScaleX()) / 2; sLoc0[1] += (v0.getMeasuredHeight() * v0.getScaleY()) / 2; sLoc1[0] += (v1.getMeasuredWidth() * v1.getScaleX()) / 2; sLoc1[1] += (v1.getMeasuredHeight() * v1.getScaleY()) / 2; if (delta == null) { delta = new int[2]; } delta[0] = sLoc1[0] - sLoc0[0]; delta[1] = sLoc1[1] - sLoc0[1]; return delta; }
public void showPicFromView(String content, View v, Bitmap placeHolder) { vFrom = v; int[] location = new int[2]; v.getLocationInWindow(location); int x = location[0]; int y = location[1]; int width = v.getWidth(); showPicFromPosition(content, placeHolder, x, y, width); }
private void updateLayoutParamsForPosiion(View anchor, LayoutParams p, int yOffset) { this.measureFloater(); int measuredHeight = this.mPopupView.getMeasuredHeight(); int paddingBottom = this.mPopupView.mMarker.getPaddingBottom(); anchor.getLocationInWindow(this.mDrawingLocation); p.x = 0; p.y = this.mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom; p.width = this.screenSize.x; p.height = measuredHeight; }
private Rect getBounds(View view) { int[] location = new int[2]; view.getLocationInWindow(location); location[1] -= statusBarHeight; return new Rect( location[0], location[1], location[0] + view.getMeasuredWidth(), location[1] + view.getMeasuredHeight()); }
public static boolean ptInView(View view, int x, int y) { int[] location = new int[2]; view.getLocationInWindow(location); if (x > location[0] && x < location[0] + view.getWidth() && y > location[1] && y < location[1] + view.getHeight()) return true; else return false; }
public Rect y() { if (ac == null) { ac = new Rect(); int[] arrayOfInt = new int[2]; View localView = findViewById(2131625381); localView.getLocationInWindow(arrayOfInt); ac = new Rect(arrayOfInt[0], arrayOfInt[1], arrayOfInt[0] + localView.getMeasuredWidth(), arrayOfInt[1] + localView.getMeasuredHeight()); } return ac; }
/** * @hide Compute the interesting insets into your UI. The default implementation uses the entire * window frame as the insets. The default touchable insets are {@link * Insets#TOUCHABLE_INSETS_FRAME}. * @param outInsets Fill in with the current UI insets. */ @SystemApi public void onComputeInsets(Insets outInsets) { int[] loc = mTmpLocation; View decor = getWindow().getWindow().getDecorView(); decor.getLocationInWindow(loc); outInsets.contentInsets.top = 0; outInsets.contentInsets.left = 0; outInsets.contentInsets.right = 0; outInsets.contentInsets.bottom = 0; outInsets.touchableInsets = Insets.TOUCHABLE_INSETS_FRAME; outInsets.touchableRegion.setEmpty(); }
/** * * Hide the searchbox using the circle animation which centres upon the provided menu item. Can * be called regardless of result list length * * @param id ID of menu item * @param activity Activity */ public void hideCircularlyToMenuItem(int id, Activity activity) { View menuButton = activity.findViewById(id); if (menuButton != null) { FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content); if (layout.findViewWithTag("searchBox") == null) { int[] location = new int[2]; menuButton.getLocationInWindow(location); hideCircularly(location[0] + menuButton.getWidth() * 2 / 3, location[1], activity); } } }
/** * * Reveal the searchbox from a menu item. Specify the menu item id and pass the activity so the * item can be found * * @param id View ID * @param activity Activity */ public void revealFromMenuItem(int id, Activity activity) { setVisibility(View.VISIBLE); View menuButton = activity.findViewById(id); if (menuButton != null) { FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content); if (layout.findViewWithTag("searchBox") == null) { int[] location = new int[2]; menuButton.getLocationInWindow(location); revealFrom((float) location[0], (float) location[1], activity, this); } } }
/** Private method for grabbing a "screenshot" of screen content */ private void drawOffscreenBitmap() { // Grab global visible rect for later use // mView.getGlobalVisibleRect(mRectVisibleGlobal); // Calculate scaled off-screen bitmap width and height int width = Math.round(mView.getWidth() * BITMAP_SCALE_FACTOR); int height = Math.round(mView.getHeight() * BITMAP_SCALE_FACTOR); // Width and height must be > 0 width = Math.max(width, 1); height = Math.max(height, 1); // Allocate new off-screen bitmap only when needed if (mBitmap == null || mBitmap.getWidth() != width || mBitmap.getHeight() != height) { mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mAllocationBitmap = Allocation.createFromBitmap(mRS, mBitmap); mAllocationBitmapTmp = Allocation.createFromBitmap(mRS, mBitmap); mSizeStruct.width = width; mSizeStruct.height = height; // Due to adjusting width into multiple of 4 calculate scale matrix // only here mMatrixScale.setScale((float) width / mView.getWidth(), (float) height / mView.getHeight()); mMatrixScale.invert(mMatrixScaleInv); } // Translate values for off-screen drawing // int dx = -(Math.min(0, mView.getLeft()) + mRectVisibleGlobal.left); // int dy = -(Math.min(0, mView.getTop()) + mRectVisibleGlobal.top); // // Replaced dx and dy with View.getLocationInWindow() coordinates // because translate was bad for using BlurLinearLayout and // BlurRelativeLayout as children for other Views than root View. mView.getLocationInWindow(mLocationInWindow); // Restore canvas to its original state mCanvas.restoreToCount(1); mCanvas.setBitmap(mBitmap); // Using scale matrix will make draw call to match // resized off-screen bitmap size mCanvas.setMatrix(mMatrixScale); // Off-screen bitmap does not cover the whole screen // Use canvas translate to match its position on screen mCanvas.translate(-mLocationInWindow[0], -mLocationInWindow[1]); // Clip rect is the same as we have // TODO: Why does this not work on API 18? // mCanvas.clipRect(mRectVisibleGlobal); // Save current canvas state mCanvas.save(); // Start drawing from the root view mView.getRootView().draw(mCanvas); }
public View copyViewInAniLayer(View view, int height, int width) { if (aniViewGroup == null) { aniViewGroup = createAnimLayout(); } int location[] = new int[2]; view.getLocationInWindow(location); ImageView imageView = new ImageView(getContext()); view.destroyDrawingCache(); view.setDrawingCacheEnabled(true); Bitmap bm = Bitmap.createBitmap(view.getDrawingCache()); imageView.setImageBitmap(bm); addViewToAnimLayout(imageView, location, height, width); return imageView; }
public void getViewRectRelativeToSelf(View v, Rect r) { int[] loc = new int[2]; getLocationInWindow(loc); int x = loc[0]; int y = loc[1]; v.getLocationInWindow(loc); int vX = loc[0]; int vY = loc[1]; int left = vX - x; int top = vY - y; r.set(left, top, left + v.getMeasuredWidth(), top + v.getMeasuredHeight()); }
private void reveal(View sourceView, int colorRes, final AnimatorListener listener) { // Make reveal cover the display final RevealView revealView = new RevealView(this); revealView.setLayoutParams(mLayoutParams); revealView.setRevealColor(getResources().getColor(colorRes)); mDisplayForeground.addView(revealView); final SupportAnimator revealAnimator; final int[] clearLocation = new int[2]; if (sourceView != null) { sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; } else { clearLocation[0] = mDisplayForeground.getWidth() / 2; clearLocation[1] = mDisplayForeground.getHeight() / 2; } final int revealCenterX = clearLocation[0] - revealView.getLeft(); final int revealCenterY = clearLocation[1] - revealView.getTop(); final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); revealAnimator = ViewAnimationUtils.createCircularReveal( revealView, revealCenterX, revealCenterY, 0.0f, revealRadius); revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); revealAnimator.addListener(listener); final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); alphaAnimator.addListener( new AnimationFinishedListener() { @Override public void onAnimationFinished() { mDisplayForeground.removeView(revealView); } }); revealAnimator.addListener( new AnimationFinishedListener() { @Override public void onAnimationFinished() { play(alphaAnimator); } }); play(revealAnimator); }
/** * 点击ITEM移动动画 * * @param moveView * @param startLocation * @param endLocation * @param moveChannel * @param clickGridView */ private void MoveAnim( View moveView, int[] startLocation, int[] endLocation, final ChannelItem moveChannel, final GridView clickGridView) { int[] initLocation = new int[2]; // 获取传递过来的VIEW的坐标 moveView.getLocationInWindow(initLocation); // 得到要移动的VIEW,并放入对应的容器中 final ViewGroup moveViewGroup = getMoveViewGroup(); final View mMoveView = getMoveView(moveViewGroup, moveView, initLocation); // 创建移动动画 TranslateAnimation moveAnimation = new TranslateAnimation(startLocation[0], endLocation[0], startLocation[1], endLocation[1]); moveAnimation.setDuration(300L); // 动画时间 // 动画配置 AnimationSet moveAnimationSet = new AnimationSet(true); moveAnimationSet.setFillAfter(false); // 动画效果执行完毕后,View对象不保留在终止的位置 moveAnimationSet.addAnimation(moveAnimation); mMoveView.startAnimation(moveAnimationSet); moveAnimationSet.setAnimationListener( new AnimationListener() { @Override public void onAnimationStart(Animation animation) { isMove = true; } @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { moveViewGroup.removeView(mMoveView); // instanceof 方法判断2边实例是不是一样,判断点击的是DragGrid还是OtherGridView if (clickGridView instanceof DragGrid) { otherAdapter.setVisible(true); otherAdapter.notifyDataSetChanged(); userAdapter.remove(); } else { userAdapter.setVisible(true); userAdapter.notifyDataSetChanged(); otherAdapter.remove(); } isMove = false; } }); }
private boolean eventInside(View v, MotionEvent ev) { // assume that x and y are window coords because we are. final int x = (int) ev.getX(); final int y = (int) ev.getY(); final int[] p = mPos; v.getLocationInWindow(p); final int l = p[0]; final int t = p[1]; final int r = p[0] + v.getWidth(); final int b = p[1] + v.getHeight(); return x >= l && x < r && y >= t && y < b; }
public static boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] leftTop = { 0, 0 }; v.getLocationInWindow(leftTop); int left = leftTop[0], top = leftTop[1], bottom = top + v.getHeight(), right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // 保留点击EditText的事件 return false; } else { return true; } } return false; }
/** * Tells the service to start its UI via an AIDL interface. Called when the onServiceConnected() * callback is received. */ void handleServiceConnected() { Log.d(TAG, "handleServiceConnected()"); // It is possible that an unbind has occurred in the time between the bind and when this // function is reached. If an unbind has already occurred, proceeding on to call startUi() // can result in a fatal error. Note that the onServiceConnected() callback is // asynchronous, so this possibility would still exist if we executed this directly in // onServiceConnected() rather than using a handler. if (!mBoundToService) { Log.d(TAG, "Dropping startUi() in handleServiceConnected() because no longer bound"); return; } try { mService.registerCallback(mFaceUnlockCallback); } catch (RemoteException e) { Log.e(TAG, "Caught exception connecting to Face Unlock: " + e.toString()); mService = null; mBoundToService = false; mIsRunning = false; return; } if (mFaceUnlockView != null) { IBinder windowToken = mFaceUnlockView.getWindowToken(); if (windowToken != null) { // When switching between portrait and landscape view while Face Unlock is running, // the screen will eventually go dark unless we poke the wakelock when Face Unlock // is restarted. mKeyguardScreenCallback.pokeWakelock(); int[] position; position = new int[2]; mFaceUnlockView.getLocationInWindow(position); startUi( windowToken, position[0], position[1], mFaceUnlockView.getWidth(), mFaceUnlockView.getHeight()); } else { Log.e(TAG, "windowToken is null in handleServiceConnected()"); } } }
/** * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时没必要隐藏 * * @param v * @param event * @return */ private boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] l = {0, 0}; v.getLocationInWindow(l); int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // 点击EditText的事件,忽略它。 return false; } else { return true; } } // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditView上,和用户用轨迹球选择其他的焦点 return false; }
public void open(ImageView srcImageView) { if (animator.isRunning()) { return; } if (parentView == null) { parentView = (View) getParent(); parentWidth = parentView.getWidth(); parentHeight = parentView.getHeight(); parentView.getLocationInWindow(parentLocation); } Drawable drawable = srcImageView.getDrawable(); right = drawableOriginWidth = drawable.getIntrinsicWidth(); bottom = drawableOriginHeight = drawable.getIntrinsicHeight(); setImageDrawable(drawable); if (parentView.getWidth() / (float) drawableOriginWidth > parentView.getHeight() / (float) drawableOriginHeight) scaleDirection = VERTICAL; // 以垂直方向参考 else scaleDirection = HORIZON; srcImageView.getLocationInWindow(srcLocation); beginLeft = srcLocation[0] - parentLocation[0]; beginTop = srcLocation[1] - parentLocation[1]; if (scaleDirection == VERTICAL) { finalTop = 0; finalLeft = (parentWidth - parentHeight * drawableOriginWidth / drawableOriginHeight) / 2; } else { finalTop = mWindowHeight / 2 - mLocation[1] - parentWidth / drawableOriginWidth * drawableOriginHeight / 2; finalLeft = 0; } mIsOpen = true; mFirstAnimPlay = true; parentView.setVisibility(VISIBLE); animator.setFloatValues(0, 1); animator.start(); }
public boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && v instanceof RelativeLayout) { int[] leftTop = {0, 0}; v.getLocationInWindow(leftTop); int left = leftTop[0]; int top = leftTop[1]; int bottom = top + v.getHeight(); int right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // 点击的是输入框区域,保留点击EditText的事件 return false; } else { return true; } } return false; }
@Override public void showMoreKeysPanel( View parentView, Controller controller, int pointX, int pointY, PopupWindow window, KeyboardActionListener listener) { mController = controller; mListener = listener; final View container = (View) getParent(); final MiniKeyboard miniKeyboard = (MiniKeyboard) getKeyboard(); parentView.getLocationInWindow(mCoordinates); final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX() + parentView.getPaddingLeft(); final int x = wrapUp( Math.max( 0, Math.min(miniKeyboardLeft, parentView.getWidth() - miniKeyboard.mOccupiedWidth)) - container.getPaddingLeft() + mCoordinates[0], container.getMeasuredWidth(), 0, parentView.getWidth()); final int y = pointY - (container.getMeasuredHeight() - container.getPaddingBottom()) + parentView.getPaddingTop() + mCoordinates[1]; window.setContentView(container); window.setWidth(container.getMeasuredWidth()); window.setHeight(container.getMeasuredHeight()); window.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y); mOriginX = x + container.getPaddingLeft() - mCoordinates[0]; mOriginY = y + container.getPaddingTop() - mCoordinates[1]; }
private void revealTray(boolean reverse) { View sourceView = mFab; mTray.setVisibility(View.VISIBLE); final SupportAnimator revealAnimator; final int[] clearLocation = new int[2]; sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; final int revealCenterX = clearLocation[0] - mTray.getLeft(); final int revealCenterY = clearLocation[1] - mTray.getTop(); final double x1_2 = Math.pow(mTray.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(mTray.getRight() - revealCenterX, 2); final double y_2 = Math.pow(mTray.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); float start = reverse ? revealRadius : 0; float end = reverse ? 0 : revealRadius; if (android.os.Build.VERSION.SDK_INT >= 21) { // The lollipop reveal uses local cords, so use tray height / 2 revealAnimator = ViewAnimationUtils.createCircularReveal( mTray, revealCenterX, mTray.getHeight() / 2, start, end); } else { // The legacy support doesn't work with gravity bottom, so use the global cords revealAnimator = ViewAnimationUtils.createCircularReveal(mTray, revealCenterX, revealCenterY, start, end); } revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)); if (reverse) { revealAnimator.addListener( new AnimationFinishedListener() { @Override public void onAnimationFinished() { mTray.setVisibility(View.INVISIBLE); } }); } play(revealAnimator); }
/** * Shows the popup with the arrow pointing to the center of the anchor view. If the anchor isn't * visible, the popup will just be shown at the top of the root view. */ public void show() { if (!mInflated) { throw new IllegalStateException("ArrowPopup#init() must be called before ArrowPopup#show()"); } final int[] anchorLocation = new int[2]; if (mAnchor != null) { mAnchor.getLocationInWindow(anchorLocation); } // If the anchor is null or out of the window bounds, just show the popup at the top of the // root view, keeping the correct X coordinate. if (mAnchor == null || anchorLocation[1] < 0) { final View decorView = ((Activity) mContext).getWindow().getDecorView(); // Bug in Android code causes the window layout parameters to be ignored // when using showAtLocation() in Gingerbread phones. if (Versions.preHC) { setWidth(decorView.getWidth()); setHeight(decorView.getHeight()); } showAtLocation(decorView, Gravity.NO_GRAVITY, anchorLocation[0] - mArrowWidth, 0); return; } // By default, the left edge of the window is aligned directly underneath the anchor. The // arrow needs to be directly under the anchor, and since we want some space between the // edge of the popup window and the arrow, we offset the window by -mArrowWidth. This is // just an arbitrary value chosen to create some space. if (isShowing()) { update(mAnchor, -mArrowWidth, -mYOffset, -1, -1); } else { showAsDropDown(mAnchor, -mArrowWidth, -mYOffset); } }