Search in sources :

Example 61 with SurfaceView

use of android.view.SurfaceView in project zxing-lib by kennydude.

the class ZXingFragment method onPause.

@Override
public void onPause() {
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    // inactivityTimer.onPause();
    // ambientLightManager.stop();
    cameraManager.closeDriver();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) getView().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 62 with SurfaceView

use of android.view.SurfaceView in project platform_frameworks_base by android.

the class DisplaySinkService method setSurfaceView.

public void setSurfaceView(final SurfaceView surfaceView) {
    if (mSurfaceView != surfaceView) {
        final SurfaceView oldSurfaceView = mSurfaceView;
        mSurfaceView = surfaceView;
        if (oldSurfaceView != null) {
            oldSurfaceView.post(new Runnable() {

                @Override
                public void run() {
                    final SurfaceHolder holder = oldSurfaceView.getHolder();
                    holder.removeCallback(DisplaySinkService.this);
                    updateSurfaceFromUi(null);
                }
            });
        }
        if (surfaceView != null) {
            surfaceView.post(new Runnable() {

                @Override
                public void run() {
                    final SurfaceHolder holder = surfaceView.getHolder();
                    holder.addCallback(DisplaySinkService.this);
                    updateSurfaceFromUi(holder);
                }
            });
        }
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 63 with SurfaceView

use of android.view.SurfaceView in project platform_frameworks_base by android.

the class GetBitmapSurfaceViewActivity 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(GetBitmapSurfaceViewActivity.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());
    });
    content.addView(mSurfaceView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
    content.addView(button, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
    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) IOException(java.io.IOException)

Example 64 with SurfaceView

use of android.view.SurfaceView in project platform_frameworks_base by android.

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 65 with SurfaceView

use of android.view.SurfaceView in project platform_frameworks_base by android.

the class CameraTooActivity method onResume.

/**
     * Called when our {@code Activity} gains focus. <p>Starts initializing the camera.</p>
     */
@Override
protected void onResume() {
    super.onResume();
    // Start a background thread to manage camera requests
    mBackgroundThread = new HandlerThread("background");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
    mForegroundHandler = new Handler(getMainLooper());
    mCameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
    // Inflate the SurfaceView, set it as the main layout, and attach a listener
    View layout = getLayoutInflater().inflate(R.layout.mainactivity, null);
    mSurfaceView = (SurfaceView) layout.findViewById(R.id.mainSurfaceView);
    mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
    setContentView(mSurfaceView);
// Control flow continues in mSurfaceHolderCallback.surfaceChanged()
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) SurfaceView(android.view.SurfaceView) View(android.view.View)

Aggregations

SurfaceView (android.view.SurfaceView)92 SurfaceHolder (android.view.SurfaceHolder)45 View (android.view.View)24 SurfaceTexture (android.graphics.SurfaceTexture)15 Surface (android.view.Surface)13 Button (android.widget.Button)12 FrameLayout (android.widget.FrameLayout)12 Intent (android.content.Intent)11 Bitmap (android.graphics.Bitmap)8 TextView (android.widget.TextView)8 FileOutputStream (java.io.FileOutputStream)8 ViewGroup (android.view.ViewGroup)6 MotionEvent (android.view.MotionEvent)5 OnClickListener (android.view.View.OnClickListener)5 ImageView (android.widget.ImageView)5 CameraManager (com.google.zxing.client.android.camera.CameraManager)5 Activity (android.app.Activity)4 PendingIntent (android.app.PendingIntent)4 IntentFilter (android.content.IntentFilter)4 UsbDevice (android.hardware.usb.UsbDevice)4