5

i am writing an app that shows missed calls and unread sms in a pop up window. it also has a reminder feature (to close the pop up window and open it after a specified time). its similar to the popup window of any.do.

i was able to created such a window by using the WindowManger, but for some reasons which i dont understand so far, the pop up window disappears after some time (although it should be opened untill the user closes it, or clicks on the reminder button which could take hours).

this is how i created the existing popup window

windowManager = (WindowManager) context.getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);              
    this.inflater = LayoutInflater.from(context);
    params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.BOTTOM;
    vgPopupWindow = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.popup_mainwindow, null);
    vgPopupContent = (ViewFlipper) vgPopupWindow.findViewById(R.id.popup_content);
    vgPopupAreaContent = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_content);
    vgPopupAreaActions = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_actions);
    vgPopupTabs = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_tabs);
    vgPopupHeader = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_main_header);
    windowManager.addView(vgPopupWindow, params);

because i was not sure if the WindowManager is really the right way for that, i also tried to do the same with an activity with following style

<style name="PopupWindow" parent="CustomTheme">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowIsTranslucent">true</item>

its looks now just like the WindowManager version, but has one problem: i can not access the window of my app below it, because the translucent parts of the window look perfect, but block any click events to the window below, so that i can not scroll it or do anything with it. like in any.do i just want that window to show up, but not to block any possibility to work on the window below while the popupwindow is opened.

EDIT: i want to see the pop up window at the bottom, covering 30% of the window, but be able to scroll the window under it (and also perform click events on it) at the same time.

so my questions are:

  1. is the WindowManager the right way to create this popupwindow?
  2. if yes, why does it disappear sometimes unwanted? how can i prevent it?
  3. if no, how can i create an activity that behaves like the window i created with the WindowManager?
  4. or are both ways wrong? in this case; whats the right way?
richard
  • 724
  • 2
  • 14
  • 36
  • did you get this done? I need some ideas on this. What i did is created an activity with relative layout and placed some components on the botton, set the theme as transpatent and set the activity animation to enter from bottom and exit to bottom. but the background activity gets stuck till my activity is running. – prashantwosti Jun 17 '14 at 06:43

1 Answers1

0

Here is the code I used to do the same thing

public class PopupActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlertDialog.Builder adb = new Builder(this);
        AlertDialog dialogTest = adb.setTitle("Test title")
                .setMessage("Test message")
                .setNeutralButton("Button", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // do something
                        PopupActivity.this.finish();
                    }
                }).create();
        adb.setCancelable(false);
        dialogTest.show();
    }
}

and the XML style(originally posted here https://stackoverflow.com/a/2700683/995020)

<style name="Theme.Transparent" parent="AppTheme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

Set the style for the activity in the manifest file. And then just start the activity any time you want to show the popup window. You may add EXTRA data to an intent and use it for customizing the popup.

Community
  • 1
  • 1
Maxim Efimov
  • 2,747
  • 1
  • 19
  • 25
  • i am not sure if i understood. you mean the activity you wrote should behave like the pop up window that i want, or the alert window that starts after the creation of the activity? in the link you sent there is nothing about an alert window. – richard Oct 03 '13 at 13:54
  • just to make sure i made my problem clear. i want to see the pop up window at the bottom, covering 30% of the window, but be able to scroll the window under it (and also perform click events on it) at the same time. – richard Oct 03 '13 at 13:54
  • @Richard I missunderstood you, unfortunally. For your purpose I would advise a `RelativeLayout` with two elements - main view and the popup(may be a fragment), attach the second element to the bottom and change it's visibility whenever you want. Thus user would see the popup, the main view and be able to interact with both of them. – Maxim Efimov Oct 03 '13 at 15:19
  • thanks, but this would work only for my app, but not for others. i need a pop up window like the app "any.do" uses that pops up when a special event occurs, even when the native app is closed. in this case the popup-window should cover parts of any other app without blocking it. all this works already with my WindowManager solution, the only problem is that it sometimes disappears without a clear reason. – richard Oct 03 '13 at 19:45