Android TextureView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TextureView class.

This code example shows how to use the following methods:setSurfaceTextureListener
    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 { 
8
CodeRank
This code example shows how to use the following methods:setOpaque, setSurfaceTextureListener
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        FrameLayout content = new FrameLayout(this);
 
        mTextureView = new TextureView(this);
        mTextureView.setSurfaceTextureListener(this);
        mTextureView.setOpaque(false);
 
        content.addView(mTextureView, new FrameLayout.LayoutParams(500, 500, Gravity.CENTER));
        setContentView(content);
    } 
 
    @Override 
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        mThread = new RenderingThread(mTextureView);
        mThread.start();
    } 
 
    @Override 
7
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener, setOnClickListener
    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 {
7
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener
  private TextureView widget=null;
  private SurfaceTexture surface=null;
 
  TexturePreviewStrategy(CameraView cameraView) {
    this.cameraView=cameraView;
    widget=new TextureView(cameraView.getContext());
    widget.setSurfaceTextureListener(this);
  } 
 
  @Override 
  public void onSurfaceTextureAvailable(SurfaceTexture surface,
                                        int width, int height) {
    this.surface=surface;
 
    cameraView.previewCreated();
    cameraView.initPreview(width, height);
  } 
 
  @Override 
  public void onSurfaceTextureSizeChanged(SurfaceTexture surface,
7
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener, setOnClickListener
 
    @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 {
7
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener
 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
 
		mTextureView = new TextureView(this);
		mTextureView.setSurfaceTextureListener(this);
		setContentView(mTextureView);
 
	} 
 
	@Override 
	public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
			int height) {
		camera = Camera.open(findFirstFrontFacingCamera());
 
		Camera.Size previewSize = camera.getParameters().getPreviewSize();
		mTextureView.setLayoutParams(new FrameLayout.LayoutParams(
				previewSize.width, previewSize.height, Gravity.CENTER));
 
6
CodeRank
This code example shows how to use the following methods:getBitmap
        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 
6
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener
    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 { 
6
CodeRank
This code example shows how to use the following methods:getBitmap
        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();
                    } 
                } 
6
CodeRank
This code example shows how to use the following methods:setSurfaceTextureListener, invalidate, requestLayout, setKeepScreenOn, setOnClickListener
	} 
 
	public void setVideoURI(Uri uri) {
		mUri = uri;
		openVideo(); 
		mTextureView.requestLayout();
		mTextureView.invalidate();
	} 
 
	public void stopPlayBack() { 
		if (mMediaPlayer != null) {
			try { 
				Log.d("Debug", "mp released. " + mMediaPlayer.toString());
				mMediaPlayer.stop();
				mMediaPlayer.release();
				mMediaPlayer = null;
				mCurrentState = STATE_IDLE;
				mTargetState = STATE_IDLE;
			} catch (Exception e) {
				e.printStackTrace();

5
CodeRank

Related Android TextureView Questions & Answers:

See Code Examples for Android TextureView Methods: