Search in sources :

Example 1 with TextureView

use of android.view.TextureView in project android_frameworks_base by ParanoidAndroid.

the class TextureViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContent = new FrameLayout(this);
    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(this);
    mTextureView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap b = mTextureView.getBitmap(800, 800);
            BufferedOutputStream out = null;
            try {
                File dump = new File(Environment.getExternalStorageDirectory(), "out.png");
                out = new BufferedOutputStream(new FileOutputStream(dump));
                b.compress(Bitmap.CompressFormat.PNG, 100, out);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
        }
    });
    Button button = new Button(this);
    button.setText("Remove/Add");
    button.setOnClickListener(new View.OnClickListener() {

        private boolean mAdded = true;

        @Override
        public void onClick(View v) {
            if (mAdded) {
                mContent.removeView(mTextureView);
            } else {
                mContent.addView(mTextureView);
            }
            mAdded = !mAdded;
        }
    });
    mContent.addView(mTextureView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    mContent.addView(button, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
    setContentView(mContent);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) FileOutputStream(java.io.FileOutputStream) TextureView(android.view.TextureView) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 2 with TextureView

use of android.view.TextureView in project android_frameworks_base by ParanoidAndroid.

the class GLTextureViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(this);
    mTextureView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap b = mTextureView.getBitmap(800, 800);
            BufferedOutputStream out = null;
            try {
                File dump = new File(Environment.getExternalStorageDirectory(), "out.png");
                out = new BufferedOutputStream(new FileOutputStream(dump));
                b.compress(Bitmap.CompressFormat.PNG, 100, out);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
        }
    });
    setContentView(mTextureView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) FrameLayout(android.widget.FrameLayout) FileNotFoundException(java.io.FileNotFoundException) TextureView(android.view.TextureView) IOException(java.io.IOException) View(android.view.View) TextureView(android.view.TextureView) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 3 with TextureView

use of android.view.TextureView in project zxing-android-embedded by journeyapps.

the class CameraPreview method setupSurfaceView.

@SuppressWarnings("deprecation")
@SuppressLint("NewAPI")
private void setupSurfaceView() {
    if (useTextureView && Build.VERSION.SDK_INT >= 14) {
        textureView = new TextureView(getContext());
        textureView.setSurfaceTextureListener(surfaceTextureListener());
        addView(textureView);
    } else {
        surfaceView = new SurfaceView(getContext());
        if (Build.VERSION.SDK_INT < 11) {
            surfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }
        surfaceView.getHolder().addCallback(surfaceCallback);
        addView(surfaceView);
    }
}
Also used : TextureView(android.view.TextureView) SurfaceView(android.view.SurfaceView) SuppressLint(android.annotation.SuppressLint)

Example 4 with TextureView

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

the class GLTextureViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(this);
    mTextureView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap b = mTextureView.getBitmap(800, 800);
            BufferedOutputStream out = null;
            try {
                File dump = new File(Environment.getExternalStorageDirectory(), "out.png");
                out = new BufferedOutputStream(new FileOutputStream(dump));
                b.compress(Bitmap.CompressFormat.PNG, 100, out);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
        }
    });
    setContentView(mTextureView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER));
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) FrameLayout(android.widget.FrameLayout) FileNotFoundException(java.io.FileNotFoundException) TextureView(android.view.TextureView) IOException(java.io.IOException) View(android.view.View) TextureView(android.view.TextureView) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 5 with TextureView

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

the class GetBitmapActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout content = new FrameLayout(this);
    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(this);
    Button button = new Button(this);
    button.setText("Copy bitmap to /sdcard/textureview.png");
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bitmap b = mTextureView.getBitmap();
            try {
                FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/textureview.png");
                try {
                    b.compress(Bitmap.CompressFormat.PNG, 100, out);
                } finally {
                    try {
                        out.close();
                    } catch (IOException e) {
                    // Ignore
                    }
                }
            } catch (FileNotFoundException e) {
            // Ignore
            }
        }
    });
    content.addView(mTextureView, 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) FileNotFoundException(java.io.FileNotFoundException) TextureView(android.view.TextureView) IOException(java.io.IOException) TextureView(android.view.TextureView) View(android.view.View)

Aggregations

TextureView (android.view.TextureView)44 FrameLayout (android.widget.FrameLayout)34 View (android.view.View)23 Bitmap (android.graphics.Bitmap)22 IOException (java.io.IOException)17 FileNotFoundException (java.io.FileNotFoundException)15 FileOutputStream (java.io.FileOutputStream)15 Button (android.widget.Button)10 BufferedOutputStream (java.io.BufferedOutputStream)10 File (java.io.File)10 SurfaceView (android.view.SurfaceView)7 Canvas (android.graphics.Canvas)6 Rect (android.graphics.Rect)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 TextView (android.widget.TextView)4 SurfaceTexture (android.graphics.SurfaceTexture)3 WindowManager (android.view.WindowManager)2 SuppressLint (android.annotation.SuppressLint)1 Espresso.onView (android.support.test.espresso.Espresso.onView)1 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)1