use of android.view.ScaleGestureDetector in project Reader by TheKeeperOfPie.
the class ImageViewZoom method initialize.
private void initialize() {
setClickable(true);
scroller = new Scroller(getContext());
scaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {
// Log.d(TAG, "onScale() called with: " + "detector = [" + detector + "]");
//
// Log.d(TAG, "onScale() called with: " + "focusX = [" + detector.getFocusX() + "], focusY = [" + detector.getFocusY() + "], width = [" + getWidth() + "], height = [" + getHeight() + "]");
// float translationX = detector.getFocusX() * (translationMaxX - translationMinX) / getWidth() + translationMinX;
// float translationY = detector.getFocusY() * (translationMaxY - translationMinY) / getHeight() + translationMinY;
// setTranslation(translationX, translationY);
applyScaleFactor(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
return true;
}
});
gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
private int pointerCount;
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// Log.d(TAG, "onScroll() called with: " + "translationX = [" + translationX + "], translationMinX = [" + translationMinX + "], translationMaxX = [" + translationMaxX + "], scaleStart = [" + scaleStart + "], scaleCurrent = [" + scaleCurrent + "], contentWidth = [" + contentWidth + "]");
// Log.d(TAG, "onScroll() called with relative: " + "x = [" + getRelativeX() + "], y = [" + getRelativeY() + "]");
scroller.forceFinished(true);
if (pointerCount == 1) {
applyTranslation(-distanceX, -distanceY);
}
return super.onScroll(e1, e2, distanceX, distanceY);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
scroller.forceFinished(true);
if (pointerCount == 1) {
Log.d(TAG, "onFling() called with: " + "e1 = [" + e1 + "], e2 = [" + e2 + "], velocityX = [" + velocityX + "], velocityY = [" + velocityY + "]");
scroller.fling((int) translationX, (int) translationY, (int) velocityX, (int) velocityY, (int) translationMinX, (int) translationMaxX, (int) translationMinY, (int) translationMaxY);
post(runnableScroll);
}
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onDown(MotionEvent e) {
pointerCount = e.getPointerCount();
return super.onDown(e);
}
});
}
use of android.view.ScaleGestureDetector in project platform_frameworks_base by android.
the class OverlayDisplayWindow method createWindow.
private void createWindow() {
LayoutInflater inflater = LayoutInflater.from(mContext);
mWindowContent = inflater.inflate(com.android.internal.R.layout.overlay_display_window, null);
mWindowContent.setOnTouchListener(mOnTouchListener);
mTextureView = (TextureView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_texture);
mTextureView.setPivotX(0);
mTextureView.setPivotY(0);
mTextureView.getLayoutParams().width = mWidth;
mTextureView.getLayoutParams().height = mHeight;
mTextureView.setOpaque(false);
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
mTitleTextView = (TextView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_title);
mTitleTextView.setText(mTitle);
mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY);
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
if (mSecure) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
if (DISABLE_MOVE_AND_RESIZE) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
}
mWindowParams.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
mWindowParams.alpha = WINDOW_ALPHA;
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.setTitle(mTitle);
mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
// Set the initial position and scale.
// The position and scale will be clamped when the display is first shown.
mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayInfo.logicalWidth;
mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayInfo.logicalHeight;
mWindowScale = INITIAL_SCALE;
}
use of android.view.ScaleGestureDetector in project ImageViewZoom by sephiroth74.
the class ImageViewTouch method init.
@Override
protected void init(Context context, AttributeSet attrs, int defStyle) {
super.init(context, attrs, defStyle);
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mGestureListener = getGestureListener();
mScaleListener = getScaleListener();
mScaleDetector = new ScaleGestureDetector(getContext(), mScaleListener);
mGestureDetector = new GestureDetector(getContext(), mGestureListener, null, true);
mDoubleTapDirection = 1;
setQuickScaleEnabled(false);
}
use of android.view.ScaleGestureDetector in project XobotOS by xamarin.
the class ZoomManager method updateMultiTouchSupport.
public void updateMultiTouchSupport(Context context) {
// check the preconditions
assert mWebView.getSettings() != null;
final WebSettings settings = mWebView.getSettings();
final PackageManager pm = context.getPackageManager();
mSupportMultiTouch = (pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT)) && settings.supportZoom() && settings.getBuiltInZoomControls();
mAllowPanAndScale = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT) || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT);
if (mSupportMultiTouch && (mScaleDetector == null)) {
mScaleDetector = new ScaleGestureDetector(context, new ScaleDetectorListener());
} else if (!mSupportMultiTouch && (mScaleDetector != null)) {
mScaleDetector = null;
}
}
use of android.view.ScaleGestureDetector in project UltimateAndroid by cymcsg.
the class GestureTouchActivity method onCreate.
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gesture_activity);
// Determine the center of the screen to center 'gesture_earth'
Display display = getWindowManager().getDefaultDisplay();
mFocusX = display.getWidth() / 2f;
mFocusY = display.getHeight() / 2f;
// Set this class as touchListener to the ImageView
ImageView view = (ImageView) findViewById(R.id.imageView);
view.setOnTouchListener(this);
// Determine dimensions of 'gesture_earth' image
Drawable d = this.getResources().getDrawable(R.drawable.gesture_earth);
mImageHeight = d.getIntrinsicHeight();
mImageWidth = d.getIntrinsicWidth();
// View is scaled and translated by matrix, so scale and translate initially
float scaledImageCenterX = (mImageWidth * mScaleFactor) / 2;
float scaledImageCenterY = (mImageHeight * mScaleFactor) / 2;
mMatrix.postScale(mScaleFactor, mScaleFactor);
mMatrix.postTranslate(mFocusX - scaledImageCenterX, mFocusY - scaledImageCenterY);
view.setImageMatrix(mMatrix);
// Setup Gesture Detectors
mScaleDetector = new ScaleGestureDetector(getApplicationContext(), new ScaleListener());
mRotateDetector = new RotateGestureDetector(getApplicationContext(), new RotateListener());
mMoveDetector = new MoveGestureDetector(getApplicationContext(), new MoveListener());
mShoveDetector = new ShoveGestureDetector(getApplicationContext(), new ShoveListener());
}
Aggregations