Skip to content

Commit 126e626

Browse files
committed
remember if the last used camera was the front or the back one
1 parent c2e16dc commit 126e626

8 files changed

Lines changed: 14 additions & 2 deletions

File tree

app/src/main/java/com/simplemobiletools/camera/Config.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.SharedPreferences;
5+
import android.hardware.Camera;
56

67
public class Config {
78
private SharedPreferences mPrefs;
@@ -69,4 +70,12 @@ public boolean getIsSoundEnabled() {
6970
public void setIsSoundEnabled(boolean enabled) {
7071
mPrefs.edit().putBoolean(Constants.SOUND, enabled).apply();
7172
}
73+
74+
public int getLastUsedCamera() {
75+
return mPrefs.getInt(Constants.LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK);
76+
}
77+
78+
public void setLastUsedCamera(int cameraId) {
79+
mPrefs.edit().putInt(Constants.LAST_USED_CAMERA, cameraId).apply();
80+
}
7281
}

app/src/main/java/com/simplemobiletools/camera/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public class Constants {
1414
public static final String FORCE_RATIO = "force_ratio";
1515
public static final String MAX_RESOLUTION = "max_resolution";
1616
public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution";
17+
public static final String LAST_USED_CAMERA = "last_used_camera";
1718
}

app/src/main/java/com/simplemobiletools/camera/activities/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ private void initializeCamera() {
159159
setContentView(R.layout.activity_main);
160160
ButterKnife.bind(this);
161161

162-
mCurrCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
162+
mCurrCamera = mConfig.getLastUsedCamera();
163163
mPreview = new Preview(this, (SurfaceView) findViewById(R.id.camera_view), this);
164164
mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
165165
mViewHolder.addView(mPreview);
166+
mToggleCameraBtn.setImageResource(mCurrCamera == Camera.CameraInfo.CAMERA_FACING_BACK ? R.mipmap.camera_front : R.mipmap.camera_back);
166167

167168
mFocusRectView = new FocusRectView(getApplicationContext());
168169
mViewHolder.addView(mFocusRectView);
@@ -214,11 +215,12 @@ public void toggleCamera() {
214215
mCurrCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
215216
}
216217

218+
mConfig.setLastUsedCamera(mCurrCamera);
217219
int newIconId = R.mipmap.camera_front;
218220
mPreview.releaseCamera();
219221
if (mPreview.setCamera(mCurrCamera)) {
220222
if (mCurrCamera == Camera.CameraInfo.CAMERA_FACING_FRONT) {
221-
newIconId = R.mipmap.camera_rear;
223+
newIconId = R.mipmap.camera_back;
222224
}
223225
mToggleCameraBtn.setImageResource(newIconId);
224226
disableFlash();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)