Window manager view is not allowing to go back - android

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.

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;

Enable/Disable Status Bar 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);

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?

adding dynamic view using WindowManager.addView

I have a code on ICS for tablets. I want to add a Imageview dynamicly to a fragment. The fragment already contains preferencelist. The code for adding the view dynamically is as follows. I am coding this drag and drop functionality. This part of the code is taken from TouchInterceptor.java file from android music app.
mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP ;
mWindowParams.x = 0;
mWindowParams.y = y
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
ImageView v = new ImageView(mContext);
int backGroundColor = mContext.getResources().getColor(R.color.bg_background);
v.setBackgroundColor(backGroundColor);
v.setImageBitmap(bm);
mWindowManager = (WindowManager)mContext.getSystemService("window");
mWindowManager.addView(v, mWindowParams);
I am specifying the x coordinate of windowlayout param as 0. Eventthen when the view is displayed , itstead of displaying from the leftside of the fragment(the right pane) ,the view is displayed from middle of the right pane and is spanning to the right pane . What I am doing wrong ? Whats has to be done to correct this ?
Try setting gravity to Gravity.TOP | Gravity.LEFT
I m working exatly on the same code taken from the old Google Music open souce project.
Like you I guess, I had a TouchInterceptor in a fragment. My problem was that the fragment does not take all the screen widht, it has an other fragment on its left.
I tried a lot using mWindowParams.gravity to be able to specify an absolute x,y but I couldn't find a solution. Eventually I solved it with mWindowParams.horizontalMargin.
Here is the code I came up with:
private int getAbsoluteLeft(){
ViewGroup parent;
View child = this;
int left_absolute_position = 0;
try{
while( (parent = (ViewGroup) child.getParent()) != null) {
left_absolute_position += child.getLeft();
child = parent;
}
}catch(ClassCastException e){
}
return left_absolute_position;
}
private void startDragging(Bitmap bm, int x, int y) {
stopDragging();
//build the view
Context context = getContext();
ImageView v = new ImageView(context);
//int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
//v.setBackgroundColor(backGroundColor);
//v.setBackgroundResource(R.drawable.playlist_tile_drag);
v.setPadding(0, 0, 0, 0);
v.setImageBitmap(bm);
mDragBitmap = bm;
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
//Build Params
mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.x = ( x - mDragPointX + mXOffset );
mWindowParams.y = ( y - mDragPointY + mYOffset );
DisplayMetrics metrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(metrics);
mWindowParams.horizontalMargin = (float)getAbsoluteLeft() / (float)metrics.widthPixels;
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
mWindowManager.addView(v, mWindowParams);
mDragView = v;
}
The part I added is:
DisplayMetrics metrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(metrics);
mWindowParams.horizontalMargin = (float)getAbsoluteLeft() / (float)metrics.widthPixels;
This parameter mWindowParams.horizontalMargin specify the margin of the window from the specified gravity side (Gravity.Left) as a % € [0,1].
So with getAbsoluteLeft() I go up to the View tree to get the absolute distance of the list from the left side.
Dividing it by the window's width, you get percent of margin you need.

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