Example usage for android.view View getLocationInWindow

List of usage examples for android.view View getLocationInWindow

Introduction

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

Prototype

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

Source Link

Document

Computes the coordinates of this view in its window.

Usage

From source file:com.efithealth.app.activity.BaseActivity.java

private boolean isHideInput(View v, MotionEvent ev) {
    if (v != null && (v instanceof EditText)) {
        int[] l = { 0, 0 };
        v.getLocationInWindow(l);
        int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
        if (ev.getX() > left && ev.getX() < right && ev.getY() > top && ev.getY() < bottom) {
            return false;
        } else {/*from   w w  w.j  a va  2  s  .  com*/
            return true;
        }
    }
    return false;
}

From source file:net.bither.fragment.hot.MarketFragment.java

public void showPriceAlertAnimTo(int fromX, int fromY, Market toMarket) {
    int[] containerOffset = new int[2];
    v.getLocationInWindow(containerOffset);
    containerOffset[0] += v.getPaddingLeft();
    containerOffset[1] += v.getPaddingTop();
    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) ivMarketPriceAnimIcon.getLayoutParams();
    lp.topMargin = fromY - containerOffset[1];
    lp.leftMargin = fromX - containerOffset[0];
    int marketIndex = markets.indexOf(toMarket);
    if (marketIndex < lv.getFirstVisiblePosition() || marketIndex > lv.getLastVisiblePosition()) {
        lv.setSelection(marketIndex);//from  ww  w . ja v a  2  s  .  com
    }
    View marketView = lv.getChildAt(marketIndex - lv.getFirstVisiblePosition());
    View toIconView = marketView.findViewById(R.id.iv_price_alert);
    int[] toLocation = new int[2];
    toIconView.getLocationInWindow(toLocation);
    TranslateAnimation anim = new TranslateAnimation(0, toLocation[0] - fromX, 0, toLocation[1] - fromY);
    anim.setDuration(300);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            doRefresh();
            ivMarketPriceAnimIcon.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    ivMarketPriceAnimIcon.setVisibility(View.VISIBLE);
    ivMarketPriceAnimIcon.startAnimation(anim);
}

From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java

private boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] leftTop = { 0, 0 };
        // ??location?
        v.getLocationInWindow(leftTop);
        int left = leftTop[0];
        int top = leftTop[1];
        int bottom = top + v.getHeight();
        int right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // ?EditText
            return false;
        } else {//from  w  w w.java2  s .com
            return true;
        }
    }
    return false;
}

From source file:com.acious.android.paginationseekbar.internal.PopupIndicator.java

private void updateLayoutParamsForPosiion(View anchor, WindowManager.LayoutParams p, int yOffset) {
    measureFloater();//from  w ww  . ja va  2  s  .c  o  m
    int measuredHeight = mPopupView.getMeasuredHeight();
    int paddingBottom = mPopupView.mMarker.getPaddingBottom();
    anchor.getLocationInWindow(mDrawingLocation);
    p.x = 0;
    p.y = mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom;
    p.width = screenSize.x;
    p.height = measuredHeight;
}

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);
    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);/*from   w  w w  .  jav  a2 s .  c  o  m*/
    qa.show(xy[0] + v.getWidth() / 2);
}

From source file:net.qiujuer.genius.ui.widget.GeniusPopupIndicator.java

private void updateLayoutParamsForPosition(View anchor, WindowManager.LayoutParams p, int yOffset) {
    measureFloater();//w  ww  .  ja va 2s.c o  m
    int measuredHeight = mPopupView.getMeasuredHeight();
    int paddingBottom = mPopupView.mMarker.getPaddingBottom();
    anchor.getLocationInWindow(mDrawingLocation);
    p.x = 0;
    p.y = mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom;
    p.width = screenSize.x;
    p.height = measuredHeight;
}

From source file:com.example.michaelg.myapplication.Item.discreteseekbar.internal.PopupIndicator.java

private void updateLayoutParamsForPosiion(View anchor, WindowManager.LayoutParams p, int yOffset) {
    DisplayMetrics displayMetrics = anchor.getResources().getDisplayMetrics();
    screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels);

    measureFloater();/*from ww w  .j a  v  a2s.c  om*/
    int measuredHeight = mPopupView.getMeasuredHeight();
    int paddingBottom = mPopupView.mMarker.getPaddingBottom();
    anchor.getLocationInWindow(mDrawingLocation);
    p.x = 0;
    p.y = mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom;
    p.width = screenSize.x;
    p.height = measuredHeight;
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java

@Override
public boolean onLongClick(View view) {
    if (view == mEditTime) {
        int[] viewPos = new int[2];
        view.getLocationInWindow(viewPos);
        int[] offsetPos = new int[2];
        view.getRootView().findViewById(android.R.id.content).getLocationInWindow(offsetPos);
        Toast toast = Toast.makeText(getActivity(), view.getContentDescription(), Toast.LENGTH_SHORT);

        toast.setGravity(Gravity.END | Gravity.TOP, 0, viewPos[1] - offsetPos[1] + view.getHeight());
        toast.show();//w ww . java 2  s  .c o  m
        return true;
    }
    return false;
}

From source file:com.android.camera.ActivityBase.java

@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
        int oldRight, int oldBottom) {
    if (mAppBridge == null)
        return;/*from www  .ja  v  a2  s .  co m*/

    if (left == oldLeft && top == oldTop && right == oldRight && bottom == oldBottom) {
        return;
    }

    int width = right - left;
    int height = bottom - top;
    if (Util.getDisplayRotation(this) % 180 == 0) {
        mCameraScreenNail.setPreviewFrameLayoutSize(width, height);
    } else {
        // Swap the width and height. Camera screen nail draw() is based on
        // natural orientation, not the view system orientation.
        mCameraScreenNail.setPreviewFrameLayoutSize(height, width);
    }

    // Find out the coordinates of the preview frame relative to GL
    // root view.
    View root = (View) getGLRoot();
    int[] rootLocation = new int[2];
    int[] viewLocation = new int[2];
    root.getLocationInWindow(rootLocation);
    v.getLocationInWindow(viewLocation);

    int l = viewLocation[0] - rootLocation[0];
    int t = viewLocation[1] - rootLocation[1];
    int r = l + width;
    int b = t + height;
    Rect frame = new Rect(l, t, r, b);
    Log.d(TAG, "set CameraRelativeFrame as " + frame);
    mAppBridge.setCameraRelativeFrame(frame);
}

From source file:com.gizwits.framework.activity.BaseActivity.java

/**
 * ?EditText????????EditText???//from  w  w w.jav  a 2 s . c  om
 * 
 * @param v
 * @param event
 * @return
 */
private boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l = { 0, 0 };
        v.getLocationInWindow(l);
        int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // EditText
            return false;
        } else {
            return true;
        }
    }
    // ?EditText??EditView?
    return false;
}