Example usage for android.graphics PointF PointF

List of usage examples for android.graphics PointF PointF

Introduction

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

Prototype

public PointF(float x, float y) 

Source Link

Usage

From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java

@Override
public void panStart(MotionEvent event) {
    if (mMode == MODE_EDIT) {
        if (null != mFeature && null != mFeature.getGeometry()) {
            //check if we are near selected point
            double dMinX = event.getX() - mTolerancePX * 2 - DrawItem.mAnchorTolerancePX;
            double dMaxX = event.getX() + mTolerancePX;
            double dMinY = event.getY() - mTolerancePX * 2 - DrawItem.mAnchorTolerancePX;
            double dMaxY = event.getY() + mTolerancePX;
            GeoEnvelope screenEnv = new GeoEnvelope(dMinX, dMaxX, dMinY, dMaxY);

            if (mSelectedItem.isTapNearSelectedPoint(screenEnv)) {
                PointF tempPoint = mSelectedItem.getSelectedPoint();
                mTempPointOffset = new PointF(tempPoint.x - event.getX(), tempPoint.y - event.getY());
                mMapViewOverlays.setLockMap(true);
                mMode = MODE_CHANGE;/*from w  w  w  . j av  a  2 s.  co  m*/
            }
        }
    }
}

From source file:xyz.zpayh.hdimage.HDImageView.java

private void fitToBounds(boolean center) {
    boolean init = false;
    if (mViewTranslate == null) {
        init = true;//  w  ww.ja  va2s.c om
        mViewTranslate = new PointF(0, 0);
    }

    mSatTemp.mScale = mScale;
    mSatTemp.mViewTranslate.set(mViewTranslate);
    fitToBounds(center, mSatTemp);
    mScale = mSatTemp.mScale;
    mViewTranslate.set(mSatTemp.mViewTranslate);
    if (init) {
        mViewTranslate.set(getTranslateForSourceCenter(getShowWidth() / 2.0F, getShowHeight() / 2.0F, mScale));
    }
}

From source file:org.akop.crosswords.view.CrosswordView.java

private void bringIntoView(Crossword.Word word, int selectedCell) {
    if (word == null) {
        return;/*from ww  w.j a  v a2  s  . com*/
    }

    RectF wordRect = new RectF();

    wordRect.left = word.getStartColumn() * mScaledCellSize - mContentRect.left;
    wordRect.top = word.getStartRow() * mScaledCellSize - mContentRect.top;

    if (word.getDirection() == Crossword.Word.DIR_ACROSS) {
        wordRect.right = wordRect.left + word.getLength() * mScaledCellSize;
        wordRect.bottom = wordRect.top + mScaledCellSize;
    } else if (word.getDirection() == Crossword.Word.DIR_DOWN) {
        wordRect.right = wordRect.left + mScaledCellSize;
        wordRect.bottom = wordRect.top + word.getLength() * mScaledCellSize;
    }

    RectF objectRect = new RectF(wordRect);
    RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(),
            -mBitmapOffset.y + mContentRect.height());

    if (visibleArea.contains(objectRect)) {
        return; // Already visible
    }

    if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) {
        // Available area isn't large enough to fit the entire word
        // Is the selected cell visible? If not, bring it into view

        CellOffset co = getCellOffset(word, selectedCell);
        RectF cellRect = new RectF();
        cellRect.left = co.mColumn * mScaledCellSize;
        cellRect.top = co.mRow * mScaledCellSize;
        cellRect.right = cellRect.left + mScaledCellSize;
        cellRect.bottom = cellRect.top + mScaledCellSize;

        if (visibleArea.contains(cellRect)) {
            return; // Already visible
        }

        objectRect.set(cellRect);
    }

    // Compute view that includes the object in the center
    PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left,
            (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top);

    // Clamp the values
    clampPointF(end, mTranslationBounds);

    // Compute the distance to travel from current location
    float distanceX = end.x - mBitmapOffset.x;
    float distanceY = end.y - mBitmapOffset.y;

    // Scroll the point into view
    mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY,
            NAVIGATION_SCROLL_DURATION_MS);
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

/**
 * Adjusts current scale and translate values to keep scale within the
 * allowed range and the image on screen. Minimum scale is set so one
 * dimension fills the view and the image is centered on the other
 * dimension.//from  w ww  . jav  a 2 s.  c o  m
 * 
 * @param center
 *            Whether the image should be centered in the dimension it's too
 *            small to fill. While animating this can be false to avoid
 *            changes in direction as bounds are reached.
 */
private void fitToBounds(boolean center) {
    boolean init = false;
    if (vTranslate == null) {
        init = true;
        vTranslate = new PointF(0, 0);
    }
    ScaleAndTranslate input = new ScaleAndTranslate(scale, vTranslate);
    fitToBounds(center, input);
    scale = input.scale;
    if (init) {
        vTranslate = vTranslateForSCenter(new PointF(sWidth() / 2, sHeight() / 2), scale);
    }
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

private void fitScreen() {
    int screenWidth = getResources().getDisplayMetrics().widthPixels;
    if (this.sWidth > screenWidth)
        return;//  ww  w  . ja  va2 s .co m
    float scale = (float) screenWidth / (float) this.sWidth;
    setScaleAndCenter(scale, new PointF(screenWidth / 2, 0));
}

From source file:org.akop.ararat.view.CrosswordView.java

private void bringIntoView(Selectable sel) {
    if (sel == null) {
        return;/*from   w w w.  j  av a  2s  .co  m*/
    }

    RectF wordRect = new RectF();

    wordRect.left = sel.getStartColumn() * mScaledCellSize - mContentRect.left;
    wordRect.top = sel.getStartRow() * mScaledCellSize - mContentRect.top;

    if (sel.getDirection() == Crossword.Word.DIR_ACROSS) {
        wordRect.right = wordRect.left + sel.mWord.getLength() * mScaledCellSize;
        wordRect.bottom = wordRect.top + mScaledCellSize;
    } else if (sel.getDirection() == Crossword.Word.DIR_DOWN) {
        wordRect.right = wordRect.left + mScaledCellSize;
        wordRect.bottom = wordRect.top + sel.mWord.getLength() * mScaledCellSize;
    }

    RectF objectRect = new RectF(wordRect);
    RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(),
            -mBitmapOffset.y + mContentRect.height());

    if (visibleArea.contains(objectRect)) {
        return; // Already visible
    }

    if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) {
        // Available area isn't large enough to fit the entire word
        // Is the selected cell visible? If not, bring it into view

        RectF cellRect = new RectF();
        cellRect.left = sel.getColumn() * mScaledCellSize;
        cellRect.top = sel.getRow() * mScaledCellSize;
        cellRect.right = cellRect.left + mScaledCellSize;
        cellRect.bottom = cellRect.top + mScaledCellSize;

        if (visibleArea.contains(cellRect)) {
            return; // Already visible
        }

        objectRect.set(cellRect);
    }

    // Compute view that includes the object in the center
    PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left,
            (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top);

    // Clamp the values
    clampPointF(end, mTranslationBounds);

    // Compute the distance to travel from current location
    float distanceX = end.x - mBitmapOffset.x;
    float distanceY = end.y - mBitmapOffset.y;

    // Scroll the point into view
    mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY,
            NAVIGATION_SCROLL_DURATION_MS);
}

From source file:me.ccrama.redditslide.Views.SubsamplingScaleImageView.java

/**
 * Called on first draw when the view has dimensions. Calculates the initial sample size and starts async loading of
 * the base layer image - the whole source subsampled as necessary.
 *//*from   w  w w .j ava  2 s  . c  o  m*/
private synchronized void initialiseBaseLayer(Point maxTileDimensions) {

    satTemp = new ScaleAndTranslate(0f, new PointF(0, 0));
    fitToBounds(true, satTemp);

    // Load double resolution - next level will be split into four tiles and at the center all four are required,
    // so don't bother with tiling until the next level 16 tiles are needed.
    fullImageSampleSize = calculateInSampleSize(satTemp.scale);
    if (fullImageSampleSize > 1) {
        fullImageSampleSize /= 2;
    }

    if (fullImageSampleSize == 1 && sRegion == null && sWidth() < maxTileDimensions.x
            && sHeight() < maxTileDimensions.y) {

        // Whole image is required at native resolution, and is smaller than the canvas max bitmap size.
        // Use BitmapDecoder for better image support.
        decoder.recycle();
        decoder = null;
        BitmapLoadTask task = new BitmapLoadTask(this, getContext(), bitmapDecoderFactory, uri, false);
        execute(task);

    } else {

        initialiseTileMap(maxTileDimensions);

        List<Tile> baseGrid = tileMap.get(fullImageSampleSize);
        for (Tile baseTile : baseGrid) {
            TileLoadTask task = new TileLoadTask(this, decoder, baseTile);
            execute(task);
        }
        refreshRequiredTiles(true);

    }

}

From source file:com.android.systemui.qs.QSDragPanel.java

private void shiftTiles(DragTileRecord startingTile, boolean forward) {
    if (DEBUG_DRAG) {
        Log.i(TAG, "shiftTiles() called with " + "startingTile = [" + startingTile + "], forward = [" + forward
                + "]");
    }/*w ww.  ja  va2 s.c o  m*/

    if (forward) {
        // startingTile and all after will need to be shifted one to the right
        // dragging tile needs room

        final int destP = startingTile.destinationPage;
        final int rowF = startingTile.row;
        final int colF = startingTile.col;
        PointF loc = new PointF(startingTile.destination.x, startingTile.destination.y);

        // the index of the original position of the statingTile before it moved
        int startingIndex = mRecords.indexOf(startingTile);
        mLastRightShift = startingIndex;
        mLastLeftShift = -1;

        shiftAllTilesRight(startingIndex);
        mRecords.add(startingIndex, mDraggingRecord);

        mPagerAdapter.notifyDataSetChanged();

        mDraggingRecord.col = colF;
        mDraggingRecord.row = rowF;
        mDraggingRecord.destination = loc;
        mDraggingRecord.destinationPage = destP;

        mDraggingRecord.tileView.setX(mDraggingRecord.destination.x);
        mDraggingRecord.tileView.setY(mDraggingRecord.destination.y);

    } else {
        // it is also probably the dragging tile
        final int startingIndex = mRecords.indexOf(startingTile);
        mLastLeftShift = startingIndex;
        mLastRightShift = -1;

        final int draggingIndex = mRecords.indexOf(mDraggingRecord);

        if (startingIndex != draggingIndex) {
            if (DEBUG_DRAG) {
                Log.e(TAG, "startinIndex: " + startingIndex + ", draggingIndex: " + draggingIndex
                        + ", and they differ!!!!");
            }
        }

        // startingTile should be the "empty" tile that things should start shifting into
        shiftAllTilesLeft(startingIndex);

        // remove the dragging record
        if (mRecords.remove(mDraggingRecord)) {
            mPagerAdapter.notifyDataSetChanged();
            if (DEBUG_DRAG) {
                Log.v(TAG, "removed dragging record after moving tiles back");
            }
        }

        // set coords off screen until we're ready to place it
        mDraggingRecord.tileView.setX(-mDraggingRecord.tileView.getMeasuredWidth());
        mDraggingRecord.tileView.setY(-mDraggingRecord.tileView.getMeasuredHeight());
    }

    mViewPager.getAdapter().notifyDataSetChanged();
}

From source file:xyz.zpayh.hdimage.HDImageView.java

public final void resetScaleAndCenter() {
    stopAnimator();//from   w w  w .ja v a 2s . com
    mPendingScale = limitedScale(0);
    if (isReady()) {
        mSourcePendingCenter = new PointF(getShowWidth() / 2.0F, getShowHeight() / 2.0F);
    } else {
        mSourcePendingCenter = new PointF(0, 0);
    }
    invalidate();
}

From source file:com.connectsdk.service.NetcastTVService.java

@Override
public void connectMouse() {
    ResponseListener<Object> listener = new ResponseListener<Object>() {

        @Override//from  w w  w  .jav a 2  s  . co  m
        public void onSuccess(Object response) {
            Log.d(Util.T, "Netcast TV's mouse has been connected");

            mMouseDistance = new PointF(0, 0);
            mMouseIsMoving = false;
        }

        @Override
        public void onError(ServiceCommandError error) {
            Log.w(Util.T, "Netcast TV's mouse connection has been failed");
        }
    };

    setMouseCursorVisible(true, listener);
}