Example usage for android.view ScaleGestureDetector ScaleGestureDetector

List of usage examples for android.view ScaleGestureDetector ScaleGestureDetector

Introduction

In this page you can find the example usage for android.view ScaleGestureDetector ScaleGestureDetector.

Prototype

public ScaleGestureDetector(Context context, OnScaleGestureListener listener) 

Source Link

Document

Creates a ScaleGestureDetector with the supplied listener.

Usage

From source file:com.om.snipit.activities.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from  w  ww.java  2s.com
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_barcode_capture);

    ButterKnife.bind(this);

    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);

    setupToolbar(toolbar, getString(R.string.barcode_capture_activity), true,
            Constants.DEFAULT_ACTIVITY_TOOLBAR_COLORS);

    // 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, R.string.capture_barcode_instructions, Snackbar.LENGTH_INDEFINITE).show();
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

private void init(Context context) {
    mSmoothMatrix = new Matrix();
    mPaint = new Paint();
    mPaint.setColor(mBgColor);//from  w  w w  .ja v  a  2  s  .com
    mPaint.setStyle(Style.FILL);
    //      setBackgroundColor(mBgColor);

    mScaleMatrix = new Matrix();
    setScaleType(ScaleType.MATRIX);

    mScaleGestureDetector = new ScaleGestureDetector(context, this);

    setOnTouchListener(this);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public boolean onDoubleTap(MotionEvent e) {

            if (isAutoScale == true) {
                return true;
            }

            float X = e.getX();
            float Y = e.getY();

            if (getScale() < mMidScale) {

                postDelayed(new AutoScaleRunnable(mMidScale, X, Y), 16);
                isAutoScale = true;

            } else if ((getScale() >= mMidScale) && (getScale() < mMaxScale)) {

                postDelayed(new AutoScaleRunnable(mMaxScale, X, Y), 16);
                isAutoScale = true;

            } else {

                postDelayed(new AutoScaleRunnable(mMinScale, X, Y), 5);
                isAutoScale = true;

            }
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mClickListener != null)
                mClickListener.onClick(ZoomImageView.this);
            return super.onSingleTapUp(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (mLongClickListener != null)
                mLongClickListener.onLongClick(ZoomImageView.this);
        }
    });
}

From source file:com.cpen321.fridgemanager.OcrReader.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from www.ja  va2  s. c  o  m
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ocr_capture);

    // Get Text
    if (getIntent().getStringArrayListExtra("texts") == null) {
        texts = new ArrayList<>();
    } else {
        texts = getIntent().getStringArrayListExtra("texts");
    }

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);

    // Set good defaults for capturing text.
    boolean autoFocus = true;
    boolean 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 Scan After Seeing Text Overlays. Pinch to Zoom.",
            Snackbar.LENGTH_LONG).show();

    SharedPreferences settings = getSharedPreferences("prefs", 0);
    boolean firstCamera = settings.getBoolean("firstCamera", false);
    if (firstCamera == false) {
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("firstCamera", true);
        editor.commit();

        showFirstTimeDialog();
    }

}

From source file:com.gmartinsribeiro.qrcodereader.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from   w w w.j  a  v a  2 s .  c o  m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.barcode_capture);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    if (Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(getResources().getColor(R.color.blue700));
    }

    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, "Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
}

From source file:it.jaschke.alexandria.BarcodeScanner.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*from   ww w.j a va  2 s . co m*/
@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, getApplicationContext().getString(R.string.tap_directions),
            Snackbar.LENGTH_INDEFINITE).show();
}

From source file:com.konker.konkersensors.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///ww w  .j  a v  a2 s .c  o m
@Override
public void onCreate(Bundle icicle) {
    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    //Bundle bundle = new Bundle();
    //bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "BarcodeCaptureActivity");
    //bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "activity");
    //mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

    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();

}

From source file:org.photosynq.android.photosynq.barcode.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from w w  w .j a  va2s  .  c  o m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_barcode_capture);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);

    // read parameters from intent and preferences
    boolean autoFocus = getIntent().getBooleanExtra(INTENT_AUTOFOCUS, false);
    boolean useFlash;
    if (getIntent().hasExtra(INTENT_FLASH)) {
        useFlash = getIntent().getBooleanExtra(INTENT_FLASH, false);
    } else {
        useFlash = getPreferences(MODE_PRIVATE).getBoolean(getString(R.string.settings_barcode_flash), false);
    }

    mAutoCapture = getIntent().getBooleanExtra(INTENT_AUTOCAPTURE, 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());

    mFlashlightButton = (ImageButton) findViewById(R.id.ib_flashlight);
    mFlashlightButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFlashlight = !mFlashlight;
            switchFlashlight(mFlashlight);
        }
    });

    mFlashlight = useFlash;
    switchFlashlight(mFlashlight);

}

From source file:com.abct.tljr.news.widget.ZoomableImageView.java

private void init(Context context) {
    mPaint = new Paint();
    mPaint.setDither(true);//  w  w  w. ja v a2s.c  o  m
    mPaint.setFilterBitmap(true);
    mPaint.setAntiAlias(true);

    // Setup the refresh runnable
    mRefresh = new Runnable() {
        @Override
        public void run() {
            postInvalidate();
        }
    };

    // Setup the gesture and scale listeners
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new MyGestureListener());

    // Force hardware acceleration
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
}

From source file:org.thoughtcrime.securesms.scribbles.widget.MotionView.java

private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
    // I fucking love Android
    setWillNotDraw(false);//ww  w  . java 2  s .  c  o  m

    selectedLayerPaint = new Paint();
    selectedLayerPaint.setAlpha((int) (255 * Constants.SELECTED_LAYER_ALPHA));
    selectedLayerPaint.setAntiAlias(true);

    this.editText = new EditText(context, attrs);
    ViewCompat.setAlpha(this.editText, 0);
    this.editText.setLayoutParams(new LayoutParams(1, 1, Gravity.TOP | Gravity.LEFT));
    this.editText.setClickable(false);
    this.editText.setBackgroundColor(Color.TRANSPARENT);
    this.editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 1);
    this.editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
            | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    this.addView(editText);
    this.editText.clearFocus();
    this.editText.addTextChangedListener(this);

    // init listeners
    this.scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());
    this.rotateGestureDetector = new RotateGestureDetector(context, new RotateListener());
    this.moveGestureDetector = new MoveGestureDetector(context, new MoveListener());
    this.gestureDetectorCompat = new GestureDetectorCompat(context, new TapsListener());

    setOnTouchListener(onTouchListener);

    updateUI();
}

From source file:com.bayarchain.OCR.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///  w w w . j a v a 2 s.c o m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.ocr_capture2);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);
    demoName = (EditText) findViewById(R.id.editText);
    clear_btn = (Button) findViewById(R.id.clear_button);
    continue_btn = (Button) findViewById(R.id.continue_button);

    continue_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (!demoName.getText().toString().equals("")) {
                Intent returnIntent = new Intent();
                returnIntent.putExtra("result", demoName.getText().toString().replace("$", ""));
                setResult(Activity.RESULT_OK, returnIntent);
                OcrCaptureActivity.this.finish();
            } else
                Toast.makeText(OcrCaptureActivity.this, "Please enter only numbers!", Toast.LENGTH_SHORT)
                        .show();
        }
    });
    clear_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            demoName.setText("");
        }
    });

    // read parameters from the intent used to launch the activity.
    boolean autoFocus = true;
    boolean 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();
}