perform back button press from an overlay window - android - android

I have an overlay view (LinearLayout) added to WindowManager with following params set:
private void setWindowParams(WindowManager.LayoutParams params) {
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
params.format = PixelFormat.TRANSLUCENT;
params.gravity = Gravity.CENTER;
}
This LinearLayout contains three buttons "HOME", "RECENTS", "BACK"
I have implemented onKeyEvent() to remove this overlay view from window manager when phone's back button is pressed.
When back button is pressed from my overlay layout, i call my accessibility service and it works normally. Now when I press my phone's back button, my overlay view stays. Because it is not receiving key events since I had WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE this flag set in params.
But when I didn't set this flag, pressing back button from overlay just hides the overlay itself rather than performing back on the activity underneath it.
I want my overlay to hide on pressing phone's back button. And also to perform back button functionality on pressing back button from my overlay.
Is there any way to differentiate actual button press and software triggered button press using performGlobalAction(MyAccessibilityService.ACTION_BACK) ?
Any suggestions on how to implement this properly?

you can't do that because Context of the Dialog Will Be Destroy when Activity is Killed , you can use
WindowManager

Related

Android Overlay View makes some applications pause

I have created an overlay activity the requests permission to create a window of type TYPE_APPLICATION_OVERLAY and then starts a service that creates the window. This all works fine and I can interact with it and the launcher home screen behind the view (It's just a search text box with interactive results as you type).
The problem is, I have found one application that when I have this overlay running, the application is frozen like it's paused (it's a game). But I have tried my overlay over other applications and it works fine like google maps and even another game.
Here is how I'm creating the window in the service
//Add the view to the window.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
//Specify the view position
params.gravity = Gravity.TOP | Gravity.LEFT; //Initially view will be added to top-left corner
params.x = 0;
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView, params);
I've also tried other apps like facebook chat heads on top of this problem application and the app works with them so it has to be doable.
Has anyone run into this before? I'm really new to Android programming so I'm just not sure what to look for
Thanks!
EDITI found that if I use FLAG_NOT_FOCUSABLE then the problem app works underneath it. But then I can't interact with the overlay :/
That application might have some code written in its onPause() method to freeze it. Usually games pause themselves in onStop() or in onPause(), so that user doesn't accidentally lose their progress. Like if a phone call comes, or they press the home or recents button.
I figured it out based on this class of the Floaties library.
https://github.com/ericbhatti/floaties/blob/master/FloatiesLibrary/floaties/src/main/java/com/bezyapps/floatieslibrary/Floaty.java
The window manager can update view params via the updateViewLayout method. Just have to remove the FLAG_NOT_FOCUSABLE and re-add it in the two different states of my overlay when I want to be able to input text or not

How to create a floating back button in Android?

I am trying to create an app similar to Samsung assist menu or Pie Control app.
I created the floating button using WindowManager.
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
And then I created simple list of options to perform using dialog box.
This is how I perform going to home button using following code:
Intent startHome = new Intent(Intent.ACTION_MAIN);
startHome.addCategory(Intent.CATEGORY_HOME);
startHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startHome);
Now I would like to know how to perform back button action similar to hardware back key of the device that is NOT rooted.
I would appreciate any help.

Overlay navigation bar & status bar on fullscreen activity

I am creating a lock screen application right now. I have been searching and trying some tricks to do it but still can't find the best approach. My previous approach that I used is to use TYPE_SYSTEM_ERROR. it worked well. it prevents navigation and status bar to get any touches. it also run any other app behind my app, including the power off options dialog.
unfortunately I think this is bad because when the app got freeze or not responding, user can't do anything but force restart his/her phone.
I have been looking and analyze some existing lock screen apps in play store. They use different ways to lock the phone but I found one app that I think I can follow. It makes the nav and status bar overlay the app. nav and status bar still can be clicked but it's all opened behind the lock screen. and when I tried to open the power off dialogs, the NavigationBar still overlay the lock screen.
I changed my app to follow that approach. I am able to make the bars overlay my lock screen but I am still not able to:
1. make other app run behind my lock screen (lock screen always on top)
2. the NavigationBar stays overlay when power off dialog appear and when user move to home as well. in my case, the NavigationBar pushed up the screen and my screen looks ugly (some components move to wrong place) and after the Dialog dismissed, it doesn't move back to original position. it's fixed but I noticed a similar problem when I touch the home button and still searching to fix this.
Here's a snippet of my codes (updated):
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
mOverlay = (RelativeLayout) inflater
.inflate(R.layout.main, (ViewGroup) null);
mOverlay.setFitsSystemWindows(false);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
mWindowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(mOverlay, params);
And here a screenshot of app in PlayStore that I want to follow:

Can't Click button in Transparent Activty Android

i am trying add an transparent activity in front of an another activity. i added the transparent activity. i want both the transparent & behind activity button's clickable. but i can click behind activity's button. but in transparent activity's button i cant click because i added one line in transparent activity that is below
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE );
if i remove the above line from transparent activity i can't click the button in behind activity. i need both the behind & transparent activity's button clickable. please post any suggestion. thanks...

System Overlay Window causes touch problems for keyboard and back button

I'm trying to create an app like the Halo Notification on Paranoid Android. So far, so good.
However, when my "halo" is on the screen I can move it around just fine and most of the touch events do work. However, when I try popping the keyboard up by tapping on an EditText nothing happens. The window seems to consume the focus. The back button also doesn't work, but the home and recent apps buttons work.
I'm testing the application on a rooted Nexus 4 running PA's AOSP 4.4
The code (layout parameters) I have used to create the halo window is:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
Any idea what's causing this selective consumption of touch events?
Try to add the flag: FLAG_NOT_FOCUSABLE .

Categories

Resources