Search in sources :

Example 31 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android-vision by googlesamples.

the class BarcodeCaptureActivity method onCreate.

/**
     * Initializes the UI and creates the detector pipeline.
     */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.barcode_capture);
    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);
    // read parameters from the intent used to launch the activity.
    boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false);
    boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);
    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }
    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
    Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) SuppressLint(android.annotation.SuppressLint)

Example 32 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project Android-Week-View by alamkanak.

the class WeekView method init.

private void init() {
    // Scrolling initialization.
    mGestureDetector = new GestureDetectorCompat(mContext, mGestureListener);
    mScroller = new OverScroller(mContext, new FastOutLinearInInterpolator());
    mMinimumFlingVelocity = ViewConfiguration.get(mContext).getScaledMinimumFlingVelocity();
    mScaledTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
    // Measure settings for time column.
    mTimeTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTimeTextPaint.setTextAlign(Paint.Align.RIGHT);
    mTimeTextPaint.setTextSize(mTextSize);
    mTimeTextPaint.setColor(mHeaderColumnTextColor);
    Rect rect = new Rect();
    mTimeTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mTimeTextHeight = rect.height();
    mHeaderMarginBottom = mTimeTextHeight / 2;
    initTextTimeWidth();
    // Measure settings for header row.
    mHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHeaderTextPaint.setColor(mHeaderColumnTextColor);
    mHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mHeaderTextPaint.setTextSize(mTextSize);
    mHeaderTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mHeaderTextHeight = rect.height();
    mHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    // Prepare header background paint.
    mHeaderBackgroundPaint = new Paint();
    mHeaderBackgroundPaint.setColor(mHeaderRowBackgroundColor);
    // Prepare day background color paint.
    mDayBackgroundPaint = new Paint();
    mDayBackgroundPaint.setColor(mDayBackgroundColor);
    mFutureBackgroundPaint = new Paint();
    mFutureBackgroundPaint.setColor(mFutureBackgroundColor);
    mPastBackgroundPaint = new Paint();
    mPastBackgroundPaint.setColor(mPastBackgroundColor);
    mFutureWeekendBackgroundPaint = new Paint();
    mFutureWeekendBackgroundPaint.setColor(mFutureWeekendBackgroundColor);
    mPastWeekendBackgroundPaint = new Paint();
    mPastWeekendBackgroundPaint.setColor(mPastWeekendBackgroundColor);
    // Prepare hour separator color paint.
    mHourSeparatorPaint = new Paint();
    mHourSeparatorPaint.setStyle(Paint.Style.STROKE);
    mHourSeparatorPaint.setStrokeWidth(mHourSeparatorHeight);
    mHourSeparatorPaint.setColor(mHourSeparatorColor);
    // Prepare the "now" line color paint
    mNowLinePaint = new Paint();
    mNowLinePaint.setStrokeWidth(mNowLineThickness);
    mNowLinePaint.setColor(mNowLineColor);
    // Prepare today background color paint.
    mTodayBackgroundPaint = new Paint();
    mTodayBackgroundPaint.setColor(mTodayBackgroundColor);
    // Prepare today header text color paint.
    mTodayHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTodayHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mTodayHeaderTextPaint.setTextSize(mTextSize);
    mTodayHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTodayHeaderTextPaint.setColor(mTodayHeaderTextColor);
    // Prepare event background color.
    mEventBackgroundPaint = new Paint();
    mEventBackgroundPaint.setColor(Color.rgb(174, 208, 238));
    // Prepare header column background color.
    mHeaderColumnBackgroundPaint = new Paint();
    mHeaderColumnBackgroundPaint.setColor(mHeaderColumnBackgroundColor);
    // Prepare event text size and color.
    mEventTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mEventTextPaint.setStyle(Paint.Style.FILL);
    mEventTextPaint.setColor(mEventTextColor);
    mEventTextPaint.setTextSize(mEventTextSize);
    // Set default event color.
    mDefaultEventColor = Color.parseColor("#9fc6e7");
    mScaleDetector = new ScaleGestureDetector(mContext, new ScaleGestureDetector.OnScaleGestureListener() {

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            mIsZooming = false;
        }

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            mIsZooming = true;
            goToNearestOrigin();
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mNewHourHeight = Math.round(mHourHeight * detector.getScaleFactor());
            invalidate();
            return true;
        }
    });
}
Also used : Rect(android.graphics.Rect) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ScaleGestureDetector(android.view.ScaleGestureDetector) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) OverScroller(android.widget.OverScroller) TextPaint(android.text.TextPaint)

Example 33 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method onHandleUiTouchEvent.

private void onHandleUiTouchEvent(MotionEvent ev) {
    final ScaleGestureDetector detector = mZoomManager.getScaleGestureDetector();
    int action = ev.getActionMasked();
    final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
    final boolean configChanged = action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN;
    final int skipIndex = pointerUp ? ev.getActionIndex() : -1;
    // Determine focal point
    float sumX = 0, sumY = 0;
    final int count = ev.getPointerCount();
    for (int i = 0; i < count; i++) {
        if (skipIndex == i)
            continue;
        sumX += ev.getX(i);
        sumY += ev.getY(i);
    }
    final int div = pointerUp ? count - 1 : count;
    float x = sumX / div;
    float y = sumY / div;
    if (configChanged) {
        mLastTouchX = Math.round(x);
        mLastTouchY = Math.round(y);
        mLastTouchTime = ev.getEventTime();
        mWebView.cancelLongPress();
        mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
    }
    if (detector != null) {
        detector.onTouchEvent(ev);
        if (detector.isInProgress()) {
            mLastTouchTime = ev.getEventTime();
            if (!mZoomManager.supportsPanDuringZoom()) {
                return;
            }
            mTouchMode = TOUCH_DRAG_MODE;
            if (mVelocityTracker == null) {
                mVelocityTracker = VelocityTracker.obtain();
            }
        }
    }
    if (action == MotionEvent.ACTION_POINTER_DOWN) {
        cancelTouch();
        action = MotionEvent.ACTION_DOWN;
    } else if (action == MotionEvent.ACTION_MOVE) {
        // negative x or y indicate it is on the edge, skip it.
        if (x < 0 || y < 0) {
            return;
        }
    }
    handleTouchEventCommon(ev, action, Math.round(x), Math.round(y));
}
Also used : ScaleGestureDetector(android.view.ScaleGestureDetector) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 34 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android_frameworks_base by ParanoidAndroid.

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 35 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project platform_frameworks_base by android.

the class ExpandHelper method cancel.

/**
     * Use this to abort any pending expansions in progress.
     */
public void cancel() {
    finishExpanding(true, 0f);
    clearView();
    // reset the gesture detector
    mSGD = new ScaleGestureDetector(mContext, mScaleGestureListener);
}
Also used : ScaleGestureDetector(android.view.ScaleGestureDetector)

Aggregations

ScaleGestureDetector (android.view.ScaleGestureDetector)46 GestureDetector (android.view.GestureDetector)23 Paint (android.graphics.Paint)8 Matrix (android.graphics.Matrix)7 LayoutInflater (android.view.LayoutInflater)6 WindowManager (android.view.WindowManager)6 MotionEvent (android.view.MotionEvent)5 Point (android.graphics.Point)4 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)4 ImageView (android.widget.ImageView)3 SuppressLint (android.annotation.SuppressLint)2 PackageManager (android.content.pm.PackageManager)2 PointF (android.graphics.PointF)2 Rect (android.graphics.Rect)2 View (android.view.View)2 ViewParent (android.view.ViewParent)2 Scroller (android.widget.Scroller)2 Drawable (android.graphics.drawable.Drawable)1 ScaleGestureDetectorCompat (android.support.v4.view.ScaleGestureDetectorCompat)1 FastOutLinearInInterpolator (android.support.v4.view.animation.FastOutLinearInInterpolator)1