Example usage for android.view SurfaceHolder addCallback

List of usage examples for android.view SurfaceHolder addCallback

Introduction

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

Prototype

public void addCallback(Callback callback);

Source Link

Document

Add a Callback interface for this holder.

Usage

From source file:com.jwetherell.quick_response_code.DecoderActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate().
    if (cameraManager == null) {
        cameraManager = new CameraManager(getApplication());
    }// w  w w. ja  va2  s  . c  om

    if (viewfinderView == null) {
        viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
        viewfinderView.setCameraManager(cameraManager);
    }

    showScanner();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
}

From source file:com.google.zxing.demo.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();
    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    handler = null;// ww  w.j a  v  a  2  s  .c o m
    lastResult = null;
    resetStatusView();

    beepManager.updatePrefs();
    // ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    sourceUrl = null;
    // scanFromWebPageManager = null;
    decodeFormats = null;
    characterSet = null;

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
}

From source file:com.orange.essentials.otb.ui.OtbTermsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.otb_terms, container, false);
    LinearLayout llayout = (LinearLayout) mView.findViewById(R.id.otb_terms_layout);
    TextView headerTv = (TextView) llayout.findViewById(R.id.otb_header_tv_text);
    headerTv.setText(R.string.otb_home_terms_content);
    List<Term> terms = TrustBadgeManager.INSTANCE.getTerms();

    for (Term term : terms) {
        View layoutToAdd = null;//from   w w w .  java  2s  .  com
        if (term.getTermType() == TermType.VIDEO
                && Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
            layoutToAdd = View.inflate(getActivity(), R.layout.otb_terms_video, null);
            TextView titleTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_video_title);
            final AutoResizingFrameLayout anchorView = (AutoResizingFrameLayout) layoutToAdd
                    .findViewById(R.id.videoSurfaceContainer);
            if (mVideoViews == null) {
                mVideoViews = new ArrayList<>();
            }
            mVideoViews.add(anchorView);
            SurfaceView videoSurface = (SurfaceView) layoutToAdd.findViewById(R.id.videoSurface);

            titleTv.setText(term.getTitleId());

            SurfaceHolder videoHolder = videoSurface.getHolder();
            MediaPlayer player = new MediaPlayer();
            if (mPlayers == null) {
                mPlayers = new ArrayList<>();
            }
            mPlayers.add(player);
            final VideoControllerView controller = new VideoControllerView(getContext());
            VideoCallback videoCallback = new VideoCallback(player, controller, anchorView);
            videoHolder.addCallback(videoCallback);
            anchorView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    controller.show();
                    return false;
                }
            });
            try {
                player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                player.setDataSource(getContext(), Uri.parse(getString(term.getContentId())));
                player.setOnPreparedListener(videoCallback);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (term.getTermType() == TermType.TEXT) {//TermType.TEXT
            layoutToAdd = View.inflate(getActivity(), R.layout.otb_terms_text, null);
            TextView titleTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_text_title);
            TextView contentTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_text_content);
            titleTv.setText(term.getTitleId());
            contentTv.setText(Html.fromHtml(getString(term.getContentId())));
            contentTv.setMovementMethod(LinkMovementMethod.getInstance());
            contentTv.setLinkTextColor(getResources().getColor(R.color.colorAccent));
        }
        if (null != layoutToAdd) {
            llayout.addView(layoutToAdd);
        }
        if (terms.indexOf(term) != terms.size() - 1) {
            View.inflate(getActivity(), R.layout.otb_separator, llayout);
        }
    }

    return mView;
}

From source file:com.agiro.scanner.android.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();
    resetStatusView();/*from   w  ww  .  ja  v  a 2  s  .  co m*/
    Log.d(TAG, "onResume");

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
}

From source file:com.nekomeshi312.whiteboardcorrection.CameraViewFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    if (MyDebug.DEBUG)
        Log.d(LOG_TAG, "onViewCreated");

    super.onViewCreated(view, savedInstanceState);
    mTextViewLineDetectErrorMsg = (TextView) mParentActivity.findViewById(R.id.line_detection_error_msg);
    mCameraSurfaceView = (CameraSurfaceView) mParentActivity.findViewById(R.id.camera_surface_view);
    SurfaceHolder holder = mCameraSurfaceView.getHolder();
    holder.addCallback(this);
    if (Build.VERSION.SDK_INT < 11) {
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }//from w  w w. ja v  a2s.  c  om
    mCameraSurfaceView.setCameraPreview(this);
    mWhiteBoardView = (WhiteBoardAreaView) mParentActivity.findViewById(R.id.whiteboard_area_view);
    mWhiteBoardView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            // TODO Auto-generated method stub
            if (mBaseWidth == -1) {
                if (mCameraSetting.isCameraOpen()) {
                    fitChildSize2CamSize();
                }
            }
        }
    });
}

From source file:com.abhi.barcode.frag.libv2.BarcodeFragment.java

@SuppressWarnings("deprecation")
@Override/*w w  w  . java  2s  . c om*/
public void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(this.getActivity(), getView());
    viewfinderView.setCameraManager(cameraManager);

    handler = null;

    resetStatusView();

    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    ambientLightManager.start(cameraManager);
    inactivityTimer.onResume();
    characterSet = null;
}

From source file:com.welcu.android.zxingfragmentlib.BarCodeScannerFragment.java

/**
 * Initializes the camera and viewfinderView.
 *///w  ww.  j  a  v  a  2s.  co  m
public void startScan() {
    if (cameraManager != null) {
        Log.e(TAG, "startScan: scan already started.");
        return;
    }

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(this.getActivity().getApplication(), getView());

    viewfinderView = (ViewfinderView) getView().findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;
    lastResult = null;

    SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (customFramingRect != null) {
        cameraManager.setManualFramingRect(customFramingRect);
    }

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());

    decodeFormats = null;
    characterSet = null;
}

From source file:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java

public void startScan() {
    if (cameraManager != null) {
        Log.e(TAG, "Camera startScan: scan already started.");
        return;//from   w w w .j  ava  2 s  .  c  om
    }
    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(this.getActivity().getApplication(), getView());

    viewfinderView = (ViewfinderView) getView().findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;
    lastResult = null;

    SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (customFramingRect != null) {
        cameraManager.setManualFramingRect(customFramingRect);
    }

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    Log.e(TAG, "Camera:5");
    inactivityTimer.onResume();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());

    decodeFormats = null;
    characterSet = null;
}

From source file:com.github.barcodeeye.scan.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    mCameraManager = new CameraManager(getApplication());
    mViewfinderView.setCameraManager(mCameraManager);

    mHandler = null;/*from ww  w  . ja  v a 2s  .  c o  m*/

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (mHasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }

    mBeepManager.updatePrefs();
    mAmbientLightManager.start(mCameraManager);

    mInactivityTimer.onResume();
}

From source file:piuk.blockchain.android.ui.zxing.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;/*from w  ww.ja v  a  2 s  .c om*/
    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }

    inactivityTimer.onResume();

    Intent intent = getIntent();

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
            decodeHints = DecodeHintManager.parseDecodeHints(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }
        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}