public StandOutLayoutParams(XStandOutWindow that, int id) : base(200, 200, TYPE_PHONE, StandOutLayoutParams.FLAG_NOT_TOUCH_MODAL | StandOutLayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT) { this.that = that; int windowFlags = that.getFlags(id); setFocusFlag(false); if (!XUtils.isSet(windowFlags, XStandOutFlags.FLAG_WINDOW_EDGE_LIMITS_ENABLE)) { // windows may be moved beyond edges flags |= FLAG_LAYOUT_NO_LIMITS; } x = getX(id, width); y = getY(id, height); gravity = Gravity.TOP | Gravity.LEFT; threshold = 10; minWidth = minHeight = 0; maxWidth = maxHeight = Integer.MAX_VALUE; }
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); }
public override bool onInterceptTouchEvent(MotionEvent @event) { XStandOutWindow.StandOutLayoutParams @params = (XStandOutWindow.StandOutLayoutParams)getLayoutParams(); // focus window if (@event.getAction() == MotionEvent.ACTION_DOWN) { if (mContext.getFocusedWindow() != this) { mContext.focus(id); } } // multitouch // script: error JSC1000: Java : Opcode not implemented: brfalse.s at PopupWebView.Library.XWindow.onInterceptTouchEvent var flag1 = @event.getPointerCount() >= 2; var flag2 = (@event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN; var flag = flag1 && XUtils.isSet(flags, XStandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE) && flag2; if (flag) { touchInfo.scale = 1; touchInfo.dist = -1; touchInfo.firstWidth = @params.width; touchInfo.firstHeight = @params.height; return(true); } return(false); }
public override bool onTouchEvent(MotionEvent @event) { // assembly: Y:\staging\clr\PopupWebView.AndroidActivity.dll // type: PopupWebView.Library.XWindow, PopupWebView.AndroidActivity, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null //offset: // 0x0083 // method: Boolean onInterceptTouchEvent(android.view.MotionEvent) } // script: error JSC1000: Java : unable to emit and at 'PopupWebView.Library.XWindow.onInterceptTouchEvent'#0085: multiple stack entries instead of one // handle touching outside if (@event.getAction() == MotionEvent.ACTION_OUTSIDE) { // unfocus window if (mContext.getFocusedWindow() == this) { mContext.unfocus(this); } // notify implementation that ACTION_OUTSIDE occurred mContext.onTouchBody(id, this, this, @event); } // handle multitouch if (@event.getPointerCount() >= 2 && XUtils.isSet(flags, XStandOutFlags.FLAG_WINDOW_PINCH_RESIZE_ENABLE)) { // 2 fingers or more float x0 = @event.getX(0); float y0 = @event.getY(0); float x1 = @event.getX(1); float y1 = @event.getY(1); double dist = System.Math .Sqrt(System.Math.Pow(x0 - x1, 2) + System.Math.Pow(y0 - y1, 2)); if ((@event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) { if (touchInfo.dist == -1) { touchInfo.dist = dist; } touchInfo.scale *= dist / touchInfo.dist; touchInfo.dist = dist; // scale the window with anchor point set to middle edit().setAnchorPoint(.5f, .5f) .setSize( (int)(touchInfo.firstWidth * touchInfo.scale), (int)(touchInfo.firstHeight * touchInfo.scale)) .commit(); } mContext.onResize(id, this, this, @event); } return(true); }
private Editor setPosition(int x, int y, bool skip) { if (mParams != null) { var flag0 = anchorX < 0 || anchorX > 1 || anchorY < 0 || anchorY > 1; if (flag0) { throw new System.Exception( "Anchor point must be between 0 and 1, inclusive." + new { anchorX, anchorY }); } // sets the x and y correctly according to anchorX and // anchorY if (x != UNCHANGED) { mParams.x = (int)(x - mParams.width * anchorX); } if (y != UNCHANGED) { mParams.y = (int)(y - mParams.height * anchorY); } if (XUtils.isSet(that.flags, XStandOutFlags.FLAG_WINDOW_EDGE_LIMITS_ENABLE)) { // if gravity is not TOP|LEFT throw exception if (mParams.gravity != (Gravity.TOP | Gravity.LEFT)) { throw new System.Exception( "The window " + that.id + " gravity must be TOP|LEFT if FLAG_WINDOW_EDGE_LIMITS_ENABLE or FLAG_WINDOW_EDGE_TILE_ENABLE is set."); } // keep window inside edges mParams.x = System.Math.Min(System.Math.Max(mParams.x, 0), that.displayWidth - mParams.width); //mParams.y = System.Math.Min( // System.Math.Max(mParams.y, 0), that.displayHeight - mParams.height //); mParams.y = System.Math.Max(mParams.y, 0); //System.Math.Min( // System.Math.Max(mParams.y, 0), that.displayHeight - 32 //); } } return(this); }
public virtual bool onFocus(bool focus) { if (!XUtils.isSet(flags, XStandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE)) { // window is focusable if (focus == focused) { // window already focused/unfocused return(false); } focused = focus; // alert callbacks and cancel if instructed if (mContext.onFocusChange(id, this, focus)) { //Log.d(TAG, "Window " + id + " focus change " // + (focus ? "(true)" : "(false)") // + " cancelled by implementation."); focused = !focus; return(false); } // set window manager params XStandOutWindow.StandOutLayoutParams @params = (XStandOutWindow.StandOutLayoutParams)getLayoutParams(); @params.setFocusFlag(focus); mContext.updateViewLayout(id, @params); if (focus) { mContext.setFocusedWindow(this); } else { if (mContext.getFocusedWindow() == this) { mContext.setFocusedWindow(null); } } return(true); } return(false); }
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 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); } }
private Editor setSize(int width, int height, bool skip) { if (mParams != null) { var flag0 = (anchorX < 0 || anchorX > 1 || anchorY < 0 || anchorY > 1); if (flag0) { throw new System.Exception( "Anchor point must be between 0 and 1, inclusive."); } int lastWidth = mParams.width; int lastHeight = mParams.height; if (width != UNCHANGED) { mParams.width = width; } if (height != UNCHANGED) { mParams.height = height; } // set max width/height int maxWidth = mParams.maxWidth; int maxHeight = mParams.maxHeight; if (XUtils.isSet(that.flags, XStandOutFlags.FLAG_WINDOW_EDGE_LIMITS_ENABLE)) { maxWidth = (int)System.Math.Min(maxWidth, that.displayWidth); //maxHeight = (int)System.Math.Min(maxHeight, that.displayHeight); //maxHeight = (int)System.Math.Min(maxHeight, that.displayHeight + mParams.height - 32); } // keep window between min and max mParams.width = System.Math.Min( System.Math.Max(mParams.width, mParams.minWidth), maxWidth); mParams.height = System.Math.Min( System.Math.Max(mParams.height, mParams.minHeight), maxHeight); // keep window in aspect ratio if (XUtils.isSet(that.flags, XStandOutFlags.FLAG_WINDOW_ASPECT_RATIO_ENABLE)) { int ratioWidth = (int)(mParams.height * that.touchInfo.ratio); int ratioHeight = (int)(mParams.width / that.touchInfo.ratio); if (ratioHeight >= mParams.minHeight && ratioHeight <= mParams.maxHeight) { // width good adjust height mParams.height = ratioHeight; } else { // height good adjust width mParams.width = ratioWidth; } } if (!skip) { // set position based on anchor point setPosition((int)(mParams.x + lastWidth * anchorX), (int)(mParams.y + lastHeight * anchorY)); } } return(this); }