Using SurfaceView without displaying it - android

I would like to draw on a SurfaceView but not display it. It's used to generate images that eventually get fed into codec to produce a video. According to the documentation, SurfaceView appears to be something that is intended to be displayed. Is it possible to use it without actually displaying it?

There is a setVisibility Method, maybe you try using that.
setVisibility(int visibility)
Set the visibility state of this view.

Related

How do I add standard scroll bars to a SurfaceView?

I got a SurfaceView, in which I display a bitmap that is much larger than the actual area of the SurfaceView, so I have implemented a way for the user to slide their finger on the bitmap and move it up and down. When doing so, I would like to be able to display a vertical scroll bar, preferably the standard Android scroll bars, instead of drawing something custom.
The thing is, I would like my SurfaceView to stay the size of the screen, that is I don't want to scroll the SurfaceView itself, I just want to create the illusion that the user is scrolling the contents, and therefore display the scrollbars.
I tried setting android:scrollbars = "vertical" in the layout's XML, I tried mSurfaceView.setVerticalScrollBarEnabled(true); and I tried awakenScrollBars(); whenever the user touches the SurfaceView, however none of those displays the scrollbars.
So, is it possible to display the standard Android scrollbar on a SurfaceView?
short answer is: no!
everything that the SurfaceView ever draws on the screen is whatever you directly call to be drawn using the whole lockCanvas and unlockCanvasAndPost that you know about.
Putting those parameters in the XML make it possible for you to read them in Java via the AttributeSet in the constructor, but that's only for configuration, it won't drawn anything.

Placing animation drawable based on touch

I have created a relative layout with couple of buttons at the bottom of the screen. The reast of the screen is blank. I want to place/drag images where user touches the screen. I am between 2 options. These images have animation so I was going to use animationdrawable
1- Use the activity OnTouchEvent to make sure the click is within empty area and start placing/moving images around
2- Create a surfaceview in this area and implements its touch events and deal with a surface view.
What do you think?
Thank you
Well, both of those ways should work and i think it is optional choise.
Here i think i would go on the onTouchListener because that all of your view is writen with xml, using surfaceView now will make the code complicate.
I think you should take it aldo because it is writen for you. This will make your life way easier.
You are using drawable, stored as integer in R and making surfaceView will be difficult because you will need to use the SurfaceView, bitmaps inside him and the xml.
To get the press you will use onThouchListiner anyway, stleast when you do it, you will make your life way easier

TextureView and Transparency

I have a TextureView with a mediaPlayer attached to it, so i can use its surface to display a video, so far it's working well.
Now i try to create a fade in animation for displaying the video and i have no clue of how to do it.
I tried with the setOpaque(false) setting and playing with the alpha setting but it doesn't have any effects.
Also i tried the textureView without a mediaPlayer and i notice that i can't change the background color either, it's always black.
The documentation say that the behaviour of this view is the same as the standard view, but it doesn't seem to be the case.
Does anyone know how to change the transparency of this view ?
Thanks
I also had this problem, and you just need to set setAlpha(0.999f) and it will have transparent background.

Overriding android default camera/activities

I have requirement where in I have to overlay a header and footer over the camera. There is a set of three button which will handle the even of camera like (click/retake).
As of now i create a surface to use as preview and add jpegcallback and picture callback to take picture and store it. I manually handle android camera hardware and parameter configuration. As all of us know there has issues around camera and picture orientation. I have worked around this by setting camera orientation and also by rotating my captured image. Though the approach looks ugly i am able to achieve the end goal.
It would be great if we have a way of overriding the android default camera activity as any of the above steps are not required. I come from a Java/Java EE background and as per my understanding we should be able to create a custom Activity and override the behaviors and properties.
My Question:
Can we override the activities for android.provider.MediaStore.ACTION_IMAGE_CAPTURE and also com.android.camera.action.CROP.
If so which package of android has the java class for this activities.
Hopefully I am not misunderstanding your question but it sounds like you want to use the camera in your app. You want to view what the camera is seeing while having a header and footer above and below the camera preview. Then you want these buttons to do things like take a picture, etc.
If I am wrong I apologize.
Just look at the Camera implementation in the docs.
http://developer.android.com/guide/topics/media/camera.html#custom-camera
You can create your own activity layout with any buttons/text above, below, or on top of a preview view that you use to display the camera feed. Then just use the on click events for the buttons or whatever to do the things you want. Majority of this is in the documentation in the link.

Android VideoView plays 2 videos at the same time

I am trying to play a videoview on top of another video view. The first video view is paused, while the second is playing. It appears to work but no second video appears on the screen (though I hear the audio and see the controls that would normally appear on top). I am assuming this is some sort of order issue. Any thoughts. By the way, I have no problem displaying other views on top of the main video view and having the video fill the background.
That won't work - the VideoView is special in the sense that it 'punches' a hole in the normal Views to allow direct access to the display pixels (or, in android terms, the 'Surface' - VideoView is a subclass of SurfaceView). You cannot layer two SurfaceViews on top of eachother - the first one that grabs the pixels (the Surface) will 'own' it. (see SurfaceHolder.Callback.surfaceCreated() / surfaceDestroyed())
Other Views on top of a SurfaceView do work, because the framework will compose the display bits of normal Views on top of the Surface. It cannot do that with another VideoView (i.e. a SurfaceView) because there is nothing to compose.
<VideoView android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<VideoView android:id="#+id/videoView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
when videoView2 starts playing setvisibilty of videoView1 invisible.
then you can make it visible when you need.
Use Thread to control both video
I don't know if this is helpful at the moment, but I managed to get something similar to what you want...
I needed to nest a VideoView on top of a SurfaceView; as long as they don't overlap 100% it can work. (what i mean is, my surfaceview is the whole screen and videoview is just a small portion of the screen)
The thing is - since you can't compose SurfaceViews, the first one to grab the pixels is the one that will be shown. Intuitiveness will drive you to Z-order your prioritized view AFTER the less-important one in the XML - but as I've said previously, the first one to grab the pixels stays, so make sure you define the smaller view FIRST, and then overlay it with the bigger one.
This will result in such behaviour that the smaller (in my case preview view) acquires the said X * Y pixels, and then the 'background' surfaceview (which is supposed to be on top of it according to the XML) takes up the rest and ignores the smaller surface.
I'm not too sure about handling events from those two though as I only have to play streams in those two views and not react to any kind of clicks/events generated by those two components, but it might be expected that if you followed this route - the bigger view will intercept all clicks made in the smaller view area (because it's on top according to the XML) so maybe you have to programatically move it on top as well upon creation.
Hope it helps.
EDIT:
Although... it like it just works once. It's a work in progress really. Upon returning from any activity, there's nothing i can do to prevent the bigger view claiming everything :/
you can add videoview a on top videoview b,like this,
parentview.removeview(a);
parentview.removviewe(b);
parentview.addview(a);
parentview.addview(b);
parentview.invalidate();
Ti's work for me. I hope it can helps.

Categories

Resources