android, use camera as a background for an activity - android

I have a request that background for my activity must be "transparent", ie. background of an activity should be camera's current view. What is the easiest way to implemet this?
I have all the activities already implemented, with all the logic already implemented. Ideally, solution wouldn't include a lot of modification of an existing code.

Normally this is done with SurfaceView. Use it via camera.setPreviewDisplay(surfaceView)
To use it in your app, the simplest way would be to use FrameLayout as a top layout of your Activity and then put SurfaceView any you current top layout inside it.
`FrameLayout`
`SurfaceView`
`yourExistingLayout`
Of course your existing layout must be transparent to see the underlying SurfaceView. Note also that this alpha blending takes a lot of processor power so it will eat battery.

Related

Tap Draw On a Section of the Screen?

I'm trying to make my app be able to draw with your finger like Snapchat on part of the screen but not the whole thing? Every example I have seen of drawing is just an app that turns your whole screen into the canvas and does nothing else but I'm having a hard time implementing it as just part of my app. So as well as how to just choose a section of the screen as the canvas is it possible to make another activity just like the examples that extends view that I include or can I put everything in MainActivity.java?
Yes, there is. You can create a fragment, or as many as you want, and them place the fragment(s) wherever you want in the activity by using some of the available layouts.
For example, you can use a relative layout. You can add a frame layout to the relative layout and align it in the activity where you want, set its size, and then add the fragment to it. You can check this link to learn about fragments and their usage if you don't know them.

Overlay a view in every activity

In an app I am working on, I'd like to have a bar with some controls always present at the bottom of the screen. It should overlay every activity in the app but also be able to disappear and reappear. To do this I've considered some options, such as simply using a linear layout and setting the visibility in every activity or using a fragment somehow. Probably those would work but I feel there must be a better solution. So my question is: what is the best way of doing this?
There are two ways you could do this. You could just use Fragments, and make your overlay be a fragment.
The other way would be to sublcass Activity with an AcitivityWithOverlay, which handles the overlay appearing and disappearing then have all of your activities inherit that. If I did it this way, I'd make my overlay a singleton so I wasn't creating extra versions all over the place that did the same thing.

When should you let SurfaceView be drawn by UI-thread?

I'm reading up on SurfaceView and how to use it, and I've come across some information that states that a SurfaceView has View#willNotDraw() set to false by default, and that it's up to you to call SurfaceView#onDraw(). I also read that RomainGuy said that this is done by default because it is more efficient. My question now is, when should you handle calling SurfaceView#onDraw() in a separate thread, and when should you just set View#willNotDraw() to true, and just call SurfaceView#invalidate(). Is there a difference between the two, and does one improve performance more than the other?
See:
http://developer.android.com/reference/android/view/View.html#setWillNotDraw(boolean)
I'm not sure where you got your information, but at least the javadoc says that most users will set this to false to get Android to send it onDraw events itself. As for your question about when you should do this, I would say it comes down to why you're using a SurfaceView.
If your view is displaying something dynamic (e.g. for a game or something that has a tight event loop), you'll want to be controlling exactly when updates happen, especially if you'll have the information to use one of the more detailed forms of invalidate to save redrawing the entire View. You won't want Android to call invalidate for you, and that's why the flag is there.
If, on the other hand, you are simply drawing something static, it makes sense to let Android's UI stack control the invalidations.
By the way, invalidate only posts a request to re-draw the View, so be aware of this if you intend to use the event-loop style (onDraw will be called sometime after you call it).
Edit: some clarifications.
Using SurfaceView.onDraw() and SurfaceView.invalidate() will make SurfaceView behave like a normal View and you will pay for the extra overhead associated with SurfaceView. If you want to draw from the UI thread, use a regular View instead. It's easier and cheaper.

Android half visible activity

I would like to ask you guys/girls, if somebody have any idea how i can achieve a two activity transition in honeycomb, where the the not used activity will be visible a quarter of the original size and the other activity will be place to the center. Also i need to mention i used activities smaller then the screen resolution with dialog theme to get them to the center.
I looked into the ViewAnimator, ViewSwitcher, ViewFlipper, but i`m not sure if can do that. (Sure need to override this classes)
Somebody have any idea ?
You cannot have two activities "active" at the same time so showing any proportion of one activity and another and interacting with both is not possible, if you don't care about interacting with both simultaneously you might look at the SlidingDrawer class, a lot of people have customized that.
It is possible to kind of fake what you are asking by using two layouts and changing their proportions/position at runtime, for instance you could have a layout that takes up the entire screen, then on some event it could be re-positioned/sized and a hidden layout shown.
That is if I am understanding your question correctly.
Update
Also have you looked at fragments?

Positioning elements outside an Activity on Android

Is there a way to absolutely position an UI element on Android so that it is located outside an Activity? For example: can you create a fullscreen ImageView simply by moving/resizing an ImageView inside an existing regular Activity instead of creating a new fullscreen activity?
EDIT: Re-reading my question I see I wasn't very clear about what I'm trying to accomplish. I'd like to temporarily extend an element to cover the notification bar at the top of the screen. I need to create a semitranslucent fullscreen overlay but since translucent activities cannot cover the notification bar I'm trying to find out if it's possible for an element to break out of activity's bounds and resize itself to fill the whole screen, top to bottom.
That depends on what specifically you're trying to do. You can easily draw graphics offscreen and then animate their movement into the screen using a Canvas, but this is more for graphics than for user-interface elements. For moving buttons or such, you can have a look at another question here "How to position View off-screen". I gave a brief intro on how to use canvases, but the questioner found another way to do it using a customised linear layout and view animations.
Lastly, if you're trying to zoom and scroll an image around that's larger than the ImageView, there are some sources you can look at for inspiration. I realies this isn't strictly your question, but I'm including it since it might be linked to what you're thinking about. You can find a tutorial on Anddev.org and an open source app on Google Code.

Categories

Resources