couple minor changes related to save image code style

This commit is contained in:
tibbi 2017-04-08 22:32:42 +02:00
parent 8627a8607a
commit 8969abd442
2 changed files with 20 additions and 17 deletions

View File

@ -35,19 +35,17 @@ import java.io.FileOutputStream
import java.io.IOException
class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
private val FOLDER_NAME = "images"
private val FILE_NAME = "simple-draw.png"
private val SAVE_FOLDER_NAME = "Simple Draw"
private val STORAGE_PERMISSION = 1
private var curFileName: String? = null
private var curExtensionId = 0
private var color = 0
private var strokeWidth = 0f
companion object {
private val FOLDER_NAME = "images"
private val FILE_NAME = "simple-draw.png"
private val SAVE_FOLDER_NAME = "Simple Draw"
private val STORAGE_PERMISSION = 1
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@ -85,7 +83,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> saveImage()
R.id.menu_save -> trySaveImage()
R.id.menu_share -> shareImage()
R.id.clear -> my_canvas.clearCanvas()
R.id.change_background -> changeBackgroundClicked()
@ -124,13 +122,16 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
}
}
private fun saveImage() {
private fun trySaveImage() {
if (!hasWriteStoragePermission()) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), STORAGE_PERMISSION)
return
saveImage()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION)
}
}
val saveFileView = layoutInflater.inflate(R.layout.save_file, null)
private fun saveImage() {
val saveFileView = layoutInflater.inflate(R.layout.dialog_save_file, null)
val builder = AlertDialog.Builder(this)
builder.setTitle(resources.getString(R.string.save_file))

View File

@ -6,19 +6,20 @@
android:orientation="vertical"
android:padding="@dimen/activity_margin">
<TextView
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/file_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_name"/>
<EditText
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/file_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/file_name_label"
android:layout_marginBottom="@dimen/activity_margin"
android:singleLine="true"/>
android:singleLine="true"
android:textCursorDrawable="@null"/>
<RadioGroup
android:id="@+id/extension_radio_group"
@ -27,16 +28,17 @@
android:layout_below="@+id/file_name"
android:checkedButton="@+id/extension_radio_png">
<RadioButton
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/extension_radio_png"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=".png"/>
<RadioButton
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/extension_radio_svg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=".svg"/>
</RadioGroup>
</RelativeLayout>