List of usage examples for android.view View getLocationOnScreen
public void getLocationOnScreen(@Size(2) int[] outLocation)
Computes the coordinates of this view on the screen.
From source file:de.dmxcontrol.activity.ControlActivity.java
private boolean isPointInsideView(float x, float y, View view) { int location[] = new int[2]; view.getLocationOnScreen(location); int viewX = location[0]; int viewY = location[1]; if ((x > viewX && x < (viewX + view.getWidth())) && (y > viewY && y < (viewY + view.getHeight()))) { return true; } else {/*from ww w.j ava 2 s . c om*/ return false; } }
From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java
private void showContactQuickActions(View v) { // Get the tag, which will provide us the KVP int[] xy = new int[2]; v.getLocationInWindow(xy);//from ww w. jav a2 s . c o m Rect rect = new Rect(xy[0], xy[1], xy[0] + v.getWidth(), xy[1] + v.getHeight()); final QuickActionWindow qa = new QuickActionWindow(v.getContext(), v, rect); qa.addItem(R.drawable.social_add_person, R.id.saveContact, this); v.getLocationOnScreen(xy); qa.show(xy[0] + v.getWidth() / 2); }
From source file:com.github.pedrovgs.DraggableView.java
/** * Calculate if one position is above any view. * * @param view to analyze.//from w ww .jav a2 s .c om * @param x position. * @param y position. * @return true if x and y positions are below the view. */ private boolean isViewHit(View view, int x, int y) { int[] viewLocation = new int[2]; view.getLocationOnScreen(viewLocation); int[] parentLocation = new int[2]; this.getLocationOnScreen(parentLocation); int screenX = parentLocation[0] + x; int screenY = parentLocation[1] + y; return screenX >= viewLocation[0] && screenX < viewLocation[0] + view.getWidth() && screenY >= viewLocation[1] && screenY < viewLocation[1] + view.getHeight(); }
From source file:io.plaidapp.ui.HomeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_filter: drawer.openDrawer(GravityCompat.END); return true; case R.id.menu_search: // get the icon's location on screen to pass through to the search screen View searchMenuView = toolbar.findViewById(R.id.menu_search); int[] loc = new int[2]; searchMenuView.getLocationOnScreen(loc); startActivityForResult(/*w w w .j a v a 2s .c o m*/ SearchActivity.createStartIntent(this, loc[0], loc[0] + (searchMenuView.getWidth() / 2)), RC_SEARCH, ActivityOptions.makeSceneTransitionAnimation(this).toBundle()); searchMenuView.setAlpha(0f); return true; case R.id.menu_dribbble_login: if (!dribbblePrefs.isLoggedIn()) { dribbblePrefs.login(HomeActivity.this); } else { dribbblePrefs.logout(); // TODO something better than a toast!! Toast.makeText(getApplicationContext(), R.string.dribbble_logged_out, Toast.LENGTH_SHORT).show(); } return true; case R.id.menu_designer_news_login: if (!designerNewsPrefs.isLoggedIn()) { startActivity(new Intent(this, DesignerNewsLogin.class)); } else { designerNewsPrefs.logout(); // TODO something better than a toast!! Toast.makeText(getApplicationContext(), R.string.designer_news_logged_out, Toast.LENGTH_SHORT) .show(); } return true; case R.id.menu_about: startActivity(new Intent(HomeActivity.this, AboutActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle()); return true; } return super.onOptionsItemSelected(item); }
From source file:net.osmand.plus.views.controls.DynamicListView.java
/** * Returns the most inner view that contains the xy coordinate. * * @param v This method gets called recursively. The initial call should be the root view. * @param x The X location to be tested. * @param y The Y location to be tested. * @return Returns the most inner view that contains the XY coordinate or null if no view could be found. *//*from w ww . j a v a 2s . co m*/ private View findViewAtPositionWithDragIconTag(View v, int x, int y) { View vXY = null; if (v instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) v; for (int i = 0; i < viewGroup.getChildCount(); i++) { View c = viewGroup.getChildAt(i); int loc[] = new int[2]; c.getLocationOnScreen(loc); if ((x >= loc[0] && (x <= (loc[0] + c.getWidth()))) && (y >= loc[1] && (y <= (loc[1] + c.getHeight())))) { vXY = c; View viewAtPosition = findViewAtPositionWithDragIconTag(c, x, y); if ((viewAtPosition != null) && (viewAtPosition.getTag() != null) && viewAtPosition.getTag() instanceof DragIcon) { vXY = viewAtPosition; break; } } } } return vXY; }
From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java
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; }//w ww .java 2 s . co m 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) { mPopup.getBackground().getPadding(mTempRect); returnedHeight -= mTempRect.top + mTempRect.bottom; } return returnedHeight; }
From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java
private void getLocationOnScreen(View view, RectF rectF) { final int[] location = new int[2]; view.getLocationOnScreen(location); rectF.set(location[0], location[1], location[0] + view.getWidth(), location[1] + view.getHeight()); }
From source file:com.andfchat.frontend.activities.ChatScreen.java
/** * Hides the soft keyboard if user is touching anywhere else. *//* www . j a va 2 s . c om*/ @Override public boolean dispatchTouchEvent(MotionEvent event) { View view = getCurrentFocus(); boolean ret = super.dispatchTouchEvent(event); if (view instanceof EditText) { View w = getCurrentFocus(); int scrcoords[] = new int[2]; w.getLocationOnScreen(scrcoords); float x = event.getRawX() + w.getLeft() - scrcoords[0]; float y = event.getRawY() + w.getTop() - scrcoords[1]; if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) { inputFragment.hideKeyboard(); inputFragment.saveEntry(); } } return ret; }
From source file:com.sonvp.tooltip.Tooltip.java
private Rect getRectView(View view) { Rect rect = new Rect(); int[] screenLoc = new int[2]; view.getLocationOnScreen(screenLoc); rect.left += screenLoc[0];//from w w w . j a v a 2 s. com rect.right += screenLoc[0] + view.getWidth(); rect.top += screenLoc[1]; rect.bottom += screenLoc[1] + view.getHeight(); return rect; }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * This will determine two things.//w w w .ja v a 2 s .c om * 1. If we need to handle the touch event * 2. If reordering needs to start due to dragHandle being clicked */ @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) { if (dragState == DragState.DRAGGING) { return true; } if (dragHandleId == INVALID_RESOURCE_ID) { return false; } View itemView = recyclerView.findChildViewUnder(event.getX(), event.getY()); if (itemView == null) { return false; } View handleView = itemView.findViewById(dragHandleId); if (handleView == null || handleView.getVisibility() != View.VISIBLE) { return false; } int[] handlePosition = new int[2]; handleView.getLocationOnScreen(handlePosition); //Determine if the MotionEvent is inside the handle if ((event.getRawX() >= handlePosition[0] && event.getRawX() <= handlePosition[0] + handleView.getWidth()) && (event.getRawY() >= handlePosition[1] && event.getRawY() <= handlePosition[1] + handleView.getHeight())) { startReorder(itemView, event); return true; } return false; }