mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-02-17 12:10:47 +01:00
convert some Actions to kotlin
This commit is contained in:
parent
dadad482ed
commit
ef19eafa1f
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
package="com.simplemobiletools.draw"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.simplemobiletools.draw">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
|
@ -59,12 +59,12 @@ class MyPath extends Path implements Serializable {
|
||||
|
||||
private void addAction(Action action) {
|
||||
if (action instanceof Move) {
|
||||
moveTo(((Move)action).x, ((Move)action).y);
|
||||
moveTo(((Move) action).getX(), ((Move) action).getY());
|
||||
} else if (action instanceof Line) {
|
||||
lineTo(((Line)action).x, ((Line)action).y);
|
||||
lineTo(((Line) action).getX(), ((Line) action).getY());
|
||||
} else if (action instanceof Quad) {
|
||||
final Quad q = (Quad)action;
|
||||
quadTo(q.x1, q.y1, q.x2, q.y2);
|
||||
quadTo(q.getX1(), q.getY1(), q.getX2(), q.getY2());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
package com.simplemobiletools.draw.actions;
|
||||
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public final class Line implements Action {
|
||||
|
||||
public final float x, y;
|
||||
|
||||
public Line(String data) {
|
||||
if (data.startsWith("L"))
|
||||
throw new InvalidParameterException("The Line data should start with 'L'.");
|
||||
|
||||
try {
|
||||
String[] xy = data.substring(1).split(",");
|
||||
x = Float.parseFloat(xy[0].trim());
|
||||
y = Float.parseFloat(xy[1].trim());
|
||||
} catch (Exception ignored) {
|
||||
throw new InvalidParameterException("Error parsing the given Line data.");
|
||||
}
|
||||
}
|
||||
|
||||
public Line(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Path path) {
|
||||
path.lineTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Writer writer) throws IOException {
|
||||
writer.write("L");
|
||||
writer.write(String.valueOf(x));
|
||||
writer.write(",");
|
||||
writer.write(String.valueOf(y));
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.simplemobiletools.draw.actions;
|
||||
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public final class Move implements Action {
|
||||
|
||||
public final float x, y;
|
||||
|
||||
public Move(String data) throws InvalidParameterException {
|
||||
if (data.startsWith("M"))
|
||||
throw new InvalidParameterException("The Move data should start with 'M'.");
|
||||
|
||||
try {
|
||||
String[] xy = data.substring(1).split(",");
|
||||
x = Float.parseFloat(xy[0].trim());
|
||||
y = Float.parseFloat(xy[1].trim());
|
||||
} catch (Exception ignored) {
|
||||
throw new InvalidParameterException("Error parsing the given Move data.");
|
||||
}
|
||||
}
|
||||
|
||||
public Move(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Path path) {
|
||||
path.moveTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Writer writer) throws IOException {
|
||||
writer.write('M');
|
||||
writer.write(String.valueOf(x));
|
||||
writer.write(',');
|
||||
writer.write(String.valueOf(y));
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.simplemobiletools.draw.actions;
|
||||
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public final class Quad implements Action {
|
||||
|
||||
public final float x1, y1, x2, y2;
|
||||
|
||||
public Quad(String data) {
|
||||
if (data.startsWith("Q"))
|
||||
throw new InvalidParameterException("The Quad data should start with 'Q'.");
|
||||
|
||||
try {
|
||||
String[] parts = data.split("\\s+");
|
||||
String[] xy1 = parts[0].substring(1).split(",");
|
||||
String[] xy2 = parts[1].split(","); // No need to skip the 'Q' here
|
||||
|
||||
x1 = Float.parseFloat(xy1[0].trim());
|
||||
y1 = Float.parseFloat(xy1[1].trim());
|
||||
x2 = Float.parseFloat(xy2[0].trim());
|
||||
y2 = Float.parseFloat(xy2[1].trim());
|
||||
} catch (Exception ignored) {
|
||||
throw new InvalidParameterException("Error parsing the given Quad data.");
|
||||
}
|
||||
}
|
||||
|
||||
public Quad(float x1, float y1, float x2, float y2) {
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Path path) {
|
||||
path.quadTo(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(Writer writer) throws IOException {
|
||||
writer.write('Q');
|
||||
writer.write(String.valueOf(x1));
|
||||
writer.write(',');
|
||||
writer.write(String.valueOf(y1));
|
||||
writer.write(' ');
|
||||
writer.write(String.valueOf(x2));
|
||||
writer.write(',');
|
||||
writer.write(String.valueOf(y2));
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.simplemobiletools.draw.actions
|
||||
|
||||
import android.graphics.Path
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.Writer
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
class Line : Action {
|
||||
|
||||
val x: Float
|
||||
val y: Float
|
||||
|
||||
@Throws(InvalidParameterException::class)
|
||||
constructor(data: String) {
|
||||
if (data.startsWith("L"))
|
||||
throw InvalidParameterException("The Line data should start with 'L'.")
|
||||
|
||||
try {
|
||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||
x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' })
|
||||
y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' })
|
||||
} catch (ignored: Exception) {
|
||||
throw InvalidParameterException("Error parsing the given Line data.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(x: Float, y: Float) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
override fun perform(path: Path) {
|
||||
path.lineTo(x, y)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun perform(writer: Writer) {
|
||||
writer.write("L")
|
||||
writer.write(x.toString())
|
||||
writer.write(",")
|
||||
writer.write(y.toString())
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.simplemobiletools.draw.actions
|
||||
|
||||
import android.graphics.Path
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.Writer
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
class Move : Action {
|
||||
|
||||
val x: Float
|
||||
val y: Float
|
||||
|
||||
@Throws(InvalidParameterException::class)
|
||||
constructor(data: String) {
|
||||
if (data.startsWith("M"))
|
||||
throw InvalidParameterException("The Move data should start with 'M'.")
|
||||
|
||||
try {
|
||||
val xy = data.substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||
x = java.lang.Float.parseFloat(xy[0].trim { it <= ' ' })
|
||||
y = java.lang.Float.parseFloat(xy[1].trim { it <= ' ' })
|
||||
} catch (ignored: Exception) {
|
||||
throw InvalidParameterException("Error parsing the given Move data.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(x: Float, y: Float) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
}
|
||||
|
||||
override fun perform(path: Path) {
|
||||
path.moveTo(x, y)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun perform(writer: Writer) {
|
||||
writer.write("M")
|
||||
writer.write(x.toString())
|
||||
writer.write(",")
|
||||
writer.write(y.toString())
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.simplemobiletools.draw.actions
|
||||
|
||||
import android.graphics.Path
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.Writer
|
||||
import java.security.InvalidParameterException
|
||||
|
||||
class Quad : Action {
|
||||
|
||||
val x1: Float
|
||||
val y1: Float
|
||||
val x2: Float
|
||||
val y2: Float
|
||||
|
||||
constructor(data: String) {
|
||||
if (data.startsWith("Q"))
|
||||
throw InvalidParameterException("The Quad data should start with 'Q'.")
|
||||
|
||||
try {
|
||||
val parts = data.split("\\s+".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||
val xy1 = parts[0].substring(1).split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray()
|
||||
val xy2 = parts[1].split(",".toRegex()).dropLastWhile(String::isEmpty).toTypedArray() // No need to skip the 'Q' here
|
||||
|
||||
x1 = java.lang.Float.parseFloat(xy1[0].trim { it <= ' ' })
|
||||
y1 = java.lang.Float.parseFloat(xy1[1].trim { it <= ' ' })
|
||||
x2 = java.lang.Float.parseFloat(xy2[0].trim { it <= ' ' })
|
||||
y2 = java.lang.Float.parseFloat(xy2[1].trim { it <= ' ' })
|
||||
} catch (ignored: Exception) {
|
||||
throw InvalidParameterException("Error parsing the given Quad data.")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(x1: Float, y1: Float, x2: Float, y2: Float) {
|
||||
this.x1 = x1
|
||||
this.y1 = y1
|
||||
this.x2 = x2
|
||||
this.y2 = y2
|
||||
}
|
||||
|
||||
override fun perform(path: Path) {
|
||||
path.quadTo(x1, y1, x2, y2)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun perform(writer: Writer) {
|
||||
writer.write("Q")
|
||||
writer.write(x1.toString())
|
||||
writer.write(",")
|
||||
writer.write(y1.toString())
|
||||
writer.write(" ")
|
||||
writer.write(x2.toString())
|
||||
writer.write(",")
|
||||
writer.write(y2.toString())
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user