Search in sources :

Example 86 with SurfaceView

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

the class SurfaceHolderTarget method onBindToView.

@Override
public void onBindToView(View view) {
    if (view instanceof SurfaceView) {
        SurfaceHolder holder = ((SurfaceView) view).getHolder();
        if (holder == null) {
            throw new RuntimeException("Could not get SurfaceHolder from SurfaceView " + view + "!");
        }
        setSurfaceHolder(holder);
    } else {
        throw new IllegalArgumentException("View must be a SurfaceView!");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 87 with SurfaceView

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

the class SmartCamera method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simplecamera);
    setTitle("Smart Camera");
    mContext = new MffContext(this);
    mCameraView = (SurfaceView) findViewById(R.id.cameraView);
    mGoodBadTextView = (TextView) findViewById(R.id.goodOrBadTextView);
    mFPSTextView = (TextView) findViewById(R.id.fpsTextView);
    mScoreTextView = (TextView) findViewById(R.id.scoreTextView);
    mStartStopButton = (Button) findViewById(R.id.startButton);
    mImagesSavedTextView = (TextView) findViewById(R.id.imagesSavedTextView);
    mImagesSavedTextView.setText("");
    mSpinner = (Spinner) findViewById(R.id.spinner);
    mLinearLayout = (LinearLayout) findViewById(R.id.scrollViewLinearLayout);
    mImages = new ArrayList<ImageView>();
    // Spinner is used to determine how many image views are displayed at the bottom
    // of the screen. Based on the item position that is selected, we inflate that
    // many imageviews into the bottom linear layout.
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            mLinearLayout.removeViews(0, numImages);
            numImages = position + 1;
            mImages.clear();
            LayoutInflater inflater = getLayoutInflater();
            for (int i = 0; i < numImages; i++) {
                ImageView tmp = (ImageView) inflater.inflate(R.layout.imageview, null);
                mImages.add(tmp);
                mLinearLayout.addView(tmp);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
        }
    });
    numImages = mSpinner.getSelectedItemPosition() + 1;
    mImages.clear();
    LayoutInflater inflater = getLayoutInflater();
    for (int i = 0; i < numImages; i++) {
        ImageView tmp = (ImageView) inflater.inflate(R.layout.imageview, null);
        mImages.add(tmp);
        mLinearLayout.addView(tmp);
    }
    // Button used to start and stop the capture of images when they are deemed great
    mStartStopButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mStartStopButton.getText().equals("Start")) {
                mGraph.getVariable("startCapture").setValue(true);
                mStartStopButton.setText("Stop");
                mSpinner.setEnabled(false);
            } else {
                boolean tmp = (Boolean) mGraph.getVariable("startCapture").getValue();
                if (tmp == false) {
                    return;
                }
                if (count == numImages - 1)
                    countHasReachedMax = true;
                captureImages();
            }
        }
    });
    // Button to open the gallery to show the images in there
    Button galleryOpen = (Button) findViewById(R.id.galleryOpenButton);
    galleryOpen.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent openGalleryIntent = new Intent(Intent.ACTION_MAIN);
            openGalleryIntent.addCategory(Intent.CATEGORY_APP_GALLERY);
            startActivity(openGalleryIntent);
        }
    });
    loadGraph();
    mGraph.getVariable("startCapture").setValue(false);
    runGraph();
}
Also used : MffContext(androidx.media.filterfw.MffContext) Intent(android.content.Intent) SurfaceView(android.view.SurfaceView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView)

Example 88 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 89 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 90 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)

Aggregations

SurfaceView (android.view.SurfaceView)93 SurfaceHolder (android.view.SurfaceHolder)45 View (android.view.View)24 SurfaceTexture (android.graphics.SurfaceTexture)16 Surface (android.view.Surface)13 Button (android.widget.Button)12 Intent (android.content.Intent)11 FrameLayout (android.widget.FrameLayout)11 Bitmap (android.graphics.Bitmap)8 TextView (android.widget.TextView)8 FileOutputStream (java.io.FileOutputStream)8 MotionEvent (android.view.MotionEvent)6 ViewGroup (android.view.ViewGroup)6 ImageView (android.widget.ImageView)6 OnClickListener (android.view.View.OnClickListener)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