Delegate event from my activity to screen - android

I have a activity themed like a dialog and I have it setup so that it finishes when the user click outside.
this.setFinishOnTouchOutside(true);
As expected when the user clicks outside, it finishes. The activity is marked as floating activity and is only shown on top of the phone.
Now, if the user click on any other part of screen like the phone button/contact button on home screen, then the activity gets finished, but the user has to click on phone/contact app icon again to open phone/conatct app.
What I want is that if user click outside my activity, then the action must be performed as if the activity is not at all present on screen. Something like notification, which does not prevent user from doing other other tasks.

The only way you might be able to do this is by using a hidden WindowManager.LayoutParams flag, FLAG_SLIPPERY.
This allows touches starting on your View to continue to whatever View is below when the touch leaves your View but remains on the screen. However, I don't think this will work.
Android prevents you from touching "through" a touchable Window because it assumes that Window should be receiving the TouchEvent. Android also prevents you from programmatically "touching" the screen (without root or system access), most likely for security reasons.
I dug through AOSP for a while and found this.
Reading the comments, it's possible to infer that, while what you see doesn't take up the whole screen, the Activity's Window does. So, while nothing in your Activity is clicked, the Window is still overlaying everything, just with a transparent background, and is dealing with the touches that aren't passed to your Activity's UI. This brings us back to the "touching through" issue.

Related

How to disable Android touch

There are some application that disables all the touch inputs, including the touch events that occur on the navigation bar.
Examples are Touch Lock or UnTouch. How one can do that?
By analyzing the second linked app seems that there is a hidden layout that capture the touch events (like an empty onClickListener).
Initially I tried to draw a transparent foreground using the SYSTEM_ALERT_WINDOW permission and by assigning an empty touch listener. However in this way I cannot draw on the navigation bar, so the user can touch the home button and the back button.
Another way that I tried is to launch an Activity with transparent background and in fullscreen mode. In this way I can capture all the events. This works, but obviously this causes other activities to go in pause state.
So my question is, how can one reach the goal? Alternatively is possible to use some root/system commands?
Thanks!
Try this link. If you want to do it on just 1 view then edit out the iteration in the methods given.

Android - get screen touch event

I need to know when the user is using the screen over my activity, even when he is not strictly on my activity (for instance when he drawed the notification drawer, or when he is on Messenger). That is because i want my app to do something after a certain time of absence of action by the user, and such cases mess with the timer, as the activity is not paused.
I tried with dispatchTouchEvent() and onTouchEvent() but they only handle event made on my activity.
So is there a way to detect touch event made on layout that has been drawn by other app over my activity?
You can cretae transparent overlay window by system alert. It always on top.
Then you can handle touch event and stretching further.
Creating a system overlay window (always on top)

Android activity with FLAG_NOT_TOUCH_MODAL flag on top of home screen

I am having an android activity with FLAG_NOT_TOUCH_MODALset.
My activity is translucent and not full screen.
I just want to by-pass the touch events outside my activity window boundary to the underlying activity.
I am able to by-pass the event successfully so that i can scroll the underlying activity when my activity is on top of it.
My problem is, When my activity is on top of the "Applications List" Screen, i am not able to launch any application from the list. But I can scroll the list and the icon of the selected application is getting highlighted when selected. But it is not getting launched.
But when my activity with FLAG_NOT_TOUCH_MODAL is on top of the home screen (where we see wallpaper) the applications can be launched when user clicks on the shortcut icons
Please help me with this issue.
Thanks in advance.
Pragadeesh

How to hide activity GUI in android 2.2

I have an activity here.
I want to click a button and then hide the activity GUI.
That is, GUI is needed and you can hide it by clicking a "Hide App" button. How can i
implement this "Hide App"?
Somebody help! Thanks in advance!
To do what you want within the organizational model of android, your "program" should be written as a service, not an activity. You would then have a gui that is an activity and a client of your service, which can be started (made visible) and paused/stopped (hidden) as desired.
Presumably when your user clicks the hide application button, you're going to want to show something - at the very least a show button, so the user isn't stuck without input options!
So what you really have then is two views, one with the GUI hidden.
Two approaches I can see:
Hide app calls another activity with only the UI shown that you want. When the activity is finished, use Activity.finish() to return to the original activity with the GUI
Look at ViewAnimator and its subclasses (ViewFlipper and ViewSwitcher)
You could also just enable the screen lock. ;-)
That would automatically lock the screen (hide your app). And when the user unlocked the screen (using the UI and a gesture the user is already very familiar with) he would automatically get back into your app without you needing to do any extra coding.
The additional advantage of the screen lock is that it can be be password-protected, so if the user has his screen-lock already set to a password, instead of a slide bar -- he would just get the slide password thingy.

How to bring an activity to the foreground from inside the activity?

I am trying to bring an activity to the foreground from inside the activity. I am implementing multiple applications that do not cover the whole screen, so you can see other applications (activities) in the background and even touch them. The activities in the background react to the on touch event (e.g. one of its buttons is pressed), but it is not getting focus. This is what I would like to change. I want the activity to get focus and come to the foreground, whenever it is touched.
I tried to call startActivity from inside, but this resulted in either starting a new activity or no reaction at all (depending on the used intent flags). I want to achieve the exact same behavior that is shown when the activity is called from recent activities window. (the window opened when you long press the home button); bring the existing activity from the background to the foreground and focus it.
Is there a way to achieve this?
Have you tried configuring the activity in the manifest as android:launchMode="singleTop"?
This way, when you launch your activity when it is already running, a duplicate won't be started.
More info here:
https://developer.android.com/guide/topics/manifest/activity-element.html

Categories

Resources