Example usage for android.graphics Rect width

List of usage examples for android.graphics Rect width

Introduction

In this page you can find the example usage for android.graphics Rect width.

Prototype

public final int width() 

Source Link

Usage

From source file:com.facebook.litho.LayoutState.java

void createDisplayList(LayoutOutput output) {
    ThreadUtils.assertMainThread();/*from w  ww  . j a  va2 s  .c o  m*/

    final Component component = output.getComponent();
    ComponentsSystrace.beginSection("createDisplayList: " + component.getSimpleName());
    final ComponentLifecycle lifecycle = component.getLifecycle();
    final DisplayList displayList = DisplayList.createDisplayList(lifecycle.getClass().getSimpleName());

    if (displayList == null) {
        ComponentsSystrace.endSection();
        return;
    }

    final ComponentContext context = mContext;

    Drawable drawable = (Drawable) ComponentsPools.acquireMountContent(context, lifecycle.getId());
    if (drawable == null) {
        drawable = (Drawable) lifecycle.createMountContent(context);
    }

    final LayoutOutput clickableOutput = findInteractiveRoot(this, output);
    boolean isStateEnabled = false;

    if (clickableOutput != null && clickableOutput.getNodeInfo() != null) {
        final NodeInfo nodeInfo = clickableOutput.getNodeInfo();

        if (nodeInfo.hasTouchEventHandlers() || nodeInfo.getFocusState() == FOCUS_SET_TRUE) {
            isStateEnabled = true;
        }
    }

    if (isStateEnabled) {
        drawable.setState(DRAWABLE_STATE_ENABLED);
    } else {
        drawable.setState(DRAWABLE_STATE_NOT_ENABLED);
    }

    lifecycle.mount(context, drawable, component);
    lifecycle.bind(context, drawable, component);

    final Rect rect = mDisplayListCreateRect;

    output.getMountBounds(rect);
    drawable.setBounds(0, 0, rect.width(), rect.height());

    try {
        final Canvas canvas = displayList.start(rect.width(), rect.height());
        drawable.draw(canvas);

        displayList.end(canvas);
        displayList.setBounds(rect.left, rect.top, rect.right, rect.bottom);

        output.setDisplayList(displayList);
    } catch (DisplayListException e) {
        // Display list creation failed. Make sure the DisplayList for this output is set
        // to null.
        output.setDisplayList(null);
    }

    lifecycle.unbind(context, drawable, component);
    lifecycle.unmount(context, drawable, component);
    ComponentsPools.release(context, lifecycle, drawable);
    ComponentsSystrace.endSection();
}

From source file:org.androfarsh.widget.DragGridLayout.java

private void requestDrop(Node node) {
    requestFreeCellRegion(node.view);/*from   w w w . j a va  2 s .c  om*/
    if (requestHoveredCells(node)) {
        requestHoverRect(mTmpRect);

        mTmpRegion.set(mFreeCellsRegion);
        mTmpRegion.op(mTmpRect, Op.INTERSECT);

        Rect bound = mTmpRegion.getBounds();
        if (!mTmpRegion.isEmpty() && !mTmpRegion.isComplex() && (bound.width() == mTmpRect.width())
                && (bound.height() == mTmpRect.height())) {
            node.startRect.offsetTo(mTmpRect.left, mTmpRect.top);
            return;
        }
    }

    final LayoutParams lp = (LayoutParams) node.view.getLayoutParams();
    final LayoutParams newLp = validateLayoutParams(generateLayoutParams(lp), mFreeCellsRegion);
    if ((lp.mX == newLp.mX) && (lp.mY == newLp.mY)) {
        return;
    }
    node.startRect.offsetTo(newLp.mX, newLp.mY);
}

From source file:com.pdftron.pdf.tools.Tool.java

public void onDraw(Canvas canvas, android.graphics.Matrix tfm) {
    // Draw page number
    if (mShowPageNum && mPageNumberIndicatorVisible) {
        int width = mPDFView.getWidth();
        int height = mPDFView.getHeight();
        int page_num = mPDFView.getCurrentPage();
        boolean restore = false;
        float yOffset = 0;

        try {//from w  w w  . j  a  va  2s  .c  o m
            // During page sliding, PDFViewCtrl might apply extra transformation
            // matrix to Canvas for animation. However, page number should not
            // move; hence applying the inverse to offset it.
            if (!tfm.isIdentity()) {
                canvas.save();
                restore = true;
                tfm.invert(mTempMtx1);
                canvas.getMatrix(mTempMtx2);
                mTempMtx2.postConcat(mTempMtx1);
                canvas.setMatrix(mTempMtx2);

                // Workaround for bug found in Android > ICS with hardware acceleration turned
                // ON. See http://code.google.com/p/android/issues/detail?id=24517 for more info
                if (Build.VERSION.SDK_INT >= 14
                        /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ && mPDFView.isHardwareAccelerated()) {
                    Rect rectangle = new Rect();
                    ((android.app.Activity) mPDFView.getContext()).getWindow().getDecorView()
                            .getWindowVisibleDisplayFrame(rectangle);
                    yOffset = rectangle.top;
                }
            }

            int page_count = mPDFView.getDoc().getPageCount();
            String str = String.format(getStringFromResId(R.string.tools_misc_pagerange), page_num, page_count);

            Rect r = new Rect();
            mPaint4PageNum.getTextBounds(str, 0, str.length(), r);
            float str_width = r.width();
            float str_height = r.height();

            float margin = str_height / 1.5f;
            float left = width - str_width * 1.5f - margin + mPDFView.getScrollX();

            float top = mPDFView.getScrollY() + height - mPageNumPosAdjust - str_height * 3.0f + yOffset;

            float right = left + str_width + margin * 2;
            float bottom = top + str_height + margin * 2;

            mTempPageDrawingRectF.set(left, top, right, bottom);
            mPaint4PageNum.setColor(
                    mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_background));
            canvas.drawRoundRect(mTempPageDrawingRectF, margin, margin, mPaint4PageNum);

            mPaint4PageNum
                    .setColor(mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_text));
            left += margin;
            top += str_height / 2 + margin + mPaint4PageNum.descent();

            canvas.drawText(str, left, top - 0.5f, mPaint4PageNum);

        } catch (Exception e) {

        } finally {
            if (restore) {
                canvas.restore();
            }
        }
    }
}

From source file:cn.ismartv.tvrecyclerview.widget.GridLayoutManager.java

@Override
public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) {
    if (mCachedBorders == null) {
        super.setMeasuredDimension(childrenBounds, wSpec, hSpec);
    }// ww w.  jav  a2s .c  om
    final int width, height;
    final int horizontalPadding = getPaddingLeft() + getPaddingRight();
    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    if (mOrientation == VERTICAL) {
        final int usedHeight = childrenBounds.height() + verticalPadding;
        height = chooseSize(hSpec, usedHeight, getMinimumHeight());
        width = chooseSize(wSpec, mCachedBorders[mCachedBorders.length - 1] + horizontalPadding,
                getMinimumWidth());
    } else {
        final int usedWidth = childrenBounds.width() + horizontalPadding;
        width = chooseSize(wSpec, usedWidth, getMinimumWidth());
        height = chooseSize(hSpec, mCachedBorders[mCachedBorders.length - 1] + verticalPadding,
                getMinimumHeight());
    }
    setMeasuredDimension(width, height);
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the horizontal steps/*w w  w .  j a va 2s . com*/
 * vertical lines and horizontal labels
 *
 * @param canvas canvas
 */
protected void drawHorizontalSteps(Canvas canvas) {
    // draw horizontal steps (vertical lines and horizontal labels)
    mPaintLabel.setColor(getHorizontalLabelsColor());
    int i = 0;
    for (Map.Entry<Integer, Double> e : mStepsHorizontal.entrySet()) {
        // draw line
        if (mStyles.highlightZeroLines) {
            if (e.getValue() == 0d) {
                mPaintLine.setStrokeWidth(5);
            } else {
                mPaintLine.setStrokeWidth(0);
            }
        }
        if (mStyles.gridStyle.drawVertical()) {
            canvas.drawLine(mGraphView.getGraphContentLeft() + e.getKey(), mGraphView.getGraphContentTop(),
                    mGraphView.getGraphContentLeft() + e.getKey(),
                    mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaintLine);
        }

        // draw label
        if (isHorizontalLabelsVisible()) {
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                if (mStyles.horizontalLabelsAngle < 90f) {
                    mPaintLabel.setTextAlign((Paint.Align.RIGHT));
                } else if (mStyles.horizontalLabelsAngle <= 180f) {
                    mPaintLabel.setTextAlign((Paint.Align.LEFT));
                }
            } else {
                mPaintLabel.setTextAlign(Paint.Align.CENTER);
                if (i == mStepsHorizontal.size() - 1)
                    mPaintLabel.setTextAlign(Paint.Align.RIGHT);
                if (i == 0)
                    mPaintLabel.setTextAlign(Paint.Align.LEFT);
            }

            // multiline labels
            String label = mLabelFormatter.formatLabel(e.getValue(), true);
            if (label == null) {
                label = "";
            }
            String[] lines = label.split("\n");

            // If labels are angled, calculate adjustment to line them up with the grid
            int labelWidthAdj = 0;
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                Rect textBounds = new Rect();
                mPaintLabel.getTextBounds(lines[0], 0, lines[0].length(), textBounds);
                labelWidthAdj = (int) Math
                        .abs(textBounds.width() * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)));
            }
            for (int li = 0; li < lines.length; li++) {
                // for the last line y = height
                float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight())
                        - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace;
                float x = mGraphView.getGraphContentLeft() + e.getKey();
                if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle < 90f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle, x + labelWidthAdj, y);
                    canvas.drawText(lines[li], x + labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle <= 180f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle - 180f, x - labelWidthAdj, y);
                    canvas.drawText(lines[li], x - labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else {
                    canvas.drawText(lines[li], x, y, mPaintLabel);
                }
            }
        }
        i++;
    }
}

From source file:com.fairphone.fplauncher3.Folder.java

private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height = getFolderHeight();

    float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
    int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;
    int currentPage = mLauncher.getWorkspace().getNextPage();
    // In case the workspace is scrolling, we need to use the final scroll to compute
    // the folders bounds.
    mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
    if (currentLayout == null) {
        return;//from   w w  w  . j a va  2 s  .  co  m
    }
    ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
    // We reset the workspaces scroll
    mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);

    // We need to bound the folder to the currently visible CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) {
        // Center the folder if it is full (on phones only)
        left = (grid.availableWidthPx - width) / 2;
    } else if (width >= bounds.width()) {
        // If the folder doesn't fit within the bounds, center it about the desired bounds
        left = bounds.left + (bounds.width() - width) / 2;
    }
    if (height >= bounds.height()) {
        top = bounds.top + (bounds.height() - height) / 2;
    }

    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));

    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
}

From source file:in.sc9.discreteslider.DiscreteSlider.java

private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
    final Rect bounds = mTempRect;
    mThumb.copyBounds(bounds);/*from  w  ww .  ja va  2s  .co  m*/
    //Grow the current thumb rect for a bigger touch area
    bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
    if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
        //If the user clicked outside the thumb, we compute the current position
        //and force an immediate drag to it.
        mIsDragging = true;
        mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
        updateDragging(ev);
        Log.d("startDragging", ev.getX() + "");
        //As the thumb may have moved, get the bounds again
        mThumb.copyBounds(bounds);
        bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    }
    if (mIsDragging) {
        setPressed(true);
        attemptClaimDrag();
        setHotspot(ev.getX(), ev.getY());
        mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
        if (mPublicChangeListener != null) {
            mPublicChangeListener.onStartTrackingTouch(this);
        }
    }
    return mIsDragging;
}

From source file:com.bytebit.classicbyte.ScreenMainMenu.java

public void draw(Canvas c) {
    this.parent.standard_paint.setColor(Color.WHITE);

    for (int i = 0; i != 9; i++) {
        for (int k = 0; k != 10; k++) {
            c.drawBitmap(TextureManager.getBitmap(3), k * (this.parent.renderer.width / 10),
                    (i + 1) * (this.parent.renderer.width / 10), this.parent.standard_paint);
        }//  ww  w. j  a  v  a  2s. c  o  m
    }

    if (this.menu_current_tab == 1) {
        Rect bounds = new Rect();
        String g;
        for (int k = 0; k != this.server_list_name.size(); k++) {
            if (k >= this.server_list_name.size()) {
                break;
            }
            if ((this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k
                    + this.server_list_y_offset) >= 0
                    && (this.parent.renderer.width * 0.12F + this.parent.renderer.width * 0.1F * k
                            + this.server_list_y_offset) <= this.parent.renderer.height) {
                this.parent.standard_paint.setColor(Color.WHITE);
                this.parent.standard_paint.setTextSize(this.parent.renderer.width * 0.04F);
                c.drawBitmap(TextureManager.getBitmap(10),
                        (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2,
                        this.parent.renderer.width * 0.02F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
                g = this.server_list_name.get(k);
                this.parent.standard_paint.getTextBounds(this.server_list_name.get(k), 0,
                        this.server_list_name.get(k).length(), bounds);
                if (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) {
                    while (bounds.width() > TextureManager.getBitmap(10).getWidth() * 0.85F) {
                        this.parent.standard_paint.getTextBounds(g + " ..", 0, (g + " ..").length(), bounds);
                        g = g.substring(0, g.length() - 1);
                    }
                    g = g + " ..";
                }
                c.drawText(g,
                        (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2
                                + this.parent.renderer.width * 0.02F,
                        this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
                this.parent.standard_paint.setColor(Color.YELLOW);
                this.parent.standard_paint.getTextBounds(this.server_list_online_data.get(k), 0,
                        this.server_list_online_data.get(k).length(), bounds);
                c.drawText(this.server_list_online_data.get(k),
                        this.parent.renderer.width
                                - (this.parent.renderer.width - TextureManager.getBitmap(10).getWidth()) / 2
                                - this.parent.renderer.width * 0.02F - bounds.width(),
                        this.parent.renderer.width * 0.08F + this.parent.renderer.width * 0.12F
                                + this.parent.renderer.width * 0.1F * k + this.server_list_y_offset,
                        this.parent.standard_paint);
            }
        }
        c.drawBitmap(
                TextureManager.getBitmap(26), 0, TextureManager.getBitmap(2).getHeight()
                        + TextureManager.getBitmap(22).getHeight() + this.scrollbar_offset,
                this.parent.standard_paint);
        if (this.menu_button_highlighted == 3) {
            c.drawBitmap(TextureManager.getBitmap(25), 0, TextureManager.getBitmap(2).getHeight(),
                    this.parent.standard_paint);
        } else {
            c.drawBitmap(TextureManager.getBitmap(24), 0, TextureManager.getBitmap(2).getHeight(),
                    this.parent.standard_paint);
        }
        if (this.menu_button_highlighted == 4) {
            c.drawBitmap(TextureManager.getBitmap(23), 0,
                    this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(),
                    this.parent.standard_paint);
        } else {
            c.drawBitmap(TextureManager.getBitmap(22), 0,
                    this.parent.renderer.height - TextureManager.getBitmap(22).getHeight(),
                    this.parent.standard_paint);
        }
    }
    if (this.menu_current_tab == 2) {
        Rect bounds = new Rect();
        this.parent.standard_paint.setColor(Color.WHITE);
        this.parent.standard_paint.setTextSize(this.parent.renderer.height * 0.25F);
        this.parent.standard_paint.getTextBounds("Nothing here", 0, "Nothing here".length(), bounds);
        c.drawText("Nothing here", (this.parent.renderer.width - bounds.width()) / 2,
                this.parent.renderer.height * 0.5F, this.parent.standard_paint);
    }

    for (int k = 0; k != 10; k++) {
        c.drawBitmap(TextureManager.getBitmap(2), k * TextureManager.getBitmap(2).getWidth(), 0,
                this.parent.standard_paint);
    }

    c.drawBitmap(TextureManager.getBitmap(4), this.parent.renderer.width * 0.05F, 0,
            this.parent.standard_paint);
    if (this.menu_button_highlighted == 1) {
        c.drawBitmap(TextureManager.getBitmap(8), this.parent.renderer.width * 0.1F * 6.5F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    } else {
        c.drawBitmap(TextureManager.getBitmap(7), this.parent.renderer.width * 0.1F * 6.5F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    }
    if (this.menu_button_highlighted == 2) {
        c.drawBitmap(TextureManager.getBitmap(6), this.parent.renderer.width * 0.1F * 8.75F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    } else {
        c.drawBitmap(TextureManager.getBitmap(5), this.parent.renderer.width * 0.1F * 8.75F,
                this.parent.renderer.width * 0.01F, this.parent.standard_paint);
    }

    //c.drawBitmap(TextureManager.getBitmap(9), this.parent.renderer.width-TextureManager.getBitmap(9).getWidth(), this.parent.renderer.height-TextureManager.getBitmap(9).getHeight(), this.parent.standard_paint);
}

From source file:org.androfarsh.widget.DragGridLayout.java

private Cell findCellUnder(Rect rect) {
    Cell resCell = null;//  ww w .  j  a  v  a 2s  .  com
    final Rect resRect = new Rect();
    for (final Cell cell : mCells) {
        if (mTmpRect.setIntersect(cell.rect, rect)) {
            if ((resCell == null)
                    || ((mTmpRect.width() * mTmpRect.height()) > (resRect.width() * resRect.height()))) {
                resRect.set(mTmpRect);
                resCell = cell;
            }
        }
    }

    return resCell;
}

From source file:com.example.SmartBoard.DrawingView.java

public boolean onTouchDragEvent(MotionEvent event) {

    boolean handled = false;

    JSONObject mObjectTouched;//  w  w w .ja v a2s.c  o  m
    int X;
    int Y;
    int pointerId;
    int actionIndex = event.getActionIndex();

    //get coordinates and make object transparent
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        dragFinished = false;

        //it's the first pointer, so clear all existing pointers data
        mObjectPointers.clear();
        X = (int) event.getX(actionIndex);
        Y = (int) event.getY(actionIndex);
        dragX = X;
        dragY = Y;
        String objectType = "";
        //check if we've touched inside some object
        mObjectTouched = getTouchedObject(X, Y);

        if (mObjectTouched == null) {
            return true;
        } else {
            objectType = getObjectType(mObjectTouched);
        }

        if (objectType.compareTo("Circle") == 0) {
            try {
                mObjectTouched.put("x", X);
                mObjectTouched.put("y", Y);

            } catch (JSONException e) {
                e.printStackTrace();

            }
        } else if (objectType.compareTo("Rectangle") == 0) {
            Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens"));
            tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height());
            try {
                mObjectTouched.put("dimens", tempRect.flattenToString());
            } catch (JSONException e) {

            }

        } else if (objectType.compareTo("Line") == 0) {

            if (lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                    mObjectTouched.optInt("starty")) < lengthOfLine(X, Y, mObjectTouched.optInt("stopx"),
                            mObjectTouched.optInt("stopy"))) {

                try {
                    mObjectTouched.put("startx", X);
                    mObjectTouched.put("starty", Y);
                    mObjectTouched.put("length",
                            lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy")));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                dragLineStart = true;
            } else {
                try {
                    mObjectTouched.put("stopx", X);
                    mObjectTouched.put("stopy", Y);
                    mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                            mObjectTouched.optInt("starty")));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                dragLineStart = false;
            }

        } else if (objectType.compareTo("Text") == 0) {
            try {
                mObjectTouched.put("x", X);
                mObjectTouched.put("y", Y);
                Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region"));
                tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y);
                mObjectTouched.put("region", tempRect.flattenToString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        mObjectPointers.put(event.getPointerId(0), mObjectTouched);
        if (mObjectTouched != null) {
            mqtt.publishObject(mObjectTouched);
        }
        invalidate();
        handled = true;
        break;

    case MotionEvent.ACTION_POINTER_DOWN:
        break;
    case MotionEvent.ACTION_MOVE:
        dragFinished = false;

        final int pointerCount = event.getPointerCount();

        for (actionIndex = 0; actionIndex < pointerCount; actionIndex++) {
            //some pointer has moved, search it by pointer id
            pointerId = event.getPointerId(actionIndex);
            X = (int) event.getX(actionIndex);
            Y = (int) event.getY(actionIndex);

            dragX = X;
            dragY = Y;

            mObjectTouched = mObjectPointers.get(pointerId);
            if (mObjectTouched == null)
                continue; // if null no object was touched so skip

            if (mObjectTouched.optString("type").compareTo("Circle") == 0) {
                try {
                    mObjectTouched.put("x", X);
                    mObjectTouched.put("y", Y);
                } catch (JSONException e) {
                }
            } else if (mObjectTouched.optString("type").compareTo("Rectangle") == 0) {

                Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens"));
                tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height());
                try {
                    mObjectTouched.put("dimens", tempRect.flattenToString());
                } catch (JSONException e) {

                }

            } else if (mObjectTouched.optString("type").compareTo("Text") == 0) {
                try {
                    mObjectTouched.put("x", X);
                    mObjectTouched.put("y", Y);
                    Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region"));
                    tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y);
                    mObjectTouched.put("region", tempRect.flattenToString());
                } catch (JSONException e) {

                    e.printStackTrace();
                }
            }

            else if (mObjectTouched.optString("type").compareTo("Line") == 0) {

                if (dragLineStart) {
                    try {
                        mObjectTouched.put("startx", X);
                        mObjectTouched.put("starty", Y);
                        mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"),
                                mObjectTouched.optInt("stopy")));

                        //mObjectTouched.put("stopx", tempStopX);
                        // mObjectTouched.put("stopy", tempStopY);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        mObjectTouched.put("stopx", X);
                        mObjectTouched.put("stopy", Y);
                        mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                                mObjectTouched.optInt("starty")));

                        //mObjectTouched.put("stopx", tempStopX);
                        // mObjectTouched.put("stopy", tempStopY);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }

            }

            if (mObjectTouched != null) {
                mqtt.publishObject(mObjectTouched);
            }
        }

        invalidate();
        handled = true;
        break;
    case MotionEvent.ACTION_UP:
        dragFinished = true;

        mObjectPointers.clear();
        invalidate();
        handled = true;
        break;
    case MotionEvent.ACTION_CANCEL:
        handled = true;
        break;

    default:
        // do nothing
        break;
    }

    return super.onTouchEvent(event) || handled;
}