Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix some bugs and add new improvments, see readme for more info

  • Loading branch information...
commit 6bed1abe07448a3c6dfc0307447795699f10acf3 1 parent 0af27e9
@lorensiuswlt authored
Showing with 566 additions and 161 deletions.
  1. +1 −1  AndroidManifest.xml
  2. BIN  bin/NewQuickAction3D.apk
  3. BIN  bin/classes.dex
  4. BIN  bin/net/londatiga/android/ActionItem.class
  5. BIN  bin/net/londatiga/android/NewQuickAction3DActivity$1.class
  6. BIN  bin/net/londatiga/android/NewQuickAction3DActivity$2.class
  7. BIN  bin/net/londatiga/android/NewQuickAction3DActivity$3.class
  8. BIN  bin/net/londatiga/android/NewQuickAction3DActivity$4.class
  9. BIN  bin/net/londatiga/android/NewQuickAction3DActivity.class
  10. BIN  bin/net/londatiga/android/QuickAction$1.class
  11. BIN  bin/net/londatiga/android/QuickAction$OnActionItemClickListener.class
  12. BIN  bin/net/londatiga/android/QuickAction.class
  13. BIN  bin/net/londatiga/android/R$drawable.class
  14. BIN  bin/net/londatiga/android/R$id.class
  15. BIN  bin/net/londatiga/android/R$layout.class
  16. BIN  bin/net/londatiga/android/R$string.class
  17. BIN  bin/net/londatiga/android/R$style.class
  18. BIN  bin/resources.ap_
  19. +15 −7 gen/net/londatiga/android/R.java
  20. +113 −7 readme.md
  21. BIN  res/drawable/dashboard.png
  22. BIN  res/drawable/kontak.png
  23. BIN  res/drawable/menu_cancel.png
  24. BIN  res/drawable/menu_down_arrow.png
  25. BIN  res/drawable/menu_eraser.png
  26. BIN  res/drawable/menu_info.png
  27. BIN  res/drawable/menu_ok.png
  28. BIN  res/drawable/menu_search.png
  29. BIN  res/drawable/menu_up_arrow.png
  30. +28 −0 res/layout/action_item_horizontal.xml
  31. 0  res/layout/{action_item.xml → action_item_vertical.xml}
  32. +12 −0 res/layout/horiz_separator.xml
  33. +1 −0  res/layout/main.xml
  34. +41 −0 res/layout/popup_horizontal.xml
  35. 0  res/layout/{popup.xml → popup_vertical.xml}
  36. +87 −15 src/net/londatiga/android/ActionItem.java
  37. +107 −0 src/net/londatiga/android/ExampleActivity.java
  38. +0 −83 src/net/londatiga/android/NewQuickAction3DActivity.java
  39. +161 −48 src/net/londatiga/android/QuickAction.java
View
2  AndroidManifest.xml
@@ -6,7 +6,7 @@
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".NewQuickAction3DActivity"
+ <activity android:name=".ExampleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
View
BIN  bin/NewQuickAction3D.apk
Binary file not shown
View
BIN  bin/classes.dex
Binary file not shown
View
BIN  bin/net/londatiga/android/ActionItem.class
Binary file not shown
View
BIN  bin/net/londatiga/android/NewQuickAction3DActivity$1.class
Binary file not shown
View
BIN  bin/net/londatiga/android/NewQuickAction3DActivity$2.class
Binary file not shown
View
BIN  bin/net/londatiga/android/NewQuickAction3DActivity$3.class
Binary file not shown
View
BIN  bin/net/londatiga/android/NewQuickAction3DActivity$4.class
Binary file not shown
View
BIN  bin/net/londatiga/android/NewQuickAction3DActivity.class
Binary file not shown
View
BIN  bin/net/londatiga/android/QuickAction$1.class
Binary file not shown
View
BIN  bin/net/londatiga/android/QuickAction$OnActionItemClickListener.class
Binary file not shown
View
BIN  bin/net/londatiga/android/QuickAction.class
Binary file not shown
View
BIN  bin/net/londatiga/android/R$drawable.class
Binary file not shown
View
BIN  bin/net/londatiga/android/R$id.class
Binary file not shown
View
BIN  bin/net/londatiga/android/R$layout.class
Binary file not shown
View
BIN  bin/net/londatiga/android/R$string.class
Binary file not shown
View
BIN  bin/net/londatiga/android/R$style.class
Binary file not shown
View
BIN  bin/resources.ap_
Binary file not shown
View
22 gen/net/londatiga/android/R.java
@@ -33,10 +33,15 @@
public static final int action_item_selected=0x7f020001;
public static final int arrow_down=0x7f020002;
public static final int arrow_up=0x7f020003;
- public static final int dashboard=0x7f020004;
- public static final int icon=0x7f020005;
- public static final int kontak=0x7f020006;
- public static final int popup=0x7f020007;
+ public static final int icon=0x7f020004;
+ public static final int menu_cancel=0x7f020005;
+ public static final int menu_down_arrow=0x7f020006;
+ public static final int menu_eraser=0x7f020007;
+ public static final int menu_info=0x7f020008;
+ public static final int menu_ok=0x7f020009;
+ public static final int menu_search=0x7f02000a;
+ public static final int menu_up_arrow=0x7f02000b;
+ public static final int popup=0x7f02000c;
}
public static final class id {
public static final int arrow_down=0x7f070008;
@@ -50,9 +55,12 @@
public static final int tv_title=0x7f070001;
}
public static final class layout {
- public static final int action_item=0x7f030000;
- public static final int main=0x7f030001;
- public static final int popup=0x7f030002;
+ public static final int action_item_horizontal=0x7f030000;
+ public static final int action_item_vertical=0x7f030001;
+ public static final int horiz_separator=0x7f030002;
+ public static final int main=0x7f030003;
+ public static final int popup_horizontal=0x7f030004;
+ public static final int popup_vertical=0x7f030005;
}
public static final class string {
public static final int app_name=0x7f050001;
View
120 readme.md
@@ -1,23 +1,129 @@
NewQuickAction3D
================
-NewQuickAction3D is a small android library to show quickaction dialog just like quickaction on Gallery3D app.
+NewQuickAction3D is a small android library to create QuickAction dialog with Gallery3D app style.
+
+How to Use
+==========
+This repo includes a sample Activity (__ExampleActivity.java__) to show how to use QuickAction.
+
+ public class ExampleActivity extends Activity {
+ //action id
+ private static final int ID_UP = 1;
+ private static final int ID_DOWN = 2;
+ private static final int ID_SEARCH = 3;
+ private static final int ID_INFO = 4;
+ private static final int ID_ERASE = 5;
+ private static final int ID_OK = 6;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main);
+
+ ActionItem nextItem = new ActionItem(ID_DOWN, "Next", getResources().getDrawable(R.drawable.menu_down_arrow));
+ ActionItem prevItem = new ActionItem(ID_UP, "Prev", getResources().getDrawable(R.drawable.menu_up_arrow));
+ ActionItem searchItem = new ActionItem(ID_SEARCH, "Find", getResources().getDrawable(R.drawable.menu_search));
+ ActionItem infoItem = new ActionItem(ID_INFO, "Info", getResources().getDrawable(R.drawable.menu_info));
+ ActionItem eraseItem = new ActionItem(ID_ERASE, "Clear", getResources().getDrawable(R.drawable.menu_eraser));
+ ActionItem okItem = new ActionItem(ID_OK, "OK", getResources().getDrawable(R.drawable.menu_ok));
+
+ //use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
+ prevItem.setSticky(true);
+ nextItem.setSticky(true);
+
+ //create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout
+ //orientation
+ final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
+
+ //add action items into QuickAction
+ quickAction.addActionItem(nextItem);
+ quickAction.addActionItem(prevItem);
+ quickAction.addActionItem(searchItem);
+ quickAction.addActionItem(infoItem);
+ quickAction.addActionItem(eraseItem);
+ quickAction.addActionItem(okItem);
+
+ //Set listener for action item clicked
+ quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
+ @Override
+ public void onItemClick(QuickAction source, int pos, int actionId) {
+ //here we can filter which action item was clicked with pos or actionId parameter
+ ActionItem actionItem = quickAction.getActionItem(pos);
+
+ Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ //set listnener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
+ //by clicking the area outside the dialog.
+ quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
+ @Override
+ public void onDismiss() {
+ Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ //show on btn1
+ Button btn1 = (Button) this.findViewById(R.id.btn1);
+ btn1.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ }
+ });
+
+ Button btn2 = (Button) this.findViewById(R.id.btn2);
+ btn2.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ }
+ });
+
+ Button btn3 = (Button) this.findViewById(R.id.btn3);
+ btn3.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ quickAction.setAnimStyle(QuickAction.ANIM_REFLECT);
+ }
+ });
+ }
+ }
**See http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ for more information.**
-![Example Image] [2]
+![Example Image](http://londatiga.net/images/quickaction3d_horizontal.png) ![Example Image](http://londatiga.net/images/quickaction3d_vertical.png)
Developed By
============
* Lorensius W. L. T - <lorenz@londatiga.net>
+Contributors
+============
+
+* Kevin Peck - <kevinwpeck@gmail.com>
+
Changes
=======
-2011-10-05:
-- Fix force close that occured when tapping randomly on a view to show quickaction dialog.
- Thanx to [Zammbi][1] for bug fix..
+### 2011-10-15:
+* Fix 'container moves' bug as addressed in this [issue](https://github.com/lorensiuswlt/NewQuickAction3D/issues/1). Thanx to [The Vaan](TheVaan@gmail.com) for giving me the clue.
+2. New improvements added by [Kevin Pack](kevinpeck@gmail.com):
+ 3. Action Item – new constructor with action id, title, icon
+ 4. Callback enhanced to return QuickAction object as source and action id (allows you to add items in any order as you base what was clicked on by the ID, not the pos)
+ 5. Action item supports sticky mode, if that is enabled the menu does not dismiss post button press. I needed this for my application.
+ 6. QuickAction has getActionItem(pos) call so you can get action item back. QuickAction has ArrayList of added items to support this
+ 7. QuickAction supports constructor with horizontal flag so you can run menu horizontally instead of just vertically
+ 8. If doing horizontal QuickAction loads the action_item_horizontal.xml and popup_horizontal.xml files instead of the vertical ones
+ 9. Added action_item_horizontal.xml with a centered image over a centered text label
+ 10. Added horiz_separator.xml file so you can show a separator between items in a horizontal layout
+ 11. Updated NewQuickAction3DActivity to show the toast message based on label of action item clicked as you now have enough info in callback to do that generically
+ 12. Update sample code to show sticky items in action, watching for dismiss action and extra menu items
+3. New listener to handle on dismiss event.
-[1]: http://github.com/zammbi
-[2]: http://londatiga.net/images/quickactions/gl3d2.jpg
+* Fix force close that occured when tapping randomly on a view to show QuickAction dialog ([issue](https://github.com/lorensiuswlt/NewQuickAction3D/issues/2)). Thanx to [Zammbi](zammbi@gmail.com) for bug fixing..
View
BIN  res/drawable/dashboard.png
Deleted file not rendered
View
BIN  res/drawable/kontak.png
Deleted file not rendered
View
BIN  res/drawable/menu_cancel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_down_arrow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_eraser.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_info.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_ok.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/menu_up_arrow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 res/layout/action_item_horizontal.xml
@@ -0,0 +1,28 @@
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="@drawable/action_item_btn">
+
+ <ImageView
+ android:id="@+id/iv_icon"
+ android:layout_centerHorizontal="true"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <TextView
+ android:id="@+id/tv_title"
+ android:layout_below="@+id/iv_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:gravity="center_horizontal"
+ android:paddingLeft="5dip"
+ android:paddingRight="5dip"
+ android:text="Chart"
+ android:textColor="#fff"/>
+
+</RelativeLayout>
View
0  res/layout/action_item.xml → res/layout/action_item_vertical.xml
File renamed without changes
View
12 res/layout/horiz_separator.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent">
+<TextView android:layout_height="fill_parent"
+ android:gravity="center"
+ android:layout_width="2px"
+ android:text=" "
+ android:background="#000000"/>
+</RelativeLayout>
View
1  res/layout/main.xml
@@ -3,6 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
+ android:padding="10dp"
android:orientation="vertical">
<LinearLayout
View
41 res/layout/popup_horizontal.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ >
+
+ <ScrollView
+ android:id="@+id/scroller"
+ android:layout_marginTop="16dip"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/popup"
+ android:fadingEdgeLength="5dip"
+ android:scrollbars="none">
+
+ <LinearLayout
+ android:id="@+id/tracks"
+ android:orientation="horizontal"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:padding="10dip"/>
+
+ </ScrollView >
+
+ <ImageView
+ android:id="@+id/arrow_up"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/arrow_up" />
+
+ <ImageView
+ android:id="@+id/arrow_down"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/scroller"
+ android:layout_marginTop="-4dip"
+ android:src="@drawable/arrow_down" />
+
+</RelativeLayout>
View
0  res/layout/popup.xml → res/layout/popup_vertical.xml
File renamed without changes
View
102 src/net/londatiga/android/ActionItem.java
@@ -6,28 +6,68 @@
/**
* Action item, displayed as menu with icon and text.
*
- * @author Lorensius. W. L. T
+ * @author Lorensius. W. L. T <lorenz@londatiga.net>
+ *
+ * Contributors:
+ * - Kevin Peck <kevinwpeck@gmail.com>
*
*/
public class ActionItem {
private Drawable icon;
private Bitmap thumb;
private String title;
- private boolean selected;
+ private int actionId = -1;
+ private boolean selected;
+ private boolean sticky;
- /**
- * Constructor
- */
- public ActionItem() {}
-
- /**
- * Constructor
- *
- * @param icon {@link Drawable} action icon
- */
- public ActionItem(Drawable icon) {
- this.icon = icon;
- }
+ /**
+ * Constructor
+ *
+ * @param actionId Action id for case statements
+ * @param title Title
+ * @param icon Icon to use
+ */
+ public ActionItem(int actionId, String title, Drawable icon) {
+ this.title = title;
+ this.icon = icon;
+ this.actionId = actionId;
+ }
+
+ /**
+ * Constructor
+ */
+ public ActionItem() {
+ this(-1, null, null);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param actionId Action id of the item
+ * @param title Text to show for the item
+ */
+ public ActionItem(int actionId, String title) {
+ this(actionId, title, null);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param icon {@link Drawable} action icon
+ */
+ public ActionItem(Drawable icon) {
+ this(-1, null, icon);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param actionId Action ID of item
+ * @param icon {@link Drawable} action icon
+ */
+ public ActionItem(int actionId, Drawable icon) {
+ this(actionId, null, icon);
+ }
/**
* Set action title
@@ -64,6 +104,38 @@ public Drawable getIcon() {
return this.icon;
}
+ /**
+ * Set action id
+ *
+ * @param actionId Action id for this action
+ */
+ public void setActionId(int actionId) {
+ this.actionId = actionId;
+ }
+
+ /**
+ * @return Our action id
+ */
+ public int getActionId() {
+ return actionId;
+ }
+
+ /**
+ * Set sticky status of button
+ *
+ * @param sticky true for sticky, pop up sends event but does not disappear
+ */
+ public void setSticky(boolean sticky) {
+ this.sticky = sticky;
+ }
+
+ /**
+ * @return true if button is sticky, menu stays visible after press
+ */
+ public boolean isSticky() {
+ return sticky;
+ }
+
/**
* Set selected flag;
*
View
107 src/net/londatiga/android/ExampleActivity.java
@@ -0,0 +1,107 @@
+package net.londatiga.android;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import android.view.View;
+import android.view.View.OnClickListener;
+
+import android.widget.Button;
+import android.widget.Toast;
+
+/**
+ * Gallery3D like QuickAction.
+ *
+ * This example shows how to use Gallery3D like QuickAction.
+ *
+ * @author Lorensius W. L. T <lorenz@londatiga.net>
+ *
+ * Contributors:
+ * - Kevin Peck <kevinwpeck@gmail.com>
+ *
+ */
+public class ExampleActivity extends Activity {
+ //action id
+ private static final int ID_UP = 1;
+ private static final int ID_DOWN = 2;
+ private static final int ID_SEARCH = 3;
+ private static final int ID_INFO = 4;
+ private static final int ID_ERASE = 5;
+ private static final int ID_OK = 6;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main);
+
+ ActionItem nextItem = new ActionItem(ID_DOWN, "Next", getResources().getDrawable(R.drawable.menu_down_arrow));
+ ActionItem prevItem = new ActionItem(ID_UP, "Prev", getResources().getDrawable(R.drawable.menu_up_arrow));
+ ActionItem searchItem = new ActionItem(ID_SEARCH, "Find", getResources().getDrawable(R.drawable.menu_search));
+ ActionItem infoItem = new ActionItem(ID_INFO, "Info", getResources().getDrawable(R.drawable.menu_info));
+ ActionItem eraseItem = new ActionItem(ID_ERASE, "Clear", getResources().getDrawable(R.drawable.menu_eraser));
+ ActionItem okItem = new ActionItem(ID_OK, "OK", getResources().getDrawable(R.drawable.menu_ok));
+
+ //use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
+ prevItem.setSticky(true);
+ nextItem.setSticky(true);
+
+ //create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout
+ //orientation
+ final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
+
+ //add action items into QuickAction
+ quickAction.addActionItem(nextItem);
+ quickAction.addActionItem(prevItem);
+ quickAction.addActionItem(searchItem);
+ quickAction.addActionItem(infoItem);
+ quickAction.addActionItem(eraseItem);
+ quickAction.addActionItem(okItem);
+
+ //Set listener for action item clicked
+ quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
+ @Override
+ public void onItemClick(QuickAction source, int pos, int actionId) {
+ //here we can filter which action item was clicked with pos or actionId parameter
+ ActionItem actionItem = quickAction.getActionItem(pos);
+
+ Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ //set listnener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
+ //by clicking the area outside the dialog.
+ quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
+ @Override
+ public void onDismiss() {
+ Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ //show on btn1
+ Button btn1 = (Button) this.findViewById(R.id.btn1);
+ btn1.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ }
+ });
+
+ Button btn2 = (Button) this.findViewById(R.id.btn2);
+ btn2.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ }
+ });
+
+ Button btn3 = (Button) this.findViewById(R.id.btn3);
+ btn3.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ quickAction.show(v);
+ quickAction.setAnimStyle(QuickAction.ANIM_REFLECT);
+ }
+ });
+ }
+}
View
83 src/net/londatiga/android/NewQuickAction3DActivity.java
@@ -1,83 +0,0 @@
-package net.londatiga.android;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-import android.view.View;
-import android.view.View.OnClickListener;
-
-import android.widget.Button;
-import android.widget.Toast;
-
-/**
- * Gallery 3D like quickaction.
- *
- * This example shows how to use Gallery3D like quickaction.
- *
- * @author Lorensius W. L. T <lorenz@londatiga.net>
- *
- */
-public class NewQuickAction3DActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.main);
-
- //dashboard action item
- ActionItem dashboard = new ActionItem();
-
- dashboard.setTitle("Dashboard");
- dashboard.setIcon(getResources().getDrawable(R.drawable.dashboard));
-
- //user action item
- ActionItem user = new ActionItem();
-
- user.setTitle("Users & Groups");
- user.setIcon(getResources().getDrawable(R.drawable.kontak));
-
- //create quickaction
- final QuickAction quickAction = new QuickAction(this);
-
- quickAction.addActionItem(dashboard);
- quickAction.addActionItem(user);
-
- quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
- @Override
- public void onItemClick(int pos) {
- if (pos == 0) {
- Toast.makeText(NewQuickAction3DActivity.this, "Dashboard item selected", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(NewQuickAction3DActivity.this, "User item selected", Toast.LENGTH_SHORT).show();
- }
- }
- });
-
- Button btn1 = (Button) this.findViewById(R.id.btn1);
- btn1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- quickAction.show(v);
- }
- });
-
- Button btn2 = (Button) this.findViewById(R.id.btn2);
- btn2.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- quickAction.show(v);
- }
- });
-
- Button btn3 = (Button) this.findViewById(R.id.btn3);
- btn3.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- quickAction.show(v);
- quickAction.setAnimStyle(QuickAction.ANIM_REFLECT);
- }
- });
-
- }
-}
View
209 src/net/londatiga/android/QuickAction.java
@@ -8,6 +8,8 @@
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ScrollView;
+import android.widget.RelativeLayout;
+import android.widget.PopupWindow.OnDismissListener;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -16,52 +18,97 @@
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
+import java.util.List;
+import java.util.ArrayList;
+
/**
- * Popup window, shows action list as icon and text like the one in Gallery3D app.
+ * QuickAction dialog, shows action list as icon and text like the one in Gallery3D app. Currently supports vertical
+ * and horizontal layout.
+ *
+ * @author Lorensius W. L. T <lorenz@londatiga.net>
*
- * @author Lorensius. W. T
+ * Contributors:
+ * - Kevin Peck <kevinwpeck@gmail.com>
*/
-public class QuickAction extends PopupWindows {
+public class QuickAction extends PopupWindows implements OnDismissListener {
private View mRootView;
private ImageView mArrowUp;
private ImageView mArrowDown;
- private LayoutInflater inflater;
+ private LayoutInflater mInflater;
private ViewGroup mTrack;
private ScrollView mScroller;
- private OnActionItemClickListener mListener;
+ private OnActionItemClickListener mItemClickListener;
+ private OnDismissListener mDismissListener;
+
+ private List<ActionItem> actionItems = new ArrayList<ActionItem>();
- protected static final int ANIM_GROW_FROM_LEFT = 1;
- protected static final int ANIM_GROW_FROM_RIGHT = 2;
- protected static final int ANIM_GROW_FROM_CENTER = 3;
- protected static final int ANIM_REFLECT = 4;
- protected static final int ANIM_AUTO = 5;
+ private boolean mDidAction;
private int mChildPos;
- private int animStyle;
+ private int mInsertPos;
+ private int mAnimStyle;
+ private int mOrientation;
+ private int rootWidth=0;
+
+ public static final int HORIZONTAL = 0;
+ public static final int VERTICAL = 1;
+
+ public static final int ANIM_GROW_FROM_LEFT = 1;
+ public static final int ANIM_GROW_FROM_RIGHT = 2;
+ public static final int ANIM_GROW_FROM_CENTER = 3;
+ public static final int ANIM_REFLECT = 4;
+ public static final int ANIM_AUTO = 5;
- /**
- * Constructor.
- *
- * @param context Context
- */
- public QuickAction(Context context) {
- super(context);
-
- inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
- setRootViewId(R.layout.popup);
-
- animStyle = ANIM_AUTO;
- mChildPos = 0;
- }
+ /**
+ * Constructor for default vertical layout
+ *
+ * @param context Context
+ */
+ public QuickAction(Context context) {
+ this(context, VERTICAL);
+ }
+
+ /**
+ * Constructor allowing orientation override
+ *
+ * @param context Context
+ * @param orientation Layout orientation, can be vartical or horizontal
+ */
+ public QuickAction(Context context, int orientation) {
+ super(context);
+
+ mOrientation = orientation;
+
+ mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ if (mOrientation == HORIZONTAL) {
+ setRootViewId(R.layout.popup_horizontal);
+ } else {
+ setRootViewId(R.layout.popup_vertical);
+ }
+ mAnimStyle = ANIM_AUTO;
+ mChildPos = 0;
+ }
+
+ /**
+ * Get action item at an index
+ *
+ * @param index Index of item (position from callback)
+ *
+ * @return Action Item at the position
+ */
+ public ActionItem getActionItem(int index) {
+ return actionItems.get(index);
+ }
+
/**
* Set root view.
*
* @param id Layout resource id
*/
public void setRootViewId(int id) {
- mRootView = (ViewGroup) inflater.inflate(id, null);
+ mRootView = (ViewGroup) mInflater.inflate(id, null);
mTrack = (ViewGroup) mRootView.findViewById(R.id.tracks);
mArrowDown = (ImageView) mRootView.findViewById(R.id.arrow_down);
@@ -80,10 +127,10 @@ public void setRootViewId(int id) {
/**
* Set animation style
*
- * @param animStyle animation style, default is set to ANIM_AUTO
+ * @param mAnimStyle animation style, default is set to ANIM_AUTO
*/
- public void setAnimStyle(int animStyle) {
- this.animStyle = animStyle;
+ public void setAnimStyle(int mAnimStyle) {
+ this.mAnimStyle = mAnimStyle;
}
/**
@@ -92,7 +139,7 @@ public void setAnimStyle(int animStyle) {
* @param listener Listener
*/
public void setOnActionItemClickListener(OnActionItemClickListener listener) {
- mListener = listener;
+ mItemClickListener = listener;
}
/**
@@ -101,52 +148,84 @@ public void setOnActionItemClickListener(OnActionItemClickListener listener) {
* @param action {@link ActionItem}
*/
public void addActionItem(ActionItem action) {
+ actionItems.add(action);
String title = action.getTitle();
Drawable icon = action.getIcon();
- View container = (View) inflater.inflate(R.layout.action_item, null);
+ View container;
+
+ if (mOrientation == HORIZONTAL) {
+ container = mInflater.inflate(R.layout.action_item_horizontal, null);
+ } else {
+ container = mInflater.inflate(R.layout.action_item_vertical, null);
+ }
ImageView img = (ImageView) container.findViewById(R.id.iv_icon);
TextView text = (TextView) container.findViewById(R.id.tv_title);
- if (icon != null)
+ if (icon != null) {
img.setImageDrawable(icon);
- else
+ } else {
img.setVisibility(View.GONE);
+ }
- if (title != null)
+ if (title != null) {
text.setText(title);
- else
+ } else {
text.setVisibility(View.GONE);
+ }
- final int pos = mChildPos;
+ final int pos = mChildPos;
+ final int actionId = action.getActionId();
container.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- if (mListener != null) mListener.onItemClick(pos);
-
- dismiss();
+ if (mItemClickListener != null) {
+ mItemClickListener.onItemClick(QuickAction.this, pos, actionId);
+ }
+
+ if (!getActionItem(pos).isSticky()) {
+ mDidAction = true;
+
+ dismiss();
+ }
}
});
container.setFocusable(true);
container.setClickable(true);
- mTrack.addView(container, mChildPos);
+ if (mOrientation == HORIZONTAL && mChildPos != 0) {
+ View separator = mInflater.inflate(R.layout.horiz_separator, null);
+
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
+
+ separator.setLayoutParams(params);
+ separator.setPadding(5, 0, 5, 0);
+
+ mTrack.addView(separator, mInsertPos);
+
+ mInsertPos++;
+ }
+
+ mTrack.addView(container, mInsertPos);
mChildPos++;
+ mInsertPos++;
}
/**
- * Show popup window. Popup is automatically positioned, on top or bottom of anchor view.
+ * Show quickaction popup. Popup is automatically positioned, on top or bottom of anchor view.
*
*/
public void show (View anchor) {
preShow();
- int xPos, yPos;
+ int xPos, yPos, arrowPos;
+
+ mDidAction = false;
int[] location = new int[2];
@@ -160,20 +239,29 @@ public void show (View anchor) {
mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootHeight = mRootView.getMeasuredHeight();
- int rootWidth = mRootView.getMeasuredWidth();
+
+ if (rootWidth == 0) {
+ rootWidth = mRootView.getMeasuredWidth();
+ }
int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
int screenHeight = mWindowManager.getDefaultDisplay().getHeight();
//automatically get X coord of popup (top left)
if ((anchorRect.left + rootWidth) > screenWidth) {
- xPos = anchorRect.left - (rootWidth-anchor.getWidth());
+ xPos = anchorRect.left - (rootWidth-anchor.getWidth());
+ xPos = (xPos < 0) ? 0 : xPos;
+
+ arrowPos = anchorRect.centerX()-xPos;
+
} else {
if (anchor.getWidth() > rootWidth) {
xPos = anchorRect.centerX() - (rootWidth/2);
} else {
xPos = anchorRect.left;
}
+
+ arrowPos = anchorRect.centerX()-xPos;
}
int dyTop = anchorRect.top;
@@ -198,7 +286,7 @@ public void show (View anchor) {
}
}
- showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX()-xPos);
+ showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), arrowPos);
setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);
@@ -216,7 +304,7 @@ public void show (View anchor) {
private void setAnimationStyle(int screenWidth, int requestedX, boolean onTop) {
int arrowPos = requestedX - mArrowUp.getMeasuredWidth()/2;
- switch (animStyle) {
+ switch (mAnimStyle) {
case ANIM_GROW_FROM_LEFT:
mWindow.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Left : R.style.Animations_PopDownMenu_Left);
break;
@@ -268,10 +356,35 @@ private void showArrow(int whichArrow, int requestedX) {
}
/**
+ * Set listener for window dismissed. This listener will only be fired if the quicakction dialog is dismissed
+ * by clicking outside the dialog or clicking on sticky item.
+ */
+ public void setOnDismissListener(QuickAction.OnDismissListener listener) {
+ setOnDismissListener(this);
+
+ mDismissListener = listener;
+ }
+
+ @Override
+ public void onDismiss() {
+ if (!mDidAction && mDismissListener != null) {
+ mDismissListener.onDismiss();
+ }
+ }
+
+ /**
* Listener for item click
*
*/
public interface OnActionItemClickListener {
- public abstract void onItemClick(int pos);
+ public abstract void onItemClick(QuickAction source, int pos, int actionId);
+ }
+
+ /**
+ * Listener for window dismiss
+ *
+ */
+ public interface OnDismissListener {
+ public abstract void onDismiss();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.