remember if the last used camera was the front or the back one

This commit is contained in:
tibbi 2016-10-10 19:14:41 +02:00
parent c2e16dcd56
commit 126e626a9c
8 changed files with 14 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.camera;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Camera;
public class Config {
private SharedPreferences mPrefs;
@ -69,4 +70,12 @@ public class Config {
public void setIsSoundEnabled(boolean enabled) {
mPrefs.edit().putBoolean(Constants.SOUND, enabled).apply();
}
public int getLastUsedCamera() {
return mPrefs.getInt(Constants.LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK);
}
public void setLastUsedCamera(int cameraId) {
mPrefs.edit().putInt(Constants.LAST_USED_CAMERA, cameraId).apply();
}
}

View File

@ -14,4 +14,5 @@ public class Constants {
public static final String FORCE_RATIO = "force_ratio";
public static final String MAX_RESOLUTION = "max_resolution";
public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution";
public static final String LAST_USED_CAMERA = "last_used_camera";
}

View File

@ -159,10 +159,11 @@ public class MainActivity extends SimpleActivity
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mCurrCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
mCurrCamera = mConfig.getLastUsedCamera();
mPreview = new Preview(this, (SurfaceView) findViewById(R.id.camera_view), this);
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mViewHolder.addView(mPreview);
mToggleCameraBtn.setImageResource(mCurrCamera == Camera.CameraInfo.CAMERA_FACING_BACK ? R.mipmap.camera_front : R.mipmap.camera_back);
mFocusRectView = new FocusRectView(getApplicationContext());
mViewHolder.addView(mFocusRectView);
@ -214,11 +215,12 @@ public class MainActivity extends SimpleActivity
mCurrCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
}
mConfig.setLastUsedCamera(mCurrCamera);
int newIconId = R.mipmap.camera_front;
mPreview.releaseCamera();
if (mPreview.setCamera(mCurrCamera)) {
if (mCurrCamera == Camera.CameraInfo.CAMERA_FACING_FRONT) {
newIconId = R.mipmap.camera_rear;
newIconId = R.mipmap.camera_back;
}
mToggleCameraBtn.setImageResource(newIconId);
disableFlash();

View File

Before

Width:  |  Height:  |  Size: 377 B

After

Width:  |  Height:  |  Size: 377 B

View File

Before

Width:  |  Height:  |  Size: 266 B

After

Width:  |  Height:  |  Size: 266 B

View File

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 489 B

View File

Before

Width:  |  Height:  |  Size: 745 B

After

Width:  |  Height:  |  Size: 745 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB