Example usage for android.view SurfaceView getHolder

List of usage examples for android.view SurfaceView getHolder

Introduction

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

Prototype

public SurfaceHolder getHolder() 

Source Link

Document

Return the SurfaceHolder providing access and control over this SurfaceView's underlying surface.

Usage

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  ww.j  a  v a 2s.co  m
        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.googlecode.android_scripting.facade.CameraFacade.java

private FutureActivityTask<SurfaceHolder> setPreviewDisplay(Camera camera)
        throws IOException, InterruptedException {
    FutureActivityTask<SurfaceHolder> task = new FutureActivityTask<SurfaceHolder>() {
        @Override//from  w  w  w.  j  a  v a 2  s.  com
        public void onCreate() {
            super.onCreate();
            final SurfaceView view = new SurfaceView(getActivity());
            getActivity().setContentView(view);
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
            view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            view.getHolder().addCallback(new Callback() {
                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                }

                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    setResult(view.getHolder());
                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                }
            });
        }
    };
    FutureActivityTaskExecutor taskQueue = ((BaseApplication) mService.getApplication()).getTaskExecutor();
    taskQueue.execute(task);
    camera.setPreviewDisplay(task.getResult());
    return task;
}

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

@Override
protected void onResume() {
    super.onResume();
    resetStatusView();/*from www  .  j a va 2 s  .c om*/
    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:piuk.blockchain.android.ui.zxing.CaptureActivity.java

@Override
protected void onPause() {

    if (handler != null) {
        handler.quitSynchronously();/* w ww  .ja v  a  2 s  .  c o m*/
        handler = null;
    }
    inactivityTimer.onPause();
    cameraManager.closeDriver();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }

    // Close scanner when going to background
    finish();

    super.onPause();
}

From source file:org.amahi.anywhere.tv.fragment.TvPlaybackVideoFragment.java

private void playVideo() {
    SurfaceView mSurfaceView = getActivity().findViewById(R.id.surfaceView);
    mSurfaceHolder = mSurfaceView.getHolder();
    setVideoHolder();//from   w w  w .ja  v a  2 s  .c  o m
    setLibVlc();

    mediaPlayer = new MediaPlayer(mLibVlc);
    Media media = new Media(mLibVlc, getFileUri());
    mediaPlayer.setMedia(media);
    media.release();

    final IVLCVout vlcVout = mediaPlayer.getVLCVout();
    vlcVout.setVideoView(mSurfaceView);

    manageLayout(vlcVout);

    vlcVout.attachViews();
    mediaPlayer.play();
}

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

public void stopScan() {
    if (cameraManager == null) {
        Log.e(TAG, "stopScan: scan already stopped");
        return;//from   ww  w.j av  a 2 s .  c o m
    }

    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    cameraManager.closeDriver();
    cameraManager = null;

    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
}

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

@Override
protected void onPause() {
    if (mHandler != null) {
        mHandler.quitSynchronously();/*from   w  ww.  j av  a 2s. c  om*/
        mHandler = null;
    }
    mInactivityTimer.onPause();
    mAmbientLightManager.stop();
    mCameraManager.closeDriver();
    if (!mHasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}

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

/**
 * Initializes the camera and viewfinderView.
 *//*w w w .  jav  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: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 w  ww.jav 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:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java

public void startScan() {
    if (cameraManager != null) {
        Log.e(TAG, "Camera startScan: scan already started.");
        return;/*from w  ww . j a v a2 s  .co m*/
    }
    // 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;
}