Example usage for android.view View getLeft

List of usage examples for android.view View getLeft

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getLeft() 

Source Link

Document

Left position of this view relative to its parent.

Usage

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

void addOnTouchListener(View view) {
    Button button = (Button) view;
    button.setOnTouchListener(new View.OnTouchListener() {
        @Override//  w  w w  .j ava2s  .c  o m
        public boolean onTouch(View v, MotionEvent e) {
            x = (int) e.getX() + v.getLeft();
            y = (int) e.getY() + v.getTop();
            return false;
        }
    });
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

void addOnTouchListenerText(View view) {
    TextView text = (TextView) view;/*from  w  w  w.ja v  a2s  .com*/
    text.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent e) {
            x = (int) e.getX() + v.getLeft();
            y = (int) e.getY() + v.getTop();
            return false;
        }
    });
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

private boolean isViewVisible(HorizontalScrollView scrollView, View view) {
    Rect scrollBounds = new Rect();
    scrollView.getDrawingRect(scrollBounds);
    float vLeft = view.getLeft();
    float vRight = view.getWidth() + vLeft;
    return scrollBounds.left < vLeft && scrollBounds.right > vRight;
}

From source file:ca.barrenechea.widget.recyclerview.decoration.DoubleHeaderDecoration.java

/**
 * {@inheritDoc}//from   w w w .j av  a2  s. c om
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();

    boolean headerDrawn = false;
    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        boolean visible = getAnimatedTop(child) > -child.getHeight()/* && child.getTop() < parent.getHeight()*/;
        final int adapterPos = parent.getChildAdapterPosition(child);
        if (visible && adapterPos != RecyclerView.NO_POSITION && (!headerDrawn || hasSubHeader(adapterPos))) {
            int left, top;
            final View header = getHeader(parent, adapterPos).itemView;
            final View subHeader = getSubHeader(parent, adapterPos).itemView;

            c.save();
            left = child.getLeft();
            top = getSubHeaderTop(parent, child, header, subHeader, adapterPos, layoutPos);
            c.translate(left, top);
            subHeader.setTranslationX(left);
            subHeader.setTranslationY(top);
            subHeader.draw(c);
            c.restore();

            if (!headerDrawn || hasHeader(adapterPos)) {
                c.save();
                left = child.getLeft();
                top = getHeaderTop(parent, child, header, subHeader, adapterPos, layoutPos);
                c.translate(left, top);
                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(c);
                c.restore();
            }

            headerDrawn = true;
        }
    }
}

From source file:com.csdn.pagerslidingtabstrip.view.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;// w  ww .  j  a v  a2 s.c o  m
    }

    if (pager == null) {
        rectPaint.setColor(indicatorColor);
        final int height = getHeight();
        /** tab **/
        View currentTab = tabsContainer.getChildAt(currentPosition);
        float lineLeft = currentTab.getLeft();
        float lineRight = currentTab.getRight();
        View lastTab = tabsContainer.getChildAt(lastposition);
        float detalLeft = lineLeft - lastTab.getLeft();
        float detalRight = lineRight - lastTab.getRight();

        if (currentTab != null) {

            canvas.drawRect(lineLeft - detalLeft, height - indicatorHeight,
                    lineLeft + currentTab.getWidth() - detalRight, height, rectPaint);

            Log.i("tteerr", "lineLeft=" + lineLeft + "--" + "lineRight=" + lineRight + "--detalLeft="
                    + detalLeft + "--+detalRight=" + detalRight);
            Log.i("tteerr", "" + "left=" + (lineLeft - detalLeft) + "top=" + (height - indicatorHeight)
                    + "right=" + (lineLeft + currentTab.getWidth() - detalRight) + "bottom=" + height);

            Log.i("tteerr", "currentPosition=" + currentPosition + "lastposition=" + lastposition);

        }
        return;
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw indicator line
    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:bulat.diet.helper_couch.adapter.ExpandableDraggableSwipeableExampleAdapter.java

@Override
public boolean onCheckGroupCanStartDrag(DayTimeViewHolder holder, int groupPosition, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View containerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    return false;//ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
}

From source file:bulat.diet.helper_couch.adapter.ExpandableDraggableSwipeableExampleAdapter.java

@Override
public boolean onCheckChildCanStartDrag(TodayDishItemViewHolder holder, int groupPosition, int childPosition,
        int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View containerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    return ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
}

From source file:bulat.diet.helper_couch.adapter.ExpandableDraggableSwipeableExampleAdapter.java

@Override
public boolean onCheckCanExpandOrCollapseGroup(DayTimeViewHolder holder, int groupPosition, int x, int y,
        boolean expand) {
    // check the item is *not* pinned
    if (mProvider.getGroupItem(groupPosition).isPinned()) {
        // return false to raise View.OnClickListener#onClick() event
        return false;
    }/*from ww w .j ava 2 s.co m*/

    // check is enabled
    if (!(holder.itemView.isEnabled() && holder.itemView.isClickable())) {
        return false;
    }

    final View containerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    return !ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
}

From source file:com.andfchat.frontend.activities.ChatScreen.java

/**
 * Hides the soft keyboard if user is touching anywhere else.
 *//*from  w w w.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:android.support.car.app.CarFragmentActivity.java

private static String viewToString(View view) {
    StringBuilder out = new StringBuilder(128);
    out.append(view.getClass().getName());
    out.append('{');
    out.append(Integer.toHexString(System.identityHashCode(view)));
    out.append(' ');
    switch (view.getVisibility()) {
    case View.VISIBLE:
        out.append('V');
        break;/*from w  w  w .  j a v a 2  s . com*/
    case View.INVISIBLE:
        out.append('I');
        break;
    case View.GONE:
        out.append('G');
        break;
    default:
        out.append('.');
        break;
    }
    out.append(view.isFocusable() ? 'F' : '.');
    out.append(view.isEnabled() ? 'E' : '.');
    out.append(view.willNotDraw() ? '.' : 'D');
    out.append(view.isHorizontalScrollBarEnabled() ? 'H' : '.');
    out.append(view.isVerticalScrollBarEnabled() ? 'V' : '.');
    out.append(view.isClickable() ? 'C' : '.');
    out.append(view.isLongClickable() ? 'L' : '.');
    out.append(' ');
    out.append(view.isFocused() ? 'F' : '.');
    out.append(view.isSelected() ? 'S' : '.');
    out.append(view.isPressed() ? 'P' : '.');
    out.append(' ');
    out.append(view.getLeft());
    out.append(',');
    out.append(view.getTop());
    out.append('-');
    out.append(view.getRight());
    out.append(',');
    out.append(view.getBottom());
    final int id = view.getId();
    if (id != View.NO_ID) {
        out.append(" #");
        out.append(Integer.toHexString(id));
        final Resources r = view.getResources();
        if (id != 0 && r != null) {
            try {
                String pkgname;
                switch (id & 0xff000000) {
                case 0x7f000000:
                    pkgname = "app";
                    break;
                case 0x01000000:
                    pkgname = "android";
                    break;
                default:
                    pkgname = r.getResourcePackageName(id);
                    break;
                }
                String typename = r.getResourceTypeName(id);
                String entryname = r.getResourceEntryName(id);
                out.append(" ");
                out.append(pkgname);
                out.append(":");
                out.append(typename);
                out.append("/");
                out.append(entryname);
            } catch (Resources.NotFoundException e) {
            }
        }
    }
    out.append("}");
    return out.toString();
}