List of usage examples for android.hardware Camera getNumberOfCameras
public native static int getNumberOfCameras();
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Orientation listenever implementation myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from www . j a v a2 s . c om*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); // stopService(new Intent(StreamingActivity.this, // BackgroundService.class)); Log.e(TAG, "onCreate"); AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); frameInfo = new FrameInfo(); // openGL overlay overlay = new OverlayController(this); // orientation mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_streaming); // Find the total number of cameras available numberOfCameras = Camera.getNumberOfCameras(); cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); prefEditor = cookies.edit(); setUsername = cookies.getString("Username", "not-set"); setRterCredentials = cookies.getString("RterCreds", "not-set"); if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) { Log.e("PREFS", "Login Not successful, please restart"); } Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not available"); } Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); Log.d(TAG, "Requesting location"); locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); if (provider != null) { Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected. and location " + location); onLocationChanged(location); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); longi = (float) (-73.576254f); Log.d(TAG, "Location not available"); } } // power manager PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire(); // test, set desired orienation to north overlay.letFreeRoam(false); overlay.setDesiredOrientation(0.0f); // CharSequence text = "Tap to start.."; // int duration = Toast.LENGTH_SHORT; // // Toast toast = Toast.makeText(this, text, duration); // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); // toast.show(); }
From source file:com.CloudRecognition.CloudReco.java
private void setSampleAppMenuSettings() { SampleAppMenuGroup group;//from w w w .ja v a 2s . c o m group = mSampleAppMenu.addGroup("", false); group.addTextItem(getString(R.string.close_app), -1); group = mSampleAppMenu.addGroup("", false); group.addTextItem(getString(R.string.menu_back), 6); group = mSampleAppMenu.addGroup("", true); group.addSelectionItem(getString(R.string.menu_extended_tracking), CMD_EXTENDED_TRACKING, false); group.addSelectionItem(getString(R.string.menu_contAutofocus), CMD_AUTOFOCUS, mContAutofocus); mFlashOptionView = group.addSelectionItem(getString(R.string.menu_flash), CMD_FLASH, false); CameraInfo ci = new CameraInfo(); boolean deviceHasFrontCamera = false; boolean deviceHasBackCamera = false; for (int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, ci); if (ci.facing == CameraInfo.CAMERA_FACING_FRONT) deviceHasFrontCamera = true; else if (ci.facing == CameraInfo.CAMERA_FACING_BACK) deviceHasBackCamera = true; } if (deviceHasBackCamera && deviceHasFrontCamera) { group = mSampleAppMenu.addGroup(getString(R.string.menu_camera), true); group.addRadioItem(getString(R.string.menu_camera_front), CMD_CAMERA_FRONT, false); group.addRadioItem(getString(R.string.menu_camera_back), CMD_CAMERA_REAR, true); } mSampleAppMenu.attachMenu(); }
From source file:com.ezartech.ezar.videooverlay.ezAR.java
private int getCameraId(CameraDirection cameraDir) { // Find number of cameras available int numberOfCameras = Camera.getNumberOfCameras(); Log.d(TAG, "Cameras:" + numberOfCameras); // Find ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); int cameraIdToOpen = UNDEFINED; for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); Log.d(TAG, "Camera facing:" + cameraInfo.facing); if (cameraInfo.facing == cameraDir.getDirection()) { cameraIdToOpen = i;//w w w .ja v a 2 s . co m break; } } if (cameraIdToOpen == UNDEFINED) { cameraIdToOpen = numberOfCameras - 1; } return cameraIdToOpen; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private int getNumberCamera() { int camcount; Camera camera = null;/*from ww w .j a va2 s . co m*/ Camera.CameraInfo cameraInfo = new CameraInfo(); camcount = Camera.getNumberOfCameras(); return camcount; }
From source file:org.eypgvnm.camera2api.CameraFragment.java
private void changeCamera() { //get the number of cameras int camerasNumber = Camera.getNumberOfCameras(); if (camerasNumber > 1) { //if the camera preview is the front if (isCameraFront) { closeCamera();/*from ww w .ja va2 s .c o m*/ stopBackgroundThread(); startBackgroundThread(); if (mTextureView.isAvailable()) { openCamera(mTextureView.getWidth(), mTextureView.getHeight()); } else { mTextureView.setSurfaceTextureListener(mSurfaceTextureListener); } isCameraFront = false; } else { mCameraId = getFrontFacingCameraId(); closeCamera(); stopBackgroundThread(); startBackgroundThread(); setUpCameraOutputs(mTextureView.getWidth(), mTextureView.getHeight()); configureTransform(mTextureView.getWidth(), mTextureView.getHeight()); Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } mCameraId = getFrontFacingCameraId(); manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } isCameraFront = true; } } else { ///... } }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub int cameraCount = 0; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras(); for (int camIdx = 0; camIdx < cameraCount; camIdx++) { Camera.getCameraInfo(camIdx, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { try { camera = Camera.open(camIdx); camera.setDisplayOrientation(90); Session.isFacingCamera = true; return; } catch (RuntimeException re) { Logging.d(re.toString()); }/*from ww w . jav a 2s . c o m*/ } } camera = Camera.open(); camera.setDisplayOrientation(90); }
From source file:com.aimfire.demo.CamcorderActivity.java
/** * Opens a camera, and attempts to establish preview mode at the specified width * and height./* w w w . j ava 2s . c om*/ * <p> * Sets mCameraPreviewWidth and mCameraPreviewHeight to the actual width/height * of the preview. */ private boolean openCamera(int desiredFacing, int videoQuality) { if (mCamera != null) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: camera already initialized"); FirebaseCrash.report(new Exception("CamcorderActivity openCamera: camera already initialized")); return false; } final Camera.CameraInfo info = new Camera.CameraInfo(); /* * Try to find camera with desired facing */ int numCameras = Camera.getNumberOfCameras(); if (numCameras == 0) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: No camera found, exiting"); FirebaseCrash.report(new Exception("openCamera: No camera found, exiting")); return false; } mCameraId = -1; for (int i = 0; i < numCameras; i++) { Camera.getCameraInfo(i, info); if (info.facing == desiredFacing) { mCameraId = i; break; } } if (mCameraId == -1) { if (BuildConfig.DEBUG) Log.d(TAG, "openCamera: No camera with desired facing found; opening default"); FirebaseCrash.report(new Exception("openCamera: No camera with desired facing found; opening default")); mCameraId = 0; } try { mCamera = Camera.open(mCameraId); } catch (RuntimeException e) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: cannot open camera!"); FirebaseCrash.report(e); return false; } mCameraOrientation = info.orientation; mCameraFacing = info.facing; mCameraParams = mCamera.getParameters(); CameraUtils.setCamParams(mCameraParams); /* * if we can find a supported video/preview size that's the same as our desired size, * use it. otherwise, use the best quality supported by the camera. */ mSupportedVideoQualities = CameraUtils.getSupportedVideoQualities(); if ((mSupportedVideoQualities & (1 << mQualityPref)) == 0) { if (BuildConfig.DEBUG) Log.d(TAG, "openCamera: desired quality " + mQualityPref + " not supported"); mQualityPref = CameraUtils.getMaxVideoQuality(); /* * since this device doesn't support whatever quality preference we had before, * we save the best quality that it does support */ updateQualityPref(mQualityPref); } mCameraParams.setPreviewSize(MainConsts.VIDEO_DIMENSIONS[mQualityPref][0], MainConsts.VIDEO_DIMENSIONS[mQualityPref][1]); AspectFrameLayout afl = (AspectFrameLayout) findViewById(R.id.cameraPreview_frame); afl.setAspectRatio((float) MainConsts.VIDEO_DIMENSIONS[mQualityPref][0] / (float) MainConsts.VIDEO_DIMENSIONS[mQualityPref][1]); /* * give the camera a hint that we're recording video. this can have a big * impact on frame rate. */ mCameraParams.setRecordingHint(true); /* * disable all the automatic settings, in the hope that frame rate will * be less variable * * TODO: if any of the default modes are not available then we need to * sync it with the remote device */ List<String> modes; modes = mCameraParams.getSupportedFocusModes(); if (modes != null) { for (String mode : modes) { if (mode.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { mCameraParams.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); break; } } } modes = mCameraParams.getSupportedFlashModes(); if (modes != null) { for (String mode : modes) { if (mode.contains(Camera.Parameters.FLASH_MODE_OFF)) { mCameraParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); break; } } } /* modes = mCameraParams.getSupportedWhiteBalance(); if(modes != null) { for(String mode : modes) { if(mode.contains(Camera.Parameters.WHITE_BALANCE_FLUORESCENT)) { mCameraParams.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_FLUORESCENT); break; } } } modes = mCameraParams.getSupportedSceneModes(); if(modes != null) { for(String mode : modes) { if(mode.contains(Camera.Parameters.SCENE_MODE_PORTRAIT)) { mCameraParams.setSceneMode(Camera.Parameters.SCENE_MODE_PORTRAIT); break; } } } */ /* * zoom can impact view angle. we should set it to 0 if it's not */ if (mCameraParams.isZoomSupported()) { int zoom = mCameraParams.getZoom(); if (zoom != 0) { if (BuildConfig.DEBUG) Log.d(TAG, "getViewAngle: camera zoom = " + zoom + ", forcing to zero"); mCameraParams.setZoom(0); } } /* * leave the frame rate set to default */ mCamera.setParameters(mCameraParams); /* int[] fpsRange = new int[2]; mCameraParams.getPreviewFpsRange(fpsRange); String previewFacts = VIDEO_DIMENSIONS[mQualityPref][0] + "x" + VIDEO_DIMENSIONS[mQualityPref][1]; if (fpsRange[0] == fpsRange[1]) { previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps"; } else { previewFacts += " @[" + (fpsRange[0] / 1000.0) + " - " + (fpsRange[1] / 1000.0) + "] fps"; } TextView text = (TextView) findViewById(R.id.cameraParams_text); text.setText(previewFacts); */ if (mNaturalOrientation == Configuration.ORIENTATION_PORTRAIT) { if (((info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) && (mLandscapeOrientation == mCameraOrientation)) || ((info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) && (mLandscapeOrientation != mCameraOrientation))) { mCamera.setDisplayOrientation(180); mCameraOrientation = (mCameraOrientation + 180) % 360; } } if (mOrientationEventListener == null) { mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int deviceOrientation) { if (deviceOrientation == ORIENTATION_UNKNOWN) return; handleOrientationChanged(deviceOrientation); } }; if (mOrientationEventListener.canDetectOrientation()) { mOrientationEventListener.enable(); } } Runnable forceOrientationCalcRunnable = new Runnable() { public void run() { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { int deviceOrientation = mCurrDeviceOrientation; mCurrDeviceOrientation = -1; handleOrientationChanged(deviceOrientation); } }, 100); } }; runOnUiThread(forceOrientationCalcRunnable); return true; }
From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java
private void initializeViews() { ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar == null) throw new AssertionError(); titleView = (ConversationTitleView) supportActionBar.getCustomView(); buttonToggle = ViewUtil.findById(this, R.id.button_toggle); sendButton = ViewUtil.findById(this, R.id.send_button); attachButton = ViewUtil.findById(this, R.id.attach_button); composeText = ViewUtil.findById(this, R.id.embedded_text_editor); charactersLeft = ViewUtil.findById(this, R.id.space_left); emojiDrawerStub = ViewUtil.findStubById(this, R.id.emoji_drawer_stub); unblockButton = ViewUtil.findById(this, R.id.unblock_button); makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button); registerButton = ViewUtil.findById(this, R.id.register_button); composePanel = ViewUtil.findById(this, R.id.bottom_panel); container = ViewUtil.findById(this, R.id.layout_container); reminderView = ViewUtil.findStubById(this, R.id.reminder_stub); unverifiedBannerView = ViewUtil.findStubById(this, R.id.unverified_banner_stub); groupShareProfileView = ViewUtil.findStubById(this, R.id.group_share_profile_view_stub); quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle); inlineAttachmentToggle = ViewUtil.findById(this, R.id.inline_attachment_container); inputPanel = ViewUtil.findById(this, R.id.bottom_panel); searchNav = ViewUtil.findById(this, R.id.conversation_search_nav); ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle); ImageButton inlineAttachmentButton = ViewUtil.findById(this, R.id.inline_attachment_button); container.addOnKeyboardShownListener(this); inputPanel.setListener(this); inputPanel.setMediaListener(this); attachmentTypeSelector = null;/* ww w.j a va 2 s .co m*/ attachmentManager = new AttachmentManager(this, this); audioRecorder = new AudioRecorder(this); typingTextWatcher = new TypingStatusTextWatcher(); SendButtonListener sendButtonListener = new SendButtonListener(); ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener(); composeText.setOnEditorActionListener(sendButtonListener); composeText.setCursorPositionChangedListener(this); attachButton.setOnClickListener(new AttachButtonListener()); attachButton.setOnLongClickListener(new AttachButtonLongClickListener()); sendButton.setOnClickListener(sendButtonListener); sendButton.setEnabled(true); sendButton.addOnTransportChangedListener((newTransport, manuallySelected) -> { calculateCharactersRemaining(); updateLinkPreviewState(); composeText.setTransport(newTransport); buttonToggle.getBackground().setColorFilter(newTransport.getBackgroundColor(), Mode.MULTIPLY); buttonToggle.getBackground().invalidateSelf(); if (manuallySelected) recordTransportPreference(newTransport); }); titleView.setOnClickListener(v -> handleConversationSettings()); titleView.setOnLongClickListener(v -> handleDisplayQuickContact()); titleView.setOnBackClickedListener(view -> super.onBackPressed()); unblockButton.setOnClickListener(v -> handleUnblock()); makeDefaultSmsButton.setOnClickListener(v -> handleMakeDefaultSms()); registerButton.setOnClickListener(v -> handleRegisterForSignal()); composeText.setOnKeyListener(composeKeyPressedListener); composeText.addTextChangedListener(composeKeyPressedListener); composeText.setOnEditorActionListener(sendButtonListener); composeText.setOnClickListener(composeKeyPressedListener); composeText.setOnFocusChangeListener(composeKeyPressedListener); if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) && Camera.getNumberOfCameras() > 0) { quickCameraToggle.setVisibility(View.VISIBLE); quickCameraToggle.setOnClickListener(new QuickCameraToggleListener()); } else { quickCameraToggle.setVisibility(View.GONE); } searchNav.setEventListener(this); inlineAttachmentButton.setOnClickListener(v -> handleAddAttachment()); }
From source file:com.codename1.impl.android.AndroidImplementation.java
public boolean hasCamera() { try {/*from w ww. ja va2 s . co m*/ int numCameras = Camera.getNumberOfCameras(); return numCameras > 0; } catch (Throwable t) { return true; } }