Search in sources :

Example 96 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by ResurrectionRemix.

the class HardwareCanvasSurfaceViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout content = new FrameLayout(this);
    mSurfaceView = new SurfaceView(this);
    mSurfaceView.getHolder().addCallback(this);
    Button button = new Button(this);
    button.setText("Copy bitmap to /sdcard/surfaceview.png");
    button.setOnClickListener((View v) -> {
        final Bitmap b = Bitmap.createBitmap(mSurfaceView.getWidth(), mSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
        PixelCopy.request(mSurfaceView, b, (int result) -> {
            if (result != PixelCopy.SUCCESS) {
                Toast.makeText(HardwareCanvasSurfaceViewActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
                    b.compress(Bitmap.CompressFormat.PNG, 100, out);
                }
            } catch (Exception e) {
            // Ignore
            }
        }, mSurfaceView.getHandler());
    });
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.addView(mSurfaceView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    setContentView(content);
}
Also used : Bitmap(android.graphics.Bitmap) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) FileOutputStream(java.io.FileOutputStream) SurfaceView(android.view.SurfaceView) View(android.view.View) SurfaceView(android.view.SurfaceView) LinearLayout(android.widget.LinearLayout)

Example 97 with SurfaceView

use of android.view.SurfaceView in project weex-example by KalicyZhou.

the class CaptureActivity method onPause.

@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    beepManager.close();
    cameraManager.closeDriver();
    // historyManager = null; // Keep for onActivityResult
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 98 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by crdroidandroid.

the class EGLImpl method eglCreateWindowSurface.

public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) {
    Surface sur = null;
    if (native_window instanceof SurfaceView) {
        SurfaceView surfaceView = (SurfaceView) native_window;
        sur = surfaceView.getHolder().getSurface();
    } else if (native_window instanceof SurfaceHolder) {
        SurfaceHolder holder = (SurfaceHolder) native_window;
        sur = holder.getSurface();
    } else if (native_window instanceof Surface) {
        sur = (Surface) native_window;
    }
    long eglSurfaceId;
    if (sur != null) {
        eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
    } else if (native_window instanceof SurfaceTexture) {
        eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, native_window, attrib_list);
    } else {
        throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
    }
    if (eglSurfaceId == 0) {
        return EGL10.EGL_NO_SURFACE;
    }
    return new EGLSurfaceImpl(eglSurfaceId);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) Surface(android.view.Surface)

Example 99 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by crdroidandroid.

the class EGL14 method eglCreateWindowSurface.

public static EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, Object win, int[] attrib_list, int offset) {
    Surface sur = null;
    if (win instanceof SurfaceView) {
        SurfaceView surfaceView = (SurfaceView) win;
        sur = surfaceView.getHolder().getSurface();
    } else if (win instanceof SurfaceHolder) {
        SurfaceHolder holder = (SurfaceHolder) win;
        sur = holder.getSurface();
    } else if (win instanceof Surface) {
        sur = (Surface) win;
    }
    EGLSurface surface;
    if (sur != null) {
        surface = _eglCreateWindowSurface(dpy, config, sur, attrib_list, offset);
    } else if (win instanceof SurfaceTexture) {
        surface = _eglCreateWindowSurfaceTexture(dpy, config, win, attrib_list, offset);
    } else {
        throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "Surface, SurfaceView, SurfaceTexture or SurfaceHolder at the moment, " + "this will be fixed later.");
    }
    return surface;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) Surface(android.view.Surface)

Example 100 with SurfaceView

use of android.view.SurfaceView in project android_frameworks_base by crdroidandroid.

the class SinkActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    setContentView(R.layout.sink_activity);
    mLogTextView = (TextView) findViewById(R.id.logTextView);
    mLogTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
    mLogger = new TextLogger();
    mFpsTextView = (TextView) findViewById(R.id.fpsTextView);
    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    mSurfaceView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            sendHidTouch(event);
            return true;
        }
    });
    mLogger.log("Waiting for accessory display source to be attached to USB...");
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    filter.addAction(ACTION_USB_DEVICE_PERMISSION);
    mReceiver = new DeviceReceiver();
    registerReceiver(mReceiver, filter);
    Intent intent = getIntent();
    if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
        UsbDevice device = intent.<UsbDevice>getParcelableExtra(UsbManager.EXTRA_DEVICE);
        if (device != null) {
            onDeviceAttached(device);
        }
    } else {
        Map<String, UsbDevice> devices = mUsbManager.getDeviceList();
        if (devices != null) {
            for (UsbDevice device : devices.values()) {
                onDeviceAttached(device);
            }
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) UsbDevice(android.hardware.usb.UsbDevice) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SurfaceView(android.view.SurfaceView) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent)

Aggregations

SurfaceView (android.view.SurfaceView)141 SurfaceHolder (android.view.SurfaceHolder)65 View (android.view.View)35 SurfaceTexture (android.graphics.SurfaceTexture)19 Intent (android.content.Intent)16 FrameLayout (android.widget.FrameLayout)15 Surface (android.view.Surface)14 Button (android.widget.Button)13 TextView (android.widget.TextView)11 SharedPreferences (android.content.SharedPreferences)10 ImageView (android.widget.ImageView)10 Bitmap (android.graphics.Bitmap)9 IOException (java.io.IOException)9 ViewGroup (android.view.ViewGroup)8 LinearLayout (android.widget.LinearLayout)8 FileOutputStream (java.io.FileOutputStream)8 AudioManager (android.media.AudioManager)7 OnClickListener (android.view.View.OnClickListener)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 IntentFilter (android.content.IntentFilter)6