I'm working with WindowManager for showing popup (myView) with a Service (I can explain why but it's not the subject)
layoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSPARENT);
layoutParams.gravity = Gravity.CENTER;
layoutParams.packageName = context.getPackageName();
layoutParams.buttonBrightness = 1f;
layoutParams.windowAnimations = R.style.DialogAnimation;
layoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
final WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
manager.addView(myView, layoutParams);
In my popup there is an EditText, when it request focus, automatically keyboard move up and the view do the same.
My problem is, when backButton is pressed, automatically keyBoard move down but not my view.
What can I do to make my view back down?
Related
Say your app has the permission to draw over other apps. You can draw a Drawable over anything with this simple code:
private void drawTheOverlay(Drawable drawable) {
WindowManager windowManager = (WindowManager) this.getSystemService(Service.WINDOW_SERVICE);
View view = new LinearLayout(this);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
view.setBackground(drawable);
windowManager.addView(view, layoutParams);
view.setVisibility(View.VISIBLE);
}
My question is if you can draw an entire activity over another app? Meaning draw an activity, including its buttons, imageviews, child layouts, and everything in it, and make it interactable like an activity would be, but with a transparent background so that the app it's drawing over appears behind it. Is this possible?
I am adding a textview to Window using the following code
public static void addViewToWindow(Activity activity, View view, WindowManager.LayoutParams params)
{
WindowManager windowManager = (WindowManager)activity.getSystemService(Context.WINDOW_SERVICE);
windowManager.addView(view, params);
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.OPAQUE);
params.gravity = Gravity.BOTTOM;
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
addViewToWindow(myActivity, myEditText, params);
But I am not able to long press on the EditText to let the user copy/paste. As soon as I change the orientation of the device to landscape, the EditText covers the entire screen and I am able to copy/paste by long press. I am not able to make out what I am doing wrong.
In an activity If I click the listview item I shld show alert dialog below the listview....
Even after getting popup window, I shld able to scroll the listview..
You can place your view in window manager. The alert view will be shown and at the same time you can access your list view too.
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
windowManager.addView(yourPopupView, params);
A window that is shows on screen
public class FlatingViewService extends Service{
public static WindowManager windowManager;
...
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
...
//Floating View Layout
li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
myView = li.inflate(R.layout.product_response_card, null);
name = (TextView) myView.findViewById(R.id.name);
editTextName = (TextView) myView.findViewById(R.id.editTextName);
...
//Layout Parameters
...
response_card_params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
When user tries to enter some text into editText, Keyboard appears but on top of editText. So the user can't see anything.
What's the actual problem?
Got the problem solved.
//Layout Parameters for Product response card
layout_params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
PixelFormat.TRANSLUCENT);
layout_params.gravity = Gravity.LEFT;
layout_params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
I was using WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, instead of WindowManager.LayoutParams.TYPE_PHONE
And WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
Starting from API 19 options SOFT_INPUT_ADJUST_PAN and SOFT_INPUT_ADJUST_RESIZE don't affect windows with types TYPE_SYSTEM_ALERT and TYPE_TOAST (and TYPE_VOLUME_OVERLAY for API 21 and 22; in API 23 TYPE_VOLUME_OVERLAY removed from this list).
Instead of use TYPE_SYSTEM_ALERT need use TYPE_PHONE.
I recently saw an image of an app that was capable of displaying a view above the status bar and was also able to cover it with a view.
I know you can get a view right below the status bar from a view with align parent top. But how would you get a view on top of the status bar??
Example
Disable the System Status Bar - Without Root
After two full days of searching through SO posts and reading the Android docs over and over.. Here is the solution that I came up with. (tested)
mView= new TextView(this);
mView.setText(".........................................................................");
mLP = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
100,
// Allows the view to be on top of the StatusBar
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
// Keeps the button presses from going to the background window
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// Enables the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
mLP.gravity = Gravity.TOP|Gravity.CENTER;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mView, mLP);
Dont forget the permissions:
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
Note:
Tested upto kitkat.
The answer by #Sadeshkumar is incorrect for ICS and above (perhaps GB as well).
A view created with TYPE_SYSTEM_ALERT and FLAG_LAYOUT_IN_SCREEN is covered by the StatusBar.
To get an overlay on top of the StatusBar, you need to use TYPE_SYSTEM_OVERLAY instead of TYPE_SYSTEM_ALERT.
The problem being then, how to get clicks/touches?
A view created with TYPE_SYSTEM_ERROR and FLAG_LAYOUT_IN_SCREEN is covered by the StatusBar.
int statusBarHeight = (int) Math.ceil(25 * getResources().getDisplayMetrics().density);
View statusBarView = new View(MyActivity.this);
statusBarView.setBackgroundColor(Color.GREEN);
WindowManager.LayoutParams params = null;
params = new WindowManager.LayoutParams(WindowManager.LayoutParams.FILL_PARENT,statusBarHeight,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(statusBarView, params);