couple styling updates

This commit is contained in:
tibbi
2017-01-20 19:00:11 +01:00
parent 9a6614d1b2
commit 08c23c851e
7 changed files with 28 additions and 33 deletions

View File

@ -94,7 +94,7 @@ public class MyCanvas extends View {
return bitmap; return bitmap;
} }
public Map<MyPath,PaintOptions> getPaths() { public Map<MyPath, PaintOptions> getPaths() {
return mPaths; return mPaths;
} }

View File

@ -7,7 +7,7 @@ class PaintOptions {
float strokeWidth = 5f; float strokeWidth = 5f;
PaintOptions() { PaintOptions() {
//Empty constructor for instantiating with default values
} }
PaintOptions(int color, float strokeWidth) { PaintOptions(int color, float strokeWidth) {

View File

@ -13,29 +13,23 @@ import java.io.Writer;
import java.util.Map; import java.util.Map;
public class Svg { public class Svg {
public static void saveSvg(File output, MyCanvas canvas) throws Exception {
public static void saveSvg(File output, MyCanvas canvas)
throws Exception {
// This might throw ClassCastException
int backgroundColor = ((ColorDrawable) canvas.getBackground()).getColor(); int backgroundColor = ((ColorDrawable) canvas.getBackground()).getColor();
// This might throw IOException
FileOutputStream out = new FileOutputStream(output); FileOutputStream out = new FileOutputStream(output);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
writeSvg(writer, backgroundColor, canvas.getPaths(), canvas.getWidth(), canvas.getHeight()); writeSvg(writer, backgroundColor, canvas.getPaths(), canvas.getWidth(), canvas.getHeight());
writer.close(); writer.close();
} }
private static void writeSvg(Writer writer, int backgroundColor, private static void writeSvg(Writer writer, int backgroundColor, Map<MyPath, PaintOptions> paths, int width, int height) throws IOException {
Map<MyPath, PaintOptions> paths, int width, int height)
throws IOException {
writer.write("<svg width=\""); writer.write("<svg width=\"");
writer.write(String.valueOf(width)); writer.write(String.valueOf(width));
writer.write("\" height=\""); writer.write("\" height=\"");
writer.write(String.valueOf(height)); writer.write(String.valueOf(height));
writer.write("\" xmlns=\"http://www.w3.org/2000/svg\">"); writer.write("\" xmlns=\"http://www.w3.org/2000/svg\">");
// Background color (use a rect) // background rect
writer.write("<rect width=\""); writer.write("<rect width=\"");
writer.write(String.valueOf(width)); writer.write(String.valueOf(width));
writer.write("\" height=\""); writer.write("\" height=\"");
@ -44,16 +38,13 @@ public class Svg {
writer.write(Integer.toHexString(backgroundColor).substring(2)); // Skip the alpha FF writer.write(Integer.toHexString(backgroundColor).substring(2)); // Skip the alpha FF
writer.write("\"/>"); writer.write("\"/>");
// Write the paths
for (Map.Entry<MyPath, PaintOptions> entry : paths.entrySet()) { for (Map.Entry<MyPath, PaintOptions> entry : paths.entrySet()) {
writePath(writer, entry.getKey(), entry.getValue()); writePath(writer, entry.getKey(), entry.getValue());
} }
writer.write("</svg>"); writer.write("</svg>");
} }
private static void writePath(Writer writer, MyPath path, PaintOptions options) private static void writePath(Writer writer, MyPath path, PaintOptions options) throws IOException {
throws IOException {
writer.write("<path d=\""); writer.write("<path d=\"");
for (Action action : path.getActions()) { for (Action action : path.getActions()) {
action.perform(writer); action.perform(writer);

View File

@ -8,5 +8,6 @@ import java.io.Writer;
public interface Action extends Serializable { public interface Action extends Serializable {
void perform(Path path); void perform(Path path);
void perform(Writer writer) throws IOException; void perform(Writer writer) throws IOException;
} }

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.draw.actions; package com.simplemobiletools.draw.actions;
import android.graphics.Path; import android.graphics.Path;
import java.io.IOException; import java.io.IOException;

View File

@ -185,9 +185,12 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
final String extension; final String extension;
switch (fileExtensionRG.getCheckedRadioButtonId()) { switch (fileExtensionRG.getCheckedRadioButtonId()) {
case R.id.extension_radio_svg:
extension = ".svg";
break;
default: default:
case R.id.extension_radio_png: extension = ".png"; break; extension = ".png";
case R.id.extension_radio_svg: extension = ".svg"; break; break;
} }
if (saveFile(fileName, extension)) { 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) { switch (extension) {
case ".png": case ".png": {
final Bitmap bitmap = mMyCanvas.getBitmap(); final Bitmap bitmap = mMyCanvas.getBitmap();
FileOutputStream out = null; FileOutputStream out = null;
try { try {
out = new FileOutputStream(file); out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
MediaScannerConnection.scanFile(getApplicationContext(), MediaScannerConnection.scanFile(getApplicationContext(), new String[]{file.getAbsolutePath()}, null, null);
new String[]{file.getAbsolutePath()}, null, null);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "MainActivity SaveFile (.png) " + e.getMessage()); Log.e(TAG, "MainActivity SaveFile (.png) " + e.getMessage());
return false; return false;
@ -238,8 +240,8 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
} }
} }
break; break;
}
case ".svg": case ".svg": {
try { try {
Svg.saveSvg(file, mMyCanvas); Svg.saveSvg(file, mMyCanvas);
} catch (Exception e) { } catch (Exception e) {
@ -247,7 +249,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
return false; return false;
} }
break; break;
}
default: default:
return false; return false;
} }
@ -349,9 +351,11 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
} }
@Override @Override
public void onStartTrackingTouch(SeekBar seekBar) { } public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) {
}
}; };
} }

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="match_parent"
android:padding="@dimen/activity_margin"> android:orientation="vertical"
android:padding="@dimen/activity_margin">
<TextView <TextView
android:id="@+id/file_name_label" android:id="@+id/file_name_label"
@ -38,5 +39,4 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=".svg"/> android:text=".svg"/>
</RadioGroup> </RadioGroup>
</RelativeLayout> </RelativeLayout>