Pass through touch events on window overlay to an Activity behind it - java

Some context.
I have a RelativeLayout that is added with a WindowManager the type is TYPE_SISTEM_ALERT with the flags FLAG_NOT_TOUCH_MODAL FLAG_WATCH_OUTSIDE_TOUCH.
I'm able to get touch events either on this RelativeLayout or in the Activity "behind" it, but as long as it's not part of the "RelativeLayout window" added.
* The black bars are the Views on my RelativeLayout;
* the red rectangle is the whole container of this RelativeLayout;
* the yellow stars are the spots of space that is created from the black views;
* the white space is the Activity behind this RelativeLayout window on top.
Imagine there is a Button on the yellow stars spots that are from the Activity A, BUT are VISIBLE to the user and if he clicks there.
the Button of the Activity A should be able to respond, even though its "behind" this RelativeLayout Window.
My references, but unfortunately without success so far are :
Android overlay to grab ALL touch, and pass them on?
Android : Multi touch and TYPE_SYSTEM_OVERLAY
Is there a workaround to this?

Is there a workaround to this?
If the activity in question is your own activity, get rid of the system-level overlay and implement the overlay in your activity's own view hierarchy.
If the activity in question is not your own activity, then AFAIK what you want is not possible. Windows in Android, at the moment at least, are purely rectangular; I know of no way that you can set up your window to be non-rectangular and have the activity truly be the top-most item in those transparent areas. And, passing touch events along has been blocked since Android 4.0, for security reasons (tapjacking attacks).

Related

How to make dimming effect of Youtube when motionLayout transitions from start to end?

I'm trying to make this effect but has no idea, how to achieve it:
My idea is to have a Frame Layout which wraps the video fragment, and the Video fragment has motion Layout as its root layout. So, Frame Layout is in main Activity, but motion Layout is inside a .xml file, which will soon be inflated as the Video fragment's layout. It looks something like this (The frag container will match parent in its width and height):
My questions are:
Is this a good idea to make this transition?
How to make the dimming effects that YouTube has? I'm planning to use this Listener for tracking the transition but has no idea how to make the slowly dimming effect :(. MotionLayout.TransitionListener
Any idea?
One way I can think of cover the screen with a a View that is
#000000 and transition the views color to #FF000000 using a custom Attribute.
The View would need to be gone, Invisible, or translationZ = -1 at the start

Whats the best way to switch between a normal view and a GLsurface view, Android

I am currently making a game, the game has a start screen and the main game screen.
My question is what is the best way to switch between the two views.
The start screen consists of just a couple of buttons one being "start game", when this is clicked GLsurface view to be created.
If i create the GLsurface view at the begining and bind the renderer here then anything from the GL surface view is displayed on top of the start up screen.
I thought i could create a viewflipper which would default to the start screen and then just create the glsurface view within the onclick method for the start button, but this doesnt seem to like having the GLsurface view in it.
Does viewFlipper support Glsurface view or is there a better way round this.
Thanks.
The easiest way is to use two activities, and just switch between them.
The trouble here is that ViewFlipper can only affect the "view" part of the GLSurfaceView, which is just a transparent hole. The surface where the GL rendering happens is composited separately, behind the layer with the view content, so it cannot be animated this way.
An example of using two activities in a GL game can be found in Android Breakout, which uses one activity for configuration and "start", and another for the game itself.
If you really want the ViewFlipper animation you could render into a TextureView, but your app would have to handle a number of things that GLSurfaceView does for you. TextureView is also less efficient than SurfaceView.

Android Button background Image changes back to state in XML

I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.

Activity on top of mapview

I have a Activity on top of a MapView that only covers a small portion at the top to display additional data.This Activity is called when a Polygon is touched on the map. The issue that I am faced with is that the first activity gets disable when the second Activity is in view. Is there a way to still interact with the first activity when the second one is being displayed? Or is there a better way of accomplishing what I am trying to achieve which is displaying a custom view at the top of the MapView. Thanks

Having activity greyed out and having two buttons to select

Is there any way I can make two buttons appear up and have the main UI greyed out without calling the pause method in android? sort of like robo defender. thanks!
I'm unfamiliar with Robo Defender, but a common way to do this sort of this is with an overlay. You can put a view over your activity with an opacity of ~30%. This view can have a grey image that cover everything but your buttons.

Categories