use of android.view.SurfaceHolder in project android-zxing by PearceXu.
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);
}
}
use of android.view.SurfaceHolder in project android_frameworks_base by crdroidandroid.
the class MediaRecorderStressTest method testStressTimeLapse.
// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
SurfaceHolder mSurfaceHolder;
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
Log.v(TAG, "Start camera time lapse stress:");
mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
try {
for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
mOutput.write("No of loop: camera " + i);
for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
// Set callback
mRecorder.setOnErrorListener(mRecorderErrorCallback);
// Set video source
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set camcorder profile for time lapse
CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
mRecorder.setProfile(profile);
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
mRecorder.setCaptureRate(captureRate);
// Set output file
mRecorder.setOutputFile(fileName);
// Set the preview display
Log.v(TAG, "mediaRecorder setPreviewDisplay");
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
// Start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(mSurfaceHolder);
mp.prepare();
mp.start();
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (j == 0) {
mOutput.write(j + 1);
} else {
mOutput.write(String.format(", %d", (j + 1)));
}
}
}
} catch (IllegalStateException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IllegalStateException");
} catch (IOException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IOException");
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test Exception");
}
}
use of android.view.SurfaceHolder in project android_frameworks_base by crdroidandroid.
the class CameraStressTest method testStressCameraZoom.
/**
* Stress test iterating on the range of supported camera zoom levels
*/
@LargeTest
public void testStressCameraZoom() throws Exception {
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
if (!params.isSmoothZoomSupported() && !params.isZoomSupported()) {
Log.v(TAG, "Device camera does not support zoom");
fail("Camera zoom stress test failed due to unsupported feature");
} else {
Log.v(TAG, "Device camera does support zoom");
Log.v(TAG, "Start preview");
mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
mOutput.write("No of loops: ");
int nextZoomLevel = 0;
for (int i = 0; i < NUMBER_OF_ZOOM_LOOPS; i++) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
mCameraTestHelper.startCameraPreview(surfaceHolder);
params = mCameraTestHelper.mCamera.getParameters();
int currentZoomLevel = params.getZoom();
if (nextZoomLevel >= params.getMaxZoom()) {
nextZoomLevel = 0;
}
++nextZoomLevel;
if (params.isSmoothZoomSupported()) {
mCameraTestHelper.mCamera.startSmoothZoom(nextZoomLevel);
} else {
params.setZoom(nextZoomLevel);
mCameraTestHelper.setParameters(params);
}
mCameraTestHelper.capturePhoto();
if (i == 0) {
mOutput.write(Integer.toString(i));
} else {
mOutput.write(", " + i);
}
}
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera zoom stress test Exception");
}
}
use of android.view.SurfaceHolder in project android_frameworks_base by crdroidandroid.
the class CameraStressTest method testStressCameraSceneModes.
/**
* Stress test iterating on the various scene modes (action, night, party, etc.)
*/
@LargeTest
public void testStressCameraSceneModes() throws Exception {
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
List<String> supportedSceneModes = params.getSupportedSceneModes();
assertNotNull("No scene modes supported", supportedSceneModes);
mOutput.write("Total number of loops: " + (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
Log.v(TAG, "Start preview");
mOutput.write("No of loop: ");
for (int i = 0; i < supportedSceneModes.size(); i++) {
for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
Log.v(TAG, "Setting scene mode to " + supportedSceneModes.get(i));
params.setSceneMode(supportedSceneModes.get(i));
mCameraTestHelper.setParameters(params);
mCameraTestHelper.startCameraPreview(surfaceHolder);
mCameraTestHelper.capturePhoto();
if (i == 0 && j == 0) {
mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
} else {
mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
}
}
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera scene mode test Exception");
}
}
use of android.view.SurfaceHolder in project smartmodule by carozhu.
the class CaptureActivity method onPause.
/**
* 暂停活动监控器,关闭摄像头
*/
@Override
protected void onPause() {
super.onPause();
if (mHandler != null) {
mHandler.quitSynchronously();
mHandler = null;
}
// 暂停活动监控器
inactivityTimer.onPause();
// 关闭摄像头
cameraManager.closeDriver();
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.removeCallback(this);
}
}
Aggregations