Search in sources :

Example 31 with SurfaceHolder

use of android.view.SurfaceHolder in project QRCode by 5peak2me.

the class CaptureActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    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;
    }
    initBeepSound();
    vibrate = true;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) AudioManager(android.media.AudioManager) SurfaceView(android.view.SurfaceView)

Example 32 with SurfaceHolder

use of android.view.SurfaceHolder in project QRCode by 5peak2me.

the class CaptureActivity method onResume.

@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.
    // 相机初始化的动作需要开启相机并测量屏幕大小,这些操作
    // 不建议放到onCreate中,因为如果在onCreate中加上首次启动展示帮助信息的代码的 话,
    // 会导致扫描窗口的尺寸计算有误的bug
    cameraManager = new CameraManager(getApplication());
    viewfinderView = (ViewfinderView) findViewById(R.id.capture_viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    handler = null;
    lastResult = null;
    // 摄像头预览功能必须借助SurfaceView,因此也需要在一开始对其进行初始化
    // 如果需要了解SurfaceView的原理
    // 参考:http://blog.csdn.net/luoshengyang/article/details/8661317
    // 预览
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.capture_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 {
        // 防止sdk8的设备初始化预览异常
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }
    // 加载声音配置,其实在BeemManager的构造器中也会调用该方法,即在onCreate的时候会调用一次
    beepManager.updatePrefs();
    // 启动闪光灯调节器
    ambientLightManager.start(cameraManager);
    // 恢复活动监控器
    inactivityTimer.onResume();
    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CameraManager(com.google.zxing.camera.CameraManager) SurfaceView(android.view.SurfaceView)

Example 33 with SurfaceHolder

use of android.view.SurfaceHolder in project zxing by zxing.

the class CaptureActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    // historyManager must be initialized here to update the history preference
    historyManager = new HistoryManager(this);
    historyManager.trimHistory();
    // 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);
    resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);
    handler = null;
    lastResult = null;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
        setRequestedOrientation(getCurrentOrientation());
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }
    resetStatusView();
    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);
    inactivityTimer.onResume();
    Intent intent = getIntent();
    copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));
    source = IntentSource.NONE;
    sourceUrl = null;
    scanFromWebPageManager = null;
    decodeFormats = null;
    characterSet = null;
    if (intent != null) {
        String action = intent.getAction();
        String dataString = intent.getDataString();
        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);
                }
            }
            if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
                int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
                if (cameraId >= 0) {
                    cameraManager.setManualCameraId(cameraId);
                }
            }
            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }
        } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) {
            // Scan only products and send the result to mobile Product Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;
        } else if (isZXingURL(dataString)) {
            // Scan formats requested in query string (all formats if none specified).
            // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(dataString);
            scanFromWebPageManager = new ScanFromWebPageManager(inputUri);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
            // Allow a sub-set of the hints to be specified by the caller.
            decodeHints = DecodeHintManager.parseDecodeHints(inputUri);
        }
        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
    }
    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);
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SharedPreferences(android.content.SharedPreferences) HistoryManager(com.google.zxing.client.android.history.HistoryManager) CameraManager(com.google.zxing.client.android.camera.CameraManager) Intent(android.content.Intent) Uri(android.net.Uri) Paint(android.graphics.Paint) ResultPoint(com.google.zxing.ResultPoint) SurfaceView(android.view.SurfaceView)

Example 34 with SurfaceHolder

use of android.view.SurfaceHolder in project android_frameworks_base by DirtyUnicorns.

the class SurfaceHolderTarget method onBindToView.

@Override
public void onBindToView(View view) {
    if (view instanceof SurfaceView) {
        SurfaceHolder holder = ((SurfaceView) view).getHolder();
        if (holder == null) {
            throw new RuntimeException("Could not get SurfaceHolder from SurfaceView " + view + "!");
        }
        setSurfaceHolder(holder);
    } else {
        throw new IllegalArgumentException("View must be a SurfaceView!");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 35 with SurfaceHolder

use of android.view.SurfaceHolder in project android_frameworks_base by DirtyUnicorns.

the class CameraFunctionalTest method testFunctionalCameraFocusModes.

/**
     * Functional test iterating on the various focus modes (auto, infinitiy, macro, etc.)
     */
@LargeTest
public void testFunctionalCameraFocusModes() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        List<String> supportedFocusModes = params.getSupportedFocusModes();
        assertNotNull("No focus modes supported", supportedFocusModes);
        for (int i = 0; i < supportedFocusModes.size(); i++) {
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mCameraTestHelper.setupCameraTest();
                }
            });
            Log.v(TAG, "Setting focus mode to: " + supportedFocusModes.get(i));
            params.setFocusMode(supportedFocusModes.get(i));
            mCameraTestHelper.setParameters(params);
            mCameraTestHelper.startCameraPreview(surfaceHolder);
            mCameraTestHelper.capturePhoto();
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera focus modes test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)189 SurfaceView (android.view.SurfaceView)62 LargeTest (android.test.suitebuilder.annotation.LargeTest)50 Parameters (android.hardware.Camera.Parameters)37 IOException (java.io.IOException)29 MediaPlayer (android.media.MediaPlayer)17 Surface (android.view.Surface)16 SurfaceTexture (android.graphics.SurfaceTexture)14 CamcorderProfile (android.media.CamcorderProfile)13 MediaRecorder (android.media.MediaRecorder)13 Camera (android.hardware.Camera)9 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)9 Paint (android.graphics.Paint)8 AudioManager (android.media.AudioManager)8 SharedPreferences (android.content.SharedPreferences)7 MediaVideoItem (android.media.videoeditor.MediaVideoItem)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 Intent (android.content.Intent)6 VideoEditor (android.media.videoeditor.VideoEditor)6 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)6