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:enterprayz.megatools.Tools.java

public static Rect getViewRect(View view) {
    int[] pointA = new int[2];
    view.getLocationOnScreen(pointA);
    return new Rect(pointA[0], pointA[1], pointA[0] + view.getWidth(), pointA[1] + view.getHeight());
}

From source file:org.catrobat.paintroid.test.espresso.util.UiInteractions.java

public static ViewAction touchAt(final float x, final float y, final Tapper tapStyle) {
    return actionWithAssertions(new GeneralClickAction(tapStyle, new CoordinatesProvider() {
        @Override/*from  w  ww . j  av  a  2 s .c  o  m*/
        public float[] calculateCoordinates(View view) {
            final int[] screenLocation = new int[2];
            view.getLocationOnScreen(screenLocation);

            final float touchX = screenLocation[0] + x;
            final float touchY = screenLocation[1] + y;
            float[] coordinates = { touchX, touchY };

            return coordinates;
        }
    }, Press.FINGER));
}

From source file:org.xbmc.kore.testhelpers.action.ViewActions.java

public static ViewAction slideSeekBar(final int progress) {
    return new ViewAction() {
        @Override/*from  w  ww .ja v  a2  s  .co m*/
        public Matcher<View> getConstraints() {
            return new TypeSafeMatcher<View>() {
                @Override
                protected boolean matchesSafely(View item) {
                    return item instanceof SeekBar;
                }

                @Override
                public void describeTo(Description description) {
                    description.appendText("is a SeekBar.");
                }
            };
        }

        @Override
        public String getDescription() {
            return "Slides seekbar to progress position " + progress;
        }

        @Override
        public void perform(UiController uiController, View view) {
            SeekBar seekBar = (SeekBar) view;

            int[] seekBarPos = { 0, 0 };
            view.getLocationOnScreen(seekBarPos);
            float[] startPos = { seekBarPos[0], seekBarPos[1] };

            MotionEvents.DownResultHolder downResultHolder = MotionEvents.sendDown(uiController, startPos,
                    Press.PINPOINT.describePrecision());

            while (seekBar.getProgress() < progress) {
                startPos[0]++;
                MotionEvents.sendMovement(uiController, downResultHolder.down, startPos);
                uiController.loopMainThreadForAtLeast(10);
            }

            MotionEvents.sendUp(uiController, downResultHolder.down, startPos);
        }
    };
}

From source file:Main.java

private static boolean showToolTip(View view, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return false;
    }//from  w  w  w.jav a  2 s .co  m

    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
        // 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
        // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up
        // its height isn't factored in.
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top - estimatedToastHeight);
    }

    cheatSheet.show();
    return true;
}

From source file:Main.java

/**
 * Internal helper method to show the cheat sheet toast.
 *///  www .  j  av  a  2s . c om
private static boolean show(View view, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        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
        // 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
        // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up
        // its height isn't factored in.
        cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2,
                screenPos[1] - displayFrame.top - estimatedToastHeight);
    }

    cheatSheet.show();
    return true;
}

From source file:com.github.piasy.dialogfragmentanywhere.BaseDialogFragment.java

public static Bundle anchorTo(View anchor, @Locate int locate, int offsetX, int offsetY) {
    Bundle args = new Bundle();
    int[] loc = new int[2];
    anchor.getLocationOnScreen(loc);
    args.putInt(ANCHOR_VIEW_X, loc[0]);// w  w  w  . j  av a2 s  .  co  m
    args.putInt(ANCHOR_VIEW_Y, loc[1]);
    args.putInt(ANCHOR_VIEW_WIDTH, anchor.getWidth());
    args.putInt(ANCHOR_VIEW_HEIGHT, anchor.getHeight());
    args.putInt(LOCATE_TO_ANCHOR, locate);
    args.putInt(OFFSET_X, offsetX);
    args.putInt(OFFSET_Y, offsetY);
    return args;
}

From source file:com.agenmate.lollipop.util.ViewUtils.java

/**
 * Determines if two views intersect in the window.
 *//*w  ww.  ja  v  a 2 s  . c o m*/
public static boolean viewsIntersect(View view1, View view2) {
    if (view1 == null || view2 == null)
        return false;

    final int[] view1Loc = new int[2];
    view1.getLocationOnScreen(view1Loc);
    final Rect view1Rect = new Rect(view1Loc[0], view1Loc[1], view1Loc[0] + view1.getWidth(),
            view1Loc[1] + view1.getHeight());
    int[] view2Loc = new int[2];
    view2.getLocationOnScreen(view2Loc);
    final Rect view2Rect = new Rect(view2Loc[0], view2Loc[1], view2Loc[0] + view2.getWidth(),
            view2Loc[1] + view2.getHeight());
    return view1Rect.intersect(view2Rect);
}

From source file:com.waz.zclient.utils.ViewUtils.java

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

From source file:com.gitstudy.rili.liarbry.YearViewSelectLayout.java

/**
 * /*ww w .  jav a 2s. c  o  m*/
 *
 * @param context context
 * @param view    view
 * @return ?
 */
private static int getHeight(Context context, View view) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    assert manager != null;
    Display display = manager.getDefaultDisplay();
    int h = display.getHeight();
    int[] location = new int[2];
    view.getLocationInWindow(location);
    view.getLocationOnScreen(location);
    return h - location[1];
}

From source file:org.mozilla.focus.fragment.UrlInputFragment.java

/**
 * Create a new UrlInputFragment and animate the url input view from the position/size of the
 * fake url bar view.//from www . j  a  va2  s  .c  o m
 */
public static UrlInputFragment createWithHomeScreenAnimation(View fakeUrlBarView) {
    int[] screenLocation = new int[2];
    fakeUrlBarView.getLocationOnScreen(screenLocation);

    Bundle arguments = new Bundle();
    arguments.putString(ARGUMENT_ANIMATION, ANIMATION_HOME_SCREEN);
    arguments.putInt(ARGUMENT_X, screenLocation[0]);
    arguments.putInt(ARGUMENT_Y, screenLocation[1]);
    arguments.putInt(ARGUMENT_WIDTH, fakeUrlBarView.getWidth());
    arguments.putInt(ARGUMENT_HEIGHT, fakeUrlBarView.getHeight());

    UrlInputFragment fragment = new UrlInputFragment();
    fragment.setArguments(arguments);

    return fragment;
}