changed popup resizing
This commit is contained in:
parent
6b47df75a7
commit
9487b5367d
1 changed files with 68 additions and 17 deletions
|
@ -41,6 +41,7 @@ import android.view.GestureDetector;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.AnticipateInterpolator;
|
import android.view.animation.AnticipateInterpolator;
|
||||||
|
@ -1010,6 +1011,14 @@ public final class PopupVideoPlayer extends Service {
|
||||||
private boolean isMoving;
|
private boolean isMoving;
|
||||||
private boolean isResizing;
|
private boolean isResizing;
|
||||||
|
|
||||||
|
//initial co-ordinates and distance between fingers
|
||||||
|
private double initPointerDistance = -1;
|
||||||
|
private float initFirstPointerX = -1;
|
||||||
|
private float initFirstPointerY = -1;
|
||||||
|
private float initSecPointerX = -1;
|
||||||
|
private float initSecPointerY = -1;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDoubleTap(final MotionEvent e) {
|
public boolean onDoubleTap(final MotionEvent e) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -1201,6 +1210,17 @@ public final class PopupVideoPlayer extends Service {
|
||||||
playerImpl.hideControls(0, 0);
|
playerImpl.hideControls(0, 0);
|
||||||
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
animateView(playerImpl.getCurrentDisplaySeek(), false, 0, 0);
|
||||||
animateView(playerImpl.getResizingIndicator(), true, 200, 0);
|
animateView(playerImpl.getResizingIndicator(), true, 200, 0);
|
||||||
|
|
||||||
|
//record co-ordinates of fingers
|
||||||
|
initFirstPointerX = event.getX(0);
|
||||||
|
initFirstPointerY = event.getY(0);
|
||||||
|
initSecPointerX = event.getX(1);
|
||||||
|
initSecPointerY = event.getY(1);
|
||||||
|
//record distance between fingers
|
||||||
|
float xDiff = event.getX(0) - event.getX(1);
|
||||||
|
float yDiff = event.getY(0) - event.getY(1);
|
||||||
|
initPointerDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||||
|
|
||||||
isResizing = true;
|
isResizing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,6 +1244,10 @@ public final class PopupVideoPlayer extends Service {
|
||||||
|
|
||||||
if (isResizing) {
|
if (isResizing) {
|
||||||
isResizing = false;
|
isResizing = false;
|
||||||
|
|
||||||
|
initPointerDistance = -1;
|
||||||
|
initFirstPointerX = initFirstPointerY = initSecPointerX = initSecPointerY = -1;
|
||||||
|
|
||||||
animateView(playerImpl.getResizingIndicator(), false, 100, 0);
|
animateView(playerImpl.getResizingIndicator(), false, 100, 0);
|
||||||
playerImpl.changeState(playerImpl.getCurrentState());
|
playerImpl.changeState(playerImpl.getCurrentState());
|
||||||
}
|
}
|
||||||
|
@ -1242,25 +1266,52 @@ public final class PopupVideoPlayer extends Service {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final float firstPointerX = event.getX(0);
|
if(initPointerDistance != -1){
|
||||||
final float secondPointerX = event.getX(1);
|
|
||||||
|
//get the movements of the fingers
|
||||||
|
float firstPointerMoveX = event.getX(0) - initFirstPointerX;
|
||||||
|
float firstPointerMoveY = event.getY(0) - initFirstPointerY;
|
||||||
|
float secPointerMoveX = event.getX(1) - initSecPointerX;
|
||||||
|
float secPointerMoveY = event.getY(1) - initSecPointerY;
|
||||||
|
//minimum threshold beyond which pinch gesture will work
|
||||||
|
int scaledTouchSlop = ViewConfiguration.get(PopupVideoPlayer.this).getScaledTouchSlop();
|
||||||
|
|
||||||
|
if(firstPointerMoveX > scaledTouchSlop ||firstPointerMoveY > scaledTouchSlop ||
|
||||||
|
secPointerMoveX > scaledTouchSlop || secPointerMoveY > scaledTouchSlop){
|
||||||
|
|
||||||
|
double newWidth = popupWidth;
|
||||||
|
|
||||||
|
//calculate current distance between the pointers
|
||||||
|
float currentXDiff = event.getX(0) - event.getX(1);
|
||||||
|
float currentYDiff = event.getY(0) - event.getY(1);
|
||||||
|
double currentPointerDistance = Math.sqrt(currentXDiff * currentXDiff + currentYDiff * currentYDiff);
|
||||||
|
|
||||||
|
//scale popup width
|
||||||
|
double scale = 1 + (currentPointerDistance - initPointerDistance)/ initPointerDistance;
|
||||||
|
|
||||||
|
newWidth = (popupWidth * scale);
|
||||||
|
|
||||||
|
//change co-ordinates of popup so the center stays at the same position
|
||||||
|
if(currentPointerDistance > initPointerDistance){
|
||||||
|
popupLayoutParams.x -= (newWidth - popupWidth)/2;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
popupLayoutParams.x += (popupWidth - newWidth)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
initPointerDistance = currentPointerDistance;
|
||||||
|
|
||||||
|
checkPopupPositionBounds();
|
||||||
|
updateScreenSize();
|
||||||
|
|
||||||
|
final int width = (int) Math.min(screenWidth, newWidth);
|
||||||
|
updatePopupSize(width, -1);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
final float diff = Math.abs(firstPointerX - secondPointerX);
|
|
||||||
if (firstPointerX > secondPointerX) {
|
|
||||||
// second pointer is the anchor (the leftmost pointer)
|
|
||||||
popupLayoutParams.x = (int) (event.getRawX() - diff);
|
|
||||||
} else {
|
|
||||||
// first pointer is the anchor
|
|
||||||
popupLayoutParams.x = (int) event.getRawX();
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
checkPopupPositionBounds();
|
|
||||||
updateScreenSize();
|
|
||||||
|
|
||||||
final int width = (int) Math.min(screenWidth, diff);
|
|
||||||
updatePopupSize(width, -1);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in a new issue