mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
remove butterknife and ambilwarna
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'android-apt'
|
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
|
||||||
@ -34,10 +33,6 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.16.1'
|
compile 'com.simplemobiletools:commons:2.16.1'
|
||||||
compile 'com.jakewharton:butterknife:8.0.1'
|
|
||||||
compile 'com.github.yukuku:ambilwarna:2.0.1'
|
|
||||||
|
|
||||||
apt 'com.jakewharton:butterknife-compiler:8.0.1'
|
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,30 +16,25 @@ import android.support.v7.app.AlertDialog
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.widget.EditText
|
||||||
import android.widget.*
|
import android.widget.RadioGroup
|
||||||
import butterknife.BindView
|
import android.widget.SeekBar
|
||||||
import butterknife.ButterKnife
|
import android.widget.Toast
|
||||||
import butterknife.OnClick
|
|
||||||
import com.simplemobiletools.commons.activities.AboutActivity
|
import com.simplemobiletools.commons.activities.AboutActivity
|
||||||
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.draw.MyCanvas
|
import com.simplemobiletools.draw.MyCanvas
|
||||||
import com.simplemobiletools.draw.R
|
import com.simplemobiletools.draw.R
|
||||||
import com.simplemobiletools.draw.Svg
|
import com.simplemobiletools.draw.Svg
|
||||||
import com.simplemobiletools.draw.helpers.Config
|
import com.simplemobiletools.draw.helpers.Config
|
||||||
import yuku.ambilwarna.AmbilWarnaDialog
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
||||||
|
|
||||||
@BindView(R.id.my_canvas) internal var mMyCanvas: MyCanvas? = null
|
|
||||||
@BindView(R.id.undo) internal var mUndoBtn: View? = null
|
|
||||||
@BindView(R.id.color_picker) internal var mColorPicker: View? = null
|
|
||||||
@BindView(R.id.stroke_width_bar) internal var mStrokeWidthBar: SeekBar? = null
|
|
||||||
|
|
||||||
private var curFileName: String? = null
|
private var curFileName: String? = null
|
||||||
private var curExtensionId = 0
|
private var curExtensionId = 0
|
||||||
|
|
||||||
@ -57,23 +52,25 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
ButterKnife.bind(this)
|
my_canvas.setListener(this)
|
||||||
mMyCanvas!!.setListener(this)
|
stroke_width_bar.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener)
|
||||||
mStrokeWidthBar!!.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener)
|
|
||||||
|
|
||||||
setBackgroundColor(Config.newInstance(this).canvasBackgroundColor)
|
setBackgroundColor(Config.newInstance(this).canvasBackgroundColor)
|
||||||
setColor(Config.newInstance(this).brushColor)
|
setColor(Config.newInstance(this).brushColor)
|
||||||
|
|
||||||
strokeWidth = Config.newInstance(this).brushSize
|
strokeWidth = Config.newInstance(this).brushSize
|
||||||
mMyCanvas!!.setStrokeWidth(strokeWidth)
|
my_canvas.setStrokeWidth(strokeWidth)
|
||||||
mStrokeWidthBar!!.progress = strokeWidth.toInt()
|
stroke_width_bar.progress = strokeWidth.toInt()
|
||||||
|
|
||||||
|
color_picker.setOnClickListener { pickColor() }
|
||||||
|
undo.setOnClickListener { undo() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val isStrokeWidthBarEnabled = Config.newInstance(this).showBrushSize
|
val isStrokeWidthBarEnabled = Config.newInstance(this).showBrushSize
|
||||||
mStrokeWidthBar!!.visibility = if (isStrokeWidthBarEnabled) View.VISIBLE else View.GONE
|
stroke_width_bar.beVisibleIf(isStrokeWidthBarEnabled)
|
||||||
mMyCanvas!!.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled)
|
my_canvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@ -107,22 +104,15 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.clear -> {
|
R.id.clear -> {
|
||||||
mMyCanvas!!.clearCanvas()
|
my_canvas.clearCanvas()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.change_background -> {
|
R.id.change_background -> {
|
||||||
val oldColor = (mMyCanvas!!.background as ColorDrawable).color
|
val oldColor = (my_canvas.background as ColorDrawable).color
|
||||||
val dialog = AmbilWarnaDialog(this, oldColor,
|
ColorPickerDialog(this, oldColor) {
|
||||||
object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
setBackgroundColor(it)
|
||||||
override fun onCancel(dialog: AmbilWarnaDialog) {}
|
Config.newInstance(applicationContext).canvasBackgroundColor = it
|
||||||
|
}
|
||||||
override fun onOk(dialog: AmbilWarnaDialog, pickedColor: Int) {
|
|
||||||
setBackgroundColor(pickedColor)
|
|
||||||
Config.newInstance(applicationContext).canvasBackgroundColor = pickedColor
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dialog.show()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.about -> {
|
R.id.about -> {
|
||||||
@ -206,7 +196,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
val file = File(directory, fileName + extension)
|
val file = File(directory, fileName + extension)
|
||||||
when (extension) {
|
when (extension) {
|
||||||
".png" -> {
|
".png" -> {
|
||||||
val bitmap = mMyCanvas!!.bitmap
|
val bitmap = my_canvas.bitmap
|
||||||
var out: FileOutputStream? = null
|
var out: FileOutputStream? = null
|
||||||
try {
|
try {
|
||||||
out = FileOutputStream(file)
|
out = FileOutputStream(file)
|
||||||
@ -217,9 +207,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
return false
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (out != null) {
|
out?.close()
|
||||||
out.close()
|
|
||||||
}
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "MainActivity SaveFile (.png) 2 " + e.message)
|
Log.e(TAG, "MainActivity SaveFile (.png) 2 " + e.message)
|
||||||
}
|
}
|
||||||
@ -228,7 +216,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
}
|
}
|
||||||
".svg" -> {
|
".svg" -> {
|
||||||
try {
|
try {
|
||||||
Svg.saveSvg(file, mMyCanvas!!)
|
Svg.saveSvg(file, my_canvas)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "MainActivity SaveFile (.svg) " + e.message)
|
Log.e(TAG, "MainActivity SaveFile (.svg) " + e.message)
|
||||||
return false
|
return false
|
||||||
@ -243,7 +231,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
|
|
||||||
private fun shareImage() {
|
private fun shareImage() {
|
||||||
val shareTitle = resources.getString(R.string.share_via)
|
val shareTitle = resources.getString(R.string.share_via)
|
||||||
val bitmap = mMyCanvas!!.bitmap
|
val bitmap = my_canvas.bitmap
|
||||||
val sendIntent = Intent()
|
val sendIntent = Intent()
|
||||||
val uri = getImageUri(bitmap) ?: return
|
val uri = getImageUri(bitmap) ?: return
|
||||||
|
|
||||||
@ -274,8 +262,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
Log.e(TAG, "getImageUri 1 " + e.message)
|
Log.e(TAG, "getImageUri 1 " + e.message)
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (fileOutputStream != null)
|
fileOutputStream?.close()
|
||||||
fileOutputStream.close()
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "getImageUri 2 " + e.message)
|
Log.e(TAG, "getImageUri 2 " + e.message)
|
||||||
}
|
}
|
||||||
@ -285,42 +272,34 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
|
|||||||
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
return FileProvider.getUriForFile(this, "com.simplemobiletools.draw.fileprovider", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.undo)
|
|
||||||
fun undo() {
|
fun undo() {
|
||||||
mMyCanvas!!.undo()
|
my_canvas.undo()
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.color_picker)
|
|
||||||
fun pickColor() {
|
fun pickColor() {
|
||||||
val dialog = AmbilWarnaDialog(this, color, object : AmbilWarnaDialog.OnAmbilWarnaListener {
|
ColorPickerDialog(this, color) {
|
||||||
override fun onCancel(dialog: AmbilWarnaDialog) {}
|
setColor(it)
|
||||||
|
}
|
||||||
override fun onOk(dialog: AmbilWarnaDialog, pickedColor: Int) {
|
|
||||||
setColor(pickedColor)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
dialog.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setBackgroundColor(pickedColor: Int) {
|
private fun setBackgroundColor(pickedColor: Int) {
|
||||||
(mUndoBtn as ImageView).setImageResource(R.drawable.ic_undo)
|
undo.setImageResource(R.drawable.ic_undo)
|
||||||
mMyCanvas!!.setBackgroundColor(pickedColor)
|
my_canvas.setBackgroundColor(pickedColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColor(pickedColor: Int) {
|
private fun setColor(pickedColor: Int) {
|
||||||
color = pickedColor
|
color = pickedColor
|
||||||
mColorPicker!!.setBackgroundColor(color)
|
color_picker.setBackgroundColor(color)
|
||||||
mMyCanvas!!.setColor(color)
|
my_canvas.setColor(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pathsChanged(cnt: Int) {
|
override fun pathsChanged(cnt: Int) {
|
||||||
mUndoBtn!!.visibility = if (cnt > 0) View.VISIBLE else View.GONE
|
undo.beVisibleIf(cnt > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var onStrokeWidthBarChangeListener: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
internal var onStrokeWidthBarChangeListener: SeekBar.OnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
mMyCanvas!!.setStrokeWidth(progress.toFloat())
|
my_canvas.setStrokeWidth(progress.toFloat())
|
||||||
strokeWidth = progress.toFloat()
|
strokeWidth = progress.toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Reference in New Issue
Block a user