add a toggle for using english

This commit is contained in:
tibbi 2017-11-21 15:17:17 +01:00
parent 1d2a5d225f
commit 608af14ce9
5 changed files with 95 additions and 43 deletions

View File

@ -19,6 +19,7 @@
tools:node="remove"/> tools:node="remove"/>
<application <application
android:name=".App"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_launcher_name" android:label="@string/app_launcher_name"

View File

@ -0,0 +1,17 @@
package com.simplemobiletools.camera
import android.app.Application
import com.simplemobiletools.camera.extensions.config
import java.util.*
class App : Application() {
override fun onCreate() {
super.onCreate()
if (config.useEnglish) {
val conf = resources.configuration
conf.locale = Locale.ENGLISH
resources.updateConfiguration(conf, resources.displayMetrics)
}
}
}

View File

@ -66,6 +66,49 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
setupOrientationEventListener() setupOrientationEventListener()
} }
override fun onResume() {
super.onResume()
if (hasStorageAndCameraPermissions()) {
resumeCameraItems()
setupPreviewImage(mIsInPhotoMode)
scheduleFadeOut()
mFocusRectView.setStrokeColor(config.primaryColor)
if (mIsVideoCaptureIntent && mIsInPhotoMode) {
handleTogglePhotoVideo()
checkButtons()
}
toggleBottomButtons(false)
}
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (hasStorageAndCameraPermissions()) {
mOrientationEventListener.enable()
}
}
override fun onPause() {
super.onPause()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (!hasStorageAndCameraPermissions() || isAskingPermissions) {
return
}
mFadeHandler.removeCallbacksAndMessages(null)
hideTimer()
mPreview?.releaseCamera()
mOrientationEventListener.disable()
if (mPreview?.isWaitingForTakePictureCallback == true) {
toast(R.string.photo_not_saved)
}
}
override fun onDestroy() {
super.onDestroy()
mPreview?.releaseCamera()
}
private fun initVariables() { private fun initVariables() {
mRes = resources mRes = resources
mIsInPhotoMode = false mIsInPhotoMode = false
@ -418,26 +461,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
}) })
} }
override fun onResume() {
super.onResume()
if (hasStorageAndCameraPermissions()) {
resumeCameraItems()
setupPreviewImage(mIsInPhotoMode)
scheduleFadeOut()
mFocusRectView.setStrokeColor(config.primaryColor)
if (mIsVideoCaptureIntent && mIsInPhotoMode) {
handleTogglePhotoVideo()
checkButtons()
}
toggleBottomButtons(false)
}
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (hasStorageAndCameraPermissions()) {
mOrientationEventListener.enable()
}
}
private fun resumeCameraItems() { private fun resumeCameraItems() {
showToggleCameraIfNeeded() showToggleCameraIfNeeded()
if (mPreview?.setCamera(mCurrCameraId) == true) { if (mPreview?.setCamera(mCurrCameraId) == true) {
@ -456,24 +479,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
toggle_camera.beInvisibleIf(Camera.getNumberOfCameras() <= 1) toggle_camera.beInvisibleIf(Camera.getNumberOfCameras() <= 1)
} }
override fun onPause() {
super.onPause()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (!hasStorageAndCameraPermissions() || isAskingPermissions) {
return
}
mFadeHandler.removeCallbacksAndMessages(null)
hideTimer()
mPreview?.releaseCamera()
mOrientationEventListener.disable()
if (mPreview?.isWaitingForTakePictureCallback == true) {
toast(R.string.photo_not_saved)
}
}
private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA) private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
private fun setupOrientationEventListener() { private fun setupOrientationEventListener() {
@ -563,11 +568,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
} }
} }
override fun onDestroy() {
super.onDestroy()
mPreview?.releaseCamera()
}
private fun checkWhatsNewDialog() { private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply { arrayListOf<Release>().apply {
add(Release(33, R.string.release_33)) add(Release(33, R.string.release_33))

View File

@ -7,12 +7,15 @@ import com.simplemobiletools.camera.BuildConfig
import com.simplemobiletools.camera.R import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.extensions.config import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.humanizePath import com.simplemobiletools.commons.extensions.humanizePath
import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.useEnglishToggled
import com.simplemobiletools.commons.helpers.LICENSE_GLIDE import com.simplemobiletools.commons.helpers.LICENSE_GLIDE
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
import java.io.File import java.io.File
import java.util.*
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -24,6 +27,7 @@ class SettingsActivity : SimpleActivity() {
super.onResume() super.onResume()
setupCustomizeColors() setupCustomizeColors()
setupUseEnglish()
setupSavePhotosFolder() setupSavePhotosFolder()
setupShowPreview() setupShowPreview()
setupSound() setupSound()
@ -56,6 +60,16 @@ class SettingsActivity : SimpleActivity() {
} }
} }
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
settings_use_english.isChecked = config.useEnglish
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
useEnglishToggled()
}
}
private fun setupSavePhotosFolder() { private fun setupSavePhotosFolder() {
settings_save_photos.text = getLastPart(config.savePhotosFolder) settings_save_photos.text = getLastPart(config.savePhotosFolder)
settings_save_photos_holder.setOnClickListener { settings_save_photos_holder.setOnClickListener {

View File

@ -30,6 +30,26 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_use_english_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_use_english"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/use_english_language"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/settings_save_photos_holder" android:id="@+id/settings_save_photos_holder"
android:layout_width="match_parent" android:layout_width="match_parent"