Java Code Examples for android.view.SurfaceView

The following examples show how to use android.view.SurfaceView. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: sealtalk-android   Source File: MultiVideoCallActivity.java    License: MIT License 6 votes vote down vote up
void addRemoteVideo(View singleRemoteView, SurfaceView video, String userId) {
        if (singleRemoteView == null)
            return;
        FrameLayout remoteVideoView = (FrameLayout) singleRemoteView.findViewById(R.id.viewlet_remote_video_user);
        remoteVideoView.removeAllViews();
        if (video.getParent() != null) {
            ((ViewGroup) video.getParent()).removeView(video);
        }
        remoteVideoView.addView(video, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
//        TextView remoteNameTextView = new TextView(this);
//        TextView tv = (TextView) singleRemoteView.findViewById(R.id.user_name);
//        ViewGroup.LayoutParams params = tv.getLayoutParams();
//        remoteNameTextView.setLayoutParams(params);
//        remoteNameTextView.setTextAppearance(this, R.style.rc_voip_text_style_style);
//        UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(userId);
//        if (userInfo != null) {
//            remoteNameTextView.setText(userInfo.getName());
//        } else {
//            remoteNameTextView.setText(userId);
//        }
//        remoteVideoView.addView(remoteNameTextView);
        remoteVideoView.setVisibility(View.VISIBLE);
        remoteVideoView.setTag(userId);
    }
 
Example 2
@Override
protected void onPause() {
    super.onPause();
    Log.v(TAG, "onPause()");

    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }

    cameraManager.closeDriver();

    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
}
 
Example 3
Source Project: goprohero   Source File: LiveStuffH4.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up a full-screen black window.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = getWindow();
    window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    window.setBackgroundDrawableResource(android.R.color.black);

    setContentView(R.layout.activity_live_stuff);

    // Configure the view that renders live video.
    SurfaceView surfaceView =
            (SurfaceView) findViewById(R.id.surfaceView);
    _surfaceHolder = surfaceView.getHolder();
    _surfaceHolder.addCallback(this);
    _surfaceHolder.setFixedSize(320, 240);
}
 
Example 4
Source Project: QrScan   Source File: CaptureActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 初始化照相机和surfaceView,使zxing不断尝试从摄像头获取照片并解码
 * 本方法在Activity的onResume中,以及在扫描功能被关闭后需要再次开启时调用
 */
private void initZXingCamera() {
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }

    vibrate = true;
}
 
Example 5
Source Project: grafika   Source File: PlayMovieSurfaceActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getContentViewId());

    mSurfaceView = (SurfaceView) findViewById(R.id.playMovie_surface);
    mSurfaceView.getHolder().addCallback(this);

    // Populate file-selection spinner.
    Spinner spinner = (Spinner) findViewById(R.id.playMovieFile_spinner);
    // Need to create one of these fancy ArrayAdapter thingies, and specify the generic layout
    // for the widget itself.
    mMovieFiles = MiscUtils.getFiles(getFilesDir(), "*.mp4");
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mMovieFiles);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    updateControls();
}
 
Example 6
Source Project: open-quartz   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.surface_view);

    /** View for OpenCV **/
    mOpenCvCameraView = (OGView) findViewById(R.id.tutorial3_activity_java_surface_view);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);

    /** Gesture for Glass **/
    mGestureDetector = new GestureDetector(this, this);
}
 
Example 7
Source Project: opencv-android-sample   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);

    // Load ndk built module, as specified
    // in moduleName in build.gradle
    System.loadLibrary("native");

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camera_view);

    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

    mOpenCvCameraView.setCvCameraViewListener(this);
}
 
Example 8
@Override
public void surfaceCreated(SurfaceHolder holder) {
    Log.d(TAG, "surfaceCreated holder=" + holder);

    File outputFile = new File(getFilesDir(), "fbo-gl-recording.mp4");
    SurfaceView sv = (SurfaceView) findViewById(R.id.fboActivity_surfaceView);
    mRenderThread = new RenderThread(sv.getHolder(), new ActivityHandler(this), outputFile,
            MiscUtils.getDisplayRefreshNsec(this));
    mRenderThread.setName("RecordFBO GL render");
    mRenderThread.start();
    mRenderThread.waitUntilReady();
    mRenderThread.setRecordMethod(mSelectedRecordMethod);

    RenderHandler rh = mRenderThread.getHandler();
    if (rh != null) {
        rh.sendSurfaceCreated();
    }

    // start the draw events
    Choreographer.getInstance().postFrameCallback(this);
}
 
Example 9
Source Project: media-samples   Source File: ScreenCaptureFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    mSurfaceView = (SurfaceView) view.findViewById(R.id.surface);
    mSurface = mSurfaceView.getHolder().getSurface();
    mButtonToggle = (Button) view.findViewById(R.id.toggle);
    mButtonToggle.setOnClickListener(this);
}
 
Example 10
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mSurfaceView = new SurfaceView(this);
    mSurfaceView.setOnClickListener(this);
    setContentView(mSurfaceView);
}
 
Example 11
Source Project: media-samples   Source File: LocalPlayer.java    License: Apache License 2.0 5 votes vote down vote up
public SurfaceViewPlayer(Context context) {
    super(context);

    mLayout = (FrameLayout)((Activity)context).findViewById(R.id.player);
    mSurfaceView = (SurfaceView)((Activity)context).findViewById(R.id.surface_view);

    // add surface holder callback
    SurfaceHolder holder = mSurfaceView.getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(this);
}
 
Example 12
Source Project: NIM_Android_UIKit   Source File: WatchVideoActivity.java    License: MIT License 5 votes vote down vote up
private void findViews() {
    downloadLayout = findViewById(R.id.layoutDownload);
    downloadProgressBackground = findViewById(R.id.downloadProgressBackground);
    downloadProgressForeground = findViewById(R.id.downloadProgressForeground);
    downloadProgressText = (TextView) findViewById(R.id.downloadProgressText);
    videoIcon = findViewById(R.id.videoIcon);

    surfaceView = (SurfaceView) findViewById(R.id.videoView);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceHolder.addCallback(this);

    playTimeTextView = (TextView) findViewById(R.id.lblVideoTimes);
    playTimeTextView.setVisibility(View.INVISIBLE);
    fileInfoTextView = (TextView) findViewById(R.id.lblVideoFileInfo);
    playTimeTextView.setVisibility(View.INVISIBLE);

    downloadBtn = (ImageView) findViewById(R.id.control_download_btn);
    downloadBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (downloading) {
                stopDownload();
            } else {
                download();
            }
            downloadBtn.setImageResource(downloading ? R.drawable.nim_icon_download_pause : R.drawable.nim_icon_download_resume);
        }
    });

    actionBar = getSupportActionBar();
}
 
Example 13
Source Project: ETSMobile-Android2   Source File: MapActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    surfaceView = (SurfaceView) findViewById(R.id.activity_map_surfaceView);
    resetBtn = (ImageButton) findViewById(R.id.activity_map_reset);
    zoomBtn = (ImageButton) findViewById(R.id.activity_map_zoom);

}
 
Example 14
public CameraSourcePreview(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mStartRequested = false;
    mSurfaceAvailable = false;

    mSurfaceView = new SurfaceView(context);
    mSurfaceView.getHolder().addCallback(new SurfaceCallback());
    addView(mSurfaceView);
}
 
Example 15
Source Project: android-chromium   Source File: UiUtils.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void prepareViewHierarchyForScreenshot(View view, boolean takingScreenshot) {
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            prepareViewHierarchyForScreenshot(viewGroup.getChildAt(i), takingScreenshot);
        }
    } else if (view instanceof SurfaceView) {
        view.setWillNotDraw(!takingScreenshot);
    }
}
 
Example 16
Source Project: QrScan   Source File: CaptureActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 重新启动扫描
 */
public void restartCamera() {
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    initCamera(surfaceHolder);
    if (handler != null) {
        handler.restartPreviewAndDecode();
    }
}
 
Example 17
Source Project: Vitamio   Source File: MediaPlayerSubtitle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if (!LibsChecker.checkVitamioLibs(this))
		return;
	setContentView(R.layout.subtitle1);
	tv = (TextView) findViewById(R.id.sub1);
	splayer = (SurfaceView) findViewById(R.id.surface);
	sholder = splayer.getHolder();
	sholder.setFormat(PixelFormat.RGBA_8888);
	sholder.addCallback(this);
}
 
Example 18
Source Project: DeviceConnect-Android   Source File: RTSPPlayerActivity.java    License: MIT License 5 votes vote down vote up
private void changePlayerSize(int pictureWidth, int pictureHeight) {
    View root = findViewById(R.id.root);
    SurfaceView surfaceView = findViewById(R.id.surface_view);

    Size changeSize;
    Size viewSize = new Size(root.getWidth(), root.getHeight());
    changeSize = calculateViewSize(pictureWidth, pictureHeight, viewSize);

    ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams();
    layoutParams.width = changeSize.getWidth();
    layoutParams.height = changeSize.getHeight();
    surfaceView.setLayoutParams(layoutParams);
}
 
Example 19
Source Project: Questor   Source File: CameraSource.java    License: MIT License 5 votes vote down vote up
/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }

        mCamera = createCamera();

        // SurfaceTexture was introduced in Honeycomb (11), so if we are running and
        // old version of Android. fall back to use SurfaceView.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
            mCamera.setPreviewTexture(mDummySurfaceTexture);
        } else {
            mDummySurfaceView = new SurfaceView(mContext);
            mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
        }
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 20
Source Project: coursera-android   Source File: AudioVideoCameraActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	mFrame = (LinearLayout) findViewById(R.id.frame);

	// Disable touches on mFrame
	mFrame.setEnabled(false);

	// Setup touch listener for taking pictures
	mFrame.setOnTouchListener(new View.OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {

			// Only respond to ACTION_UP
			if (event.getActionMasked() == (MotionEvent.ACTION_UP)) {

				// Take picture
				// Pass in shutterCallback and PictureCallback Objects
				mCamera.takePicture(mShutterCallback, null,
						mPictureCallback);

			}

			return true;
		}
	});

	// Setup SurfaceView for previewing camera image
	SurfaceView surfaceView = (SurfaceView) findViewById(R.id.cameraView);

	// Get SurfaceHolder for accessing the SurfaceView's Surface
	mSurfaceHolder = surfaceView.getHolder();

	// Set callback Object for the SurfaceHolder
	mSurfaceHolder.addCallback(mSurfaceHolderCallback);

}
 
Example 21
@Override
protected void onResume() {
    super.onResume();
    Log.v(TAG, "onResume()");

    // CameraManager must be initialized here, not in onCreate().
    if (cameraManager == null) cameraManager = new CameraManager(getApplication());

    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);
    }
}
 
Example 22
Source Project: grafika   Source File: HardwareScalerActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * onClick handler for radio buttons.
 */
public void onRadioButtonClicked(View view) {
    int newSize;

    RadioButton rb = (RadioButton) view;
    if (!rb.isChecked()) {
        Log.d(TAG, "Got click on non-checked radio button");
        return;
    }

    switch (rb.getId()) {
        case R.id.surfaceSizeTiny_radio:
            newSize = SURFACE_SIZE_TINY;
            break;
        case R.id.surfaceSizeSmall_radio:
            newSize = SURFACE_SIZE_SMALL;
            break;
        case R.id.surfaceSizeMedium_radio:
            newSize = SURFACE_SIZE_MEDIUM;
            break;
        case R.id.surfaceSizeFull_radio:
            newSize = SURFACE_SIZE_FULL;
            break;
        default:
            throw new RuntimeException("Click from unknown id " + rb.getId());
    }
    mSelectedSize = newSize;

    int[] wh = mWindowWidthHeight[newSize];

    // Update the Surface size.  This causes a "surface changed" event, but does not
    // destroy and re-create the Surface.
    SurfaceView sv = (SurfaceView) findViewById(R.id.hardwareScaler_surfaceView);
    SurfaceHolder sh = sv.getHolder();
    Log.d(TAG, "setting size to " + wh[0] + "x" + wh[1]);
    sh.setFixedSize(wh[0], wh[1]);
}
 
Example 23
Source Project: sealtalk-android   Source File: MultiVideoCallActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
    //incoming状态,localViewUserId为空
    if (localViewUserId == null)
        return;
    if (localViewUserId.equals(userId)) {
        localViewContainer.removeAllViews();
        String currentUserId = RongIMClient.getInstance().getCurrentUserId();
        FrameLayout remoteVideoView = (FrameLayout) remoteViewContainer.findViewWithTag(currentUserId);
        localView = (SurfaceView) remoteVideoView.getChildAt(0);
        remoteVideoView.removeAllViews();
        localViewContainer.addView(localView);
        TextView topUserNameView = (TextView) topContainer.findViewById(R.id.rc_voip_user_name);
        UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(currentUserId);
        if (userInfo != null) {
            topUserNameView.setText(userInfo.getName());
        } else {
            topUserNameView.setText(currentUserId);
        }
        localViewUserId = currentUserId;
    }

    View singleRemoteView = remoteViewContainer.findViewWithTag(userId + "view");

    if (singleRemoteView == null)
        return;

    LinearLayout container = (LinearLayout) singleRemoteView.getParent();
    container.removeView(singleRemoteView);
    if (container.equals(remoteViewContainer2)) {
        if (remoteViewContainer1.getChildCount() > 0) {
            View childView = remoteViewContainer1.getChildAt(0);
            remoteViewContainer1.removeView(childView);
            remoteViewContainer2.addView(childView);
        }
    }
}
 
Example 24
Source Project: Camdroid   Source File: ProcessFramesView.java    License: Apache License 2.0 5 votes vote down vote up
private void initView(Context context) {
    Log.d(TAG, "initView()");

    this.setBackgroundColor(this.getResources().getColor(
            android.R.color.black));

    SurfaceView view = new SurfaceView(context);
    view.setWillNotDraw(false);

    this.addView(view, 0);

    SurfaceHolder holder = view.getHolder();
    holder.addCallback(this);
}
 
Example 25
Source Project: OpenCV-AndroidSamples   Source File: Tutorial1Activity.java    License: MIT License 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_tutorial1);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);

    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

    mOpenCvCameraView.setCvCameraViewListener(this);
}
 
Example 26
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);
    validateCameraPermission();
    classifier = initClassifier();
    imageSaver = new ImageSaver();
    imageSaver.createFolderIfNotExist();
    mOpenCvCameraView= findViewById(R.id.cameraView1);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);

}
 
Example 27
Source Project: apollo-DuerOS   Source File: CarlifeActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EncryptSetupManager.getInstance();

    LogUtil.d(TAG, "onCreate");
    mTimeCarlifeStart = SystemClock.elapsedRealtime();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    mRootView = (ViewGroup) findViewById(R.id.main_root_view);
    PreferenceUtil.getInstance().init(this);
    mCarLifeFragmentManager = new CarLifeFragmentManager(this);
    // initialize basefragment, must be called before using it's subclass
    BaseFragment.initBeforeAll(this);
    mCarLifeFragmentManager.showFragment(LaunchFragment.getInstance());
    mSurfaceView = (SurfaceView) findViewById(R.id.main_video_surface_view);
    mSurfaceView.getHolder().addCallback(this);
    mMainActivityHandler = new MsgMainActivityHandler();

    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    MsgHandlerCenter.registerMessageHandler(mMainActivityHandler);
    ErrorCodeReport.getInterface().init(this);
    mMainActivityHandler.sendEmptyMessageDelayed(CommonParams.MSG_CONNECT_INIT, 500);
    ControlTestWindow.getInstance().init(this, mRootView);
    SettingAboutWindow.getInstance().init(this, mRootView);

    initLaunchMode(getIntent());
    mTimeCarlifeInit = SystemClock.elapsedRealtime();
    LogUtil.d(TAG, "-QA_Test- OnCreate_InitTime = " + (mTimeCarlifeInit - mTimeCarlifeStart));

    DebugLogUtil.getInstance().init(this);
}
 
Example 28
Source Project: Fatigue-Detection   Source File: EGLBase.java    License: MIT License 5 votes vote down vote up
EglSurface(final EGLBase egl, final Object surface) {
	if (DEBUG) Log.v(TAG, "EglSurface:");
	if (!(surface instanceof SurfaceView)
		&& !(surface instanceof Surface)
		&& !(surface instanceof SurfaceHolder)
		&& !(surface instanceof SurfaceTexture))
		throw new IllegalArgumentException("unsupported surface");
	mEgl = egl;
	mEglSurface = mEgl.createWindowSurface(surface);
       mWidth = mEgl.querySurface(mEglSurface, EGL14.EGL_WIDTH);
       mHeight = mEgl.querySurface(mEglSurface, EGL14.EGL_HEIGHT);
       if (DEBUG) Log.v(TAG, String.format("EglSurface:size(%d,%d)", mWidth, mHeight));
}
 
Example 29
public CameraSourcePreview(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mStartRequested = false;
    mSurfaceAvailable = false;

    mSurfaceView = new SurfaceView(context);
    mSurfaceView.getHolder().addCallback(new SurfaceCallback());
    addView(mSurfaceView);
}
 
Example 30
Source Project: barterli_android   Source File: ScanIsbnActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Stop scanning for a barcode, and release the camera
 */
private void stopScanningForBarcode() {
    if (mDecoderActivityHandler != null) {
        mDecoderActivityHandler.quitSynchronously();
        mDecoderActivityHandler = null;
    }

    mCameraManager.closeDriver();

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