mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
convert Config and Constants to kotlin
This commit is contained in:
@ -23,6 +23,7 @@ import butterknife.ButterKnife
|
||||
import butterknife.OnClick
|
||||
import com.simplemobiletools.commons.activities.AboutActivity
|
||||
import com.simplemobiletools.draw.*
|
||||
import com.simplemobiletools.draw.helpers.Config
|
||||
import yuku.ambilwarna.AmbilWarnaDialog
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
@ -57,17 +58,17 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
||||
mMyCanvas!!.setListener(this)
|
||||
mStrokeWidthBar!!.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener)
|
||||
|
||||
setBackgroundColor(Config.newInstance(this).backgroundColor)
|
||||
setBackgroundColor(Config.newInstance(this).canvasBackgroundColor)
|
||||
setColor(Config.newInstance(this).brushColor)
|
||||
|
||||
strokeWidth = Config.newInstance(this).strokeWidth
|
||||
strokeWidth = Config.newInstance(this).brushSize
|
||||
mMyCanvas!!.setStrokeWidth(strokeWidth)
|
||||
mStrokeWidthBar!!.progress = strokeWidth.toInt()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val isStrokeWidthBarEnabled = Config.newInstance(this).showBrushSizeEnabled
|
||||
val isStrokeWidthBarEnabled = Config.newInstance(this).showBrushSize
|
||||
mStrokeWidthBar!!.visibility = if (isStrokeWidthBarEnabled) View.VISIBLE else View.GONE
|
||||
mMyCanvas!!.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled)
|
||||
}
|
||||
@ -75,7 +76,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Config.newInstance(this).brushColor = color
|
||||
Config.newInstance(this).strokeWidth = strokeWidth
|
||||
Config.newInstance(this).brushSize = strokeWidth
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@ -114,7 +115,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
||||
|
||||
override fun onOk(dialog: AmbilWarnaDialog, pickedColor: Int) {
|
||||
setBackgroundColor(pickedColor)
|
||||
Config.newInstance(applicationContext).backgroundColor = pickedColor
|
||||
Config.newInstance(applicationContext).canvasBackgroundColor = pickedColor
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.simplemobiletools.draw.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.draw.Config
|
||||
import com.simplemobiletools.draw.helpers.Config
|
||||
import com.simplemobiletools.draw.R
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
@ -27,10 +27,10 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun setupBrushSize() {
|
||||
settings_show_brush_size.isChecked = Config.newInstance(this).showBrushSizeEnabled
|
||||
settings_show_brush_size.isChecked = Config.newInstance(this).showBrushSize
|
||||
settings_show_brush_size_holder.setOnClickListener {
|
||||
settings_show_brush_size.toggle()
|
||||
Config.newInstance(this).showBrushSizeEnabled = settings_show_brush_size.isChecked
|
||||
Config.newInstance(this).showBrushSize = settings_show_brush_size.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.simplemobiletools.draw.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
fun newInstance(context: Context) = Config(context)
|
||||
}
|
||||
|
||||
var showBrushSize: Boolean
|
||||
get() = prefs.getBoolean(SHOW_BRUSH_SIZE, false)
|
||||
set(showBrushSize) = prefs.edit().putBoolean(SHOW_BRUSH_SIZE, showBrushSize).apply()
|
||||
|
||||
var brushColor: Int
|
||||
get() = prefs.getInt(BRUSH_COLOR, Color.BLACK)
|
||||
set(color) = prefs.edit().putInt(BRUSH_COLOR, color).apply()
|
||||
|
||||
var brushSize: Float
|
||||
get() = prefs.getFloat(BRUSH_SIZE, 5.0f)
|
||||
set(brushSize) = prefs.edit().putFloat(BRUSH_SIZE, brushSize).apply()
|
||||
|
||||
var canvasBackgroundColor: Int
|
||||
get() = prefs.getInt(CANVAS_BACKGROUND_COLOR, Color.WHITE)
|
||||
set(canvasBackgroundColor) = prefs.edit().putInt(CANVAS_BACKGROUND_COLOR, canvasBackgroundColor).apply()
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.draw.helpers
|
||||
|
||||
val BRUSH_COLOR = "brush_color"
|
||||
val CANVAS_BACKGROUND_COLOR = "canvas_background_color"
|
||||
val SHOW_BRUSH_SIZE = "show_brush_size"
|
||||
val BRUSH_SIZE = "brush_size"
|
Reference in New Issue
Block a user