@Override public boolean onTouchEvent(MotionEvent event) { // handle touching outside switch (event.getAction()) { case MotionEvent.ACTION_OUTSIDE: // unfocus window if (mContext.getFocusedWindow() == this) { mContext.unfocus(this); } // notify implementation that ACTION_OUTSIDE occurred mContext.onTouchBody(id, this, this, event); break; } // handle multitouch if (event.getPointerCount() >= 2 && Utils.isSet(flags, StandOutFlags.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 = Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); switch (event.getAction() & MotionEvent.ACTION_MASK) { case 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(); break; } mContext.onResize(id, this, this, event); } return true; }
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (mContext.onKeyEvent(id, this, event)) { Log.d(TAG, "Window " + id + " key event " + event + " cancelled by implementation."); return false; } if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: mContext.unfocus(this); return true; } } return super.dispatchKeyEvent(event); }