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:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

@SuppressWarnings("deprecation")
private int getScreenSideAuto(int newLeft, int newRight) {

    int newScreenSide;

    if (mScreenSide == STICK_TO_AUTO) {
        int screenWidth;
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();/*from  w  ww  .j  a  va  2s  .  c  o  m*/
        try {
            Class<?> cls = Display.class;
            Class<?>[] parameterTypes = { Point.class };
            Point parameter = new Point();
            Method method = cls.getMethod("getSize", parameterTypes);
            method.invoke(display, parameter);
            screenWidth = parameter.x;
        } catch (Exception e) {
            screenWidth = display.getWidth();
        }

        boolean boundToLeftBorder = newLeft == 0;
        boolean boundToRightBorder = newRight == screenWidth;

        if (boundToLeftBorder == boundToRightBorder && getLayoutParams().width == LayoutParams.MATCH_PARENT) {
            newScreenSide = STICK_TO_MIDDLE;
        } else if (boundToLeftBorder) {
            newScreenSide = STICK_TO_LEFT;
        } else {
            newScreenSide = STICK_TO_RIGHT;
        }
    } else {
        newScreenSide = mScreenSide;
    }

    return newScreenSide;
}

From source file:com.klinker.android.launcher.addons.view.LauncherDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    // "|" used deliberately here; both methods should be invoked.
    final boolean interceptForDrag = !isDrawerOpen(Gravity.LEFT)
            ? (mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev))
            : mLeftDragger.shouldInterceptTouchEvent(ev);

    if (DEBUG) {//from  w  w  w .  j  a v  a2s  .co m
        Log.v("intercept_drag", "intercepting: " + interceptForDrag);
    }

    boolean interceptForTap = false;
    boolean draggedLeft = false;
    boolean draggedRight = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
            interceptForTap = true;
        }
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        // If we cross the touch slop, don't perform the delayed peek for an edge touch.
        if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
            mLeftCallback.removeCallbacks();
            mRightCallback.removeCallbacks();
        }

        float x = ev.getX();
        float dx = mInitialMotionX - x;
        float y = ev.getY();
        float dy = mInitialMotionY - y;
        float slope = Math.abs(dy / dx);

        if (slope >= 2) {
            return false;
        }

        if (dx >= 5) {
            draggedLeft = true;
        }

        if (dx <= -5) {
            draggedRight = true;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        closeDrawers(true);
        mDisallowInterceptRequested = false;
        mChildrenCanceledTouch = false;
    }
    }

    interceptForTap = false;

    if (!isDrawerOpen(Gravity.LEFT)) {
        return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    } else {
        Point displaySize = new Point();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getSize(displaySize);
        if (mInitialMotionX > displaySize.x * .95) {
            return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
        } else {
            if (draggedLeft && currentDrawerPage == maxDrawerPage) {
                return true;
            } else {
                return false;
            }
        }
    }
}

From source file:com.ape.camera2raw.Camera2RawFragment.java

/**
 * Configure the necessary {@link Matrix} transformation to `mTextureView`,
 * and start/restart the preview capture session if necessary.
 * <p/>/* w w  w .ja v  a  2s  .c o m*/
 * This method should be called after the camera state has been initialized in
 * setUpCameraOutputs.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    synchronized (mCameraStateLock) {
        if (null == mTextureView || null == activity) {
            return;
        }

        StreamConfigurationMap map = mCharacteristics
                .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

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

        // Find the rotation of the device relative to the native device orientation.
        int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        Point displaySize = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(displaySize);

        // Find the rotation of the device relative to the camera sensor's orientation.
        int totalRotation = sensorToDeviceRotation(mCharacteristics, deviceRotation);

        // Swap the view dimensions for calculation as needed if they are rotated relative to
        // the sensor.
        boolean swappedDimensions = totalRotation == 90 || totalRotation == 270;
        int rotatedViewWidth = viewWidth;
        int rotatedViewHeight = viewHeight;
        int maxPreviewWidth = displaySize.x;
        int maxPreviewHeight = displaySize.y;

        if (swappedDimensions) {
            rotatedViewWidth = viewHeight;
            rotatedViewHeight = viewWidth;
            maxPreviewWidth = displaySize.y;
            maxPreviewHeight = displaySize.x;
        }

        // Preview should not be larger than display size and 1080p.
        if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
            maxPreviewWidth = MAX_PREVIEW_WIDTH;
        }

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

        // Find the best preview size for these view dimensions and configured JPEG size.
        Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth,
                rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg);

        if (swappedDimensions) {
            mTextureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
        } else {
            mTextureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
        }

        // Find rotation of device in degrees (reverse device orientation for front-facing
        // cameras).
        int rotation = (mCharacteristics
                .get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT)
                        ? (360 + ORIENTATIONS.get(deviceRotation)) % 360
                        : (360 - ORIENTATIONS.get(deviceRotation)) % 360;

        Matrix matrix = new Matrix();
        RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
        RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
        float centerX = viewRect.centerX();
        float centerY = viewRect.centerY();

        // Initially, output stream images from the Camera2 API will be rotated to the native
        // device orientation from the sensor's orientation, and the TextureView will default to
        // scaling these buffers to fill it's view bounds.  If the aspect ratios and relative
        // orientations are correct, this is fine.
        //
        // However, if the device orientation has been rotated relative to its native
        // orientation so that the TextureView's dimensions are swapped relative to the
        // native device orientation, we must do the following to ensure the output stream
        // images are not incorrectly scaled by the TextureView:
        //   - Undo the scale-to-fill from the output buffer's dimensions (i.e. its dimensions
        //     in the native device orientation) to the TextureView's dimension.
        //   - Apply a scale-to-fill from the output buffer's rotated dimensions
        //     (i.e. its dimensions in the current device orientation) to the TextureView's
        //     dimensions.
        //   - Apply the rotation from the native device orientation to the current device
        //     rotation.
        if (Surface.ROTATION_90 == deviceRotation || Surface.ROTATION_270 == deviceRotation) {
            bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
            matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
            float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                    (float) viewWidth / previewSize.getWidth());
            matrix.postScale(scale, scale, centerX, centerY);

        }
        matrix.postRotate(rotation, centerX, centerY);

        mTextureView.setTransform(matrix);

        // Start or restart the active capture session if the preview was initialized or
        // if its aspect ratio changed significantly.
        if (mPreviewSize == null || !checkAspectsEqual(previewSize, mPreviewSize)) {
            mPreviewSize = previewSize;
            if (mState != STATE_CLOSED) {
                createCameraPreviewSessionLocked();
            }
        }
    }
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

private void getScreenSizeOfDevice2() {
    Point point = new Point();
    getWindowManager().getDefaultDisplay().getRealSize(point);
    DisplayMetrics dm = getResources().getDisplayMetrics();
    double x = Math.pow(point.x / dm.xdpi, 2);
    double y = Math.pow(point.y / dm.ydpi, 2);
    double screenInches = Math.sqrt(x + y);

    point = new Point();
    getWindowManager().getDefaultDisplay().getSize(point);

    Log.i("Trim", "screenInches: " + screenInches + " point.x = " + point.x + " point.y = " + point.y);
    if (screenInches > 9 && point.x == 800) {
        setTheme(R.style.AppBaseThemeForV9);
    }/*  w  w  w. j  av  a2s .  c o  m*/
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private int getNavBarSize() {
    Point size = new Point();
    Point realSize = new Point();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    display.getSize(size);//from   ww w.j a  va 2  s  .co m
    display.getRealSize(realSize);

    return realSize.y - size.y;
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

public void showFirstRunSimpleCling(boolean animate) {
    // Enable the clings only if they have not been dismissed before
    if (isClingsEnabled() && !CalculatorSettings.isDismissed(getContext(), Cling.SIMPLE_CLING_DISMISSED_KEY)) {
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);/*  w ww .j  a va 2s . c o  m*/
        int[] location = new int[3];
        location[0] = 0;
        location[1] = size.y / 2;
        location[2] = 10;
        initCling(R.id.simple_cling, location, 0, true, animate);
    } else {
        removeCling(R.id.simple_cling);
    }
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoInfo() {
    try {// ww w  .  j ava  2s. co m
        /* First, get the Display from the WindowManager */
        Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
        /* Now we can retrieve all display-related infos */
        Point size = new Point();
        display.getSize(size);
        PackageManager manager = this.getPackageManager();
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        makeToast("PackageName = " + info.packageName + "\nVersionName = " + info.versionName
                + "\nAndroid version " + Build.VERSION.RELEASE + "\nScreen size = " + size.x + "x" + size.y
                + "\nDevelopment: (2013-2016)" + "\n  Android  - P. van der Wielen (Ezac)"
                + "\n  Web Site - E. Fekkes (Ezac)", 0);
        Log.d(TAG, "Name " + info.versionName + ", Code " + info.versionCode);
    } catch (NameNotFoundException pkg) {
        Log.d(TAG, "unable to get app version info !" + pkg.getMessage());
    } finally {
        ;
    }
}

From source file:com.aimfire.gallery.GalleryActivity.java

@SuppressWarnings("deprecation")
private void initViewPager() {
    if (BuildConfig.DEBUG)
        if (VERBOSE)
            Log.d(TAG, "initViewPager");

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*from  ww w  .  ja v a2 s. co m*/

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(new MediaPagerAdapter(this, size.x, size.y));
    mViewPager.setOnTouchListener(otl);
    mViewPager.setOnPageChangeListener(opcl);
    mViewPager.setOffscreenPageLimit(MAX_PAGE);
}

From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java

public void setDrawerRightEdgeSize(Activity activity, float displayWidthPercentage) {
    Point displaySize = new Point();
    activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
    mRightDragger.setEdgeSize((int) (displaySize.x * displayWidthPercentage));
}

From source file:app.sunstreak.yourpisd.MainActivity.java

public int screenHeight() {
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*w w w .  jav  a  2 s .co  m*/
    return size.x;
}