public virtual bool focus(int id)
        {
            // check if that window is focusable
            XWindow window = getWindow(id);

            if (window == null)
            {
                throw new System.Exception("Tried to focus(" + id
                                           + ") a null window.");
            }

            if (!XUtils.isSet(window.flags,
                              XStandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE))
            {
                // remove focus from previously focused window
                if (sFocusedWindow != null)
                {
                    unfocus(sFocusedWindow);
                }

                return(window.onFocus(true));
            }

            return(false);
        }
예제 #2
0
            public Editor(XWindow that)
            {
                this.that = that;

                mParams = (XStandOutWindow.StandOutLayoutParams) this.that.getLayoutParams();
                anchorX = 0;
                anchorY = 0;
            }
 public virtual bool unfocus(XWindow window)
 {
     if (window == null)
     {
         throw new System.Exception(
                   "Tried to unfocus a null window.");
     }
     return(window.onFocus(false));
 }
예제 #4
0
        public virtual void putCache(int id, Class cls, XWindow window)
        {
            SparseArray l2 = (SparseArray)sWindows.get(cls);
            if (l2 == null)
            {
                l2 = new SparseArray();
                sWindows.put(cls, l2);
            }

            l2.put(id, window);
        }
예제 #5
0
        public virtual void putCache(int id, Class cls, XWindow window)
        {
            SparseArray l2 = (SparseArray)sWindows.get(cls);

            if (l2 == null)
            {
                l2 = new SparseArray();
                sWindows.put(cls, l2);
            }

            l2.put(id, window);
        }
        public virtual void bringToFront(int id)
        {
            XWindow window = getWindow(id);

            if (window == null)
            {
                throw new System.Exception("Tried to bringToFront(" + id
                                           + ") a null window.");
            }

            if (window.visibility == XWindow.VISIBILITY_GONE)
            {
                throw new System.Exception("Tried to bringToFront(" + id
                                           + ") a window that is not shown.");
            }

            if (window.visibility == XWindow.VISIBILITY_TRANSITION)
            {
                return;
            }

            // alert callbacks and cancel if instructed
            if (onBringToFront(id, window))
            {
                //Log.w(TAG, "Window " + id
                //+ " bring to front cancelled by implementation.");
                return;
            }

            StandOutLayoutParams @params = (StandOutLayoutParams)window.getLayoutParams();

            // remove from window manager then add back
            try
            {
                mWindowManager.removeView(window);
            }
            catch // (Exception ex)
            {
                //ex.printStackTrace();
            }
            try
            {
                mWindowManager.addView(window, @params);
            }
            catch //(Exception ex)
            {
                //ex.printStackTrace();
            }
        }
        public virtual bool onTouchHandleResize(int id, XWindow window, View view, MotionEvent @event)
        {
            StandOutLayoutParams @params = (StandOutLayoutParams)window
                                           .getLayoutParams();

            if (@event.getAction() == MotionEvent.ACTION_DOWN)
            {
                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                window.touchInfo.firstX = window.touchInfo.lastX;
                window.touchInfo.firstY = window.touchInfo.lastY;
            }
            else
            if (@event.getAction() == MotionEvent.ACTION_MOVE)
            {
                int deltaX = (int)@event.getRawX() - window.touchInfo.lastX;
                int deltaY = (int)@event.getRawY() - window.touchInfo.lastY;

                // update the size of the window
                @params.width  += deltaX;
                @params.height += deltaY;

                // keep window between min/max width/height
                if (@params.width >= @params.minWidth &&
                    @params.width <= @params.maxWidth)
                {
                    window.touchInfo.lastX = (int)@event.getRawX();
                }

                if (@params.height >= @params.minHeight &&
                    @params.height <= @params.maxHeight)
                {
                    window.touchInfo.lastY = (int)@event.getRawY();
                }

                window.edit().setSize(@params.width, @params.height).commit();
            }

            onResize(id, window, view, @event);

            return(true);
        }
        public virtual void updateViewLayout(int id, XStandOutWindow.StandOutLayoutParams @params)
        {
            XWindow window = getWindow(id);

            if (window == null)
            {
                throw new System.Exception("Tried to updateViewLayout("
                                           + id + ") a null window.");
            }

            if (window.visibility == XWindow.VISIBILITY_GONE)
            {
                return;
            }

            if (window.visibility == XWindow.VISIBILITY_TRANSITION)
            {
                return;
            }

            // alert callbacks and cancel if instructed
            if (onUpdate(id, window, @params))
            {
                //Log.w(TAG, "Window " + id + " update cancelled by implementation.");
                return;
            }

            try
            {
                window.setLayoutParams(@params);
                mWindowManager.updateViewLayout(window, @params);
            }
            catch// (Exception ex)
            {
                //ex.printStackTrace();
            }
        }
 public virtual bool onKeyEvent(int arg0, XWindow arg1, KeyEvent arg2)
 {
     return false;
 }
예제 #10
0
 public virtual bool onKeyEvent(int arg0, XWindow arg1, KeyEvent arg2)
 {
     return(false);
 }
예제 #11
0
 public virtual bool onClose(int arg0, XWindow arg1)
 {
     return(false);
 }
예제 #12
0
        public virtual void hide(int id)
        {
            // get the view corresponding to the id
            XWindow window = getWindow(id);

            if (window == null)
            {
                throw new System.Exception("Tried to hide(" + id
                                           + ") a null window.");
            }

            if (window.visibility == XWindow.VISIBILITY_GONE)
            {
                throw new System.Exception("Tried to hide(" + id
                                           + ") a window that is not shown.");
            }

            // alert callbacks and cancel if instructed
            if (onHide(id, window))
            {
                //Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
                return;
            }

            // check if hide enabled
            if (XUtils.isSet(window.flags, XStandOutFlags.FLAG_WINDOW_HIDE_ENABLE))
            {
                window.visibility = XWindow.VISIBILITY_TRANSITION;

                // get the hidden notification for this view
                Notification notification = getHiddenNotification(id);

                // get animation
                Animation animation = getHideAnimation(id);

                try
                {
                    // animate
                    //if (animation != null) {
                    //    animation.setAnimationListener(new AnimationListener() {

                    //        @Override
                    //        public void onAnimationStart(Animation animation) {
                    //        }

                    //        @Override
                    //        public void onAnimationRepeat(Animation animation) {
                    //        }

                    //        @Override
                    //        public void onAnimationEnd(Animation animation) {
                    //            // remove the window from the window manager
                    //            mWindowManager.removeView(window);
                    //            window.visibility = Window.VISIBILITY_GONE;
                    //        }
                    //    });
                    //    window.getChildAt(0).startAnimation(animation);
                    //} else {
                    // remove the window from the window manager
                    mWindowManager.removeView(window);
                    //}
                }
                catch// (Exception ex)
                {
                    //ex.printStackTrace();
                }

                // display the notification
                notification.flags = notification.flags
                                     | Notification.FLAG_NO_CLEAR
                                     | Notification.FLAG_AUTO_CANCEL;

                mNotificationManager.notify(GetType().ToClass().GetHashCode() + id,
                                            notification);
            }
            else
            {
                // if hide not enabled, close window
                close(id);
            }
        }
 public abstract StandOutLayoutParams getParams(int id, XWindow window);
 public virtual bool onUpdate(int arg0, XWindow arg1, XStandOutWindow.StandOutLayoutParams arg2)
 {
     return false;
 }
        public virtual bool onTouchHandleResize(int id, XWindow window, View view, MotionEvent @event)
        {
            StandOutLayoutParams @params = (StandOutLayoutParams)window
                .getLayoutParams();

            if (@event.getAction() == MotionEvent.ACTION_DOWN)
            {
                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                window.touchInfo.firstX = window.touchInfo.lastX;
                window.touchInfo.firstY = window.touchInfo.lastY;
            }
            else
                if (@event.getAction() == MotionEvent.ACTION_MOVE)
                {
                    int deltaX = (int)@event.getRawX() - window.touchInfo.lastX;
                    int deltaY = (int)@event.getRawY() - window.touchInfo.lastY;

                    // update the size of the window
                    @params.width += deltaX;
                    @params.height += deltaY;

                    // keep window between min/max width/height
                    if (@params.width >= @params.minWidth
                            && @params.width <= @params.maxWidth)
                    {
                        window.touchInfo.lastX = (int)@event.getRawX();
                    }

                    if (@params.height >= @params.minHeight
                            && @params.height <= @params.maxHeight)
                    {
                        window.touchInfo.lastY = (int)@event.getRawY();
                    }

                    window.edit().setSize(@params.width, @params.height).commit();
                }

            onResize(id, window, view, @event);

            return true;
        }
        public virtual bool onTouchHandleMove(int id, XWindow window, View view, MotionEvent @event)
        {
            var @params = (StandOutLayoutParams)window.getLayoutParams();

            // how much you have to move in either direction in order for the
            // gesture to be a move and not tap

            int totalDeltaX = window.touchInfo.lastX - window.touchInfo.firstX;
            int totalDeltaY = window.touchInfo.lastY - window.touchInfo.firstY;

            if (@event.getAction() == MotionEvent.ACTION_DOWN)
            {
                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                window.touchInfo.firstX = window.touchInfo.lastX;
                window.touchInfo.firstY = window.touchInfo.lastY;
            }
            else if (@event.getAction() == MotionEvent.ACTION_MOVE)
            {
                int deltaX = (int)@event.getRawX() - window.touchInfo.lastX;
                int deltaY = (int)@event.getRawY() - window.touchInfo.lastY;

                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                if (window.touchInfo.moving
                        || System.Math.Abs(totalDeltaX) >= @params.threshold
                        || System.Math.Abs(totalDeltaY) >= @params.threshold)
                {
                    window.touchInfo.moving = true;

                    // if window is moveable
                    if (XUtils.isSet(window.flags,
                            XStandOutFlags.FLAG_BODY_MOVE_ENABLE))
                    {

                        // update the position of the window
                        if (@event.getPointerCount() == 1)
                        {
                            @params.x += deltaX;
                            @params.y += deltaY;
                        }

                        window.edit().setPosition(@params.x, @params.y).commit();
                    }
                }
            }
            else if (@event.getAction() == MotionEvent.ACTION_UP)
            {
                window.touchInfo.moving = false;

                if (@event.getPointerCount() == 1)
                {

                    // bring to front on tap
                    var tap = System.Math.Abs(totalDeltaX) < @params.threshold
                            && System.Math.Abs(totalDeltaY) < @params.threshold;
                    if (tap
                            && XUtils.isSet(
                                    window.flags,
                                    XStandOutFlags.FLAG_WINDOW_BRING_TO_FRONT_ON_TAP))
                    {
                        this.bringToFront(id);
                    }
                }

                // bring to front on touch
                else if (XUtils.isSet(window.flags,
                        XStandOutFlags.FLAG_WINDOW_BRING_TO_FRONT_ON_TOUCH))
                {
                    this.bringToFront(id);
                }

            }

            onMove(id, window, view, @event);

            return true;
        }
 public virtual bool onTouchBody(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
 {
     return false;
 }
 public virtual bool onShow(int arg0, XWindow arg1)
 {
     return false;
 }
        //public event Action SizeChanged;

        public virtual void onResize(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
        {
            //if (SizeChanged != null)
            //    SizeChanged();
        }
 public virtual void onMove(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
 { }
 // static constructors
 static XStandOutWindow()
 {
     sWindowCache = new XWindowCache();
     sFocusedWindow = null;
 }
 public virtual bool onBringToFront(int arg0, XWindow arg1)
 {
     return false;
 }
 public virtual void setFocusedWindow(XWindow window)
 {
     sFocusedWindow = window;
 }
예제 #24
0
 // static constructors
 static XStandOutWindow()
 {
     sWindowCache   = new XWindowCache();
     sFocusedWindow = null;
 }
        public virtual XWindow show(int id)
        {
            // get the window corresponding to the id
            XWindow cachedWindow = getWindow(id);
            XWindow window;

            // check cache first
            if (cachedWindow != null)
            {
                window = cachedWindow;
            }
            else
            {
                window = new XWindow(this, id);
            }

            if (window.visibility == XWindow.VISIBILITY_VISIBLE)
            {
                throw new System.Exception("Tried to show(" + id
                        + ") a window that is already shown.");
            }

            // alert callbacks and cancel if instructed
            if (onShow(id, window))
            {
                //Log.d(TAG, "Window " + id + " show cancelled by implementation.");
                return null;
            }

            window.visibility = XWindow.VISIBILITY_VISIBLE;

            // get animation
            Animation animation = getShowAnimation(id);

            // get the params corresponding to the id
            StandOutLayoutParams @params = (StandOutLayoutParams)window.getLayoutParams();

            try
            {
                // add the view to the window manager
                mWindowManager.addView(window, @params);

                // animate
                if (animation != null)
                {
                    window.getChildAt(0).startAnimation(animation);
                }
            }
            catch // (Exception ex) 
            {
                //ex.printStackTrace();
            }

            // add view to internal map
            sWindowCache.putCache(id, GetType().ToClass(), window);

            // get the persistent notification
            var nn = getPersistentNotification(id);
            var notification = nn.Notification;
            // show the notification
            if (notification != null)
            {
                notification.flags = notification.flags
                        | Notification.FLAG_NO_CLEAR;

                nn.update = delegate
                {
                    mNotificationManager.notify(
                        GetType().ToClass().GetHashCode()
                           + ONGOING_NOTIFICATION_ID, notification);
                };
                // only show notification if not shown before
                if (!startedForeground)
                {
                    // tell Android system to show notification
                    startForeground(
                            GetType().ToClass().GetHashCode() + ONGOING_NOTIFICATION_ID,
                            notification);
                    startedForeground = true;
                }
                else
                {
                    // update notification if shown before
                    nn.update();

                }
            }
            else
            {
                // notification can only be null if it was provided before
                if (!startedForeground)
                {
                    throw new System.Exception("Your StandOutWindow service must"
                            + "provide a persistent notification."
                            + "The notification prevents Android"
                            + "from killing your service in low"
                            + "memory situations.");
                }
            }

            focus(id);

            return window;
        }
예제 #26
0
        public virtual void close(int id)
        {
            // get the view corresponding to the id
            XWindow window = getWindow(id);

            if (window == null)
            {
                throw new System.Exception("Tried to close(" + id
                                           + ") a null window.");
            }

            if (window.visibility == XWindow.VISIBILITY_TRANSITION)
            {
                return;
            }

            // alert callbacks and cancel if instructed
            if (onClose(id, window))
            {
                //Log.w(TAG, "Window " + id + " close cancelled by implementation.");
                return;
            }

            // remove hidden notification
            mNotificationManager.cancel(this.GetType().ToClass().GetHashCode() + id);

            unfocus(window);

            window.visibility = XWindow.VISIBILITY_TRANSITION;

            // get animation
            Animation animation = getCloseAnimation(id);

            // remove window
            try
            {
                // animate
                //if (animation != null) {
                //    animation.setAnimationListener(new AnimationListener() {

                //        @Override
                //        public void onAnimationStart(Animation animation) {
                //        }

                //        @Override
                //        public void onAnimationRepeat(Animation animation) {
                //        }

                //        @Override
                //        public void onAnimationEnd(Animation animation) {
                //            // remove the window from the window manager
                //            mWindowManager.removeView(window);
                //            window.visibility = Window.VISIBILITY_GONE;

                //            // remove view from internal map
                //            sWindowCache.removeCache(id,
                //                    StandOutWindow.this.getClass());

                //            // if we just released the last window, quit
                //            if (getExistingIds().size() == 0) {
                //                // tell Android to remove the persistent
                //                // notification
                //                // the Service will be shutdown by the system on low
                //                // memory
                //                startedForeground = false;
                //                stopForeground(true);
                //            }
                //        }
                //    });
                //    window.getChildAt(0).startAnimation(animation);
                //} else
                {
                    // remove the window from the window manager
                    mWindowManager.removeView(window);

                    // remove view from internal map
                    sWindowCache.removeCache(id, this.GetType().ToClass());

                    // if we just released the last window, quit
                    if (sWindowCache.getCacheSize(this.GetType().ToClass()) == 0)
                    {
                        // tell Android to remove the persistent notification
                        // the Service will be shutdown by the system on low memory
                        startedForeground = false;
                        stopForeground(true);
                    }
                }
            }
            catch // (Exception ex)
            {
                //ex.printStackTrace();
            }
        }
 public virtual bool onClose(int arg0, XWindow arg1)
 {
     return false;
 }
예제 #28
0
 public abstract StandOutLayoutParams getParams(int id, XWindow window);
예제 #29
0
        //public event Action SizeChanged;

        public virtual void onResize(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
        {
            //if (SizeChanged != null)
            //    SizeChanged();
        }
예제 #30
0
 public virtual bool onBringToFront(int arg0, XWindow arg1)
 {
     return(false);
 }
예제 #31
0
 public virtual bool onTouchBody(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
 {
     return(false);
 }
예제 #32
0
 public virtual bool onFocusChange(int arg0, XWindow arg1, bool arg2)
 {
     return(false);
 }
예제 #33
0
 public override XStandOutWindow.StandOutLayoutParams getParams(int id, XWindow window)
 {
     return new XStandOutWindow.StandOutLayoutParams(this, id,
         400, 250,
     StandOutLayoutParams.CENTER, StandOutLayoutParams.CENTER);
 }
예제 #34
0
 public virtual void onMove(int arg0, XWindow arg1, View arg2, MotionEvent arg3)
 {
 }
 public virtual bool onFocusChange(int arg0, XWindow arg1, bool arg2)
 {
     return false;
 }
예제 #36
0
 public virtual bool onShow(int arg0, XWindow arg1)
 {
     return(false);
 }
예제 #37
0
 public virtual void setFocusedWindow(XWindow window)
 {
     sFocusedWindow = window;
 }
예제 #38
0
        public virtual bool onTouchHandleMove(int id, XWindow window, View view, MotionEvent @event)
        {
            var @params = (StandOutLayoutParams)window.getLayoutParams();

            // how much you have to move in either direction in order for the
            // gesture to be a move and not tap

            int totalDeltaX = window.touchInfo.lastX - window.touchInfo.firstX;
            int totalDeltaY = window.touchInfo.lastY - window.touchInfo.firstY;

            if (@event.getAction() == MotionEvent.ACTION_DOWN)
            {
                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                window.touchInfo.firstX = window.touchInfo.lastX;
                window.touchInfo.firstY = window.touchInfo.lastY;
            }
            else if (@event.getAction() == MotionEvent.ACTION_MOVE)
            {
                int deltaX = (int)@event.getRawX() - window.touchInfo.lastX;
                int deltaY = (int)@event.getRawY() - window.touchInfo.lastY;

                window.touchInfo.lastX = (int)@event.getRawX();
                window.touchInfo.lastY = (int)@event.getRawY();

                if (window.touchInfo.moving ||
                    System.Math.Abs(totalDeltaX) >= @params.threshold ||
                    System.Math.Abs(totalDeltaY) >= @params.threshold)
                {
                    window.touchInfo.moving = true;

                    // if window is moveable
                    if (XUtils.isSet(window.flags,
                                     XStandOutFlags.FLAG_BODY_MOVE_ENABLE))
                    {
                        // update the position of the window
                        if (@event.getPointerCount() == 1)
                        {
                            @params.x += deltaX;
                            @params.y += deltaY;
                        }

                        window.edit().setPosition(@params.x, @params.y).commit();
                    }
                }
            }
            else if (@event.getAction() == MotionEvent.ACTION_UP)
            {
                window.touchInfo.moving = false;

                if (@event.getPointerCount() == 1)
                {
                    // bring to front on tap
                    var tap = System.Math.Abs(totalDeltaX) < @params.threshold &&
                              System.Math.Abs(totalDeltaY) < @params.threshold;
                    if (tap &&
                        XUtils.isSet(
                            window.flags,
                            XStandOutFlags.FLAG_WINDOW_BRING_TO_FRONT_ON_TAP))
                    {
                        this.bringToFront(id);
                    }
                }

                // bring to front on touch
                else if (XUtils.isSet(window.flags,
                                      XStandOutFlags.FLAG_WINDOW_BRING_TO_FRONT_ON_TOUCH))
                {
                    this.bringToFront(id);
                }
            }

            onMove(id, window, view, @event);

            return(true);
        }
예제 #39
0
        public virtual XWindow show(int id)
        {
            // get the window corresponding to the id
            XWindow cachedWindow = getWindow(id);
            XWindow window;

            // check cache first
            if (cachedWindow != null)
            {
                window = cachedWindow;
            }
            else
            {
                window = new XWindow(this, id);
            }

            if (window.visibility == XWindow.VISIBILITY_VISIBLE)
            {
                throw new System.Exception("Tried to show(" + id
                                           + ") a window that is already shown.");
            }

            // alert callbacks and cancel if instructed
            if (onShow(id, window))
            {
                //Log.d(TAG, "Window " + id + " show cancelled by implementation.");
                return(null);
            }

            window.visibility = XWindow.VISIBILITY_VISIBLE;

            // get animation
            Animation animation = getShowAnimation(id);

            // get the params corresponding to the id
            StandOutLayoutParams @params = (StandOutLayoutParams)window.getLayoutParams();

            try
            {
                // add the view to the window manager
                mWindowManager.addView(window, @params);

                // animate
                if (animation != null)
                {
                    window.getChildAt(0).startAnimation(animation);
                }
            }
            catch // (Exception ex)
            {
                //ex.printStackTrace();
            }

            // add view to internal map
            sWindowCache.putCache(id, GetType().ToClass(), window);

            // get the persistent notification
            var nn           = getPersistentNotification(id);
            var notification = nn.Notification;

            // show the notification
            if (notification != null)
            {
                notification.flags = notification.flags
                                     | Notification.FLAG_NO_CLEAR;

                nn.update = delegate
                {
                    mNotificationManager.notify(
                        GetType().ToClass().GetHashCode()
                        + ONGOING_NOTIFICATION_ID, notification);
                };
                // only show notification if not shown before
                if (!startedForeground)
                {
                    // tell Android system to show notification
                    startForeground(
                        GetType().ToClass().GetHashCode() + ONGOING_NOTIFICATION_ID,
                        notification);
                    startedForeground = true;
                }
                else
                {
                    // update notification if shown before
                    nn.update();
                }
            }
            else
            {
                // notification can only be null if it was provided before
                if (!startedForeground)
                {
                    throw new System.Exception("Your StandOutWindow service must"
                                               + "provide a persistent notification."
                                               + "The notification prevents Android"
                                               + "from killing your service in low"
                                               + "memory situations.");
                }
            }

            focus(id);

            return(window);
        }
예제 #40
0
 public virtual bool onUpdate(int arg0, XWindow arg1, XStandOutWindow.StandOutLayoutParams arg2)
 {
     return(false);
 }
예제 #41
0
        public virtual bool unfocus(int id)
        {
            XWindow window = getWindow(id);

            return(unfocus(window));
        }
예제 #42
0
            public Editor(XWindow that)
            {
                this.that = that;

                mParams = (XStandOutWindow.StandOutLayoutParams)this.that.getLayoutParams();
                anchorX = 0;
                anchorY = 0;
            }
 public virtual bool unfocus(XWindow window)
 {
     if (window == null)
     {
         throw new System.Exception(
                 "Tried to unfocus a null window.");
     }
     return window.onFocus(false);
 }