mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	add an initial version of the Commons library
This commit is contained in:
		| @@ -32,10 +32,7 @@ android { | ||||
| } | ||||
|  | ||||
| dependencies { | ||||
|     compile 'com.android.support:appcompat-v7:25.3.0' | ||||
|     compile 'com.android.support:design:25.3.0' | ||||
|     compile 'com.simplemobiletools:filepicker:1.6.1@aar' | ||||
|     compile 'com.github.bumptech.glide:glide:3.7.0' | ||||
|     compile 'com.simplemobiletools:commons:2.13.5' | ||||
|     compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,62 +1,44 @@ | ||||
| package com.simplemobiletools.camera | ||||
|  | ||||
| import android.content.Context | ||||
| import android.content.SharedPreferences | ||||
| import android.hardware.Camera | ||||
| import android.os.Environment | ||||
| import com.simplemobiletools.commons.helpers.BaseConfig | ||||
|  | ||||
| class Config(context: Context) { | ||||
|     private val mPrefs: SharedPreferences | ||||
|  | ||||
| class Config(context: Context) : BaseConfig(context) { | ||||
|     companion object { | ||||
|         fun newInstance(context: Context) = Config(context) | ||||
|     } | ||||
|  | ||||
|     init { | ||||
|         mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE) | ||||
|     } | ||||
|  | ||||
|     var isFirstRun: Boolean | ||||
|         get() = mPrefs.getBoolean(IS_FIRST_RUN, true) | ||||
|         set(firstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, firstRun).apply() | ||||
|  | ||||
|     var isDarkTheme: Boolean | ||||
|         get() = mPrefs.getBoolean(IS_DARK_THEME, false) | ||||
|         set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply() | ||||
|  | ||||
|     var savePhotosFolder: String | ||||
|         get() = mPrefs.getString(SAVE_PHOTOS, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString()) | ||||
|         set(path) = mPrefs.edit().putString(SAVE_PHOTOS, path).apply() | ||||
|         get() = prefs.getString(SAVE_PHOTOS, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString()) | ||||
|         set(path) = prefs.edit().putString(SAVE_PHOTOS, path).apply() | ||||
|  | ||||
|     var isShowPreviewEnabled: Boolean | ||||
|         get() = mPrefs.getBoolean(SHOW_PREVIEW, false) | ||||
|         set(enabled) = mPrefs.edit().putBoolean(SHOW_PREVIEW, enabled).apply() | ||||
|         get() = prefs.getBoolean(SHOW_PREVIEW, false) | ||||
|         set(enabled) = prefs.edit().putBoolean(SHOW_PREVIEW, enabled).apply() | ||||
|  | ||||
|     var forceRatioEnabled: Boolean | ||||
|         get() = mPrefs.getBoolean(FORCE_RATIO, true) | ||||
|         set(enabled) = mPrefs.edit().putBoolean(FORCE_RATIO, enabled).apply() | ||||
|         get() = prefs.getBoolean(FORCE_RATIO, true) | ||||
|         set(enabled) = prefs.edit().putBoolean(FORCE_RATIO, enabled).apply() | ||||
|  | ||||
|     var maxPhotoResolution: Int | ||||
|         get() = mPrefs.getInt(MAX_PHOTO_RESOLUTION, FIVE_MPX) | ||||
|         set(maxRes) = mPrefs.edit().putInt(MAX_PHOTO_RESOLUTION, maxRes).apply() | ||||
|         get() = prefs.getInt(MAX_PHOTO_RESOLUTION, FIVE_MPX) | ||||
|         set(maxRes) = prefs.edit().putInt(MAX_PHOTO_RESOLUTION, maxRes).apply() | ||||
|  | ||||
|     var maxVideoResolution: Int | ||||
|         get() = mPrefs.getInt(MAX_VIDEO_RESOLUTION, P720) | ||||
|         set(maxRes) = mPrefs.edit().putInt(MAX_VIDEO_RESOLUTION, maxRes).apply() | ||||
|         get() = prefs.getInt(MAX_VIDEO_RESOLUTION, P720) | ||||
|         set(maxRes) = prefs.edit().putInt(MAX_VIDEO_RESOLUTION, maxRes).apply() | ||||
|  | ||||
|     var isSoundEnabled: Boolean | ||||
|         get() = mPrefs.getBoolean(SOUND, true) | ||||
|         set(enabled) = mPrefs.edit().putBoolean(SOUND, enabled).apply() | ||||
|         get() = prefs.getBoolean(SOUND, true) | ||||
|         set(enabled) = prefs.edit().putBoolean(SOUND, enabled).apply() | ||||
|  | ||||
|     var lastUsedCamera: Int | ||||
|         get() = mPrefs.getInt(LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK) | ||||
|         set(cameraId) = mPrefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply() | ||||
|         get() = prefs.getInt(LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK) | ||||
|         set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply() | ||||
|  | ||||
|     var lastFlashlightState: Boolean | ||||
|         get() = mPrefs.getBoolean(LAST_FLASHLIGHT_STATE, false) | ||||
|         set(enabled) = mPrefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply() | ||||
|  | ||||
|     var treeUri: String | ||||
|         get() = mPrefs.getString(TREE_URI, "") | ||||
|         set(uri) = mPrefs.edit().putString(TREE_URI, uri).apply() | ||||
|         get() = prefs.getBoolean(LAST_FLASHLIGHT_STATE, false) | ||||
|         set(enabled) = prefs.edit().putBoolean(LAST_FLASHLIGHT_STATE, enabled).apply() | ||||
| } | ||||
|   | ||||
| @@ -15,9 +15,6 @@ 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 SHOW_PREVIEW = "show_preview" | ||||
| val SOUND = "sound" | ||||
| @@ -26,4 +23,3 @@ val MAX_PHOTO_RESOLUTION = "max_photo_resolution" | ||||
| val MAX_VIDEO_RESOLUTION = "max_video_resolution" | ||||
| val LAST_USED_CAMERA = "last_used_camera" | ||||
| val LAST_FLASHLIGHT_STATE = "last_flashlight_state" | ||||
| val TREE_URI = "tree_uri" | ||||
|   | ||||
| @@ -5,9 +5,9 @@ import android.os.AsyncTask | ||||
| import android.os.Environment | ||||
| import android.util.Log | ||||
| import com.simplemobiletools.camera.activities.MainActivity | ||||
| import com.simplemobiletools.filepicker.extensions.getFileDocument | ||||
| import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions | ||||
| import com.simplemobiletools.filepicker.extensions.toast | ||||
| import com.simplemobiletools.commons.extensions.getFileDocument | ||||
| import com.simplemobiletools.commons.extensions.needsStupidWritePermissions | ||||
| import com.simplemobiletools.commons.extensions.toast | ||||
| import java.io.* | ||||
| import java.lang.ref.WeakReference | ||||
|  | ||||
| @@ -46,8 +46,8 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?) : AsyncTask<Byte | ||||
|                     return "" | ||||
|                 } | ||||
|                 var document = activity.getFileDocument(path, config.treeUri) | ||||
|                 document = document.createFile("", path.substring(path.lastIndexOf('/') + 1)) | ||||
|                 fos = activity.contentResolver.openOutputStream(document.uri) | ||||
|                 document = document?.createFile("", path.substring(path.lastIndexOf('/') + 1)) | ||||
|                 fos = activity.contentResolver.openOutputStream(document?.uri) | ||||
|             } else { | ||||
|                 fos = FileOutputStream(photoFile) | ||||
|             } | ||||
|   | ||||
| @@ -9,9 +9,9 @@ import android.graphics.Point | ||||
| import android.hardware.Camera | ||||
| import android.support.v4.content.ContextCompat | ||||
| import android.view.Surface | ||||
| import com.simplemobiletools.filepicker.extensions.getFileDocument | ||||
| import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions | ||||
| import com.simplemobiletools.filepicker.extensions.toast | ||||
| import com.simplemobiletools.commons.extensions.getFileDocument | ||||
| import com.simplemobiletools.commons.extensions.needsStupidWritePermissions | ||||
| import com.simplemobiletools.commons.extensions.toast | ||||
| import java.io.File | ||||
| import java.text.SimpleDateFormat | ||||
| import java.util.* | ||||
|   | ||||
| @@ -1,12 +1,10 @@ | ||||
| package com.simplemobiletools.camera.activities | ||||
|  | ||||
| import android.content.ActivityNotFoundException | ||||
| import android.content.Intent | ||||
| import android.net.Uri | ||||
| import android.os.Bundle | ||||
| import android.text.Html | ||||
| import android.text.method.LinkMovementMethod | ||||
| import android.view.View | ||||
| import com.simplemobiletools.camera.BuildConfig | ||||
| import com.simplemobiletools.camera.R | ||||
| import kotlinx.android.synthetic.main.activity_about.* | ||||
| @@ -43,7 +41,7 @@ class AboutActivity : SimpleActivity() { | ||||
|     } | ||||
|  | ||||
|     private fun setupRateUs() { | ||||
|         if (config.isFirstRun) { | ||||
|         /*if (config.isFirstRun) { | ||||
|             about_rate_us.visibility = View.GONE | ||||
|         } else { | ||||
|             about_rate_us.setOnClickListener { | ||||
| @@ -54,7 +52,7 @@ class AboutActivity : SimpleActivity() { | ||||
|                     startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getStoreUrl()))) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         }*/ | ||||
|     } | ||||
|  | ||||
|     fun setupInvite() { | ||||
|   | ||||
| @@ -22,9 +22,10 @@ import com.bumptech.glide.Glide | ||||
| import com.bumptech.glide.load.engine.DiskCacheStrategy | ||||
| import com.simplemobiletools.camera.* | ||||
| import com.simplemobiletools.camera.Preview.PreviewListener | ||||
| import com.simplemobiletools.camera.extensions.config | ||||
| import com.simplemobiletools.camera.views.FocusRectView | ||||
| import com.simplemobiletools.filepicker.extensions.hasStoragePermission | ||||
| import com.simplemobiletools.filepicker.extensions.toast | ||||
| import com.simplemobiletools.commons.extensions.hasWriteStoragePermission | ||||
| import com.simplemobiletools.commons.extensions.toast | ||||
| import kotlinx.android.synthetic.main.activity_main.* | ||||
| import java.util.* | ||||
|  | ||||
| @@ -97,7 +98,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho | ||||
|             if (!Utils.hasCameraPermission(applicationContext)) { | ||||
|                 permissions.add(Manifest.permission.CAMERA) | ||||
|             } | ||||
|             if (!hasStoragePermission()) { | ||||
|             if (!hasWriteStoragePermission()) { | ||||
|                 permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||||
|             } | ||||
|             ActivityCompat.requestPermissions(this, permissions.toTypedArray(), CAMERA_STORAGE_PERMISSION) | ||||
| @@ -156,7 +157,7 @@ class MainActivity : SimpleActivity(), SensorEventListener, PreviewListener, Pho | ||||
|         toggle_photo_video.setOnClickListener { handleTogglePhotoVideo() } | ||||
|     } | ||||
|  | ||||
|     private fun hasCameraAndStoragePermission() = Utils.hasCameraPermission(applicationContext) && hasStoragePermission() | ||||
|     private fun hasCameraAndStoragePermission() = Utils.hasCameraPermission(applicationContext) && hasWriteStoragePermission() | ||||
|  | ||||
|     override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { | ||||
|         super.onRequestPermissionsResult(requestCode, permissions, grantResults) | ||||
|   | ||||
| @@ -1,22 +1,10 @@ | ||||
| package com.simplemobiletools.camera.activities | ||||
|  | ||||
| import android.annotation.TargetApi | ||||
| import android.app.Activity | ||||
| import android.content.Intent | ||||
| import android.os.Build | ||||
| import android.os.Bundle | ||||
| import android.support.v4.app.TaskStackBuilder | ||||
| import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import android.view.View | ||||
| import android.widget.AdapterView | ||||
| import com.simplemobiletools.camera.* | ||||
| import com.simplemobiletools.filepicker.dialogs.FilePickerDialog | ||||
| import com.simplemobiletools.filepicker.extensions.getBasePath | ||||
| import com.simplemobiletools.filepicker.extensions.getHumanReadablePath | ||||
| import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions | ||||
| import kotlinx.android.synthetic.main.activity_settings.* | ||||
| import java.io.File | ||||
| import com.simplemobiletools.camera.R | ||||
|  | ||||
| class SettingsActivity : SimpleActivity() { | ||||
|     val OPEN_DOCUMENT_TREE = 1 | ||||
| @@ -27,13 +15,12 @@ class SettingsActivity : SimpleActivity() { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         setContentView(R.layout.activity_settings) | ||||
|  | ||||
|         setupDarkTheme() | ||||
|         setupSavePhotosFolder() | ||||
|         /*setupSavePhotosFolder() | ||||
|         setupShowPreview() | ||||
|         setupSound() | ||||
|         setupForceRatio() | ||||
|         setupMaxPhotoResolution() | ||||
|         setupMaxVideoResolution() | ||||
|         setupMaxVideoResolution()*/ | ||||
|     } | ||||
|  | ||||
|     override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||||
| @@ -51,37 +38,23 @@ class SettingsActivity : SimpleActivity() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun setupDarkTheme() { | ||||
|         settings_dark_theme.isChecked = config.isDarkTheme | ||||
|         settings_dark_theme_holder.setOnClickListener { | ||||
|             settings_dark_theme.toggle() | ||||
|             config.isDarkTheme = settings_dark_theme.isChecked | ||||
|             restartActivity() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun setupSavePhotosFolder() { | ||||
|     /*private fun setupSavePhotosFolder() { | ||||
|         mCurrPath = config.savePhotosFolder | ||||
|         settings_save_photos.text = getHumanPath() | ||||
|         settings_save_photos_holder.setOnClickListener { | ||||
|             FilePickerDialog(this, mCurrPath, false, false, object : FilePickerDialog.OnFilePickerListener { | ||||
|                 override fun onFail(error: FilePickerDialog.FilePickerResult) { | ||||
|             FilePickerDialog(this, mCurrPath, false) { | ||||
|                 mWantedPath = pickedPath | ||||
|                 if (!isShowingWritePermissions(File(pickedPath), config.treeUri, OPEN_DOCUMENT_TREE)) { | ||||
|                     mCurrPath = if (pickedPath.length == 1) pickedPath else pickedPath.trimEnd('/') | ||||
|                     config.savePhotosFolder = mCurrPath | ||||
|                     settings_save_photos.text = getHumanPath() | ||||
|                 } | ||||
|  | ||||
|                 override fun onSuccess(pickedPath: String) { | ||||
|                     mWantedPath = pickedPath | ||||
|                     if (!isShowingWritePermissions(File(pickedPath), config.treeUri, OPEN_DOCUMENT_TREE)) { | ||||
|                         mCurrPath = if (pickedPath.length == 1) pickedPath else pickedPath.trimEnd('/') | ||||
|                         config.savePhotosFolder = mCurrPath | ||||
|                         settings_save_photos.text = getHumanPath() | ||||
|                     } | ||||
|                 } | ||||
|             }) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getHumanPath(): String { | ||||
|         val basePath = mCurrPath.getBasePath(applicationContext) | ||||
|         val basePath = mCurrPath.getBasePath(this) | ||||
|         val path = mCurrPath.replaceFirst(basePath, getStorageName(basePath)).trimEnd('/') | ||||
|  | ||||
|         return if (path.contains('/')) | ||||
| @@ -200,9 +173,5 @@ class SettingsActivity : SimpleActivity() { | ||||
|             2 -> P1080 | ||||
|             else -> -1 | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun restartActivity() { | ||||
|         TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities() | ||||
|     } | ||||
|     }*/ | ||||
| } | ||||
|   | ||||
| @@ -1,32 +1,10 @@ | ||||
| package com.simplemobiletools.camera.activities | ||||
|  | ||||
| import android.os.Bundle | ||||
| import android.support.v7.app.AppCompatActivity | ||||
| import android.view.MenuItem | ||||
|  | ||||
| import com.simplemobiletools.camera.Config | ||||
| import com.simplemobiletools.camera.R | ||||
|  | ||||
| open class SimpleActivity : AppCompatActivity() { | ||||
|     lateinit var config: Config | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
|  | ||||
| open class SimpleActivity : BaseSimpleActivity() { | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         config = Config.newInstance(applicationContext) | ||||
|         var theme = if (config.isDarkTheme) R.style.AppTheme_Base_Dark else R.style.AppTheme_Base | ||||
|         if (this is MainActivity) { | ||||
|             theme = if (config.isDarkTheme) R.style.FullScreenTheme_Dark else R.style.FullScreenTheme | ||||
|         } | ||||
|         setTheme(theme) | ||||
|         super.onCreate(savedInstanceState) | ||||
|     } | ||||
|  | ||||
|     override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||||
|         return when (item.itemId) { | ||||
|             android.R.id.home -> { | ||||
|                 finish() | ||||
|                 true | ||||
|             } | ||||
|             else -> super.onOptionsItemSelected(item) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,6 @@ | ||||
| package com.simplemobiletools.camera.extensions | ||||
|  | ||||
| import android.content.Context | ||||
| import com.simplemobiletools.camera.Config | ||||
|  | ||||
| val Context.config: Config get() = Config.newInstance(this) | ||||
| @@ -12,34 +12,6 @@ | ||||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="vertical"> | ||||
|  | ||||
|         <RelativeLayout | ||||
|             android:id="@+id/settings_dark_theme_holder" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginTop="@dimen/settings_padding" | ||||
|             android:background="?attr/selectableItemBackground" | ||||
|             android:padding="@dimen/activity_margin"> | ||||
|  | ||||
|             <TextView | ||||
|                 android:id="@+id/settings_dark_theme_label" | ||||
|                 android:layout_width="wrap_content" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_centerVertical="true" | ||||
|                 android:paddingLeft="@dimen/settings_padding" | ||||
|                 android:paddingStart="@dimen/settings_padding" | ||||
|                 android:text="@string/dark_theme"/> | ||||
|  | ||||
|             <android.support.v7.widget.SwitchCompat | ||||
|                 android:id="@+id/settings_dark_theme" | ||||
|                 android:layout_width="wrap_content" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_alignParentEnd="true" | ||||
|                 android:layout_alignParentRight="true" | ||||
|                 android:background="@null" | ||||
|                 android:clickable="false"/> | ||||
|  | ||||
|         </RelativeLayout> | ||||
|  | ||||
|         <RelativeLayout | ||||
|             android:id="@+id/settings_save_photos_holder" | ||||
|             android:layout_width="match_parent" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user