Quick Actions
Last time, I told you how to setup Green Droid in Eclipse in preparation for this article. This time, I am going to show you how I got the Quick Action Bar working in my application.
Why Quick Actions
As mobile development matures, design patterns (such as Quick Actions) are being documented. By looking at successful patterns, developers can ease the acceptance of their applications.
Quick Actions are really just like a right-click. They provide a context sensitive menu for the currently available options. Here is the quick-action bar from an application I have been working on. When you tap on the screen, this menu pops up and you can pick the desired action.
Don't Do What I Did!
The GreenDroid sample code shows how to display a quick action bar, but I kind of got distracted by the line:
- public class QuickActionActivity extends GDActivity {
The "extends Activity" wasn't the main distraction: it was the "extends GDActivity" that really got me. As a result, I kept trying to launch this activity whenever the main activity received an onTouch event. What happens? Well, as you would expect, it launched a new Activity and my application disappeared behind the Quick Action menu...but I was getting a pretty new screen with an Action Bar.
Quick Lesson: If my mistake wasn't completely clear to you, then it would be worth reviewing a little more about Activities and the Android Framework. I certainly needed to!
The Quick Action Bar
Looking further at the sample code, the author creates a new QuickActionBar object and stores it in a QuickActionWidget. (The QuickActionBar is derived from the QuickActionWidget.) Ultimately, here is what I did:
- QuickActionBar bar = new QuickActionBar(this);
-
- bar.setOnQuickActionClickListener(new OnQuickActionClickListener() {
- public void onQuickActionClicked(QuickActionWidget widget, int position) {
- QuickActionBar bar = (QuickActionBar) widget;
-
- switch (position) {
- // Define Cases Here
- }
- }
- });
-
- // Add Quick Actions
- bar.addQuickAction(new QuickAction(this, R.drawable.quick_action_text, R.string.quick_action_text));
- bar.addQuickAction(new QuickAction(this, R.drawable.quick_action_draw, R.string.quick_action_draw));
- bar.addQuickAction(new QuickAction(this, R.drawable.quick_action_camera, R.string.quick_action_camera));
-
Showing the Quick Action Bar is really easy and can be accomplished with a single line of code:
- mBar.show(view);
where view is the current view object.
That's It!
The GreenDroid Quick Action Bar should be working for you now. If you getting some class definition not found or class cast errors, don't forget the set the Green Droid Theme explained last time.

