1 package com.folioreader.model.quickaction;
\r
3 import android.content.Context;
\r
4 import android.graphics.drawable.BitmapDrawable;
\r
5 import android.graphics.drawable.Drawable;
\r
6 import android.view.LayoutInflater;
\r
7 import android.view.MotionEvent;
\r
8 import android.view.View;
\r
9 import android.view.View.OnTouchListener;
\r
10 import android.view.WindowManager;
\r
11 import android.widget.PopupWindow;
\r
14 * Custom popup window.
\r
16 * @author Lorensius W. L. T <lorenz@londatiga.net>
\r
18 public class PopupWindows {
\r
19 protected Context mContext;
\r
20 protected PopupWindow mWindow;
\r
21 protected View mRootView;
\r
22 protected Drawable mBackground = null;
\r
23 protected WindowManager mWindowManager;
\r
28 * @param context Context
\r
30 public PopupWindows(Context context) {
\r
32 mWindow = new PopupWindow(context);
\r
34 mWindow.setTouchInterceptor(new OnTouchListener() {
\r
36 public boolean onTouch(View v, MotionEvent event) {
\r
37 if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
\r
47 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
\r
53 protected void onDismiss() {
\r
59 protected void onShow() {
\r
65 protected void preShow() {
\r
66 if (mRootView == null)
\r
67 throw new IllegalStateException("setContentView was not called with a view to display");
\r
71 if (mBackground == null) {
\r
72 mWindow.setBackgroundDrawable(new BitmapDrawable());
\r
74 mWindow.setBackgroundDrawable(mBackground);
\r
77 mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
\r
78 mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
\r
79 mWindow.setTouchable(true);
\r
80 mWindow.setFocusable(true);
\r
81 mWindow.setOutsideTouchable(true);
\r
83 mWindow.setContentView(mRootView);
\r
87 * Set background drawable.
\r
89 * @param background Background drawable
\r
91 public void setBackgroundDrawable(Drawable background) {
\r
92 mBackground = background;
\r
98 * @param root Root view
\r
100 public void setContentView(View root) {
\r
103 mWindow.setContentView(root);
\r
107 * Set content view.
\r
109 * @param layoutResID Resource id
\r
111 public void setContentView(int layoutResID) {
\r
112 LayoutInflater inflator =
\r
113 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
\r
115 setContentView(inflator.inflate(layoutResID, null));
\r
119 * Set listener on window dismissed.
\r
121 public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
\r
122 mWindow.setOnDismissListener(listener);
\r
126 * Dismiss the popup window.
\r
128 public void dismiss() {
\r