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:
		@@ -1,61 +0,0 @@
 | 
			
		||||
package com.simplemobiletools.draw;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.graphics.Color;
 | 
			
		||||
 | 
			
		||||
public class Config {
 | 
			
		||||
    private SharedPreferences mPrefs;
 | 
			
		||||
 | 
			
		||||
    public static Config newInstance(Context context) {
 | 
			
		||||
        return new Config(context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Config(Context context) {
 | 
			
		||||
        mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean getIsFirstRun() {
 | 
			
		||||
        return mPrefs.getBoolean(Constants.IS_FIRST_RUN, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIsFirstRun(boolean firstRun) {
 | 
			
		||||
        mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIsDarkTheme(boolean isDarkTheme) {
 | 
			
		||||
        mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean getShowBrushSizeEnabled() {
 | 
			
		||||
        return mPrefs.getBoolean(Constants.SHOW_BRUSH_SIZE, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setShowBrushSizeEnabled(boolean showBrushSize) {
 | 
			
		||||
        mPrefs.edit().putBoolean(Constants.SHOW_BRUSH_SIZE, showBrushSize).apply();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getBrushColor() {
 | 
			
		||||
        return mPrefs.getInt(Constants.BRUSH_COLOR_KEY, Color.BLACK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBrushColor(int color) {
 | 
			
		||||
        mPrefs.edit().putInt(Constants.BRUSH_COLOR_KEY, color).apply();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getStrokeWidth() {
 | 
			
		||||
        return mPrefs.getFloat(Constants.STROKE_WIDTH_KEY, 5.0f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setStrokeWidth(float strokeWidth) {
 | 
			
		||||
        mPrefs.edit().putFloat(Constants.STROKE_WIDTH_KEY, strokeWidth).apply();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getBackgroundColor() {
 | 
			
		||||
        return mPrefs.getInt(Constants.BACKGROUND_COLOR_KEY, Color.WHITE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBackgroundColor(int color) {
 | 
			
		||||
        mPrefs.edit().putInt(Constants.BACKGROUND_COLOR_KEY, color).apply();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
package com.simplemobiletools.draw;
 | 
			
		||||
 | 
			
		||||
public class Constants {
 | 
			
		||||
    // shared preferences
 | 
			
		||||
    public static final String PREFS_KEY = "Draw";
 | 
			
		||||
    public static final String BRUSH_COLOR_KEY = "brush_color";
 | 
			
		||||
    public static final String STROKE_WIDTH_KEY = "stroke_width";
 | 
			
		||||
    public static final String BACKGROUND_COLOR_KEY = "background_color";
 | 
			
		||||
    public static final String IS_FIRST_RUN = "is_first_run";
 | 
			
		||||
    public static final String IS_DARK_THEME = "is_dark_theme";
 | 
			
		||||
    public static final String SHOW_BRUSH_SIZE = "show_brush_size";
 | 
			
		||||
}
 | 
			
		||||
@@ -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