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() 

Source Link

Usage

From source file:com.example.android.navigationdrawer.QRCode.java

public void onQR(View v) {
    switch (v.getId()) {
    case R.id.button1:
        String qrInputText = MidiFile.readString;

        //Find screen size
        WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);//from   w  w  w.j av  a2  s  .  c o m
        int width = point.x;
        int height = point.y;
        int smallerDimension = width < height ? width : height;
        smallerDimension = smallerDimension * 3 / 4;
        //Encode with a QR Code image
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT,
                BarcodeFormat.QR_CODE.toString(), smallerDimension);
        try {
            Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
            ImageView myImage = (ImageView) findViewById(R.id.imageView1);
            myImage.setImageBitmap(bitmap);

            // Get screen size
            Display display1 = this.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display1.getSize(size);
            int screenWidth = size.x;
            int screenHeight = size.y;

            // Get target image size
            Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap();
            int bitmapHeight = bitmap1.getHeight();
            int bitmapWidth = bitmap1.getWidth();

            // Scale the image down to fit perfectly into the screen
            // The value (250 in this case) must be adjusted for phone/tables displays
            while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) {
                bitmapHeight = bitmapHeight / 2;
                bitmapWidth = bitmapWidth / 2;
            }

            // Create resized bitmap image
            BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(),
                    Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));

            // Create dialog
            Dialog dialog = new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.thumbnail);

            ImageView image = (ImageView) dialog.findViewById(R.id.imageview);

            // !!! Do here setBackground() instead of setImageDrawable() !!! //
            image.setBackground(resizedBitmap);

            // Without this line there is a very small border around the image (1px)
            // In my opinion it looks much better without it, so the choice is up to you.
            dialog.getWindow().setBackgroundDrawable(null);
            dialog.show();

        } catch (WriterException e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.manufacton.cordova.MyCameraManager.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   w w w.  ja v  a  2  s . c om
private void setUpCameraOutputs(int width, int height) {
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());

            // Find out if we need to swap dimension to get the preview size relative to sensor
            // coordinate.
            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            //noinspection ConstantConditions
            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();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            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.
            int cameraLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
            if (cameraLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY
                    && android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.LOLLIPOP) {
                Log.d(TAG, "LEGACY CAMERA DETECTED & OLD OS DETECTED");
                Size[] sizes = map.getOutputSizes(SurfaceTexture.class);
                for (Size option : sizes) {
                    Log.d(TAG, "available : WIDTH: " + option.getWidth() + " HEIGHT: " + option.getHeight());
                }
                mImageReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 2);
            } else {
                Log.d(TAG, "LEGACY CAMERA NOT DETECTED");
                mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                        rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);
                mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(),
                        ImageFormat.JPEG, 2);
                Log.d(TAG, "For mPreviewSize: WIDTH: " + mPreviewSize.getWidth() + " HEIGHT: "
                        + mPreviewSize.getHeight());
            }

            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            // int orientation = getResources().getConfiguration().orientation;
            // 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;

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

public static int getDisplayWidth(AppCompatActivity activity) {
    int width = 0;
    if (activity != null && activity.getWindowManager() != null
            && activity.getWindowManager().getDefaultDisplay() != null) {
        Point point = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(point);
        width = point.x;/*from  www  . ja  v  a2s . c  o  m*/
    }
    return width;
}

From source file:com.android.launcher2.Workspace.java

/**
 * Used to inflate the Workspace from XML.
 *
 * @param context The application's context.
 * @param attrs The attributes set containing the Workspace's customization values.
 * @param defStyle Unused./* www.j a va  2  s .  c  o  m*/
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContentIsRefreshable = false;
    mOriginalPageSpacing = mPageSpacing;

    mDragEnforcer = new DropTarget.DragEnforcer(context);
    // With workspace, data is available straight from the get-go
    setDataIsReady();

    mLauncher = (Launcher) context;
    final Resources res = getResources();
    mWorkspaceFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens);
    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    int cellCountX = DEFAULT_CELL_COUNT_X;
    int cellCountY = DEFAULT_CELL_COUNT_Y;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);

    if (LauncherApplication.isScreenLarge()) {
        // Determine number of rows/columns dynamically
        // TODO: This code currently fails on tablets with an aspect ratio < 1.3.
        // Around that ratio we should make cells the same size in portrait and
        // landscape
        TypedArray actionBarSizeTypedArray = context
                .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
        final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f);

        Point minDims = new Point();
        Point maxDims = new Point();
        DisplayCompt.getCurrentSizeRange(mLauncher.getWindowManager().getDefaultDisplay(), minDims, maxDims);

        cellCountX = 1;
        while (CellLayout.widthInPortrait(res, cellCountX + 1) <= minDims.x) {
            cellCountX++;
        }

        cellCountY = 1;
        while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1) <= minDims.y) {
            cellCountY++;
        }
    }

    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mSpringLoadedPageSpacing = res.getDimensionPixelSize(R.dimen.workspace_spring_loaded_page_spacing);
    mCameraDistance = res.getInteger(R.integer.config_cameraDistance);

    // if the value is manually specified, use that instead
    cellCountX = a.getInt(R.styleable.Workspace_cellCountX, cellCountX);
    cellCountY = a.getInt(R.styleable.Workspace_cellCountY, cellCountY);
    mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    a.recycle();

    setOnHierarchyChangeListener(this);

    LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);

    // Unless otherwise specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, View.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}

From source file:com.oakesville.mythling.app.AppData.java

public Point getScreenSize() {
    if (screenSize == null) {
        WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        screenSize = new Point();
        display.getSize(screenSize);/*  w w w .  j  a va  2s  . c  om*/
    }
    return screenSize;
}

From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java

private void guideDownloadLabels() {
    MainActivity activity = getActivity2();
    if (null == activity || !Settings.getGuideDownloadLabels()) {
        return;//from  w  w w  .j ava 2 s. c o  m
    }

    Display display = activity.getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);

    mShowcaseView = new ShowcaseView.Builder(activity).withMaterialShowcase().setStyle(R.style.Guide)
            .setTarget(new PointTarget(point.x, point.y / 3)).blockAllTouches()
            .setContentTitle(R.string.guide_download_labels_title)
            .setContentText(R.string.guide_download_labels_text).replaceEndButton(R.layout.button_guide)
            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                @Override
                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                    mShowcaseView = null;
                    ViewUtils.removeFromParent(showcaseView);
                    Settings.puttGuideDownloadLabels(false);
                    openDrawer(Gravity.RIGHT);
                }
            }).build();
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

public static int getDisplayHeight(AppCompatActivity activity) {
    int height = 0;
    if (activity != null && activity.getWindowManager() != null
            && activity.getWindowManager().getDefaultDisplay() != null) {
        Point point = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(point);
        height = point.y;/*from  ww  w .ja va 2  s. co m*/
    }

    Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar);

    if (isSupportSmartBar) {
        int smartBarHeight = getSmartBarHeight(activity);
        Log.e(TAG, "smartBarHeight:" + smartBarHeight);
        height -= smartBarHeight;
    }

    if (activity.getSupportActionBar() != null) {
        int actionbar = activity.getSupportActionBar().getHeight();
        if (actionbar == 0) {
            TypedArray actionbarSizeTypedArray = activity
                    .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
            actionbar = (int) actionbarSizeTypedArray.getDimension(0, 0);
        }
        Log.d(TAG, "actionbar:" + actionbar);
        height -= actionbar;
    }

    int status = getStatusBarHeight(activity);
    Log.d(TAG, "status:" + status);

    height -= status;

    Log.d(TAG, "height:" + height);
    return height;
}

From source file:com.frostwire.android.gui.fragments.ImageViewerFragment.java

private Point displaySize() {
    Point size = new Point();
    getActivity().getWindowManager().getDefaultDisplay().getSize(size);
    return size;
}

From source file:com.microblink.barcode.customcamera.camera2.Camera2Fragment.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  v  a2  s.c om*/
private void setUpCameraOutputs(int width, int height) {
    Activity activity = getActivity();
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

            // We don't use a front facing camera in this sample.
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                continue;
            }

            StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.YUV_420_888)),
                    new CompareSizesByArea());

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

            Point displaySize = new Point();
            activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
            int maxPreviewWidth = displaySize.x;
            int maxPreviewHeight = displaySize.y;

            if (swappedDimensions) {
                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.
            mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), maxPreviewWidth,
                    maxPreviewHeight, largest);

            Log.i(TAG, "Preview size is " + mPreviewSize.toString());

            mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(),
                    ImageFormat.YUV_420_888, /*maxImages*/1);
            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

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

            mCameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        // Currently an NPE is thrown when the Camera2API is used but not supported on the
        // device this code runs.
        ErrorDialog.newInstance("Camera error").show(getChildFragmentManager(), FRAGMENT_DIALOG);
    }
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m965k(Context context) {
    String str = "";
    if (context == null) {
        return str;
    }/*from  w  ww .j  a  v a 2s . co m*/
    Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    if (VERSION.SDK_INT < NETWORK_TYPE_LTE) {
        return "" + defaultDisplay.getWidth() + "_" + defaultDisplay.getHeight();
    }
    Point point = new Point();
    defaultDisplay.getSize(point);
    return point.x + "_" + point.y;
}