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-556 - New Shapes-2 #1335

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"),
GIF("gif");

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 <MainActivity> 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,21 @@
*/
package org.catrobat.paintroid

import java.io.File
import java.lang.IllegalArgumentException

import android.graphics.Bitmap

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

init {
throw IllegalArgumentException()
return Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888)
}
}
}






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?)
fun showGifInformationDialog()
}

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 @@ -36,19 +37,36 @@ import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatImageButton
import androidx.appcompat.widget.AppCompatTextView
import org.catrobat.paintroid.FileIO
import org.catrobat.paintroid.FileIO.FileType


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 All @@ -57,6 +75,7 @@ class SaveInformationDialog :
private lateinit var inflater: LayoutInflater
private lateinit var specificFormatLayout: ViewGroup
private lateinit var jpgView: View

private lateinit var percentage: AppCompatTextView
private lateinit var imageName: AppCompatEditText
private lateinit var fileName: String
Expand All @@ -73,7 +92,7 @@ class SaveInformationDialog :
if (isStandard) {
FileIO.filename = STANDARD_FILE_NAME
FileIO.compressFormat = Bitmap.CompressFormat.PNG
FileIO.fileType = PNG

}
return SaveInformationDialog().apply {
arguments = Bundle().apply {
Expand Down Expand Up @@ -118,17 +137,21 @@ class SaveInformationDialog :
FileIO.storeImageUri = null
if (FileIO.checkFileExists(FileIO.fileType, FileIO.defaultFileName, requireContext().contentResolver)) {
presenter.showOverwriteDialog(permission, isExport)

} else {
presenter.switchBetweenVersions(permission, isExport)

}
dismiss()
}
.setNegativeButton(R.string.cancel_button_text) { _, _ -> dismiss() }
.create()
}


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


initJpgView()
initSeekBar()
initPercentage()
Expand All @@ -141,6 +164,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,16 +195,19 @@ 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 }
val adapter = ArrayAdapter(spinner.context, android.R.layout.simple_spinner_item, spinnerArray)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) //xml file
spinner.adapter = adapter
spinner.onItemSelectedListener = this
}
Expand All @@ -204,6 +234,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 +243,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 +259,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 @@ -60,7 +60,7 @@ class SaveImage(
val imageUri = FileIO.saveBitmapToFile(filename, bitmap, callback.contentResolver, context)
imageUri
} else {
uri?.let { FileIO.saveBitmapToUri(it, bitmap, context) }
uri?.let { FileIO.saveBitmapToUri<Any>(it, bitmap, context) }
}
}

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

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

import android.graphics.Path


class ArrowDrawable :ShapeDrawable {
private val path = Path()
override fun draw(canvas: Canvas, shapeRect: RectF, drawPaint: Paint) {
val midWidth = shapeRect.width() / 2
val midHeight = shapeRect.height() / 2

path.run {
reset()
moveTo(shapeRect.left, midHeight)
lineTo(midWidth, shapeRect.top)
lineTo(shapeRect.right, midHeight)
lineTo(midWidth, shapeRect.bottom)
close()
offset(shapeRect.left, shapeRect.top)
}
canvas.drawPath(path, drawPaint)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ class DrawableFactory {
DrawableShape.OVAL -> OvalDrawable()
DrawableShape.HEART -> HeartDrawable()
DrawableShape.STAR -> StarDrawable()
DrawableShape.PENTAGON -> PentagonDrawable()
DrawableShape.TRIANGLE -> TriangleDrawable()
DrawableShape.HEXAGON -> HexagonDrawable()
DrawableShape.OCTAGON -> OctagonDrawable()
DrawableShape.ARROW -> ArrowDrawable()
DrawableShape.CROSS -> ArrowDrawable()
DrawableShape.TICK -> ArrowDrawable()
DrawableShape.MOON -> ArrowDrawable()
DrawableShape.LIGHTNING -> ArrowDrawable()
DrawableShape.SPEECH -> ArrowDrawable()


}
}
}
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 , OCTAGON,ARROW,CROSS,TICK,MOON,LIGHTNING,SPEECH
}
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 = 2f
private const val CONSTANT_2 = 1.7f
class LightningDrawable: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 - height)

lineTo(midWidth, midHeight + height)
lineTo(midWidth + width, midHeight - height)
lineTo(midWidth + width / 2, midHeight - height)
lineTo(midWidth + width / 2, midHeight + height)
lineTo(midWidth + width * 2, midHeight - height)

lineTo(midWidth + width * 2, midHeight + height)
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 = 2f
private const val CONSTANT_2 = 1.7f

class MoonDrawable : 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()

val leftArcRect = RectF(midWidth - width, midHeight - height, midWidth + width, midHeight + height)
arcTo(leftArcRect, 90f, 180f)


val rightArcRect = RectF(midWidth, midHeight - height, midWidth + width * 2, midHeight + height)
arcTo(rightArcRect, -90f, 180f)

close()
offset(shapeRect.left, shapeRect.top)
}
canvas.drawPath(path, drawPaint)
}
}
Loading