View getLocationOnScreen - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for View getLocationOnScreen method.

This code example shows how to use the following methods:getContext, getHeight, getLocationOnScreen, getWidth, getWindowVisibleDisplayFrame
            return false; 
        } 
 
        final int[] screenPos = new int[2]; // origin is device display
        final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar)
        view.getLocationOnScreen(screenPos);
        view.getWindowVisibleDisplayFrame(displayFrame);
 
        final Context context = view.getContext();
        final int viewWidth = view.getWidth();
        final int viewHeight = view.getHeight();
        final int viewCenterX = screenPos[0] + viewWidth / 2;
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS
                * context.getResources().getDisplayMetrics().density);
 
        Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        boolean showBelow = screenPos[1] < estimatedToastHeight;
        if (showBelow) {
            // Show below 
9
CodeRank
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getWidth
 
        // Replaces the background of the popup with a cleared background 
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
 
        final int[] loc = mLocation;
        anchor.getLocationOnScreen(loc);
        mRect.set(loc[0], loc[1], loc[0] + anchor.getWidth(), loc[1] + anchor.getHeight());
 
        if (mIsDirty) {
            clearQuickActions(); 
            populateQuickActions(mQuickActions);
        } 
 
        onMeasureAndLayout(mRect, contentView);
 
        if ((mPrivateFlags & MEASURE_AND_LAYOUT_DONE) != MEASURE_AND_LAYOUT_DONE) {
            throw new IllegalStateException("onMeasureAndLayout() did not set the widget specification by calling"
                    + " setWidgetSpecs()"); 
        } 
 
8
CodeRank
This code example shows how to use the following methods:getContentDescription, getHeight, getId, getLocationOnScreen, getWidth
 
	@SuppressWarnings({ "rawtypes", "unchecked" }) 
	public static Object extractDataFromView(View v) {		
		 
		Map data = new HashMap();
		data.put("class", v.getClass().getName());		
		data.put("description", v.toString());
		CharSequence description = v.getContentDescription();
		data.put("contentDescription", description != null ? description.toString() : null);
		data.put("enabled", v.isEnabled());
		String id = null;
		try { 
			id = InstrumentationBackend.solo.getCurrentActivity()
					.getResources().getResourceEntryName(v.getId());
		} catch (Resources.NotFoundException e) {
			System.out.println("Resource not found for " + v.getId()
					+ ". Moving on."); 
		} 
		data.put("id", id);
 

8
CodeRank
This code example shows how to use the following methods:getContext, getHeight, getLocationOnScreen, getWindowVisibleDisplayFrame
        return listContent + otherHeights;
    } 
 
    private int getMaxAvailableHeight(View anchor, int yOffset, boolean ignoreBottomDecorations) {
        final Rect displayFrame = new Rect();
        anchor.getWindowVisibleDisplayFrame(displayFrame);
 
        final int[] anchorPos = new int[2];
        anchor.getLocationOnScreen(anchorPos);
 
        int bottomEdge = displayFrame.bottom;
        if (ignoreBottomDecorations) {
            Resources res = anchor.getContext().getResources();
            bottomEdge = res.getDisplayMetrics().heightPixels;
        } 
        final int distanceToBottom = bottomEdge - (anchorPos[1] + anchor.getHeight()) - yOffset;
        final int distanceToTop = anchorPos[1] - displayFrame.top + yOffset;
 
        // anchorPos[1] is distance from anchor to top of screen 
        int returnedHeight = Math.max(distanceToBottom, distanceToTop);
        if (mPopup.getBackground() != null) {
8
CodeRank
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getWidth
 
        // Replaces the background of the popup with a cleared background 
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
 
        final int[] loc = mLocation;
        anchor.getLocationOnScreen(loc);
        mRect.set(loc[0], loc[1], loc[0] + anchor.getWidth(), loc[1] + anchor.getHeight());
 
        if (mIsDirty) {
            clearQuickActions(); 
            populateQuickActions(mQuickActions);
        } 
 
        onMeasureAndLayout(mRect, contentView);
 
        if ((mPrivateFlags & MEASURE_AND_LAYOUT_DONE) != MEASURE_AND_LAYOUT_DONE) {
            throw new IllegalStateException("onMeasureAndLayout() did not set the widget specification by calling"
                    + " setWidgetSpecs()"); 
        } 
 
8
CodeRank
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getParent
 
	public View getScrollOrListParent(View view) {
 
	    if (!(view instanceof android.widget.AbsListView) && !(view instanceof android.widget.ScrollView) && !(view instanceof WebView)) {
	        try{ 
	            return getScrollOrListParent((View) view.getParent());
	        }catch(Exception e){
	            return null; 
	        } 
	    } else { 
	        return view;
	    } 
	} 
 
	/** 
	 * Returns views from the shown DecorViews. 
	 * 
	 * @param onlySufficientlyVisible if only sufficiently visible views should be returned 
	 * @return all the views contained in the DecorViews 
	 */ 

7
CodeRank
This code example shows how to use the following methods:getLocationOnScreen, getScale
	} 
	 
	public static Map<String, Object> translateRectToScreenCoordinates(WebView webView, Map<String, Object> rectangle) {
		try { 
			 
            float scale = webView.getScale();
 
			int[] webviewLocation = new int[2];
			webView.getLocationOnScreen(webviewLocation);
			//center_x, center_y 
			//left, top, width, height 
			float center_x = translateCoordToScreen(webviewLocation[0], scale,
					rectangle.get("center_x"));
			float center_y = translateCoordToScreen(webviewLocation[1], scale,
					rectangle.get("center_y"));
									 
			float x = translateCoordToScreen(webviewLocation[0], scale, rectangle.get("left"));
			float y = translateCoordToScreen(webviewLocation[0], scale, rectangle.get("top"));
			Map<String,Object> result = new HashMap<String, Object>(rectangle);
			 
7
CodeRank
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getWidth
		} 
 
		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()); 
        } 
	}; 
 
	 
 
} 
7
CodeRank
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getWidth
This code example shows how to use the following methods:getHeight, getLocationOnScreen, getWidth
 
    // Replaces the background of the popup with a cleared background 
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
 
    final int[] loc = mLocation;
    anchor.getLocationOnScreen(loc);
    mRect.set(loc[0], loc[1], loc[0] + anchor.getWidth(), loc[1] + anchor.getHeight());
 
    if (mIsDirty) {
      clearQuickActions(); 
      populateQuickActions(mQuickActions);
    } 
 
    onMeasureAndLayout(mRect, contentView);
 
    if ((mPrivateFlags & MEASURE_AND_LAYOUT_DONE) != MEASURE_AND_LAYOUT_DONE) {
      throw new IllegalStateException(
          "onMeasureAndLayout() did not set the widget specification by calling" 
              + " setWidgetSpecs()"); 
    } 
7
CodeRank

Related View getLocationOnScreen Questions & Answers:

getLocationOnScreen Method Overview
Computes the coordinates of this view on the screen.
See Code Examples for other Android View Methods: