Enable/Disable Status Bar Android - android

I am developing an application in which i want to disable status bar on the user side and enable when used by admin. I'm successful in disabling status bar with the below code:
WindowManager manager= ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
// PrefUtils.setKioskModeActive(false, getApplicationContext());
view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
But I'm not able to again enable to status bar.Is this possible to enable again with this code. or any other way to disable/enable status bar.
Thanks in Advance!.

#Kaifi you should remove same view from WindowManager as:
((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(YOUR_VIEW);
Or as:
manager.removeView(YOUR_VIEW);

Related

Android Full screen float window cannot touch

mWindowManager =(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
wmParams.format = PixelFormat.TRANSPARENT;
wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
wmParams.gravity = Gravity.TOP;
wmParams.x = 0;
wmParams.y = 0;
wmParams.width = WindowManager.LayoutParams.MATCH_PARENT;
wmParams.height = WindowManager.LayoutParams.MATCH_PARENT;
This is my float window in system window, but it cannot touch to other app. Please help.
your can change the flag of params
wmParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
| LayoutParams.FLAG_NOT_FOCUSABLE
| LayoutParams.FLAG_NOT_TOUCHABLE;

Window manager view is not allowing to go back

I am adding a view from XML to Window Manager view, Everything is working fine but when i want to go back to previous activity back button is not working even i have removed the added view from window manager inside onBackPressed.
manager = ((WindowManager) getApplicationContext().getSystemService(
Context.WINDOW_SERVICE));
localLayoutParams = getWindow().getAttributes();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.flags = 0x80000000 | localLayoutParams.flags;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
localLayoutParams.format = PixelFormat.TRANSPARENT;
localLayoutParams.screenBrightness = brightness / (float) 255;
LayoutInflater inflater = getLayoutInflater();
overlay = inflater.inflate(R.layout.activity_main, null);
manager.addView(overlay, localLayoutParams);
And when i press the back button here is the code to remove the view
if(overlay!=null)
manager.removeView(overlay);
Please help me out of this issue.

Making navigation bar touchable in android windowsmanager

WindowManager.LayoutParams wmlp;
wmlp = new WindowManager.LayoutParams();
wmlp.width = WindowManager.LayoutParams.MATCH_PARENT;
wmlp.height = WindowManager.LayoutParams.MATCH_PARENT;
wmlp.alpha = 1.0f;
wmlp.flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.TYPE_STATUS_BAR
|WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
wmlp.flags &= ~(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
);
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
wmlp.format = -1;
wmlp.token = null;
wmlp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
I am applying those parameters to a layout. I want the background activity should not be touchable. It is working fine. But with this having issue as the navigation bar is also untouchable. I want to make it enabled. What can i do?

Animation in status bar like in Mailbox app

Any idea how to implement animation in status bar like in Mailbox app?
Link to the app
What I'm curious the most is the fade in & fade out animation and that the list can be scrolled during it.
Any help appreciated. Thanks in advance.
This works for me in android 4.4.4 and 5.0.
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
int statusBarHeight = (int) Math.ceil(25 * getResources().getDisplayMetrics().density);
TextView textView = new TextView(this);
textView.setText("I am on top of status bar");
textView.setBackgroundColor(Color.BLACK);
textView.setGravity(Gravity.CENTER);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
statusBarHeight,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.RIGHT;
windowManager.addView(textView, params);

Add AdMob banner without XML

Can I add AdMob banner without using XML layout? I have't found anything about this in the admob documentation.
In the documentation I find nothing about using XML-Layout (see here).
However, registering the Activity in the Android Manifest and declaring your needed permissions must be done in XML.
You can actually do that by using Window instance.
Here is the snippet of sample code:
WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.x = 0;
mWindowParams.y = 0;
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
WindowManager wm = (WindowManager) _applicationActivity.getSystemService(Context.WINDOW_SERVICE);
if (wm != null)
{
wm.addView(_bannerAdView, mWindowParams);
}

Categories

Resources