Making linear layout translucent and blurry - android

So what I'm trying to do is create a translucent and blurry background to a linear layout.
Right now I have a linear layout thats completely black covering up some information that a key must be purchased to show, however I would like it to be blurred out, not completely covered as it ruins the layout, it needs to stay there, just blurry and illegible.
Thanks for your help!

I'm not sure for Linearlayout. But for your activity you can try this.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
and use the setContentView(R.layout.your_layout); method

If you want to make any View Background translucent then use below code
android:background="#null"
it work me for EditText. And AFAIK it should work for any view.So once try for this one

How about trying GLSurfaceView:
http://developer.android.com/resources/articles/glsurfaceview.html
Within Android SDK there is an example on getting translucent surface (app/TranslucentActivity.java), essentially setting the alpha channel:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create our Preview view and set it as the content of our
// Activity
mGLSurfaceView = new GLSurfaceView(this);
// We want an 8888 pixel format because that's required for
// a translucent window.
// And we want a depth buffer.
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
// Tell the cube renderer that we want to render a translucent version
// of the cube:
mGLSurfaceView.setRenderer(new CubeRenderer(true));
// Use a surface format with an Alpha channel:
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
setContentView(mGLSurfaceView);
}
For other threads on using Alpha channel refer to:
Alpha Channel Blur
How can I blur and dim an image to be used as an activity background?
blur a image at android
Another example is the app/TranslucentBlurActivity.java (from Android SDK):
public class TranslucentBlurActivity extends Activity {
/**
* Initialization of the Activity after it is first created. Must at least
* call {#link android.app.Activity#setContentView setContentView()} to
* describe what is to be displayed in the screen.
*/
#Override
protected void onCreate(Bundle icicle) {
// Be sure to call the super class.
super.onCreate(icicle);
// Have the system blur any windows behind this one.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
// See assets/res/any/layout/translucent_background.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.translucent_background);
}
}

Related

Take screenshot of Unity scene in Android app

I have a Unity scene as a part of a view in my Android app. This is how I set it after exporting the project from Unity editor.
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
mUnityPlayer = new UnityPlayer(this);
binding = DataBindingUtil.setContentView(this, R.layout.main);
mUnityPlayer.setBackgroundResource(R.drawable.some_drawable);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
binding.scene.addView(mUnityPlayer.getView(), 0, lp);
}
This works fine. Now I need to take the screenshot of this scene and show it in another ImageView. The problem is that UnityPlayer is a FrameLayout and I expected to use getDrawingCache() on that to get the screenshot.
But that only returns me my background image R.drawable.some_drawable and any text and other info in the Unity scene isn't present in the screenshot. I think this is happening probably because the other contents aren't part of a FrameLayout and are rendered on some TextureView or something. I may be completely wrong. But I can't figure out how to get a screenshot of the contents inside the scene as a Bitmap that I can set on another imageView.
Any pointers or help would be appreciated. Thanks!

Drawing over my own custom View

I've created my own View (in which I draw on Canvas), and I want to make another Layer (with buttons etc.) on top of it. How can I do this?
Create a FrameLayout and add the views you want there - the FrameLayout allows for Overlaying of controls.
Just be sure that the top one has some opacity set, otherwise you won't see the controls below it - also be careful of the order you add the Views.
FrameLayout layers = new FrameLayout(this);
CustomViewBottom bottom = new CustomViewBottom(this);
CustomViewOverlay overlay = new CustomViewOverlay(this);
//the overlay class must set the ALPHA property
//of the PAINT object that it uses to draw
layers.addView(bottom);
layers.addView(overlay);
this.setContentView(layers);
How to draw an overlay on a SurfaceView used by Camera on Android?

Dynamically show/hide multiple OpenGL-views on Android

I'm using OpenGL to dynamically render images on a GLSurfaceView within android.
The application runs perfectly fine for (static) XML-based layout with multiple instances of a custom GLSurfaceView. (top left- and top right on the image)
If these instances get dynamically interchanged by the visibility value, the last visible OpenGL-image is still on top of the new one. (bottom left- and bottom right on the image)
top left picture: 4 instances, normal size
top right picture: 4 instances, big size
bottom left picture: 1 instance, normal size (top left picture as unwanted overlay)
bottom right picture: 1 instance, big size (top left picture as unwanted overlay)
What I tried so far:
did not remove the unwanted instances:
hide unused images by android::visibility="gone" (does not work smooth)
move the views out of the visible area and resize them to 0 by 0
use plain colors instead of dynamic images to simplify the output
force a redraw of the view by invalidating it (I actually tried almost every function a view offers)
clear various buffers in the onDraw()-function (I actually tried almost every function the GLSurfaceView offers)
force a onPause()-event to stop the renderer
use the ViewPager to switch between the views
removed the unwanted instances successfully:
restart OpenGL by reentering the app (can't be used like this)
recursively hide all other GLSurfaceViews by android::visibility="gone" (bugged the engine, so it stopped working)
The unwanted images does not change with layout reflows like a visibility change of a view.
They are only visible if a GLSurfaceView is over another GLSurfaceView (hidden by android::visibility="gone").
There is no problem if a ImageView is used instead.
The first created instance do not have this problem, because it is on top (or bottom?) of the child-stack and is on top of its siblings.
I guess android supports only one OpenGL based view which is used by all instances of GLSurfaceView.
All instances seem to share some preferences (especially the visibility), so it can't just turned off or moved out.
GLSurfaceView-class:
public class Panel extends GLSurfaceView implements Renderer {
private static native void nativeRender();
public Panel(Context context) {
super(context);
this.setRenderer(this);
this.setRenderMode(RENDERMODE_WHEN_DIRTY);
}
public void onDrawFrame(GL10 gl) {
nativeRender();
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
super.surfaceDestroyed(holder);
}
public void callback() {
this.requestRender();
}
}
So is it possible to use multiple OpenGL-views within (especially on top) of each other? is there a better way to interchange them without the use of the visibility value?
I was having same problem and couldn't solved the problem as i finally understand that one GLSurfaceView will be one top if we make another GLSurfaceView's visibility GONE & it won't be coming back on top of screen.
But i solved the problem with a trick. Instead of hiding the view, i changed it's width and height to 1 px, it's makes the view invisible to user. And when i need to show it , i changed it width & height via LayoutParams. And it partially solved my problem. I am showing you my code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/smallVideoRenderLayoutIncoming"
android:layout_width="1dp"
android:layout_height="1dp"
android:background="#color/transparent"
android:orientation="vertical"/>
<LinearLayout
android:id="#+id/largeVideoRenderLayoutIncoming"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ConstantFunctions.dpToPx(120),ConstantFunctions.dpToPx(170));
smallVideoRenderLayoutIncoming.setLayoutParams(layoutParams);
When i need to show it, i changed it's size as i needed.

Android GLSurfaceView with drawable background

I have a GLSurfaceView with a drawable as background, however only the background is visible when rendered without surfaceView.setZOrderOnTop(true)
I need to avoid using setZOrderOnTop(true) because there are static TextView's being used on top of the GLSurfaceView.
Any suggestions for getting this to work?
GLSurfaceView cannot really have a background. The way a surface view works is by cutting a hole through your Activity's window and showing another surface behind. Setting setZOrderOnTop(true) moves the surface above the Activity's window.
false! You can do it.
Just an example to show how it works.
glRenderer = new OpenGLRenderer(context);
view = new GLSurfaceView(context);
view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
view.setRenderer(glRenderer);
view.getHolder().setFormat(PixelFormat.RGBA_8888);
view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
Then use framelayout to put a view under glsurfaceview!
Try setZOrderMediaOverlay(true); which should put the gl layer above the background but below the window.
Well, since GLSurfaceView is just another view, why not use a FrameLayout to place the GLSurfaceView on top of the ImageView (or whatever you're using to display the drawable.)

Display gif on imagebutton android

I was wondering if it is possible to display a gif animation on an image button. I followed the example on Android API BitmapDecode sample and can now display animated gifs on the canvas.
Is it possible to display this same gif on an imagebutton. I tried using the setBackgroundDrawable() and setImageDrawable() but it gives me an empty button.
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.test);
ImageButton btn = (ImageButton) findViewById(R.id.ImageButton01);
SampleView p=new SampleView(this);
p.setDrawingCacheEnabled(true);
p.buildDrawingCache();
btn.setBackgroundDrawable(p.getBackground());
}
The SampleView() class is similar to the one provided in the BitmapDecode sample (i have removed all other code snippets and it now displays only gif animation)
Thanks,
New Guy.
I guess this should be possible just like it is with ImageViews - split up the animation into frames and then animate these frames using the android frame by frame animation. You might want to refer to http://www.app-solut.com/blog/2011/05/playing-animations-in-android/ for more information on how to use such a frame-by-frame animation

Categories

Resources