Example usage for android.view View getLocationOnScreen

List of usage examples for android.view View getLocationOnScreen

Introduction

In this page you can find the example usage for android.view View getLocationOnScreen.

Prototype

public void getLocationOnScreen(@Size(2) int[] outLocation) 

Source Link

Document

Computes the coordinates of this view on the screen.

Usage

From source file:com.hustunique.jianguo.materialsearchview.SearchViewUtil.java

public static int getBottomY(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    return location[1] + view.getHeight();
}

From source file:com.hustunique.jianguo.materialsearchview.SearchViewUtil.java

public static int getUpY(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    return location[1];
}

From source file:com.gc.markdown.utils.ViewUtils.java

/**
 * ?View????//w  w  w .  j  a  v  a 2 s. c o  m
 * obtain access to View the absolute coordinates of within the entire screen
 *
 * @param view view
 * @return int[] x y
 */
public static int[] getLocationOnScreen(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    return location;
}

From source file:Main.java

public static boolean inViewInBounds(View view, int x, int y) {
    Rect outRect = new Rect();
    int[] location = new int[2];

    view.getDrawingRect(outRect);//w ww . java 2 s  .co  m
    view.getLocationOnScreen(location);
    outRect.offset(location[0], location[1]);
    return outRect.contains(x, y);
}

From source file:Main.java

/**
 * This method finds location of the view on the screen.
 * /*from w w  w  .java2s. c  om*/
 * @param view
 * @return rect
 */
public static Rect locateView(View view) {
    int[] loc_int = new int[2];
    if (view == null)
        return null;
    try {
        view.getLocationOnScreen(loc_int);
    } catch (NullPointerException npe) {
        // Happens when the view doesn't exist on screen anymore.
        return null;
    }
    Rect location = new Rect();
    location.left = loc_int[0];
    location.top = loc_int[1];
    location.right = location.left + view.getWidth();
    location.bottom = location.top + view.getHeight();
    return location;
}

From source file:Main.java

/**
 * Computes the center of the clipping circle used by transform and reveal animations
 * The result is relative to the target.
 *
 * @param origin The Origin of the effect (eg. pressed view)
 * @param target Targeted view, that will be clipped
 * @return x and y coordinates in an array, in that order
 *///from www .ja  va  2 s  .c o  m
public static int[] getCenter(View origin, View target) {

    //the top left corner of origin
    int[] originPosition = new int[2];
    origin.getLocationOnScreen(originPosition);

    //the center of origin
    originPosition[0] = originPosition[0] + origin.getWidth() / 2;
    originPosition[1] = originPosition[1] + origin.getHeight() / 2;

    // get the center for the clipping circle for the view
    int[] targetPosition = new int[2];
    target.getLocationOnScreen(targetPosition);

    int[] center = new int[2];

    center[0] = originPosition[0] - targetPosition[0];
    center[1] = originPosition[1] - targetPosition[1];

    return center;
}

From source file:com.ruesga.rview.fragments.RevealDialogFragment.java

public static Rect computeViewOnScreen(View v) {
    int[] pos = new int[2];
    v.getLocationOnScreen(pos);
    Rect rect = new Rect();
    rect.set(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight());
    return rect;// w ww  .  ja  v  a  2s .c o  m
}

From source file:net.nym.napply.library.behavior.HeadOffsetBehavior.java

public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth()) || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }/*from  ww w.  j  ava  2s. c  o m*/
    return true;
}

From source file:Main.java

public static boolean isInVisisble(View view) {
    if (screenHeight == -1) {
        screenHeight = view.getContext().getResources().getDisplayMetrics().heightPixels;
        screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels;
    }//from w  w w.ja  v  a2s  .  c o  m

    view.getLocationOnScreen(location);
    int left = location[0];
    int top = location[1];
    int height = view.getHeight();

    //in top
    if ((top + height) < -0.5 * screenHeight) {
        return true;
    }

    //in bottom
    if (top > screenHeight + 0.5 * screenHeight) {
        return true;
    }

    return false;
}

From source file:Main.java

/**
 * Display a {@link Toast} letting the user know what an item does when long
 * pressed./*  w  w w.j a  v  a 2 s  .c o m*/
 * 
 * @param view The {@link View} to copy the content description from.
 */
public static void showCheatSheet(final View view) {

    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) (48 * context.getResources().getDisplayMetrics().density);

    final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), Toast.LENGTH_SHORT);
    final boolean showBelow = screenPos[1] < estimatedToastHeight;
    if (showBelow) {
        // Show below
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top + viewHeight);
    } else {
        // Show above
        // Offsets are after decorations (e.g. status bar) are factored in
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                displayFrame.bottom - screenPos[1]);
    }
    cheatSheet.show();
}