couple styling updates
This commit is contained in:
parent
9a6614d1b2
commit
08c23c851e
|
@ -94,7 +94,7 @@ public class MyCanvas extends View {
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
public Map<MyPath,PaintOptions> getPaths() {
|
||||
public Map<MyPath, PaintOptions> getPaths() {
|
||||
return mPaths;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class PaintOptions {
|
|||
float strokeWidth = 5f;
|
||||
|
||||
PaintOptions() {
|
||||
//Empty constructor for instantiating with default values
|
||||
|
||||
}
|
||||
|
||||
PaintOptions(int color, float strokeWidth) {
|
||||
|
|
|
@ -13,29 +13,23 @@ import java.io.Writer;
|
|||
import java.util.Map;
|
||||
|
||||
public class Svg {
|
||||
|
||||
public static void saveSvg(File output, MyCanvas canvas)
|
||||
throws Exception {
|
||||
// This might throw ClassCastException
|
||||
public static void saveSvg(File output, MyCanvas canvas) throws Exception {
|
||||
int backgroundColor = ((ColorDrawable) canvas.getBackground()).getColor();
|
||||
|
||||
// This might throw IOException
|
||||
FileOutputStream out = new FileOutputStream(output);
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
|
||||
writeSvg(writer, backgroundColor, canvas.getPaths(), canvas.getWidth(), canvas.getHeight());
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private static void writeSvg(Writer writer, int backgroundColor,
|
||||
Map<MyPath, PaintOptions> paths, int width, int height)
|
||||
throws IOException {
|
||||
private static void writeSvg(Writer writer, int backgroundColor, Map<MyPath, PaintOptions> paths, int width, int height) throws IOException {
|
||||
writer.write("<svg width=\"");
|
||||
writer.write(String.valueOf(width));
|
||||
writer.write("\" height=\"");
|
||||
writer.write(String.valueOf(height));
|
||||
writer.write("\" xmlns=\"http://www.w3.org/2000/svg\">");
|
||||
|
||||
// Background color (use a rect)
|
||||
// background rect
|
||||
writer.write("<rect width=\"");
|
||||
writer.write(String.valueOf(width));
|
||||
writer.write("\" height=\"");
|
||||
|
@ -44,16 +38,13 @@ public class Svg {
|
|||
writer.write(Integer.toHexString(backgroundColor).substring(2)); // Skip the alpha FF
|
||||
writer.write("\"/>");
|
||||
|
||||
// Write the paths
|
||||
for (Map.Entry<MyPath, PaintOptions> entry : paths.entrySet()) {
|
||||
writePath(writer, entry.getKey(), entry.getValue());
|
||||
}
|
||||
writer.write("</svg>");
|
||||
}
|
||||
|
||||
private static void writePath(Writer writer, MyPath path, PaintOptions options)
|
||||
throws IOException {
|
||||
|
||||
private static void writePath(Writer writer, MyPath path, PaintOptions options) throws IOException {
|
||||
writer.write("<path d=\"");
|
||||
for (Action action : path.getActions()) {
|
||||
action.perform(writer);
|
||||
|
|
|
@ -8,5 +8,6 @@ import java.io.Writer;
|
|||
|
||||
public interface Action extends Serializable {
|
||||
void perform(Path path);
|
||||
|
||||
void perform(Writer writer) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.simplemobiletools.draw.actions;
|
||||
|
||||
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -185,9 +185,12 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||
if (!fileName.isEmpty()) {
|
||||
final String extension;
|
||||
switch (fileExtensionRG.getCheckedRadioButtonId()) {
|
||||
case R.id.extension_radio_svg:
|
||||
extension = ".svg";
|
||||
break;
|
||||
default:
|
||||
case R.id.extension_radio_png: extension = ".png"; break;
|
||||
case R.id.extension_radio_svg: extension = ".svg"; break;
|
||||
extension = ".png";
|
||||
break;
|
||||
}
|
||||
|
||||
if (saveFile(fileName, extension)) {
|
||||
|
@ -215,16 +218,15 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||
}
|
||||
}
|
||||
|
||||
final File file = new File(directory, fileName+extension);
|
||||
final File file = new File(directory, fileName + extension);
|
||||
switch (extension) {
|
||||
case ".png":
|
||||
case ".png": {
|
||||
final Bitmap bitmap = mMyCanvas.getBitmap();
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(file);
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||
MediaScannerConnection.scanFile(getApplicationContext(),
|
||||
new String[]{file.getAbsolutePath()}, null, null);
|
||||
MediaScannerConnection.scanFile(getApplicationContext(), new String[]{file.getAbsolutePath()}, null, null);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "MainActivity SaveFile (.png) " + e.getMessage());
|
||||
return false;
|
||||
|
@ -238,8 +240,8 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ".svg":
|
||||
}
|
||||
case ".svg": {
|
||||
try {
|
||||
Svg.saveSvg(file, mMyCanvas);
|
||||
} catch (Exception e) {
|
||||
|
@ -247,7 +249,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -349,9 +351,11 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) { }
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) { }
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/file_name_label"
|
||||
|
@ -38,5 +39,4 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text=".svg"/>
|
||||
</RadioGroup>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue