Android Open Source - ParticlePlay Popup Windows






From Project

Back to project page ParticlePlay.

License

The source code is released under:

GNU General Public License

If you think the Android project ParticlePlay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.droidinteractive.particleplay.game;
/*/* w  w w.  j a v  a 2 s .  co  m*/
 * Copyright (c) Lorensius W. L. T. <lorenz@londatiga.net>
 * Copyright (c) 2010 Ragdoll Games
 * Copyright (c) 2010-2014 Droid Interactive
 * Copyright (c) 2010-2014 IDKJava Team
 * 
 * This file is part of Particle Play.
 * 
 * Particle Play is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Particle Play is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Particle Play. If not, see <http://www.gnu.org/licenses/>.
 */
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnTouchListener;

import android.widget.PopupWindow;
import android.content.Context;

/**
 * Custom popup window.
 * 
 * @author Lorensius W. L. T <lorenz@londatiga.net>
 *
 */
public class PopupWindows {
        protected Context mContext;
        protected PopupWindow mWindow;
        protected View mRootView;
        protected Drawable mBackground = null;
        protected WindowManager mWindowManager;
        
        /**
         * Constructor.
         * 
         * @param context Context
         */
        public PopupWindows(Context context) {
                mContext        = context;
                mWindow         = new PopupWindow(context);

                mWindow.setTouchInterceptor(new OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                                        mWindow.dismiss();
                                        
                                        return true;
                                }
                                
                                return false;
                        }
                });

                mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        }
        
        /**
         * On dismiss
         */
        protected void onDismiss() {                
        }
        
        /**
         * On show
         */
        protected void onShow() {                
        }

        /**
         * On pre show
         */
        protected void preShow() {
                if (mRootView == null) 
                        throw new IllegalStateException("setContentView was not called with a view to display.");
        
                onShow();

                if (mBackground == null) 
                        mWindow.setBackgroundDrawable(new BitmapDrawable());
                else 
                        mWindow.setBackgroundDrawable(mBackground);

                mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
                mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
                mWindow.setTouchable(true);
                mWindow.setFocusable(true);
                mWindow.setOutsideTouchable(true);

                mWindow.setContentView(mRootView);
        }

        /**
         * Set background drawable.
         * 
         * @param background Background drawable
         */
        public void setBackgroundDrawable(Drawable background) {
                mBackground = background;
        }

        /**
         * Set content view.
         * 
         * @param root Root view
         */
        public void setContentView(View root) {
                mRootView = root;
                
                mWindow.setContentView(root);
        }

        /**
         * Set content view.
         * 
         * @param layoutResID Resource id
         */
        public void setContentView(int layoutResID) {
                LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                
                setContentView(inflator.inflate(layoutResID, null));
        }

        /**
         * Set listener on window dismissed.
         * 
         * @param listener
         */
        public void setOnDismissListener(PopupWindow.OnDismissListener listener) {
                mWindow.setOnDismissListener(listener);  
        }

        /**
         * Dismiss the popup window.
         */
        public void dismiss() {
                mWindow.dismiss();
        }
}




Java Source Code List

com.droidinteractive.colorpicker.ColorPickerBox.java
com.droidinteractive.colorpicker.ColorPickerDialog.java
com.droidinteractive.colorpicker.widget.ColorPickerPreferenceWidgetView.java
com.droidinteractive.colorpicker.widget.ColorPickerPreference.java
com.droidinteractive.particleplay.FixMeActivity.java
com.droidinteractive.particleplay.Globals.java
com.droidinteractive.particleplay.LoadStateActivity.java
com.droidinteractive.particleplay.MainActivity.java
com.droidinteractive.particleplay.MenuActivity.java
com.droidinteractive.particleplay.SaveStateActivity.java
com.droidinteractive.particleplay.SplashActivity.java
com.droidinteractive.particleplay.custom.CustomElementActivity.java
com.droidinteractive.particleplay.custom.CustomElementAdvancedActivity.java
com.droidinteractive.particleplay.custom.CustomElementBasicActivity.java
com.droidinteractive.particleplay.custom.CustomElementManagerActivity.java
com.droidinteractive.particleplay.custom.CustomElementManager.java
com.droidinteractive.particleplay.custom.CustomElement.java
com.droidinteractive.particleplay.game.ActionItem.java
com.droidinteractive.particleplay.game.Control.java
com.droidinteractive.particleplay.game.CustomElementManager.java
com.droidinteractive.particleplay.game.FileManager.java
com.droidinteractive.particleplay.game.MenuBar.java
com.droidinteractive.particleplay.game.PopupWindows.java
com.droidinteractive.particleplay.game.QuickAction.java
com.droidinteractive.particleplay.game.SandView.java
com.droidinteractive.particleplay.game.SaveManager.java
com.droidinteractive.particleplay.game.Temperature.java
com.droidinteractive.particleplay.preferences.AlphaPatternDrawable.java
com.droidinteractive.particleplay.preferences.ColorPickerDialogPref.java
com.droidinteractive.particleplay.preferences.ColorPickerPanelView.java
com.droidinteractive.particleplay.preferences.ColorPickerPreference.java
com.droidinteractive.particleplay.preferences.ColorPickerView.java
com.droidinteractive.particleplay.preferences.PreferencesActivity.java
com.droidinteractive.particleplay.preferences.Preferences.java
com.droidinteractive.particleplay.preferences.SeekBarPreference.java
com.droidinteractive.slidingdrawer.OnDrawerCloseListener.java
com.droidinteractive.slidingdrawer.OnDrawerOpenListener.java
com.droidinteractive.slidingdrawer.OnDrawerScrollListener.java
com.droidinteractive.slidingdrawer.SlidingDrawer.java