Skip to content

Commit c9537ec

Browse files
committed
fix #56, add a toggle for enabling front camera photo flipping
1 parent 02978b8 commit c9537ec

19 files changed

Lines changed: 59 additions & 0 deletions

File tree

app/src/main/kotlin/com/simplemobiletools/camera/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class Config(context: Context) : BaseConfig(context) {
4242
get() = prefs.getBoolean(TURN_FLASH_OFF_AT_STARTUP, false)
4343
set(turnFlashOffAtStartup) = prefs.edit().putBoolean(TURN_FLASH_OFF_AT_STARTUP, turnFlashOffAtStartup).apply()
4444

45+
var flipPhotos: Boolean
46+
get() = prefs.getBoolean(FLIP_PHOTOS, false)
47+
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
48+
4549
var lastUsedCamera: Int
4650
get() = prefs.getInt(LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK)
4751
set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply()

app/src/main/kotlin/com/simplemobiletools/camera/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ val SOUND = "sound"
1111
val FOCUS_BEFORE_CAPTURE = "focus_before_capture"
1212
val VOLUME_BUTTONS_AS_SHUTTER = "volume_buttons_as_shutter"
1313
val TURN_FLASH_OFF_AT_STARTUP = "turn_flash_off_at_startup"
14+
val FLIP_PHOTOS = "flip_photos"
1415
val LAST_USED_CAMERA = "last_used_camera"
1516
val FLASHLIGHT_STATE = "flashlight_state"
1617
val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index"

app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.simplemobiletools.camera
33
import android.graphics.Bitmap
44
import android.graphics.BitmapFactory
55
import android.graphics.Matrix
6+
import android.hardware.Camera
67
import android.media.ExifInterface
78
import android.net.Uri
89
import android.os.AsyncTask
@@ -73,6 +74,16 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
7374
image = rotate(image, totalRotation)
7475
}
7576

77+
if (currCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT && !activity.config.flipPhotos) {
78+
val matrix = Matrix()
79+
if (path.startsWith(activity.internalStoragePath)) {
80+
matrix.preScale(1f, -1f)
81+
} else {
82+
matrix.preScale(-1f, 1f)
83+
}
84+
image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false)
85+
}
86+
7687
if (image != null) {
7788
image.compress(Bitmap.CompressFormat.JPEG, 80, fos)
7889
fos?.close()

app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
3030
setupFocusBeforeCapture()
3131
setupVolumeButtonsAsShutter()
3232
setupTurnFlashOffAtStartup()
33+
setupFlipPhotos()
3334
updateTextColors(settings_holder)
3435
}
3536

@@ -108,4 +109,12 @@ class SettingsActivity : SimpleActivity() {
108109
config.turnFlashOffAtStartup = settings_turn_flash_off_at_startup.isChecked
109110
}
110111
}
112+
113+
private fun setupFlipPhotos() {
114+
settings_flip_photos.isChecked = config.flipPhotos
115+
settings_flip_photos_holder.setOnClickListener {
116+
settings_flip_photos.toggle()
117+
config.flipPhotos = settings_flip_photos.isChecked
118+
}
119+
}
111120
}

app/src/main/res/layout/activity_settings.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,25 @@
164164
android:text="@string/turn_flash_off_at_startup"/>
165165

166166
</RelativeLayout>
167+
168+
<RelativeLayout
169+
android:id="@+id/settings_flip_photos_holder"
170+
android:layout_width="match_parent"
171+
android:layout_height="wrap_content"
172+
android:layout_marginTop="@dimen/medium_margin"
173+
android:background="?attr/selectableItemBackground"
174+
android:padding="@dimen/activity_margin">
175+
176+
<com.simplemobiletools.commons.views.MySwitchCompat
177+
android:id="@+id/settings_flip_photos"
178+
android:layout_width="match_parent"
179+
android:layout_height="wrap_content"
180+
android:background="@null"
181+
android:clickable="false"
182+
android:paddingLeft="@dimen/medium_margin"
183+
android:paddingStart="@dimen/medium_margin"
184+
android:text="@string/flip_front_camera_photos_horizontally"/>
185+
186+
</RelativeLayout>
167187
</LinearLayout>
168188
</ScrollView>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string name="focus_before_capture">Vor der Aufnahme fokussieren</string>
2828
<string name="volume_buttons_as_shutter">Benutze Lautstärkeregler als Shutter</string>
2929
<string name="turn_flash_off_at_startup">Schalte Blitzlicht bei Start aus</string>
30+
<string name="flip_front_camera_photos_horizontally">Flip front camera photos horizontally</string>
3031

3132
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
3233
<!-- Short description has to have less than 80 chars -->

app/src/main/res/values-es/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string name="focus_before_capture">Enfocar antes de la captura</string>
2828
<string name="volume_buttons_as_shutter">Utilizar los botones de volumen como obturador</string>
2929
<string name="turn_flash_off_at_startup">Turn flash off at startup</string>
30+
<string name="flip_front_camera_photos_horizontally">Flip front camera photos horizontally</string>
3031

3132
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
3233
<!-- Short description has to have less than 80 chars -->

app/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string name="focus_before_capture">Focus before capture</string>
2828
<string name="volume_buttons_as_shutter">Use volume buttons as shutter</string>
2929
<string name="turn_flash_off_at_startup">Turn flash off at startup</string>
30+
<string name="flip_front_camera_photos_horizontally">Flip front camera photos horizontally</string>
3031

3132
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
3233
<!-- Short description has to have less than 80 chars -->

app/src/main/res/values-it/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string name="focus_before_capture">Messa a fuoco prima della cattura</string>
2828
<string name="volume_buttons_as_shutter">Use volume buttons as shutter</string>
2929
<string name="turn_flash_off_at_startup">Turn flash off at startup</string>
30+
<string name="flip_front_camera_photos_horizontally">Flip front camera photos horizontally</string>
3031

3132
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
3233
<!-- Short description has to have less than 80 chars -->

app/src/main/res/values-ja/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<string name="focus_before_capture">キャプチャ前に再度焦点を合わせる</string>
2828
<string name="volume_buttons_as_shutter">Use volume buttons as shutter</string>
2929
<string name="turn_flash_off_at_startup">Turn flash off at startup</string>
30+
<string name="flip_front_camera_photos_horizontally">Flip front camera photos horizontally</string>
3031

3132
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
3233
<!-- Short description has to have less than 80 chars -->

0 commit comments

Comments
 (0)