\r
/**\r
* Represents a custom PopupWindows\r
+ * \r
* @author Lorensius. W. T\r
- *\r
+ * \r
*/\r
public class CustomPopup {\r
- protected final View mAnchor;\r
- protected final PopupWindow mWindow;\r
- private View root;\r
- private Drawable background = null;\r
- protected final WindowManager mWManager;\r
- \r
- public CustomPopup(View anchor) {\r
- mAnchor = anchor;\r
- mWindow = new PopupWindow(anchor.getContext());\r
- \r
- mWindow.setTouchInterceptor(new OnTouchListener() {\r
- \r
- public boolean onTouch(View v, MotionEvent event) {\r
- if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {\r
- CustomPopup.this.dismiss();\r
- return true;\r
+ protected final View mAnchor;\r
+ protected final PopupWindow mWindow;\r
+ private View root;\r
+ private Drawable background = null;\r
+ protected final WindowManager mWManager;\r
+\r
+ public CustomPopup(View anchor) {\r
+ mAnchor = anchor;\r
+ mWindow = new PopupWindow(anchor.getContext());\r
+\r
+ mWindow.setTouchInterceptor(new OnTouchListener() {\r
+\r
+ public boolean onTouch(View v, MotionEvent event) {\r
+ if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {\r
+ CustomPopup.this.dismiss();\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+ });\r
+\r
+ mWManager = (WindowManager) anchor.getContext().getSystemService(\r
+ Context.WINDOW_SERVICE);\r
+ onCreate();\r
+ }\r
+\r
+ public void onCreate() {\r
+ }\r
+\r
+ public void onShow() {\r
+ }\r
+\r
+ public void preShow() {\r
+ if (root == null) {\r
+ throw new IllegalStateException(\r
+ "setContentView called with a view to display");\r
}\r
- return false;\r
- }\r
- });\r
- \r
- mWManager = (WindowManager) anchor.getContext().getSystemService(Context.WINDOW_SERVICE);\r
- onCreate();\r
- }\r
- \r
- \r
- public void onCreate() {}\r
- public void onShow() {}\r
- \r
- public void preShow() {\r
- if (root == null) {\r
- throw new IllegalStateException("setContentView called with a view to display");\r
+\r
+ onShow();\r
+\r
+ if (background == null) {\r
+ mWindow.setBackgroundDrawable(new BitmapDrawable());\r
+ } else {\r
+ mWindow.setBackgroundDrawable(background);\r
+ }\r
+\r
+ mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);\r
+ mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);\r
+ mWindow.setTouchable(true);\r
+ mWindow.setFocusable(true);\r
+ mWindow.setOutsideTouchable(true);\r
+\r
+ mWindow.setContentView(root);\r
+ }\r
+\r
+ public void setBackgroundDrawable(Drawable background) {\r
+ this.background = background;\r
+ }\r
+\r
+ public void setContentView(View root) {\r
+ this.root = root;\r
+ mWindow.setContentView(root);\r
+ }\r
+\r
+ public void setContentView(int layoutResId) {\r
+ LayoutInflater inflater = (LayoutInflater) mAnchor.getContext()\r
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
+ setContentView(inflater.inflate(layoutResId, null));\r
+ }\r
+\r
+ public void showDropDown() {\r
+ showDropDown(0, 0);\r
}\r
- \r
- onShow();\r
- \r
- if (background == null) {\r
- mWindow.setBackgroundDrawable(new BitmapDrawable());\r
- } else {\r
- mWindow.setBackgroundDrawable(background);\r
+\r
+ public void showDropDown(int x, int y) {\r
+ preShow();\r
+ mWindow.setAnimationStyle(android.R.style.Animation_Dialog);\r
+ mWindow.showAsDropDown(mAnchor, x, y);\r
}\r
- \r
- mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);\r
- mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);\r
- mWindow.setTouchable(true);\r
- mWindow.setFocusable(true);\r
- mWindow.setOutsideTouchable(true);\r
- \r
- mWindow.setContentView(root);\r
- }\r
- \r
- public void setBackgroundDrawable(Drawable background) {\r
- this.background = background;\r
- }\r
- \r
- public void setContentView(View root) {\r
- this.root = root;\r
- mWindow.setContentView(root);\r
- }\r
- \r
- public void setContentView(int layoutResId) {\r
- LayoutInflater inflater = \r
- (LayoutInflater) mAnchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
- setContentView(inflater.inflate(layoutResId, null));\r
- }\r
- \r
- public void showDropDown() {\r
- showDropDown(0, 0);\r
- }\r
- \r
- public void showDropDown(int x, int y) {\r
- preShow();\r
- mWindow.setAnimationStyle(android.R.style.Animation_Dialog);\r
- mWindow.showAsDropDown(mAnchor, x, y);\r
- }\r
- \r
- public void showLikeQuickAction() {\r
- showLikeQuickAction(0, 0);\r
- }\r
- \r
- public void showLikeQuickAction(int x, int y) {\r
- preShow();\r
- \r
- mWindow.setAnimationStyle(android.R.style.Animation_Dialog);\r
- int[] location = new int[2];\r
- mAnchor.getLocationOnScreen(location);\r
- \r
- Rect anchorRect = \r
- new Rect(location[0], location[1], location[0] + mAnchor.getWidth(), location[1] + mAnchor.getHeight());\r
- \r
- root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));\r
- root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);\r
- \r
- int rootW = root.getWidth(), rootH = root.getHeight();\r
- int screenW = mWManager.getDefaultDisplay().getWidth();\r
- \r
- int xpos = ((screenW-rootW)/2) + x;\r
- int ypos = anchorRect.top - rootH + y;\r
- \r
- if (rootH > anchorRect.top) {\r
- ypos = anchorRect.bottom + y;\r
+\r
+ public void showLikeQuickAction() {\r
+ showLikeQuickAction(0, 0);\r
}\r
- mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos);\r
- }\r
- \r
- public void dismiss() {\r
- mWindow.dismiss();\r
- }\r
- \r
+\r
+ public void showLikeQuickAction(int x, int y) {\r
+ preShow();\r
+\r
+ mWindow.setAnimationStyle(android.R.style.Animation_Dialog);\r
+ int[] location = new int[2];\r
+ mAnchor.getLocationOnScreen(location);\r
+\r
+ Rect anchorRect = new Rect(location[0], location[1], location[0]\r
+ + mAnchor.getWidth(), location[1] + mAnchor.getHeight());\r
+\r
+ root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,\r
+ LayoutParams.WRAP_CONTENT));\r
+ root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);\r
+\r
+ int rootW = root.getWidth(), rootH = root.getHeight();\r
+ int screenW = mWManager.getDefaultDisplay().getWidth();\r
+\r
+ int xpos = ((screenW - rootW) / 2) + x;\r
+ int ypos = anchorRect.top - rootH + y;\r
+\r
+ if (rootH > anchorRect.top) {\r
+ ypos = anchorRect.bottom + y;\r
+ }\r
+ mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos);\r
+ }\r
+\r
+ public void dismiss() {\r
+ mWindow.dismiss();\r
+ }\r
+\r
}\r