Android Custom View to Activity communication - android

I have a custom control/view that observes the direction of a gesture within its bounds. I would like to send a different message back to the Activity hosting the View depending on the direction of the gesture. I'm having a hard time determine what the right way to do this is. I would think I could raise a custom event in the control and then stick a listener on the control in the activity, but I cannot find any information on custom events in Android. Any help would be appreciated.
Thanks.

Boy, just a little bit more digging and I wouldn't have had to ask the question. For those who come this way wondering the same thing, though, I found this article did exactly what I was looking for:
http://www.helloandroid.com/tutorials/custom-view-horizontalslider

Related

Creating a custom ui element and making it respond to user input

I have a volume knob and would like to know how to make it respond to user input in android. Please point me in the right direction as i have no idea how i can go about it ? Custom Knob looks like something created in this article. My question is what would be the general approach to port this knob into an android application. Do i have to extend the view class and draw this as a Bitmap. If so how exactly would i respond to user input. If this is not possible and i am on the wrong track could someone please tell me how to achieve this?
I would extend the View class.
View is the baseclass for widgets in android (by widgets I mean textfields, buttons, etc), so I think a volue knob would fit right in among those. About the user input, I'm not so sure. I think it depends on how you want to control the knob. I think looking at the onTouchEvent(MotionEvent) would be a good start. My guess is that you will need to overload a similar method anyways.
Related links:
http://developer.android.com/reference/android/view/View.html
http://www.vogella.com/articles/AndroidGestures/article.html

Circular / rotary dial view in android

I have a need to create a circular dial/rotary style component for use in an application. It's essentially a circular menu that allows users to select from the items that are ringed around it, and then they can click the button in the center to activate the selected item. However, I've never created a custom UIView of this type, and don't really know where to begin. Can anyone give me any pointers as to how I would draw the view and then rotate it as the user drags their finger? I obviously know how to intercept touch events, etc. but I'm not sure how to actually go about manipulating the UI appropriately. Any tips or pointers would be great!
I don't know if you've already found a solution to this, but here is a nice overview of how to get started:
http://shahabhameed.blogspot.com/2011/05/custom-views-in-android.html
For you, I think you can extend an existing View, that View being the SeekBar. You can take the standard SeekBar and draw it in a circle.
Finally, here is a source code that does the rotation with a volume knob. It is its own project though, so you have to do some work to use it in your own app.
http://mindtherobot.com/blog/534/android-ui-making-an-analog-rotary-knob/
Good Luck!
I have a neat library to do this. It is extremely stable and well maintained. https://bitbucket.org/warwick/hgdialrepo
Heres a youtube demo: https://youtu.be/h_7VxrZ2W-g
This library comes with a demo app with source code and the demo app actually uses a dial as a menu, So I think this should be the perfect solution for you.

When to use Android PopupWindow vs Dialog

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.

Implementation of slide gesture like is done in the call log list view

In the call log, there is a feature that when you slide one direction it will call the number and in the other direction message the missed number. In each case the missed number in the list view is pushed aside by either "Call" with a green background or "Message" with an orange background. I think this is really need and would like to implement this type of interaction in an app.
First question, what is the actual term for this operation? Is this a fling, swipe, slide, etc.?
Second question. I have seen sporadic code snippets for handling fling gestures in list views but not a solid unified example for what I am looking for. Perhaps I am just not searching using the right terms. In any respect, does anyone know of a solid example implementing the functionality (i.e. handling the user input, painting the widget, etc.) ??
Thanks for the help.
I believe it's called a "fling" gesture. Question 937313 has a bunch of great links, code snip its and further information.

Should one use an Activity or a Service when using a button in a Widget?

I'm been trying to figure this out for a while now, and have just become more and more confused.
I have made a Android Widget which displays two articles (title + image). In addition to this, I have buttons for flipping backward and forward through the articles. What I don't understand is how I can change the Widgets RemoteViews when the buttons are pressed. Which should be one of the most basic operations in a widget, however, I can't seem to figure it out.
So...
Can I do this with just a OnClickListener in the AppWidgetProvider?
Or do I have to create an Activity without a window (visibility = false)?
Please excuse my stupidity. This is probably very basic.
I don't think this is basic at all - it's something I thought about for a while in relation to the Headset Blocker app I wrote, which is just a widget that you toggle on/off.
I ended up looking through Google's source code for what they did. The answer is to use the AppWidget's receiver nature to receive updates via setOnClickPendingIntent(). Then in onReceive(), you react differently to your own clicks than someone trying to create a widget. You can see a sample of what I did in the Headset Blocker source.
Ultimately, an Activity or a Service is too heavy weight for what you want. Using the same BroadcastReceiver as the app widget itself is much better.

Categories

Resources