Example usage for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY

List of usage examples for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY

Introduction

In this page you can find the example usage for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY.

Prototype

int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY

To view the source code for android.hardware.display DisplayManager VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY.

Click Source Link

Document

Virtual display flag: Only show this display's own content; do not mirror the content of another display.

Usage

From source file:android.car.cluster.sample.NavigationFragment.java

private VirtualDisplay createVirtualDisplay(Surface surface, int width, int height) {
    Log.i(TAG, "createVirtualDisplay, surface: " + surface + ", width: " + width + "x" + height);
    return mDisplayManager.createVirtualDisplay("Cluster-App-VD", width, height, 160, surface,
            DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
}

From source file:com.flyingcrop.ScreenCaptureFragment.java

public void saveImage() {
    if (mMediaProjection != null) {

        final Notification.Builder builder = new Notification.Builder(getActivity())
                .setContentTitle(getResources().getString(R.string.fragment_saving_crop))
                .setContentText(getResources().getString(R.string.fragment_wait))
                .setSmallIcon(com.flyingcrop.R.drawable.ab_ico);

        final NotificationManager notificationManager = (NotificationManager) getActivity()
                .getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(1, builder.build());

        STORE_DIRECTORY = storage;//from w w w . j a va2s.  co  m

        int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
                | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;

        mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
        mMediaProjection.createVirtualDisplay("screencap", mWidth, mHeight, mScreenDensity, flags,
                mImageReader.getSurface(), new VirtualDisplayCallback(), mHandler);
        if (ServiceIsRunning()) {
            Intent mIntent = new Intent(getActivity(), Brush.class);
            getActivity().bindService(mIntent, mConnection, Context.BIND_AUTO_CREATE);
        }

        mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {

            @Override
            public void onImageAvailable(ImageReader reader) {

                image_available = true;

                Log.d("teste", "image_available : " + image_available.toString());

                try {

                    final long time_now = System.currentTimeMillis();
                    image = mImageReader.acquireLatestImage();

                    Log.i(TAG, "Time 1 " + (System.currentTimeMillis() - time_now));

                    if (image != null) {

                        if (ServiceIsRunning()) {
                            if (loop == 0) {
                                View v = mServer.getView();
                                WindowManager wm = mServer.getWindowM();
                                if (v != null)
                                    wm.removeViewImmediate(v);
                                else
                                    mServer.removeAllView();

                            }
                            loop++;
                        }

                        if (!isFolder()) {
                            Notification.Builder builder = new Notification.Builder(getActivity())
                                    .setContentTitle(getResources().getString(R.string.fragment_error))
                                    .setContentText(getResources().getString(R.string.fragment_error_access))
                                    .setSmallIcon(com.flyingcrop.R.drawable.ab_ico);
                            Toast.makeText(getActivity(),
                                    getResources().getString(R.string.fragment_error_toast), Toast.LENGTH_SHORT)
                                    .show();

                            NotificationManager notificationManager = (NotificationManager) getActivity()
                                    .getSystemService(Context.NOTIFICATION_SERVICE);

                            notificationManager.notify(1, builder.build());

                            getActivity().finish();
                        }

                        savePlanes();

                    }

                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (fos != null) {
                        try {
                            fos.close();
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        }
                    }

                    if (bitmap != null) {
                        bitmap.recycle();
                    }

                    if (image != null) {
                        image.close();
                    }
                }
            }

        }, null);
    }
}