@Override public boolean onTouch(View v, MotionEvent event) { paramsF = mParams; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = paramsF.x; initialY = paramsF.y; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); animateShowing(); break; case MotionEvent.ACTION_UP: if (AppHelper.isEdged(context)) { moveToEdge(); } else { if (AppHelper.isSavePositionEnabled(context)) { AppHelper.savePosition(context, paramsF.y, paramsF.x); } } animateHidden(); break; case MotionEvent.ACTION_MOVE: if (paramsF.y < 0) { paramsF.y = 0; } if (paramsF.y >= 0 || paramsF.y <= (szWindow.y - AppHelper.getFinalSize(context))) { paramsF.x = initialX + (int) (event.getRawX() - initialTouchX); paramsF.y = initialY + (int) (event.getRawY() - initialTouchY); try { windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF); if (view.isShown()) { showRecycler(); } } catch (Exception e) { e.printStackTrace(); } animateShowing(); } else if (paramsF.y > (szWindow.y - AppHelper.getFinalSize(context))) { paramsF.y = (szWindow.y - AppHelper.getFinalSize(context)); } break; } return false; }
private void setupParams() { int iconSize = AppHelper.getFinalSize(context); int pX = AppHelper.getPositionX(context); int pY = AppHelper.getPositionY(context); rParams.width = MATCH_PARENT; rParams.height = iconSize; mParams.width = iconSize; mParams.height = iconSize; if (AppHelper.isSavePositionEnabled(context)) { mParams.x = pX; mParams.y = pY; rParams.y = pY + iconSize; rParams.x = pX; } else { mParams.x = 0; mParams.y = 100; rParams.x = 0; rParams.y = 100 + iconSize; } }