Skip to content

Commit d31a3c1

Browse files
author
Noel Algora
committed
camera activity fixes
1 parent bec970e commit d31a3c1

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

app/src/main/java/d2d/testing/CameraActivity.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ else if (mVideoMode && availableFocusModes.contains(Camera.Parameters.FOCUS_MODE
137137
mCurrentFocus = Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO;
138138
else if (availableFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
139139
mCurrentFocus = Camera.Parameters.FOCUS_MODE_AUTO;
140+
else if (availableFocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED))
141+
mCurrentFocus = Camera.Parameters.FOCUS_MODE_FIXED;
142+
else if (availableFocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY))
143+
mCurrentFocus = Camera.Parameters.FOCUS_MODE_INFINITY;
144+
else if (availableFocusModes.contains(Camera.Parameters.FOCUS_MODE_EDOF))
145+
mCurrentFocus = Camera.Parameters.FOCUS_MODE_EDOF;
140146
}
141147
params.setFocusMode(mCurrentFocus);
142148

@@ -149,6 +155,27 @@ public void setButtonsRotation(int rotation) {
149155
btnSwitchVideo.setRotation(rotation);
150156
}
151157

158+
public void updateButtonsStatus() {
159+
if(mVideoMode)
160+
{
161+
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(android.R.color.holo_red_dark)));
162+
if(mRecording)
163+
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_stop));
164+
else
165+
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_video_camera));
166+
167+
btnSwitchVideo.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_camera));
168+
btnSwitchCamera.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_switch_camera));
169+
btnSwitchCamera.refreshDrawableState();
170+
} else {
171+
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorCameraButton)));
172+
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_camera));
173+
btnSwitchVideo.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_video_camera));
174+
btnSwitchCamera.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_switch_camera));
175+
btnSwitchCamera.refreshDrawableState();
176+
}
177+
}
178+
152179
@Override
153180
protected void onPause() {
154181
super.onPause();
@@ -249,11 +276,6 @@ public void onSwitchCamera (View view){
249276
mPreview.setCamera(mCamera);
250277
}
251278

252-
private Camera.Parameters setDefaultFlashMode(Camera.Parameters params, List<String> flashModes) {
253-
params.setFlashMode(FLASH_OPTIONS[mCurrentFlash]);
254-
return params;
255-
}
256-
257279
public void onCapture(View view){
258280
if(!mVideoMode){
259281
mCamera.takePicture(null, null, mPictureCallback);
@@ -266,11 +288,9 @@ public void onCapture(View view){
266288
Logger.d("Exception stopping MediaRecorder: " + e.toString());
267289
}
268290
mStreamWorker.stop();
269-
270-
//btnSwitchMode.setEnabled(false);
271-
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(android.R.color.holo_red_dark)));
272-
btnCapture.setImageDrawable(null);
273291
mRecording = false;
292+
293+
updateButtonsStatus();
274294
}else{
275295
try {
276296
prepareVideoRecorder();
@@ -279,30 +299,17 @@ public void onCapture(View view){
279299
Logger.d("Exception starting MediaRecorder: " + e.toString());
280300
}
281301
mStreamWorker.start();
282-
283-
//btnSwitchMode.setEnabled(true);
284-
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorCameraButton)));
285-
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_stop));
286302
mRecording = true;
303+
304+
updateButtonsStatus();
287305
}
288306
}
289307
}
290308

291309
public void onSwitchMode(View view){
292-
if(mVideoMode)
293-
{
294-
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorCameraButton)));
295-
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_camera));
296-
btnSwitchVideo.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_video_camera));
297-
btnSwitchCamera.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_switch_camera));
298-
mVideoMode = false;
299-
} else {
300-
btnCapture.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(android.R.color.holo_red_dark)));
301-
btnCapture.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_video_camera));
302-
btnSwitchVideo.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_camera));
303-
btnSwitchCamera.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_switch_camera));
304-
mVideoMode = true;
305-
}
310+
mVideoMode = !mVideoMode;
311+
312+
updateButtonsStatus();
306313
}
307314

308315
private boolean prepareVideoRecorder(){

0 commit comments

Comments
 (0)