I am using these parameters to show an image on the screen. (this is running on a service cause of that i am using windowmanager instead of usual way- the image comes and goes continuesly)
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT
);
The Point is when I use FLAG_NOT_TOUCHABLE it allows user's touch go through the Picture, Which is fine and it is what I want. but when there is a need for text entry the keyboard keeps disappering (I want it to be there so I am able to input text even though the Picture is overlapping). this works for buttons and other input but the the keybord vanishes. How can I keep both?
changing WindowManager.LayoutParams.TYPE_PHONE to WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY solved the problem.
Related
I'm trying to draw an overlay over the android phone using my application so that I can draw a stroke over the edges of the android phone with a color using the custom view. But when I pass it the flag of WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY it works fine but it only draw the border under the status bar while I want to draw it on the whole screen of the phone on the status bar too. So I have did some research and it said that I should use WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, so when I tried to use this flag the app crashes with and error of permission denied 2003. Can anyone have any idea about this error or how to draw the overlay on the whole screen of the phone including the status bar.
Here is my code I'm using to draw the overlay in the service onCreate method:
val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val params = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
windowManager.addView(GlowingBorderView(this), params)
It is working fine for the area where my application display but it is not going all the way up to the status bar of the phone.
Here's my code
val params = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT
)
my end goal is to create a overlay that will lessen the overall brightness of the screen.
everything is working, i can tap/access all of the icon from other app.
The issue is, soft keyboard is not showing.
the device I am using is a Asus Zenfone 6 (Android 5.0)
I'm making an overlay by adding views directly to the window using WindowManager. However, I can't seem to find flags necessary to do what chathead does, which is to have the overlay on top of the soft keyboard. My overlay always gets covered by keyboard when it pops up.
this is the params I am using for my views that are added to the window
private WindowManager.LayoutParams touchableParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
Don't know your other requirements. I have been using this setup under Android 7.1.12 on a Google Pixel to make the overlay show on top of the soft keyboard. Hopefully this is what your are looking for.
mWindowsParams = new WindowManager.LayoutParams(
width,
height,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
I need to display my view on top of dialer application, so I was using TYPE_PHONE for this purpose which is touchable, but still on some devices like Nexus 5 dialer application of device is hiding it.
Tried using TYPE_SYSTEM_OVERLAY makes view visible on top of dialer application, but touch is not there. Any help regarding this will be great.
After lot of searching for above problem, I found solution my self. Here it is how I made view to be on top of everything inside device and also making it touchable which was not possible with TYPE_SYSTEM_OVERLAY.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSPARENT);
params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(view, params);
I have started working on an app that uses an overlay service to display a utility sidebar on the phone.
What I did was to add a small arrow handle to the right side of the screen, and when the user swipes over it, the sidebar shows up.
This worked without issue up to Jelly Bean. Starting with JB, the entire process of showing the sidebar started to become animated. Which would be very cool, if it were not animating all over the place.
What I did to show and hide the sidebar was a simple updateViewLayout command as below.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
handlesize, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT|Gravity.CENTER_VERTICAL;
wm.updateViewLayout(mOverlay, params);
handleButton.setImageResource(R.drawable.handle);
isCompact=true;
This piece of code hides the sidebar. The handlesize variable is the width of the handle. The wm variable is the window manager. So basically, what I do is only show the width of the handle, so anything else that might be next to the handle(the sidebar is not visible). I also use WRAP_CONTENT for the height, to make sure the only part that absorbs touch events is the area used by the handle, so as to not block off the entire right hand side of the screen from registering touches.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT|Gravity.CENTER_VERTICAL;
wm.updateViewLayout(mOverlay, params);
handleButton.setImageResource(R.drawable.handle_back);
isCompact=false;
This is the code that displays the sidebar. The width of the whole view is set to WRAP_CONTENT, so it shows all the content, and the height is set to MATCH_PARENT, because the sidebar is full height when it's visible.
Now normally, this code should instantly switch between one width and height set to the other width and height set, nothing in between. But since Jelly Bean, this has started doing this through some weird animation. I'm not sure, but it may have something to do with Project Butter.
In the link below, you can see some frames of the animation.
http://i.stack.imgur.com/QzZGO.png
If I set the height of the view, even when closed, to MATCH_PARENT, then the animation is just on the horizontal plane, so right to left, which does look nice. The problem with that is I don't want to block the entire right hand side of the screen. There are a lot of uses for sliding from the right in other apps that might run under the service, like switching tabs in Chrome.
So my question is, do you have any idea what I should do to stop this behavior, or, even better, to use it to my advantage in order to make the sidebar do some smooth animations, but in a way that works on Android 2.2 and above?
Thanks a lot!
Since JB Android has added window animations to layout changes. If you disable window animation in Developer settings, the behavior will stop. Also, you cannot disable/enable this programmatically (requires system permission if I remember correctly), so the solution is to remove the view completely and attach it again. Instead of wm.updateViewLayout(view,params) you have to wm.removeView(view) and then wm.addView(view,params).