Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-708- Added GIF format to image saving options #1333

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ object FileIO {
PNG("png"),
JPG("jpg"),
ORA("ora"),
CATROBAT("catrobat-image");
CATROBAT("catrobat-image"),


fun toExtension(): String = ".$value"
}
Expand Down Expand Up @@ -132,7 +133,7 @@ object FileIO {
}

@Throws(IOException::class)
fun saveBitmapToUri(uri: Uri, bitmap: Bitmap?, context: Context): Uri {
fun saveBitmapToUri(uri: Uri, bitmap: Bitmap?, context: Context): Uri {
val uid = UUID.randomUUID()
val cachedImageUri = saveBitmapToCache(bitmap, context as MainActivity, uid.toString())
var cachedFile: File? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,26 @@
*/
package org.catrobat.paintroid


import android.graphics.Bitmap
import java.io.File
import java.lang.IllegalArgumentException


@SuppressWarnings("ThrowingExceptionsWithoutMessageOrCause")
class PaintroidApplication private constructor() {
companion object {
@JvmStatic
var cacheDir: File? = null
}

init {
throw IllegalArgumentException()
init {
throw IllegalArgumentException()
}
}
}






Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ interface MainActivityContracts {
fun checkForTemporaryFile(): Boolean

fun setColorHistoryAfterLoadImage(colorHistory: ColorHistory?)

}

interface Model {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.annotation.SuppressLint
import android.app.Dialog
import android.graphics.Bitmap
import android.os.Bundle
import android.os.Environment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -41,14 +42,30 @@ import org.catrobat.paintroid.FileIO.FileType.PNG
import org.catrobat.paintroid.FileIO.FileType.JPG
import org.catrobat.paintroid.FileIO.FileType.CATROBAT
import org.catrobat.paintroid.FileIO.FileType.ORA
import org.catrobat.paintroid.PaintroidApplication


import org.catrobat.paintroid.R
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.util.Locale








private const val STANDARD_FILE_NAME = "image"
private const val SET_NAME = "setName"
private const val PERMISSION = "permission"
private const val IS_EXPORT = "isExport"




class SaveInformationDialog :
MainActivityDialogFragment(),
OnItemSelectedListener,
Expand Down Expand Up @@ -118,6 +135,7 @@ class SaveInformationDialog :
FileIO.storeImageUri = null
if (FileIO.checkFileExists(FileIO.fileType, FileIO.defaultFileName, requireContext().contentResolver)) {
presenter.showOverwriteDialog(permission, isExport)

} else {
presenter.switchBetweenVersions(permission, isExport)
}
Expand All @@ -127,8 +145,12 @@ class SaveInformationDialog :
.create()
}



private fun initViews(customLayout: View) {
initSpecificFormatLayout(customLayout)


initJpgView()
initSeekBar()
initPercentage()
Expand All @@ -141,6 +163,10 @@ class SaveInformationDialog :
specificFormatLayout = view.findViewById(R.id.pocketpaint_save_format_specific_options)
}





private fun initJpgView() {
jpgView = inflater.inflate(
R.layout.dialog_pocketpaint_save_jpg_sub_dialog,
Expand Down Expand Up @@ -168,11 +194,14 @@ class SaveInformationDialog :
JPG -> presenter.showJpgInformationDialog()
ORA -> presenter.showOraInformationDialog()
CATROBAT -> presenter.showCatrobatInformationDialog()
FileType.GIF -> presenter.showGifInformationDialog()
else -> presenter.showPngInformationDialog()
}
}
}



private fun initSpinner(view: View) {
spinner = view.findViewById(R.id.pocketpaint_save_dialog_spinner)
val spinnerArray = FileType.values().map { it.value }
Expand Down Expand Up @@ -204,6 +233,7 @@ class SaveInformationDialog :
JPG -> spinner.setSelection(JPG.ordinal)
ORA -> spinner.setSelection(ORA.ordinal)
CATROBAT -> spinner.setSelection(CATROBAT.ordinal)

else -> spinner.setSelection(PNG.ordinal)
}
}
Expand All @@ -212,8 +242,10 @@ class SaveInformationDialog :
when (parent?.getItemAtPosition(position).toString().toLowerCase(Locale.getDefault())) {
JPG.value -> setFileDetails(Bitmap.CompressFormat.JPEG, JPG)
PNG.value -> setFileDetails(Bitmap.CompressFormat.PNG, PNG)

ORA.value -> setFileDetails(Bitmap.CompressFormat.PNG, ORA)
CATROBAT.value -> setFileDetails(Bitmap.CompressFormat.PNG, CATROBAT)

}
}

Expand All @@ -226,3 +258,6 @@ class SaveInformationDialog :
override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar) = Unit
}



Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class DrawableFactory {
DrawableShape.OVAL -> OvalDrawable()
DrawableShape.HEART -> HeartDrawable()
DrawableShape.STAR -> StarDrawable()
DrawableShape.PENTAGON -> PentagonDrawable()
DrawableShape.TRIANGLE -> TriangleDrawable()
DrawableShape.HEXAGON -> HexagonDrawable()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
package org.catrobat.paintroid.tools.drawable

enum class DrawableShape {
RECTANGLE, OVAL, HEART, STAR
RECTANGLE, OVAL, HEART, STAR , PENTAGON, TRIANGLE, HEXAGON
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.catrobat.paintroid.tools.drawable
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF

private const val CONSTANT_1 = 2f
private const val CONSTANT_2 = 1.7f
class HexagonDrawable:ShapeDrawable {
private val path = Path()
override fun draw(canvas: Canvas, shapeRect: RectF, drawPaint: Paint) {
val midWidth = shapeRect.width() / 2
val midHeight = shapeRect.height() / 2
val height = shapeRect.height() / CONSTANT_2
val width = shapeRect.width() / CONSTANT_1
path.run {
reset()
moveTo(midWidth - width, midHeight)
lineTo(midWidth - width/2, midHeight - height)
lineTo(midWidth + width/2, midHeight - height)
lineTo(midWidth + width, midHeight)
lineTo(midWidth + width/2, midHeight + height)
lineTo(midWidth - width/2, midHeight + height)
lineTo(midWidth - width, midHeight)
close()
offset(shapeRect.left, shapeRect.top)
}
canvas.drawPath(path, drawPaint)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.catrobat.paintroid.tools.drawable

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF

private const val CONSTANT_1 = 0.95f
private const val CONSTANT_2 = 0.31f
private const val CONSTANT_3 = 0.59f
class PentagonDrawable : ShapeDrawable{

private val path = Path()

override fun draw(canvas: Canvas, shapeRect: RectF, drawPaint: Paint) {
val midWidth = shapeRect.width() / 2
val midHeight = shapeRect.height() / 2
val height = shapeRect.height()
val width = shapeRect.width()
path.run {
reset()
moveTo(midWidth, 0f)
lineTo(midWidth + CONSTANT_1 * width / 2, CONSTANT_2 * height)
lineTo(midWidth + CONSTANT_3 * width / 2, height)
lineTo(midWidth - CONSTANT_3 * width / 2, height)
lineTo(midWidth - CONSTANT_1 * width / 2, CONSTANT_2 * height)
lineTo(midWidth, 0f)
close()
offset(shapeRect.left, shapeRect.top)
}
canvas.drawPath(path, drawPaint)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.catrobat.paintroid.tools.drawable

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
class TriangleDrawable :ShapeDrawable{
private val path = Path()

override fun draw(canvas: Canvas, shapeRect: RectF, drawPaint: Paint) {
path.run {
reset()
moveTo(shapeRect.left, shapeRect.bottom)
lineTo(shapeRect.right, shapeRect.bottom)
lineTo(shapeRect.centerX(), shapeRect.top)
lineTo(shapeRect.left, shapeRect.bottom)
close()
}
canvas.drawPath(path, drawPaint)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
drawingThread?.stop()
}

fun copyBitmap() {

}

private inner class DrawLoop : Runnable {
val holder: SurfaceHolder = getHolder()
override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
private val outlineWidthEditText: AppCompatEditText
private val shapeToolDialogTitle: AppCompatTextView
private val shapeToolFillOutline: AppCompatTextView
private val triangleButton: AppCompatImageButton
private val pentagonButton: AppCompatImageButton
private val hexagonButton: AppCompatImageButton

init {
val inflater = LayoutInflater.from(rootView.context)
Expand All @@ -74,6 +77,9 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
outlineTextView = findViewById(R.id.pocketpaint_outline_view_text_view)
outlineWidthSeekBar = findViewById(R.id.pocketpaint_shape_stroke_width_seek_bar)
outlineWidthEditText = findViewById(R.id.pocketpaint_shape_outline_edit)
triangleButton = findViewById(R.id.pocketpaint_shapes_triangle_btn)
pentagonButton = findViewById(R.id.pocketpaint_shapes_pentagon_btn)
hexagonButton = findViewById(R.id.pocketpaint_shapes_hexagon_btn)
}
outlineWidthEditText.filters =
arrayOf<InputFilter>(DefaultNumberRangeFilter(MIN_VAL, MAX_VAL))
Expand All @@ -89,6 +95,10 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
circleButton.setOnClickListener { onShapeClicked(DrawableShape.OVAL) }
heartButton.setOnClickListener { onShapeClicked(DrawableShape.HEART) }
starButton.setOnClickListener { onShapeClicked(DrawableShape.STAR) }
triangleButton.setOnClickListener { onShapeClicked(DrawableShape.TRIANGLE) }
pentagonButton.setOnClickListener { onShapeClicked(DrawableShape.PENTAGON) }
hexagonButton.setOnClickListener { onShapeClicked(DrawableShape.HEXAGON) }

fillButton.setOnClickListener { onDrawTypeClicked(DrawableStyle.FILL) }
outlineButton.setOnClickListener { onDrawTypeClicked(DrawableStyle.STROKE) }
outlineWidthSeekBar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
Expand Down Expand Up @@ -141,7 +151,16 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
}

private fun resetShapeActivated() {
val buttons = arrayOf<View>(squareButton, circleButton, heartButton, starButton)
//val buttons = arrayOf<View>(squareButton, circleButton, heartButton, starButton,)
val buttons = arrayOf<View>(
squareButton,
circleButton,
heartButton,
starButton,
triangleButton,
pentagonButton,
hexagonButton
)
for (button in buttons) {
button.isSelected = false
}
Expand Down Expand Up @@ -175,6 +194,18 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
starButton.isSelected = true
setShapeToolDialogTitle(R.string.shape_tool_dialog_star_title)
}
DrawableShape.TRIANGLE -> {
triangleButton.isSelected = true
setShapeToolDialogTitle(R.string.shape_tool_dialog_triangle_title)
}
DrawableShape.PENTAGON -> {
pentagonButton.isSelected = true
setShapeToolDialogTitle(R.string.shape_tool_dialog_pentagon_title)
}
DrawableShape.HEXAGON -> {
hexagonButton.isSelected = true
setShapeToolDialogTitle(R.string.shape_tool_dialog_hexagon_title)
}
}
}

Expand All @@ -184,13 +215,21 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
circleButtonResource: Int,
heartButtonResource: Int,
starButtonResource: Int,
triangleButtonResource: Int,
pentagonButtonResource: Int,
hexagonButtonResource: Int,

visibility: Int
) {
shapeToolFillOutline.setText(fillTitle)
squareButton.setImageResource(squareButtonResource)
circleButton.setImageResource(circleButtonResource)
heartButton.setImageResource(heartButtonResource)
starButton.setImageResource(starButtonResource)
triangleButton.setImageResource(triangleButtonResource)
pentagonButton.setImageResource(pentagonButtonResource)
hexagonButton.setImageResource(hexagonButtonResource)

outlineWidthSeekBar.visibility = visibility
outlineWidthEditText.visibility = visibility
outlineView.visibility = visibility
Expand All @@ -208,6 +247,9 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
R.drawable.ic_pocketpaint_circle,
R.drawable.ic_pocketpaint_heart,
R.drawable.ic_pocketpaint_star,
R.drawable.ic_pocketpaint_triangle,
R.drawable.ic_pocketpaint_pentagon,
R.drawable.ic_pocketpaint_hexagon,
View.GONE
)
}
Expand All @@ -219,6 +261,9 @@ class DefaultShapeToolOptionsView(rootView: ViewGroup) : ShapeToolOptionsView {
R.drawable.ic_pocketpaint_circle_out,
R.drawable.ic_pocketpaint_heart_out,
R.drawable.ic_pocketpaint_star_out,
R.drawable.ic_pocketpaint_triangle_out,
R.drawable.ic_pocketpaint_pentagon_out,
R.drawable.ic_pocketpaint_hexagon_out,
View.VISIBLE
)
}
Expand Down
Loading