When to use Android PopupWindow vs Dialog - android

I'm unclear about when to use PopupWindow vs Dialog. Any insight would be much appreciated. Thanks.

They both use the addView() method along with various windowManager methods. The two are similar in that regard.
Dialogs seem to come with more built-in features for interaction, such as handlers and buttons already included in the base class, while PopupWindows come with more built-in methods for positioning them about the screen.
I think that each of them can do exactly the same as the other, but choosing between the two will be a matter of convenience to the programmer with regards to how you want to use the Object. I'm not a phD in computer science, but I do not think there is a significant difference in processing time between the two based on what I saw in their respective class definitions.
My advice: If you want to have greater control over where your View appears on the display, use a PopupWindow. If you want to add more control and feedback between your View then use a Dialog. If you, like me, want master control over everything, I would suggest a PopupWindow since it has fewer user-evident default methods to override.

I think, that you should use Dialog for simple user interaction (YES,NO).
I usually use Dialog for simple user interaction and WindowPopup for a little bit more complex view.
One example of WindowPopup is AutoCompleteTextView.
Hope it helps.

I think Dialog should use when you need to take action before proceed to continue next. It never cover the screen and always adjust center aligned as modal event.
On other side, PopupWindow has flexibility to adjust information anywhere in the screen as position wise like sticky footer, sticky header, on left, right, center etc. as per location set.
For Showing Information it's good option as there is facility to animate also.
In short, For Showing Information with minimal action go with PopupWindow and for controlled action to proceed next go with Dialog.

Related

Android - Show more information on a popup

I'm developing an app that includes reviews of items and due to my design, I want to only show all the reviews in a popup window like in Google Play Store:
What should I use to create that white panel that appears over the current window and contains the necessary information? This should be simple but I'm a newbie and I can't seem to figure out what this "widget" is. Please help me if you are familiar with this so I can use this cool design pattern. Thanks.
It seems you want to display a layout as a popup in another activity.
If you want to do this using an Activity instead of a Dialog, you can do this by setting the activity's theme to android:theme="#android:style/Theme.Dialog" in the manifest - this will make the activity appear like a dialog (floating on top of whatever was underneath it).
A better way to do it would be using a DialogFragment. You can display information in the form of a popup and it will have its own lifecycle. That will be much better than displaying an activity like a dialog
Ram kiran's answer is a good one and one which I like to give also. But just so you have another option to look at you can consider PopupWindow
As stated in the docs, it is
A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
I've used this and it works out nicely in some situations. It really depends on what your exact needs are as to which will work best for you.

In-app only notifications / interactive toasts

Our Android app currently has a large number of dialog and alert boxes. I'd like to switch these to toasts, but there's a problem - some of them require the user to choose whether to view more info or just dismiss the popup. It doesn't look like there's a way to do this with toasts.
Is there any existing Android library that supports tappable toasts (i.e., you tap it and it triggers a function call to a listener in the app, sort of like a notification)? If not, is there a recommended alternative for this "tap-here-to-do-something-otherwise-I'll-just-vanish-in-a-few-seconds" UI pattern, or should I just roll my own fragment class for it?
I have to do something similar to my app so I wrote, DropViewNotification, a boiler plate to make it happen by animating the so-called notification into the screen. It doesn't do automatic dismiss as this should only act as a tool.
It accept any kind of view to make it versatile as I need to put at least two or three obvious view into it (TextView, ProgressBar, ImageView). You can switch it's content on the fly if you want to. Animation can also be customized for both showing and dismissing of the notification and the main content.
In real-life you might want to consider adding controller class to handle the display of the content and auto dismissal, etc. Hope it's of some use to you.

QuickAction in Widget

I'd like to add a QuickAction-Bar to my Widget-Project like discussed here.
The problem is, that all those implementations need a View as an anchor. But since I'm building a Widget, I only have RemoteViews.
I checked the source of those implementations and did some research and I found that they all use the standard PopupWindow-class (which is part of Android since API-Level 1). This class offers three methods to be shown and they all want a View as a parameter.
My question is, is there any workaround for that to make this UI-Pattern usable in a Widget? I know it does work since "SUI Call Log" and the "HTC Sense SMS-Widget" do it, too (But I cant get my fingers on source code of neither of them).
(source: suisolutions.com)
The "HTC Sense SMS-Widget" may not be an app widget, but rather a feature of the home screen. Only if you are able to add it to an alternative home screen can you tell if it is an app widget or not.
Regardless, you could start up an activity that displays the quick action. Give it a transparent theme and pass any information you can via extras in terms of where to place the popup. Place a transparent 1px square View at that location as your anchor, then use QuickContactBadge or PopupWindow or whatever you like.

Small Popup for Instructions, like foursquare ones

After seeing the last screenshots of new foursquare application and their balloon like cartoon instructions, I'd like to create some of these in my application.
I found a similar question for iPhone
Small popup for instructions... How?
Here is another screenshot of foursquare app:
I'd like to know how I could achieve that with Android.
Thanks in advance for any help.
UPDATE: This is what I could get so far but adding some buttons with a custom drawn background and layering them with a FrameLayout:
But I still couldn't get the triangle effect. Maybe there is something I can do with my custom background shape?
UPDATE2
After checking your suggestions, I decided to go with Aaron C idea and added an image with an arrow on it. This is my current result:
Thank you Snailer, QuickAction API project seems very much promissing. I'll check it out when implementing more features in my app.
Now, I just need to get the right color or maybe I could just let it this way. It seems nice too.
And, so, to summarize what I did:
Got my initial xml layout inside a FrameView.
As I'm using a frameview, everything I put in here will be piled one over the other. That's how I could add things to the layout.
In that framelayout, I put 2 relativelayouts whith an image with the triangle and a button to create the two upper popups. In the bottom I put a button only.
That's it. I hope it helps somebody.
Thank you very much again for all your help!
That sounds like a neat thing to implement. There might be a built-in Android variation on AlertDialog that achieves this, but if not here is how I would go about implementing it:
Create a new Activity whose background is black with a very high (low?) alpha color value. This will allow you to see through it to the previous Activity in the stack. Then, add your alert at whatever coordinates you like using a relative layout with padding values.
You might also want to add a touch listener that exits the Activity if the user touches the balloon (or maybe anywhere in the screen).
If you want to be fancy with coordinate placement of the balloon, you can pass this information into the new Activity using the Activity's launch Intent with the putExtra() methods.
It's probably achieved through skinning a toast.
The developer documentation shows a skinned toast in "Creating a custom toast view" at http://developer.android.com/guide/topics/ui/notifiers/toasts.html
You may want to look at the QuickAction API. It acheives this by using PopupWindow, skinned, positioned, and animated.

Starting a View from a Service?

Already asked a similar question, yet without much luck.
Suppose I have a service and I need a view to pop up above it. In the same time, they both should be intractable, i.e. the user should be able to both click buttons within the view, as well as ones on the service in the background.
Is this in theory possible? If yes, how should I initialize that view?
Thanks!
Yes it's possible, what you need to do is call the WindowManager service and add your view via the same.
WindowManager windowManager=(WindowManager)getSystemService(WINDOW_SERVICE);
LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
RelativeLayout layout=(RelativeLayout) inflater.inflate(R.layout.box,null);
You need a WindowManager.LayoutParams object which should contain the parameters for the layout
windowManager.addView(layout,params);
Well, adds the view
What you want is to add a view from your running service instance. This way you can persist the view across all activities - and from anywhere else. See this great example:
http://www.piwai.info/chatheads-basics/
Services most definitely can have a user interface: Input methods are an obvious example. See http://developer.android.com/resources/samples/SoftKeyboard/index.html for an example.
I guess you are misusing the word "Service".
Service is invisible, Activities are visible.
There are no buttons in an Service!
So you have no choice! You should put both views in one Activity, and I would use a RelativeLayout and set the visibility of your chidren to GONE/Visible.
http://developer.android.com/reference/android/widget/RelativeLayout.html
Also using a popup and making the layout under it clickable will disturb the user. You are completely changing User experience. I strongly suggest too make your popup appear at the top/bottom of your initial layout
Services run in the background and do not have an UI. So you can not show something over a Service.
If you need a Service to notify user about something, then use Notification.
Ayou could use a Toast, but I advise against it, as it can confuse users since it can pop-out over another app's activity.
What you want is an Activity instead of a Service and a Dialog instead View. I suggest you read this document by google: http://developer.android.com/guide/topics/fundamentals.html
However to answer your question about both being interactable. This isn't possible. At any given time 1 and only 1 activity is on the top of the activity stack. The user can only interact with that activity. If you want something like a floating window then will have to create it yourself. Although keep in mind that goes against the android design principles.

Categories

Resources