Example usage for android.graphics Point Point

List of usage examples for android.graphics Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Usage

From source file:com.mediatek.galleryfeature.stereo.fancycolor.FancyColorActivity.java

private Point calcClickPosition(int viewW, int viewH, float x, float y) {
    int thumbW = mThumbBitmapWidth;
    int thumbH = mThumbBitmapHeight;
    int gap;//w  ww  .ja v  a2s  .c om
    int mapX;
    int mapY;
    Rect validRange = new Rect();
    if (thumbH >= thumbW) {
        // bitmap height fulfills view height
        gap = (viewW - viewH * thumbW / thumbH) / 2;
        validRange.left = gap;
        validRange.right = viewW - gap;
        validRange.top = 0;
        validRange.bottom = viewH;
        mapX = thumbW * ((int) x - gap) / validRange.width();
        mapY = thumbH * (int) y / validRange.height();
    } else {
        // bitmap width fullfills view width
        gap = (viewH - viewW * thumbH / thumbW) / 2;
        validRange.left = 0;
        validRange.right = viewW;
        validRange.top = gap;
        validRange.bottom = viewH - gap;
        mapX = thumbW * (int) x / validRange.width();
        mapY = thumbH * ((int) y - gap) / validRange.height();
    }
    MtkLog.d(TAG,
            "<calcClickPosition> thumbW " + thumbW + ", thumbH " + thumbH + ", gap " + gap + ", rect lrtb "
                    + validRange.left + ", " + validRange.right + ", " + validRange.top + ", "
                    + validRange.bottom + ", mapX " + mapX + ", mapY " + mapY);
    if (!validRange.contains((int) x, (int) y)) {
        MtkLog.d(TAG, "<calcClickPosition> invalid click");
        return null;
    }
    return new Point(mapX, mapY);
}

From source file:com.prt.thirdeye.CamManager.java

public void setPreviewSize(int width, int height) {
    mTargetSize = new Point(width, height);

    if (mCamera != null) {
        Camera.Parameters params = getParameters();
        params.setPreviewSize(width, height);

        Log.v(TAG, "Preview size is " + width + "x" + height);

        if (!mIsModeSwitching) {
            synchronized (mParametersSync) {
                try {
                    safeStopPreview();//from  w  w  w. j  a  va2 s. c  o m
                    mParameters = params;
                    mCamera.setParameters(mParameters);
                    // TODO: preview aspect ratio is wrong in video mode
                    mPreview.notifyPreviewSize(width, height);

                    // TODO: why dont restart preview here?
                    // setPreviewSize is called on video mode switching too
                    // if (mIsResuming) {
                    updateDisplayOrientation();
                    safeStartPreview();
                    // mIsResuming = false;
                    // }

                    mPreview.setPauseCopyFrame(false);
                } catch (RuntimeException ex) {
                    Log.e(TAG, "Unable to set Preview Size", ex);
                }
            }

            Log.d(TAG, "setPreviewSize - stop");
        }
    }
}

From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java

@Override
public Point getTextPosition() {
    if (lineCount == 1) {
        return collapsingText.getTextTopLeft();
    } else {//from  w w w .j av  a  2s .c o  m
        return new Point(titleInsetStart, (int) Math.max(textTop - scrollOffset, titleInsetTop));
    }
}

From source file:com.ktouch.kdc.launcher4.camera.CameraManager.java

public void setPreviewSize(int width, int height) {
    mTargetSize = new Point(width, height);

    if (mCamera != null) {
        Camera.Parameters params = getParameters();
        params.setPreviewSize(width, height);

        Log.v(TAG, "Preview size is " + width + "x" + height);

        if (!mIsModeSwitching) {
            synchronized (mParametersSync) {
                try {
                    safeStopPreview();/*from   w  ww.  j a  v  a2s  .c o  m*/
                    mParameters = params;
                    mCamera.setParameters(mParameters);
                    // TODO: preview aspect ratio is wrong in video mode
                    mPreview.notifyPreviewSize(width, height);

                    // TODO: why dont restart preview here?
                    // setPreviewSize is called on video mode switching too
                    //if (mIsResuming) {
                    updateDisplayOrientation();
                    safeStartPreview();
                    //mIsResuming = false;
                    //}

                    mPreview.setPauseCopyFrame(false);
                } catch (RuntimeException ex) {
                    Log.e(TAG, "Unable to set Preview Size", ex);
                }
            }

            Log.d(TAG, "setPreviewSize - stop");
        }
    }
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void processScribble(Path scribble) {
    try {//from  www.j  a  va2 s .com
        // the file we're given via createTempFile is unplayable, but the name creation routine is useful...
        File outputFile = File.createTempFile(getString(R.string.app_name), ".mp4", getCacheDir());
        String outputFilePath = outputFile.getAbsolutePath();
        if (outputFile.delete()) {
            // get the bounding box and add to our list
            RectF scribbleBox = new RectF();
            scribble.computeBounds(scribbleBox, true);
            Rect audioArea = new Rect();
            scribbleBox.roundOut(audioArea);
            int scribbleWidth = Math
                    .round(getResources().getDimensionPixelSize(R.dimen.scribble_stroke_width) / 2f); // expand to include stroke width (half either side of line)
            audioArea.inset(-scribbleWidth, -scribbleWidth);

            // initialise recording
            resetRecordingInterface();
            mAudioRecorder = AudioRecorder.build(PaperChainsActivity.this, outputFilePath);

            mCurrentAudioRect = audioArea;
            mImageView.addAudioAreaRect(audioArea);
            mImageView.setScribbleEnabled(false);

            // position the recording buttons
            PointF centrePoint = mImageView
                    .imagePointToScreenPoint(new Point(audioArea.centerX(), audioArea.centerY()));
            initialiseRecordingButtons(centrePoint);
        } else {
            Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                    Toast.LENGTH_SHORT).show();
        }

    } catch (IOException | IllegalArgumentException e) {
        Toast.makeText(PaperChainsActivity.this, getString(R.string.audio_recording_setup_error),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again/* w ww. ja v a  2 s .c  om*/
 */
private void showCalendarPicker() {
    // Inflate the popup_layout.xml
    ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root);
    LayoutInflater layoutInflater = (LayoutInflater) getMainActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup);
    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    //or if popup is on edge display it to the left of the circle
    Display display = getMainActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point(0, 0);
    display.getSize(size);

    int OFFSET_X = 25;
    int OFFSET_Y = 25;

    final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(getMainActivity());
    popup.setAnimationStyle(android.R.style.Animation_Dialog);
    popup.setContentView(layout);

    popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    popup.setFocusable(true);
    //gets rid of default background
    popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null));
    //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu));

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y);
    Calendar minDate;
    minDate = Calendar.getInstance();
    this.tempY = minDate.get(Calendar.YEAR);
    this.tempM = minDate.get(Calendar.MONTH);
    this.tempD = minDate.get(Calendar.DAY_OF_MONTH);
    dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                // Months start from 0, so January is month 0
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    tempY = year;
                    tempM = monthOfYear;
                    tempD = dayOfMonth;
                    Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY);
                }
            });
    ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept);
    ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(tempY, tempM, tempD, 1, 0);
            Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis());
            // clear items from clustermanager and submissionMarkerList, as all new submissions
            // need to be fetched based on the selected date
            clusterManager.clearItems();
            submissionMarkerIdList.clear();
            addAdminMarkersToMap();
            setMinDateInMs(calendar.getTimeInMillis());
            popup.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setMinDateInMs(0);
            popup.dismiss();

        }
    });
}

From source file:com.askjeffreyliu.camera2barcode.camera.CameraSource.java

/**
 * Sets up member variables related to camera.
 *
 * @param width  The width of available size for camera preview
 * @param height The height of available size for camera preview
 *//*from   ww  w  .j a va  2  s .  c om*/
private void setUpCameraOutputs(int width, int height) {
    try {
        if (ContextCompat.checkSelfPermission(mContext,
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
            throw new RuntimeException("Time out waiting to lock camera opening.");
        }
        if (manager == null)
            manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (map == null) {
            return;
        }

        // For still image captures, we use the largest available size.
        Size largest = getBestAspectPictureSize(map.getOutputSizes(ImageFormat.JPEG));

        // Find out if we need to swap dimension to get the preview size relative to sensor
        // coordinate.
        int displayRotation = mDisplayOrientation;
        //noinspection ConstantConditions
        int mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
        boolean swappedDimensions = false;
        switch (displayRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
            if (mSensorOrientation == 90 || mSensorOrientation == 270) {
                swappedDimensions = true;
            }
            break;
        case Surface.ROTATION_90:
        case Surface.ROTATION_270:
            if (mSensorOrientation == 0 || mSensorOrientation == 180) {
                swappedDimensions = true;
            }
            break;
        default:
            Log.e(TAG, "Display rotation is invalid: " + displayRotation);
        }

        Point displaySize = new Point(Utils.getScreenWidth(mContext), Utils.getScreenHeight(mContext));
        int rotatedPreviewWidth = width;
        int rotatedPreviewHeight = height;
        int maxPreviewWidth = displaySize.x;
        int maxPreviewHeight = displaySize.y;

        if (swappedDimensions) {
            rotatedPreviewWidth = height;
            rotatedPreviewHeight = width;
            maxPreviewWidth = displaySize.y;
            maxPreviewHeight = displaySize.x;
        }

        if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
            maxPreviewWidth = MAX_PREVIEW_WIDTH;
        }

        if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
            maxPreviewHeight = MAX_PREVIEW_HEIGHT;
        }

        // Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
        // bus' bandwidth limitation, resulting in gorgeous previews but the storage of
        // garbage capture data.
        Size[] outputSizes = Utils.sizeToSize(map.getOutputSizes(SurfaceTexture.class));
        mPreviewSize = chooseOptimalSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight,
                maxPreviewWidth, maxPreviewHeight, largest);

        // We fit the aspect ratio of TextureView to the size of preview we picked.
        int orientation = mDisplayOrientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        } else {
            mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
        }

        // Check if the flash is supported.
        Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        mFlashSupported = available == null ? false : available;

        // control.aeTargetFpsRange
        Range<Integer>[] availableFpsRange = characteristics
                .get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);

        configureTransform(width, height);

        manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        Log.d(TAG, "Camera Error: " + e.getMessage());
    }
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Initiate the dragging process. Create a bitmap that is displayed as the dragging event
 * happens and is moved around across the screen.  This function is called once for each time
 * that a dragging event is initiated.//from   w ww. j a  v a  2s. c o m
 *
 * The logic to this method was borrowed from the TouchInterceptor.java class from the
 * music app.
 *
 * @param draggedChild The child view being dragged
 * @param x The x coordinate of this view where dragging began
 * @param y The y coordinate of this view where dragging began
 */
private void startDragging(final View draggedChild, final int x, final int y) {
    if (!isDragReorderingSupported()) {
        return;
    }

    mDragBitmap = createDraggedChildBitmap(draggedChild);
    if (mDragBitmap == null) {
        // It appears that creating bitmaps for large views fail. For now, don't allow
        // dragging in this scenario.  When using the framework's drag and drop implementation,
        // drag shadow also fails with a OutofResourceException when trying to draw the drag
        // shadow onto a Surface.
        mReorderHelper.handleDragCancelled(draggedChild);
        return;
    }
    mTouchOffsetToChildLeft = x - draggedChild.getLeft();
    mTouchOffsetToChildTop = y - draggedChild.getTop();
    updateReorderStates(ReorderUtils.DRAG_STATE_DRAGGING);

    initializeDragScrollParameters(y);

    final LayoutParams params = (LayoutParams) draggedChild.getLayoutParams();
    mReorderHelper.handleDragStart(draggedChild, params.position, params.id,
            new Point(mTouchDownForDragStartX, mTouchDownForDragStartY));

    // TODO: Reconsider using the framework's DragShadow support for dragging,
    // and only draw the bitmap in onDrop for animation.
    final Context context = getContext();
    mDragView = new ImageView(context);
    mDragView.setImageBitmap(mDragBitmap);
    mDragView.setAlpha(160);

    mWindowParams = new WindowManager.LayoutParams();
    mWindowParams.gravity = Gravity.TOP | Gravity.START;

    mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowParams.flags = mWindowManagerLayoutFlags;
    mWindowParams.format = PixelFormat.TRANSLUCENT;
    // Use WindowManager to overlay a transparent image on drag
    mWindowManager.addView(mDragView, mWindowParams);
    updateDraggedBitmapLocation(x, y);
}

From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;/* www  .j av a  2  s.  co m*/
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }

    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    Point previewPadding = null;

    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // This can happen in some weird cases involving multi-touch. We can't start dragging
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }

        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);

        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);

        int[] previewSizeBeforeScale = new int[1];

        preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.componentName,
                createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight, null,
                previewSizeBeforeScale);

        // Compare the size of the drag preview to the preview in the AppsCustomize tray
        int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0],
                getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX));
        scale = previewWidthInAppsCustomize / (float) preview.getWidth();

        // The bitmap in the AppsCustomize tray is always the the same size, so there
        // might be extra pixels around the preview itself - this accounts for that
        if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) {
            int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2;
            previewPadding = new Point(padding, 0);
        }
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

        mCanvas.setBitmap(preview);
        mCanvas.save();
        WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(),
                icon.getIntrinsicHeight());
        mCanvas.restore();
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo
            && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));

    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);

    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY,
            previewPadding, scale);
    outline.recycle();
    preview.recycle();
    return true;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Update the visual state of the drag event based on the current drag location.  If the user
 * has attempted to re-order by dragging a child over another child's drop zone, call the
 * appropriate {@link ReorderListener} callback.
 *
 * @param x The current x coordinate of the drag event
 * @param y The current y coordinate of the drag event
 *///from  ww  w . java 2s.com
private void handleDrag(int x, int y) {
    if (mDragState != ReorderUtils.DRAG_STATE_DRAGGING) {
        return;
    }

    // TODO: Consider moving drag shadow management logic into mReorderHelper as well, or
    // scrap the custom logic and use the framework's drag-and-drop support now that we're not
    // doing anything special to the drag shadow.
    updateDraggedBitmapLocation(x, y);

    if (mCurrentRunningAnimatorSet == null) {
        // If the current animator set is not null, then animation is running, in which case,
        // we shouldn't do any reordering processing, as views will be moving around, and
        // interfering with drag target calculations.
        mReorderHelper.handleDrag(new Point(x, y));
    }
}