diff --git a/camera/MultiCameraApplication/java/com/intel/multicamera/CameraBase.java b/camera/MultiCameraApplication/java/com/intel/multicamera/CameraBase.java index a9aa89e..67c5931 100644 --- a/camera/MultiCameraApplication/java/com/intel/multicamera/CameraBase.java +++ b/camera/MultiCameraApplication/java/com/intel/multicamera/CameraBase.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.graphics.Camera; import android.graphics.ImageFormat; import android.graphics.Matrix; import android.graphics.RectF; @@ -70,7 +71,7 @@ public class CameraBase implements MediaRecorder.OnErrorListener, MediaRecorder. * An {@link AutoFitTextureView} for camera preview. */ private AutoFitTextureView textureView; - private ImageButton FullScrn, SettingsView, takePictureButton, TakeVideoButton; + private ImageButton FullScrn, SettingsView, takePictureButton, TakeVideoButton, cameraSwitch, cameraSplit; private MediaRecorder mMediaRecorder; private String cameraId; @@ -132,7 +133,7 @@ public CameraBase(Activity activity, AutoFitTextureView mtextureView, ImageButto RoundedThumbnailView roundedThumbnailView) { this.mActivity = activity; this.textureView = mtextureView; - this.ClickListeners(Button[0], Button[1]); + this.ClickListeners(Button[0], Button[1], Button[4], Button[5]); SettingsView = Button[2]; FullScrn = Button[3]; this.settings = PreferenceManager.getDefaultSharedPreferences(activity); @@ -336,10 +337,12 @@ private void showRecordingUI(boolean recording) { } } - private void ClickListeners(ImageButton PictureButton, ImageButton RecordButton) { + private void ClickListeners(ImageButton PictureButton, ImageButton RecordButton, ImageButton CameraSwitch, ImageButton CameraSplit) { TakePicureOnClicked(PictureButton); StartVideoRecording(RecordButton); + CameraSwitch(CameraSwitch); + CameraSplit(CameraSplit); } private void TakePicureOnClicked(ImageButton PictureButton) { @@ -354,6 +357,59 @@ public void onClick(View v) { }); } + private void CameraSwitch(ImageButton CameraSwitch) { + cameraSwitch = CameraSwitch; + if (cameraSwitch == null) return; + + cameraSwitch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + IntelCamera ic_camera = IntelCamera.getInstance(); + if(ic_camera.getWhichCamera() == 0) { + MultiViewActivity Mactivity = (MultiViewActivity) mActivity; + Mactivity.openFrontCamera(); + ic_camera.setWhichCamera(1); + } + else { + System.out.println("shiva open back camera"); + MultiViewActivity Mactivity = (MultiViewActivity) mActivity; + Mactivity.openBackCamera(); + ic_camera.setWhichCamera(0); + } + } + }); + } + + private void CameraSplit(ImageButton cameraSplit) { + cameraSplit = cameraSplit; + if (cameraSplit == null) return; + + cameraSplit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //Toast.makeText(mActivity, "camera split clicked ", Toast.LENGTH_LONG).show(); + IntelCamera ic_camera = IntelCamera.getInstance(); + MultiViewActivity Mactivity = (MultiViewActivity) mActivity; + if(ic_camera.getIsCameraOrSurveillance() == 0){ + Mactivity.startCamera(); + Mactivity.hideCameraSwitchButton(); + ic_camera.setIsCameraOrSurveillance(1); + } + else { + Mactivity.visibleCameraSwitchButton(); + if(ic_camera.getWhichCamera() == 0) { + Mactivity.openBackCamera(); + } + else { + Mactivity.openFrontCamera(); + } + ic_camera.setIsCameraOrSurveillance(0); + } + } + }); + } + private void StartVideoRecording(ImageButton RecordButton) { TakeVideoButton = RecordButton; diff --git a/camera/MultiCameraApplication/java/com/intel/multicamera/IntelCamera.java b/camera/MultiCameraApplication/java/com/intel/multicamera/IntelCamera.java new file mode 100644 index 0000000..df35297 --- /dev/null +++ b/camera/MultiCameraApplication/java/com/intel/multicamera/IntelCamera.java @@ -0,0 +1,40 @@ +package com.intel.multicamera; + +import java.util.ArrayList; +import java.util.HashMap; + +public class IntelCamera { + private static IntelCamera ic_instance = null; + + IntelCamera() { + WhichCamera = 0; + IsCameraOrSurveillance = 0; + } + public static IntelCamera getInstance() { + if (ic_instance == null) { + ic_instance = new IntelCamera(); + } + + return ic_instance; + } + + private int WhichCamera; + + private int IsCameraOrSurveillance; + + public int getWhichCamera() { + return WhichCamera; + } + + public void setWhichCamera(int whichCamera) { + WhichCamera = whichCamera; + } + + public int getIsCameraOrSurveillance() { + return IsCameraOrSurveillance; + } + + public void setIsCameraOrSurveillance(int isCameraOrSurveillance) { + IsCameraOrSurveillance = isCameraOrSurveillance; + } +} diff --git a/camera/MultiCameraApplication/java/com/intel/multicamera/MultiViewActivity.java b/camera/MultiCameraApplication/java/com/intel/multicamera/MultiViewActivity.java index d13f9d8..1a61f6f 100644 --- a/camera/MultiCameraApplication/java/com/intel/multicamera/MultiViewActivity.java +++ b/camera/MultiCameraApplication/java/com/intel/multicamera/MultiViewActivity.java @@ -52,9 +52,10 @@ public class MultiViewActivity extends AppCompatActivity { private AutoFitTextureView mTopLeftCam_textureView, mTopRightCam_textureView, mBotmLeftCam_textureView, mBotmRightCam_textureView; - private ImageButton mTopLeftCam_RecordButton, mTopLeftCam_PictureButton, - mTopRightCam_PictureButton, mBotmLeftCam_PictureButton, mBotmRightCam_PictureButton, - mTopRightCam_RecordButton, mBotmLeftCam_RecordButton, mBotmRightCam_RecordButton; + private ImageButton mTopLeftCam_RecordButton, mTopLeftCam_PictureButton, mTopLeftCam_Switch, mTopLeftCam_Split, + mTopRightCam_PictureButton, mTopRightCam_RecordButton, mTopRightCam_Switch, mTopRightCam_Split, + mBotmLeftCam_PictureButton, mBotmLeftCam_RecordButton, mBotmLeftCam_Switch, mBotmLeftCam_Split, + mBotmRightCam_PictureButton, mBotmRightCam_RecordButton, mBotRightCam_Switch, mBotRightCam_Split; private ImageButton SettingView0, SettingView1, SettingView2, SettingView3, SettingClose0, SettingClose1, SettingClose2, SettingClose3, FullScrn0, FullScrn1, FullScrn2, FullScrn3, @@ -117,8 +118,9 @@ protected void onCreate(Bundle savedInstanceState) { FullScrn_Init(); set_FrameVisibilities(); - - startCamera(); + + openBackCamera(); + IntentFilter filter = new IntentFilter(); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); @@ -174,6 +176,42 @@ void startCamera() { Log.d(TAG, "onResume No CAMERA CONNECTED"); } } + + public void openFrontCamera() { + closeCamera(); + GetCameraCnt(); + updateStorageSpace(null); + + LinearLayout LinLayout1 = findViewById(R.id.TopLayout); + + LinearLayout LinLayout2 = findViewById(R.id.BtmLayout); + + LinLayout1.setVisibility(View.GONE); + LinLayout2.setVisibility(View.GONE); + + frameView1.setVisibility(FrameLayout.GONE); + LinLayout1.setVisibility(View.VISIBLE); + OpenOnlyFrontCamera(); + } + public void openBackCamera() { + closeCamera(); + GetCameraCnt(); + if(numOfCameras == 1) { + findViewById(R.id.camera_switch0).setVisibility(View.GONE); + } + updateStorageSpace(null); + + LinearLayout LinLayout1 = findViewById(R.id.TopLayout); + + LinearLayout LinLayout2 = findViewById(R.id.BtmLayout); + + LinLayout1.setVisibility(View.GONE); + LinLayout2.setVisibility(View.GONE); + + frameView1.setVisibility(FrameLayout.GONE); + LinLayout1.setVisibility(View.VISIBLE); + OpenOnlyBackCamera(); + } private void set_FrameVisibilities() { FrameVisibility = new int[4]; frameView0 = findViewById(R.id.control1); @@ -252,18 +290,23 @@ public void GetCameraCnt() { public void Open_TopLeftCam() { String[] Data = new String[5]; - ImageButton[] Buttons = new ImageButton[4]; + ImageButton[] Buttons = new ImageButton[6]; mTopLeftCam_textureView = findViewById(R.id.textureview0); if (mTopLeftCam_textureView == null) return; + mTopLeftCam_Switch = findViewById(R.id.camera_switch0); + mTopLeftCam_Switch.setVisibility(View.VISIBLE); mTopLeftCam_PictureButton = findViewById(R.id.Picture0); mTopLeftCam_RecordButton = findViewById(R.id.Record0); + mTopLeftCam_Split = findViewById(R.id.camera_split_view0); Buttons[0] = mTopLeftCam_PictureButton; Buttons[1] = mTopLeftCam_RecordButton; Buttons[2] = SettingView0; Buttons[3] = FullScrn0; + Buttons[4] = mTopLeftCam_Switch; + Buttons[5] = mTopLeftCam_Split; mRecordingTimeView = findViewById(R.id.recording_time); @@ -281,17 +324,22 @@ public void Open_TopLeftCam() { public void Open_TopRightCam() { String[] Data = new String[5]; - ImageButton[] Buttons = new ImageButton[4]; + ImageButton[] Buttons = new ImageButton[6]; mTopRightCam_textureView = findViewById(R.id.textureview1); if (mTopRightCam_textureView == null) return; + mTopRightCam_Switch = findViewById(R.id.camera_switch1); + mTopRightCam_Switch.setVisibility(View.VISIBLE); mTopRightCam_PictureButton = findViewById(R.id.Picture1); mTopRightCam_RecordButton = findViewById(R.id.Record1); + mTopRightCam_Split = findViewById(R.id.camera_split_view1); Buttons[0] = mTopRightCam_PictureButton; Buttons[1] = mTopRightCam_RecordButton; Buttons[2] = SettingView1; Buttons[3] = FullScrn1; + Buttons[4] = mTopRightCam_Switch; + Buttons[5] = mTopRightCam_Split; Data[0] = "TopRightCam"; Data[1] = CameraIds[1]; @@ -309,17 +357,21 @@ public void Open_TopRightCam() { public void Open_BotmLeftCam() { String[] Data = new String[5]; - ImageButton[] Buttons = new ImageButton[4]; + ImageButton[] Buttons = new ImageButton[6]; mBotmLeftCam_textureView = findViewById(R.id.textureview2); if (mBotmLeftCam_textureView == null) return; + mBotmLeftCam_Switch = findViewById(R.id.camera_switch2); mBotmLeftCam_PictureButton = findViewById(R.id.Picture2); mBotmLeftCam_RecordButton = findViewById(R.id.Record2); + mBotmLeftCam_Split = findViewById(R.id.camera_split_view2); Buttons[0] = mBotmLeftCam_PictureButton; Buttons[1] = mBotmLeftCam_RecordButton; Buttons[2] = SettingView2; Buttons[3] = FullScrn2; + Buttons[4] = mBotmLeftCam_Switch; + Buttons[5] = mBotmLeftCam_Split; Data[0] = "BotmLeftCam"; Data[1] = CameraIds[2]; @@ -337,17 +389,21 @@ public void Open_BotmLeftCam() { public void Open_BotmRightCam() { String[] Data = new String[5]; - ImageButton[] Buttons = new ImageButton[4]; + ImageButton[] Buttons = new ImageButton[6]; mBotmRightCam_textureView = findViewById(R.id.textureview3); if (mTopRightCam_textureView == null) return; + mBotRightCam_Switch = findViewById(R.id.camera_switch3); mBotmRightCam_PictureButton = findViewById(R.id.Picture3); mBotmRightCam_RecordButton = findViewById(R.id.Record3); + mBotRightCam_Split = findViewById(R.id.camera_split_view3); Buttons[0] = mBotmRightCam_PictureButton; Buttons[1] = mBotmRightCam_RecordButton; Buttons[2] = SettingView3; Buttons[3] = FullScrn3; + Buttons[4] = mBotRightCam_Switch; + Buttons[5] = mBotRightCam_Split; Data[0] = "BotmRightCam"; Data[1] = CameraIds[3]; @@ -362,7 +418,25 @@ public void Open_BotmRightCam() { mBotmRightCam = new CameraBase(this, mBotmRightCam_textureView, Buttons, mRecordingTimeView2, Data, roundedThumbnailView); } + private void OpenOnlyBackCamera() { + frameView0.setVisibility(FrameLayout.VISIBLE); + FrameVisibility[0] = frameView0.getVisibility(); + if (mTopLeftCam == null) { + Open_TopLeftCam(); + } else if (mTopLeftCam_textureView == null) { + mTopLeftCam_textureView = findViewById(R.id.textureview0); + } + if (mTopLeftCam_textureView.isAvailable()) { + mTopLeftCam.textureListener.onSurfaceTextureAvailable( + mTopLeftCam_textureView.getSurfaceTexture(), mTopLeftCam_textureView.getWidth(), + mTopLeftCam_textureView.getHeight()); + } else { + mTopLeftCam_textureView.setSurfaceTextureListener(mTopLeftCam.textureListener); + } + if(numOfCameras > 1) + findViewById(R.id.camera_switch0).setVisibility(View.VISIBLE); + } private void manageTopLeftCam() { frameView0.setVisibility(FrameLayout.VISIBLE); FrameVisibility[0] = frameView0.getVisibility(); @@ -379,8 +453,52 @@ private void manageTopLeftCam() { } else { mTopLeftCam_textureView.setSurfaceTextureListener(mTopLeftCam.textureListener); } + findViewById(R.id.camera_switch0).setVisibility(View.VISIBLE); + } + + private void OpenOnlyFrontCamera() { + frameView0.setVisibility(View.GONE); + frameView1.setVisibility(FrameLayout.VISIBLE); + FrameVisibility[0] = frameView1.getVisibility(); + if (mTopRightCam == null) { + Open_TopRightCam(); + + } else if (mTopRightCam_textureView == null) { + mTopRightCam_textureView = findViewById(R.id.textureview1); + } + + if (mTopRightCam_textureView.isAvailable()) { + mTopRightCam.textureListener.onSurfaceTextureAvailable( + mTopRightCam_textureView.getSurfaceTexture(), + mTopRightCam_textureView.getWidth(), mTopRightCam_textureView.getHeight()); + } else { + mTopRightCam_textureView.setSurfaceTextureListener(mTopRightCam.textureListener); + } } + public void hideCameraSwitchButton() { + findViewById(R.id.camera_switch0).setVisibility(View.GONE); + findViewById(R.id.camera_switch1).setVisibility(View.GONE); + findViewById(R.id.camera_switch2).setVisibility(View.GONE); + findViewById(R.id.camera_switch3).setVisibility(View.GONE); + + findViewById(R.id.imageView0).setVisibility(View.VISIBLE); + findViewById(R.id.imageView1).setVisibility(View.VISIBLE); + findViewById(R.id.imageView2).setVisibility(View.VISIBLE); + findViewById(R.id.imageView3).setVisibility(View.VISIBLE); + + } + public void visibleCameraSwitchButton() { + findViewById(R.id.camera_switch0).setVisibility(View.VISIBLE); + findViewById(R.id.camera_switch1).setVisibility(View.VISIBLE); + findViewById(R.id.camera_switch2).setVisibility(View.VISIBLE); + findViewById(R.id.camera_switch3).setVisibility(View.VISIBLE); + + findViewById(R.id.imageView0).setVisibility(View.GONE); + findViewById(R.id.imageView1).setVisibility(View.GONE); + findViewById(R.id.imageView2).setVisibility(View.GONE); + findViewById(R.id.imageView3).setVisibility(View.GONE); + } private void manageTopRightCam() { frameView1.setVisibility(FrameLayout.VISIBLE); FrameVisibility[1] = frameView1.getVisibility(); @@ -442,8 +560,20 @@ private void manageBotmRightCam() { protected void onResume() { super.onResume(); Log.e(TAG, "onResume"); + IntelCamera ic_cam = IntelCamera.getInstance(); + if(ic_cam.getIsCameraOrSurveillance() == 1){ + startCamera(); + hideCameraSwitchButton(); + } + else { + if(ic_cam.getWhichCamera() == 0) { + openBackCamera(); + } + else { + openFrontCamera(); + } - + } } private void closeCamera() { diff --git a/camera/MultiCameraApplication/res/drawable/camera_switch.png b/camera/MultiCameraApplication/res/drawable/camera_switch.png new file mode 100644 index 0000000..f675aca Binary files /dev/null and b/camera/MultiCameraApplication/res/drawable/camera_switch.png differ diff --git a/camera/MultiCameraApplication/res/drawable/ic_camera_switch.png b/camera/MultiCameraApplication/res/drawable/ic_camera_switch.png new file mode 100644 index 0000000..f180dc9 Binary files /dev/null and b/camera/MultiCameraApplication/res/drawable/ic_camera_switch.png differ diff --git a/camera/MultiCameraApplication/res/drawable/ic_wall_moun_camera.png b/camera/MultiCameraApplication/res/drawable/ic_wall_moun_camera.png new file mode 100644 index 0000000..ef3044f Binary files /dev/null and b/camera/MultiCameraApplication/res/drawable/ic_wall_moun_camera.png differ diff --git a/camera/MultiCameraApplication/res/layout/activity_itscameraintents.xml b/camera/MultiCameraApplication/res/layout/activity_itscameraintents.xml index 3389cdc..dae53bf 100644 --- a/camera/MultiCameraApplication/res/layout/activity_itscameraintents.xml +++ b/camera/MultiCameraApplication/res/layout/activity_itscameraintents.xml @@ -53,6 +53,15 @@ android:orientation="horizontal"> + + + diff --git a/camera/MultiCameraApplication/res/layout/botmleftcam.xml b/camera/MultiCameraApplication/res/layout/botmleftcam.xml index bc24fe1..86d86b3 100644 --- a/camera/MultiCameraApplication/res/layout/botmleftcam.xml +++ b/camera/MultiCameraApplication/res/layout/botmleftcam.xml @@ -69,6 +69,15 @@ android:gravity="bottom|center" android:orientation="horizontal"> + + + + + + + + + + + + diff --git a/camera/MultiCameraApplication/res/layout/toprightcam.xml b/camera/MultiCameraApplication/res/layout/toprightcam.xml index 6498df8..b0e7262 100644 --- a/camera/MultiCameraApplication/res/layout/toprightcam.xml +++ b/camera/MultiCameraApplication/res/layout/toprightcam.xml @@ -68,6 +68,15 @@ android:gravity="bottom|center" android:orientation="horizontal"> + + + + +