mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-05-04 17:08:47 +02:00
convert Constants to kotlin
This commit is contained in:
parent
924f3585ce
commit
b2869fc6ba
@ -1,29 +0,0 @@
|
|||||||
package com.simplemobiletools.camera;
|
|
||||||
|
|
||||||
public class Constants {
|
|
||||||
public static final int ORIENT_PORTRAIT = 0;
|
|
||||||
public static final int ORIENT_LANDSCAPE_LEFT = 1;
|
|
||||||
public static final int ORIENT_LANDSCAPE_RIGHT = 2;
|
|
||||||
|
|
||||||
public static final int TWO_MPX = 3000000;
|
|
||||||
public static final int FIVE_MPX = 6000000;
|
|
||||||
public static final int EIGHT_MPX = 9000000;
|
|
||||||
|
|
||||||
public static final int P480 = 400000;
|
|
||||||
public static final int P720 = 1000000;
|
|
||||||
public static final int P1080 = 2100000;
|
|
||||||
|
|
||||||
// shared preferences
|
|
||||||
public static final String PREFS_KEY = "Camera";
|
|
||||||
public static final String IS_FIRST_RUN = "is_first_run";
|
|
||||||
public static final String IS_DARK_THEME = "is_dark_theme";
|
|
||||||
public static final String SAVE_PHOTOS = "save_photos";
|
|
||||||
public static final String SOUND = "sound";
|
|
||||||
public static final String FORCE_RATIO = "force_ratio";
|
|
||||||
public static final String MAX_PHOTO_RESOLUTION = "max_photo_resolution";
|
|
||||||
public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution";
|
|
||||||
public static final String MAX_RESOLUTION = "max_resolution";
|
|
||||||
public static final String LAST_USED_CAMERA = "last_used_camera";
|
|
||||||
public static final String LAST_FLASHLIGHT_STATE = "last_flashlight_state";
|
|
||||||
public static final String TREE_URI = "tree_uri";
|
|
||||||
}
|
|
@ -396,9 +396,9 @@ public class Preview extends ViewGroup
|
|||||||
int degrees = 0;
|
int degrees = 0;
|
||||||
boolean isFrontCamera = (mCurrCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT);
|
boolean isFrontCamera = (mCurrCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT);
|
||||||
int deviceOrientation = mCallback.getCurrentOrientation();
|
int deviceOrientation = mCallback.getCurrentOrientation();
|
||||||
if (deviceOrientation == Constants.ORIENT_LANDSCAPE_LEFT) {
|
if (deviceOrientation == Constants.INSTANCE.getORIENT_LANDSCAPE_LEFT()) {
|
||||||
degrees += isFrontCamera ? 90 : 270;
|
degrees += isFrontCamera ? 90 : 270;
|
||||||
} else if (deviceOrientation == Constants.ORIENT_LANDSCAPE_RIGHT) {
|
} else if (deviceOrientation == Constants.INSTANCE.getORIENT_LANDSCAPE_RIGHT()) {
|
||||||
degrees += isFrontCamera ? 270 : 90;
|
degrees += isFrontCamera ? 270 : 90;
|
||||||
}
|
}
|
||||||
return degrees;
|
return degrees;
|
||||||
|
@ -13,66 +13,66 @@ class Config(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE)
|
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
var isFirstRun: Boolean
|
var isFirstRun: Boolean
|
||||||
get() = mPrefs.getBoolean(Constants.IS_FIRST_RUN, true)
|
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
|
||||||
set(firstRun) = mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply()
|
set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply()
|
||||||
|
|
||||||
var isDarkTheme: Boolean
|
var isDarkTheme: Boolean
|
||||||
get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, false)
|
get() = mPrefs.getBoolean(IS_DARK_THEME, false)
|
||||||
set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply()
|
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
|
||||||
|
|
||||||
var savePhotosFolder: String
|
var savePhotosFolder: String
|
||||||
get() = mPrefs.getString(Constants.SAVE_PHOTOS, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString())
|
get() = mPrefs.getString(SAVE_PHOTOS, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString())
|
||||||
set(path) = mPrefs.edit().putString(Constants.SAVE_PHOTOS, path).apply()
|
set(path) = mPrefs.edit().putString(SAVE_PHOTOS, path).apply()
|
||||||
|
|
||||||
var forceRatioEnabled: Boolean
|
var forceRatioEnabled: Boolean
|
||||||
get() = mPrefs.getBoolean(Constants.FORCE_RATIO, true)
|
get() = mPrefs.getBoolean(FORCE_RATIO, true)
|
||||||
set(enabled) = mPrefs.edit().putBoolean(Constants.FORCE_RATIO, enabled).apply()
|
set(enabled) = mPrefs.edit().putBoolean(FORCE_RATIO, enabled).apply()
|
||||||
|
|
||||||
// todo: delete this
|
// todo: delete this
|
||||||
val maxResolution: Int
|
val maxResolution: Int
|
||||||
get() = mPrefs.getInt(Constants.MAX_RESOLUTION, -1)
|
get() = mPrefs.getInt(MAX_RESOLUTION, -1)
|
||||||
|
|
||||||
var maxPhotoResolution: Int
|
var maxPhotoResolution: Int
|
||||||
get() = mPrefs.getInt(Constants.MAX_PHOTO_RESOLUTION, oldDefaultResolution)
|
get() = mPrefs.getInt(MAX_PHOTO_RESOLUTION, oldDefaultResolution)
|
||||||
set(maxRes) = mPrefs.edit().putInt(Constants.MAX_PHOTO_RESOLUTION, maxRes).apply()
|
set(maxRes) = mPrefs.edit().putInt(MAX_PHOTO_RESOLUTION, maxRes).apply()
|
||||||
|
|
||||||
private val oldDefaultResolution: Int
|
private val oldDefaultResolution: Int
|
||||||
get() {
|
get() {
|
||||||
return when (maxResolution) {
|
return when (maxResolution) {
|
||||||
1 -> Constants.EIGHT_MPX
|
1 -> EIGHT_MPX
|
||||||
2 -> 0
|
2 -> 0
|
||||||
else -> Constants.FIVE_MPX
|
else -> FIVE_MPX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxVideoResolution: Int
|
var maxVideoResolution: Int
|
||||||
get() {
|
get() {
|
||||||
val maxRes = mPrefs.getInt(Constants.MAX_VIDEO_RESOLUTION, Constants.P720)
|
val maxRes = mPrefs.getInt(MAX_VIDEO_RESOLUTION, P720)
|
||||||
return when (maxRes) {
|
return when (maxRes) {
|
||||||
0 -> Constants.P480
|
0 -> P480
|
||||||
2 -> Constants.P1080
|
2 -> P1080
|
||||||
else -> Constants.P720
|
else -> P720
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set(maxRes) = mPrefs.edit().putInt(Constants.MAX_VIDEO_RESOLUTION, maxRes).apply()
|
set(maxRes) = mPrefs.edit().putInt(MAX_VIDEO_RESOLUTION, maxRes).apply()
|
||||||
|
|
||||||
var isSoundEnabled: Boolean
|
var isSoundEnabled: Boolean
|
||||||
get() = mPrefs.getBoolean(Constants.SOUND, true)
|
get() = mPrefs.getBoolean(SOUND, true)
|
||||||
set(enabled) = mPrefs.edit().putBoolean(Constants.SOUND, enabled).apply()
|
set(enabled) = mPrefs.edit().putBoolean(SOUND, enabled).apply()
|
||||||
|
|
||||||
var lastUsedCamera: Int
|
var lastUsedCamera: Int
|
||||||
get() = mPrefs.getInt(Constants.LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK)
|
get() = mPrefs.getInt(LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK)
|
||||||
set(cameraId) = mPrefs.edit().putInt(Constants.LAST_USED_CAMERA, cameraId).apply()
|
set(cameraId) = mPrefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply()
|
||||||
|
|
||||||
var lastFlashlightState: Boolean
|
var lastFlashlightState: Boolean
|
||||||
get() = mPrefs.getBoolean(Constants.LAST_FLASHLIGHT_STATE, false)
|
get() = mPrefs.getBoolean(LAST_FLASHLIGHT_STATE, false)
|
||||||
set(enabled) = mPrefs.edit().putBoolean(Constants.LAST_FLASHLIGHT_STATE, enabled).apply()
|
set(enabled) = mPrefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply()
|
||||||
|
|
||||||
var treeUri: String
|
var treeUri: String
|
||||||
get() = mPrefs.getString(Constants.TREE_URI, "")
|
get() = mPrefs.getString(TREE_URI, "")
|
||||||
set(uri) = mPrefs.edit().putString(Constants.TREE_URI, uri).apply()
|
set(uri) = mPrefs.edit().putString(TREE_URI, uri).apply()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.simplemobiletools.camera
|
||||||
|
|
||||||
|
object Constants {
|
||||||
|
val ORIENT_PORTRAIT = 0
|
||||||
|
val ORIENT_LANDSCAPE_LEFT = 1
|
||||||
|
val ORIENT_LANDSCAPE_RIGHT = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
val TWO_MPX = 3000000
|
||||||
|
val FIVE_MPX = 6000000
|
||||||
|
val EIGHT_MPX = 9000000
|
||||||
|
|
||||||
|
val P480 = 400000
|
||||||
|
val P720 = 1000000
|
||||||
|
val P1080 = 2100000
|
||||||
|
|
||||||
|
// shared preferences
|
||||||
|
val PREFS_KEY = "Camera"
|
||||||
|
val IS_FIRST_RUN = "is_first_run"
|
||||||
|
val IS_DARK_THEME = "is_dark_theme"
|
||||||
|
val SAVE_PHOTOS = "save_photos"
|
||||||
|
val SOUND = "sound"
|
||||||
|
val FORCE_RATIO = "force_ratio"
|
||||||
|
val MAX_PHOTO_RESOLUTION = "max_photo_resolution"
|
||||||
|
val MAX_VIDEO_RESOLUTION = "max_video_resolution"
|
||||||
|
val MAX_RESOLUTION = "max_resolution"
|
||||||
|
val LAST_USED_CAMERA = "last_used_camera"
|
||||||
|
val LAST_FLASHLIGHT_STATE = "last_flashlight_state"
|
||||||
|
val TREE_URI = "tree_uri"
|
||||||
|
|
@ -57,14 +57,14 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?) : AsyncTask<Byte
|
|||||||
fos?.close()
|
fos?.close()
|
||||||
return photoFile.absolutePath
|
return photoFile.absolutePath
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
Log.e(TAG, "PhotoProcessor file not found: " + e.message)
|
Log.e(TAG, "PhotoProcessor file not found: $e")
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "PhotoProcessor ioexception " + e.message)
|
Log.e(TAG, "PhotoProcessor ioexception $e")
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fos?.close()
|
fos?.close()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "PhotoProcessor close ioexception " + e.message)
|
Log.e(TAG, "PhotoProcessor close ioexception $e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import com.simplemobiletools.camera.Constants
|
import com.simplemobiletools.camera.*
|
||||||
import com.simplemobiletools.camera.R
|
|
||||||
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
|
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.filepicker.extensions.getBasePath
|
import com.simplemobiletools.filepicker.extensions.getBasePath
|
||||||
import com.simplemobiletools.filepicker.extensions.getHumanReadablePath
|
import com.simplemobiletools.filepicker.extensions.getHumanReadablePath
|
||||||
@ -90,7 +89,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStorageName(basePath: String) = getHumanReadablePath(basePath) + "/"
|
private fun getStorageName(basePath: String) = "${getHumanReadablePath(basePath)}/"
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
@ -148,18 +147,18 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
private fun getMaxPhotoSelection(): Int {
|
private fun getMaxPhotoSelection(): Int {
|
||||||
val maxRes = config.maxPhotoResolution
|
val maxRes = config.maxPhotoResolution
|
||||||
return when (maxRes) {
|
return when (maxRes) {
|
||||||
Constants.TWO_MPX -> 0
|
TWO_MPX -> 0
|
||||||
Constants.FIVE_MPX -> 1
|
FIVE_MPX -> 1
|
||||||
Constants.EIGHT_MPX -> 2
|
EIGHT_MPX -> 2
|
||||||
else -> 3
|
else -> 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMaxPhotoPx(index: Int): Int {
|
private fun getMaxPhotoPx(index: Int): Int {
|
||||||
return when (index) {
|
return when (index) {
|
||||||
0 -> Constants.TWO_MPX
|
0 -> TWO_MPX
|
||||||
1 -> Constants.FIVE_MPX
|
1 -> FIVE_MPX
|
||||||
2 -> Constants.EIGHT_MPX
|
2 -> EIGHT_MPX
|
||||||
else -> -1
|
else -> -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,18 +178,18 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
private fun getMaxVideoSelection(): Int {
|
private fun getMaxVideoSelection(): Int {
|
||||||
val maxRes = config.maxVideoResolution
|
val maxRes = config.maxVideoResolution
|
||||||
return when (maxRes) {
|
return when (maxRes) {
|
||||||
Constants.P480 -> 0
|
P480 -> 0
|
||||||
Constants.P720 -> 1
|
P720 -> 1
|
||||||
Constants.P1080 -> 2
|
P1080 -> 2
|
||||||
else -> 3
|
else -> 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMaxVideoPx(index: Int): Int {
|
private fun getMaxVideoPx(index: Int): Int {
|
||||||
return when (index) {
|
return when (index) {
|
||||||
0 -> Constants.P480
|
0 -> P480
|
||||||
1 -> Constants.P720
|
1 -> P720
|
||||||
2 -> Constants.P1080
|
2 -> P1080
|
||||||
else -> -1
|
else -> -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user