How to OverlayService Fullscreen? - android

wm = (WindowManager) getSystemService(WINDOW_SERVICE);
int type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
int flags = WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
int format = PixelFormat.TRANSLUCENT;
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
type, flags, format);
params.gravity = Gravity.RIGHT | Gravity.TOP;
wm.addView(lockScreenView, params);
I tried to use FLAG_LAYOUT_NO_LIMIT or FLAG_FULLSCREEN. But it's only available on devices that have a hard home button. They are unavailable in devices have a navigation bar or virtual keyboard.

Related

Fullscreen view with gravity.BOTTOM is unwantingly clipped when an overscan value is set

My Android (8.0+) app is implementing a narrow overlay along the bottom of the screen, but when a user sets an overscan value, it disappears. How can I make my view respect what is actually visible so Gravity.BOTTOM will not be clipped? I have tried countless combinations of flags, but nothing seems to ackknowledge the overscan value.
Point screen_size = new Point();
WindowManager.LayoutParams mParams;
WindowManager mWindowManager = getSystemService(WINDOW_SERVICE);
mWindowManager.getDefaultDisplay().getRealSize(screen_size);
layout = new LinearLayout(getApplicationContext());
layout.setOnTouchListener(this);
// color for debug.
layout.setBackgroundColor(0x55ff0000);
mParams = new WindowManager.LayoutParams(
screen_size.x,
40,
0,
0,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.BOTTOM;
mWindowManager.addView(layout, mParams);

how to set color in navigation bar in service

I want to set the color in navigation bar, but it is not covering.even i set FLAG_LAYOUT_IN_SCREEN . how to set the transparent layout in entire screen ,in service . Plz help me?
**This is my code : **
View mView = new View(this);
mView.setBackgroundColor(shared.getColor());
// get the WindowManager for the context-specific Display
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
// create the LayoutParams for the new Window
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,//width
WindowManager.LayoutParams.FILL_PARENT,//height
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,//xpos // TYPE_SYSTEM_ALERT is denied in apiLevel >=19
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,// flags
PixelFormat.TRANSLUCENT //formats // the pixel format, here: translucent
);
wm.addView(mView, params);
Replace your code with below......
View mView = new View(this);
mView.setBackgroundColor(shared.getColor());
// get the WindowManager for the context-specific Display
WindowManager wm = (WindowManager)
getApplicationContext().getSystemService(WINDOW_SERVICE);
// create the LayoutParams for the new Window
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
int max = Math.max(getScreenWidth(), getScreenHeight());
params.type = TYPE_SYSTEM_OVERLAY;
params.height = max + 200;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
params.format = PixelFormat.TRANSPARENT;
wm.addView(mView, params);
//getting screen height and width
public static int getScreenWidth() {
return Resources.getSystem().getDisplayMetrics().widthPixels;
}
public static int getScreenHeight() {
return Resources.getSystem().getDisplayMetrics().heightPixels;
}

Move popup window out of screen

Hello i have this code to show popup window...
final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
(width/100)*50, height, WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
parameters.gravity = Gravity.CENTER | Gravity.CENTER;
parameters.x = (width/100)*50;
parameters.y = 0;
But i need to show it out of screen...
When i set x position to more then windows size it's stuck at corner and not go over screen...
Thanks.
Edit: Because some people don't know what i mean.. i mean half outside screen not full..
You need to add one more flag which is flag_layout_no_limits
final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
(width/100)*50, height,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
parameters.gravity = Gravity.CENTER | Gravity.CENTER;
parameters.x = (width/2);
parameters.y = 0;

Android chathead is killed when I open game

I'm using https://github.com/recruit-lifestyle/FloatingView
to create chathead like messenger on android.
But when I open a game, the chathead get killed.
Is there any way to display the chathead above the game?
Please help, thanks
Config of WindowManager in the lib:
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mParams = new WindowManager.LayoutParams();
mMetrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
mParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
mParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
mParams.format = PixelFormat.TRANSLUCENT;
mParams.gravity = Gravity.LEFT | Gravity.BOTTOM;

WindowManager can not always draw on top

In my app I use a BroadcastReceiver to catch incoming calls. So when someone calls and in case that I have the phone number stored in my application's DB, I display a window with the name of the caller.
The problem is that in some devices this window is not displayed if the device's screen is off before the phone rings.(If the screen of the device is on, when the phone rings, the window is displayed).
I also delay the drawing of the window for 3 seconds, but this doesn't seem to work.
To display the window I use the following code, where mView is a RelativeLayout with a TextView. This code runs in a Service.
WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
dpToPx(72),
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.TOP;
WindowManager mWindowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mParams);
After several failing tries I found it.
I had to replace the flag TYPE_PHONEwith TYPE_SYSTEM_OVERLAY.
try this, this will surely work
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Layout_Flag = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Layout_Flag = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Layout_Flag = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
}
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
Layout_Flag,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
try {
mWindowManager.addView(windowView, params);

Categories

Resources