Java Code Examples for android.view.View.getLocationOnScreen()

The following are Jave code examples for showing how to use getLocationOnScreen() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: chromium-for-android-56-debug-video   File: ToolbarLayout.java   Source Code and License Vote up 7 votes
/**
 * Shows the content description toast for items on the toolbar.
 * @param view The view to anchor the toast.
 * @param description The string shown in the toast.
 * @return Whether a toast has been shown successfully.
 */
protected boolean showAccessibilityToast(View view, CharSequence description) {
    if (description == null) return false;

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;
    final int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);
    final int width = view.getWidth();

    Toast toast = Toast.makeText(getContext(), description, Toast.LENGTH_SHORT);
    toast.setGravity(
            Gravity.TOP | Gravity.END,
            screenWidth - screenPos[0] - width / 2,
            screenPos[1] + getHeight() / 2);
    toast.show();
    return true;
}
 
Example 2
Project: GitHub   File: BasePopupWindow.java   Source Code and License Vote up 6 votes
/**
 * 计算popupwindow的偏移量
 *
 * @param anchorView
 * @return
 * @see #showPopupWindow(View)
 */
private int[] calcuateOffset(View anchorView) {
    int[] offset = {offsetX, offsetY};
    anchorView.getLocationOnScreen(mAnchorViewLocation);
    if (isAutoLocatePopup) {
        final boolean onTop = (getScreenHeight() - (mAnchorViewLocation[1] + offset[1]) < getHeight());
        if (onTop) {
            offset[1] = -anchorView.getHeight() - getHeight() - offset[1];
            showOnTop(mPopupView);
        } else {
            showOnDown(mPopupView);
        }
    }
    return offset;

}
 
Example 3
Project: NestedWebView   File: NestedWebViewAppBarLayout.java   Source Code and License Vote up 6 votes
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child,
        View target, int dx, int dy, int[] consumed, int type) {
    if (this.toolbar == null) {
        this.toolbar = findToolbar(child);
        if (this.toolbar == null) {
            return;
        }
    }
    int[] toolbarLocation = new int[2];
    toolbar.getLocationOnScreen(toolbarLocation);
    int[] targetLocation = new int[2];
    target.getLocationOnScreen(targetLocation);
    int toolbarBottomY = toolbarLocation[1] + toolbar.getHeight();
    int[] appbarLocation = new int[2];
    int nestedScrollViewTopY = targetLocation[1];
    child.getLocationOnScreen(appbarLocation);
    NestedWebView nestedWebView = (NestedWebView) target;
    if (nestedScrollViewTopY <= toolbarBottomY) {
        nestedWebView.onChangeCollapseToolbar(true, dy);
    } else {
        nestedWebView.onChangeCollapseToolbar(false, dy);
    }
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
}
 
Example 4
Project: FragmentRigger   File: SharedElementFragment.java   Source Code and License Vote up 6 votes
private void startSecondFragment(int type, View view) {
  SharedTargetFragment fragment = SharedTargetFragment.newInstance(type);
  Bundle bundle = fragment.getArguments();
  int[] screenLocation = new int[2];
  view.getLocationOnScreen(screenLocation);
  bundle.putIntArray(BUNDLE_KEY + 1, screenLocation);
  bundle.putIntArray(BUNDLE_KEY + 2, new int[]{view.getWidth(), view.getHeight()});
  switch (type) {
    case TYPE_HAMMER:
      break;
    case TYPE_HOURGLASS:
      break;
    case TYPE_SEND:
      break;
    case TYPE_CLOUD:
      break;
  }
  Rigger.getRigger(this).startFragment(fragment);
}
 
Example 5
Project: PeSanKita-android   File: AttachmentTypeSelector.java   Source Code and License Vote up 6 votes
private Pair<Integer, Integer> getClickOrigin(@Nullable View anchor, @NonNull View contentView) {
  if (anchor == null) return new Pair<>(0, 0);

  final int[] anchorCoordinates = new int[2];
  anchor.getLocationOnScreen(anchorCoordinates);
  anchorCoordinates[0] += anchor.getWidth() / 2;
  anchorCoordinates[1] += anchor.getHeight() / 2;

  final int[] contentCoordinates = new int[2];
  contentView.getLocationOnScreen(contentCoordinates);

  int x = anchorCoordinates[0] - contentCoordinates[0];
  int y = anchorCoordinates[1] - contentCoordinates[1];

  return new Pair<>(x, y);
}
 
Example 6
Project: Phial   File: AnimatorFactory.java   Source Code and License Vote up 5 votes
AnimatorFactory(View startView) {
    final int width = startView.getWidth();
    final int height = startView.getHeight();
    startRadius = Math.min(width, height) / 2;

    int[] location = new int[2];
    startView.getLocationOnScreen(location);
    x = location[0] + width / 2;
    y = location[1] + height / 2;
}
 
Example 7
Project: MySelfDemo   File: MyDemoActivity.java   Source Code and License Vote up 5 votes
public void showUpPop(View view) {
        if (popupWindow != null && popupWindow.isShowing()) return;
        popupWindow = new MyCommonPopularWindow.Builder(this)
                .setView(R.layout.layout_popular_2)
                .setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .create();
//        popupWindow.showAsDropDown(view, 0, -(popupWindow.getHeight() + view.getMeasuredHeight()));

        int[] location = new int[2];
        view.getLocationOnScreen(location);
        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight());
    }
 
Example 8
Project: FragmentRigger   File: SharedTargetFragment.java   Source Code and License Vote up 5 votes
private static void captureScreenLocationValues(@NonNull Bundle b, @NonNull View view) {
  if (view instanceof ImageView) {
    int[] size = ImageViewUtil.getDisplayedImageLocation((ImageView) view);
    b.putInt(PROPNAME_SCREENLOCATION_LEFT, size[0]);
    b.putInt(PROPNAME_SCREENLOCATION_TOP, size[1]);
  } else {
    int[] screenLocation = new int[2];
    view.getLocationOnScreen(screenLocation);
    b.putInt(PROPNAME_SCREENLOCATION_LEFT, screenLocation[0]);
    b.putInt(PROPNAME_SCREENLOCATION_TOP, screenLocation[1]);
  }
}
 
Example 9
Project: animator   File: FAnimator.java   Source Code and License Vote up 5 votes
private void updateTempLocation(View view)
{
    if (view == null)
    {
        return;
    }
    if (mTempLocation == null)
    {
        mTempLocation = new int[]{0, 0};
    }
    view.getLocationOnScreen(mTempLocation);
}
 
Example 10
Project: TestChat   File: BaseItemClickListener.java   Source Code and License Vote up 5 votes
private boolean isOnRange(MotionEvent e, View childView) {
//                        LogUtil.e("更改" + mPressedView.getTop());
//                        LogUtil.e("1点的位置x:" + e.getRawX() + "    y:" + e.getRawY());
//                        int newLeft = childView.getLeft() + mPressedView.getLeft();
//                        int newRight = childView.getRight() + mPressedView.getLeft();
//                        int newTop = childView.getTop() + mPressedView.getTop();
//                        int newBottom = childView.getBottom() + mPressedView.getTop();
//                        LogUtil.e("newLeft:" + newLeft + "    newRight:" + newRight);
//                        LogUtil.e("newTop:" + newTop + "     newBottom" + newBottom);
//                        if ((newLeft <= e.getRawX() && e.getRawX() <= newRight) &&
//                                (newTop <= e.getRawY() && e.getRawY() <= newBottom)) {
//                                return true;
//                        } else {
//                                return false;
//                        }


                        int[] location = new int[2];
                        childView.getLocationOnScreen(location);
//                        LogUtil.e("scrollX" + childView.getScrollX() + "     scrollY" + childView.getScrollY());
                        LogUtil.e("1view点的位置x:" + location[0] + "    y:" + location[1]);
                        LogUtil.e("1点的位置x:" + e.getRawX() + "    y:" + e.getRawY());
                        LogUtil.e("1view的大小w:" + childView.getWidth() + "    h:" + childView.getHeight());

                        if ((location[0] < e.getRawX() && e.getRawX() < location[0] + childView.getWidth()) &&
                                (location[1] < e.getRawY() && e.getRawY() < location[1] + childView.getHeight())) {
                                LogUtil.e("true");
                                return true;
                        }
                        LogUtil.e("false");
                        return false;
                }
 
Example 11
Project: LQRWeChat   File: SessionActivity.java   Source Code and License Vote up 5 votes
private boolean isCancelled(View view, MotionEvent event) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);

    if (event.getRawX() < location[0] || event.getRawX() > location[0] + view.getWidth()
            || event.getRawY() < location[1] - 40) {
        return true;
    }

    return false;
}
 
Example 12
Project: godlibrary   File: HorizontalListView.java   Source Code and License Vote up 5 votes
private boolean isEventWithinView(MotionEvent e, View child) {
    Rect viewRect = new Rect();
    int[] childPosition = new int[2];
    child.getLocationOnScreen(childPosition);
    int left = childPosition[0];
    int right = left + child.getWidth();
    int top = childPosition[1];
    int bottom = top + child.getHeight();
    viewRect.set(left, top, right, bottom);
    return viewRect.contains((int) e.getRawX(), (int) e.getRawY());
}
 
Example 13
Project: rongyunDemo   File: DragPointView.java   Source Code and License Vote up 4 votes
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
    View root = getRootView();
    if (root == null || !(root instanceof ViewGroup)) {
        return false;
    }
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            root.getLocationOnScreen(p);
            scrollParent = getScrollParent();
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(true);
            }
            int location[] = new int[2];
            getLocationOnScreen(location);
            x = location[0] + (getWidth() / 2) - p[0];
            y = location[1] + (getHeight() / 2) - p[1];
            r = (getWidth() + getHeight()) / 4;
            pointView = new PointView(getContext());
            pointView.setLayoutParams(new ViewGroup.LayoutParams(root.getWidth(), root.getHeight()));
            setDrawingCacheEnabled(true);
            pointView.catchBitmap = getDrawingCache();
            pointView.setLocation(x, y, r, event.getRawX() - p[0], event.getRawY() - p[1]);
            ((ViewGroup) root).addView(pointView);
            setVisibility(View.INVISIBLE);
            break;
        case MotionEvent.ACTION_MOVE:
            pointView.refrashXY(event.getRawX() - p[0], event.getRawY() - p[1]);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(false);
            }
            if (!pointView.broken) { // 没有拉断
                pointView.cancel();
            } else if (pointView.nearby) {// 拉断了,但是又回去了
                pointView.cancel();
            } else { // 彻底拉断了
                pointView.broken();
            }
            break;
        default:
            break;
    }
    return true;
}
 
Example 14
Project: Sega   File: SearchView.java   Source Code and License Vote up 4 votes
private int getCenterX(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    return location[0] + view.getWidth() / 2;
}
 
Example 15
Project: prismoji-android   File: PrismojiVariantPopup.java   Source Code and License Vote up 4 votes
void show(@NonNull final View clickedImage, @NonNull final Emoji emoji) {
    dismiss();

    final View content = View.inflate(clickedImage.getContext(), R.layout.emoji_skin_popup, null);
    final LinearLayout imageContainer = (LinearLayout) content.findViewById(R.id.container);

    popupWindow = new PopupWindow(content,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT
    );

    final List<Emoji> variants = emoji.getBase().getVariants();
    variants.add(0, emoji.getBase());

    final LayoutInflater inflater = LayoutInflater.from(clickedImage.getContext());

    for (final Emoji variant : variants) {
        final ImageView emojiImage = (ImageView) inflater.inflate(R.layout.emoji_item, imageContainer, false);
        final ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) emojiImage.getLayoutParams();
        final int margin = Utils.dpToPx(clickedImage.getContext(), MARGIN);

        // Use the same size for Emojis as in the picker.
        layoutParams.width = clickedImage.getWidth();
        layoutParams.setMargins(margin, margin, margin, margin);
        emojiImage.setImageResource(variant.getResource());

        emojiImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                if (listener != null) {
                    listener.onEmojiClicked(variant);
                }
            }
        });

        imageContainer.addView(emojiImage);
    }

    content.measure(makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

    popupWindow.setOutsideTouchable(true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable(clickedImage.getContext().getResources(), (Bitmap) null));

    final int[] location = new int[2];
    clickedImage.getLocationOnScreen(location);

    final int x = location[0] - popupWindow.getContentView().getMeasuredWidth() / 2 + clickedImage.getWidth() / 2;
    final int y = location[1] - popupWindow.getContentView().getMeasuredHeight();

    popupWindow.showAtLocation(((Activity) content.getContext()).getWindow().getDecorView(),
            Gravity.NO_GRAVITY, x, y);
}
 
Example 16
Project: AndroidTvDemo   File: BaseEffectBridgeWrapper.java   Source Code and License Vote up 4 votes
public int[] getViewLocationScreen(View v)
{
    int[] location = new int[2];
    v.getLocationOnScreen(location);
    return location;
}
 
Example 17
Project: sealtalk-android-master   File: DragPointView.java   Source Code and License Vote up 4 votes
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
    View root = getRootView();
    if (root == null || !(root instanceof ViewGroup)) {
        return false;
    }
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            root.getLocationOnScreen(p);
            scrollParent = getScrollParent();
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(true);
            }
            int location[] = new int[2];
            getLocationOnScreen(location);
            x = location[0] + (getWidth() / 2) - p[0];
            y = location[1] + (getHeight() / 2) - p[1];
            r = (getWidth() + getHeight()) / 4;
            pointView = new PointView(getContext());
            pointView.setLayoutParams(new ViewGroup.LayoutParams(root.getWidth(), root.getHeight()));
            setDrawingCacheEnabled(true);
            pointView.catchBitmap = getDrawingCache();
            pointView.setLocation(x, y, r, event.getRawX() - p[0], event.getRawY() - p[1]);
            ((ViewGroup) root).addView(pointView);
            setVisibility(View.INVISIBLE);
            break;
        case MotionEvent.ACTION_MOVE:
            pointView.refrashXY(event.getRawX() - p[0], event.getRawY() - p[1]);
            break;
        case MotionEvent.ACTION_CANCEL:

        case MotionEvent.ACTION_UP:
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(false);
            }
            if (!pointView.broken) { // 没有拉断
                pointView.cancel();
            } else if (pointView.nearby) {// 拉断了,但是又回去了
                pointView.cancel();
            } else { // 彻底拉断了
                pointView.broken();
            }
            break;
        default:
            break;
    }
    return true;
}
 
Example 18
Project: boohee_v5.6   File: ListPopupWindow.java   Source Code and License Vote up 4 votes
private boolean toLocalMotionEvent(View view, MotionEvent event) {
    int[] loc = this.mTmpLocation;
    view.getLocationOnScreen(loc);
    event.offsetLocation((float) (-loc[0]), (float) (-loc[1]));
    return true;
}
 
Example 19
Project: ClassifyView   File: ClassifyView.java   Source Code and License Vote up 4 votes
private void getLocationAndFixHeight(@NonNull View container, @NonNull int[] holder) {
    container.getLocationOnScreen(holder);
    fixHeight(holder);
}
 
Example 20
Project: react-native-udesk   File: UdeskMultiMenuHorizontalWindow.java   Source Code and License Vote up 0 votes
public void show(Context content,View locationView,String[] menuLabelArray,OnPopMultiMenuClick onPopMultiMenuClick){
        try {
            //check
            if(menuLabelArray==null || menuLabelArray.length<1){
                throw new RuntimeException(" menu label can not be empty ");
            }

            // ready
            LayoutInflater layoutInflater=LayoutInflater.from(content);
            mOnPopMultiMenuClick = onPopMultiMenuClick;

            // 如果只有一个,则把divider删除掉
            ViewGroup popupView =(ViewGroup) layoutInflater.inflate(R.layout.udesk_multi_horizontal_popmenu, null);

            // 把菜单都添加进去
            addChildView(popupView,layoutInflater,menuLabelArray);
            setContentView(popupView);


            // 测绘并定位
            popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
            int popupWidth = popupView.getMeasuredWidth();
            int popupHeight =  popupView.getMeasuredHeight();
            setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
            setHeight(popupHeight);

            //显示出来
            int[] location = new int[2];
            locationView.getLocationOnScreen(location);

            showAtLocation(locationView, Gravity.NO_GRAVITY , /*location[0]*/(location[0]+locationView.getWidth()/2)-popupWidth/2,
                    location[1]-popupHeight/*location[1]- getHeight()*/);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }