Search in sources :

Example 11 with SurfaceView

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

the class TvView method resetSurfaceView.

private void resetSurfaceView() {
    if (mSurfaceView != null) {
        mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback);
        removeView(mSurfaceView);
    }
    mSurface = null;
    mSurfaceView = new SurfaceView(getContext(), mAttrs, mDefStyleAttr) {

        @Override
        protected void updateWindow(boolean force, boolean redrawNeeded) {
            super.updateWindow(force, redrawNeeded);
            relayoutSessionOverlayView();
        }
    };
    // The surface view's content should be treated as secure all the time.
    mSurfaceView.setSecure(true);
    mSurfaceView.getHolder().addCallback(mSurfaceHolderCallback);
    if (mWindowZOrder == ZORDER_MEDIA_OVERLAY) {
        mSurfaceView.setZOrderMediaOverlay(true);
    } else if (mWindowZOrder == ZORDER_ON_TOP) {
        mSurfaceView.setZOrderOnTop(true);
    }
    addView(mSurfaceView);
}
Also used : SurfaceView(android.view.SurfaceView)

Example 12 with SurfaceView

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

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

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

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

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

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

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

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)

Aggregations

SurfaceView (android.view.SurfaceView)137 SurfaceHolder (android.view.SurfaceHolder)65 View (android.view.View)35 SurfaceTexture (android.graphics.SurfaceTexture)18 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 Bitmap (android.graphics.Bitmap)9 ImageView (android.widget.ImageView)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