From ffc79f55782008ccc59a40a6109fe4995d0b75a9 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Sat, 14 Jan 2017 18:44:43 +0100 Subject: [PATCH 1/6] Implement changing brush size (saves in preferences) --- .../com/simplemobiletools/draw/Config.java | 8 +++ .../com/simplemobiletools/draw/Constants.java | 1 + .../com/simplemobiletools/draw/MyCanvas.java | 60 ++++++++++++++----- .../simplemobiletools/draw/PaintOptions.java | 17 ++++++ .../draw/activities/MainActivity.java | 23 +++++++ app/src/main/res/layout/activity_main.xml | 10 ++++ app/src/main/res/values/dimens.xml | 1 + 7 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/draw/PaintOptions.java diff --git a/app/src/main/java/com/simplemobiletools/draw/Config.java b/app/src/main/java/com/simplemobiletools/draw/Config.java index 8bbfa34..92ce7b0 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Config.java +++ b/app/src/main/java/com/simplemobiletools/draw/Config.java @@ -39,6 +39,14 @@ public class Config { mPrefs.edit().putInt(Constants.BRUSH_COLOR_KEY, color).apply(); } + public float getStrokeWidth() { + return mPrefs.getFloat(Constants.STROKE_WIDTH_KEY, 5.0f); + } + + public void setStrokeWidth(float strokeWidth) { + mPrefs.edit().putFloat(Constants.STROKE_WIDTH_KEY, strokeWidth).apply(); + } + public int getBackgroundColor() { return mPrefs.getInt(Constants.BACKGROUND_COLOR_KEY, Color.WHITE); } diff --git a/app/src/main/java/com/simplemobiletools/draw/Constants.java b/app/src/main/java/com/simplemobiletools/draw/Constants.java index 64f7709..306f373 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Constants.java +++ b/app/src/main/java/com/simplemobiletools/draw/Constants.java @@ -4,6 +4,7 @@ public class Constants { // shared preferences public static final String PREFS_KEY = "Draw"; public static final String BRUSH_COLOR_KEY = "brush_color"; + public static final String STROKE_WIDTH_KEY = "stroke_width"; public static final String BACKGROUND_COLOR_KEY = "background_color"; public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index 4c28e94..707cd84 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -17,29 +17,31 @@ import java.util.Map; public class MyCanvas extends View { private Paint mPaint; private MyPath mPath; - private Map mPaths; + private Map mPaths; private PathsChangedListener mListener; - private int mColor; + private PaintOptions mPaintOptions; private float mCurX; private float mCurY; private float mStartX; private float mStartY; + private boolean mIsSaving = false; public MyCanvas(Context context, AttributeSet attrs) { super(context, attrs); mPath = new MyPath(); mPaint = new Paint(); - mPaint.setColor(Color.BLACK); + mPaintOptions = new PaintOptions(); + mPaint.setColor(mPaintOptions.color); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); - mPaint.setStrokeWidth(5f); + mPaint.setStrokeWidth(mPaintOptions.strokeWidth); mPaint.setAntiAlias(true); mPaths = new LinkedHashMap<>(); - mPaths.put(mPath, mPaint.getColor()); + mPaths.put(mPath, mPaintOptions); pathsUpdated(); } @@ -62,14 +64,22 @@ public class MyCanvas extends View { } public void setColor(int newColor) { - mColor = newColor; + mPaintOptions.color = newColor; + invalidate(); + } + + public void setStrokeWidth(float newStrokeWidth){ + mPaintOptions.strokeWidth = newStrokeWidth; + invalidate(); } public Bitmap getBitmap() { final Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); + mIsSaving = true; draw(canvas); + mIsSaving = false; return bitmap; } @@ -77,13 +87,30 @@ public class MyCanvas extends View { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - for (Map.Entry entry : mPaths.entrySet()) { - mPaint.setColor(entry.getValue()); + for (Map.Entry entry : mPaths.entrySet()) { + changePaint(entry.getValue()); canvas.drawPath(entry.getKey(), mPaint); } - mPaint.setColor(mColor); + changePaint(mPaintOptions); canvas.drawPath(mPath, mPaint); + + if(!mIsSaving) { + drawPreviewDot(canvas); + } + } + + private void drawPreviewDot(Canvas canvas) { + mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color)?Color.WHITE:Color.BLACK); + mPaint.setStrokeWidth(100); + canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); + changePaint(mPaintOptions); + canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); + } + + private void changePaint(PaintOptions paintOptions) { + mPaint.setColor(paintOptions.color); + mPaint.setStrokeWidth(paintOptions.strokeWidth); } public void clearCanvas() { @@ -116,9 +143,10 @@ public class MyCanvas extends View { mPath.lineTo(mCurX + 1, mCurY); } - mPaths.put(mPath, mPaint.getColor()); + mPaths.put(mPath, mPaintOptions); pathsUpdated(); mPath = new MyPath(); + mPaintOptions = new PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth); } private void pathsUpdated() { @@ -179,7 +207,7 @@ public class MyCanvas extends View { } static class SavedState extends BaseSavedState { - Map mPaths; + Map mPaths; SavedState(Parcelable superState) { super(superState); @@ -189,9 +217,11 @@ public class MyCanvas extends View { public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeInt(mPaths.size()); - for (Map.Entry entry : mPaths.entrySet()) { + for (Map.Entry entry : mPaths.entrySet()) { out.writeSerializable(entry.getKey()); - out.writeInt(entry.getValue()); + PaintOptions paintOptions = entry.getValue(); + out.writeInt(paintOptions.color); + out.writeFloat(paintOptions.strokeWidth); } } @@ -211,8 +241,8 @@ public class MyCanvas extends View { int size = in.readInt(); for (int i = 0; i < size; i++) { MyPath key = (MyPath) in.readSerializable(); - int value = in.readInt(); - mPaths.put(key, value); + PaintOptions paintOptions = new PaintOptions(in.readInt(), in.readFloat()); + mPaths.put(key, paintOptions); } } } diff --git a/app/src/main/java/com/simplemobiletools/draw/PaintOptions.java b/app/src/main/java/com/simplemobiletools/draw/PaintOptions.java new file mode 100644 index 0000000..4a72bdd --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/draw/PaintOptions.java @@ -0,0 +1,17 @@ +package com.simplemobiletools.draw; + +import android.graphics.Color; + +class PaintOptions { + int color = Color.BLACK; + float strokeWidth = 5f; + + PaintOptions() { + //Empty constructor for instantiating with default values + } + + PaintOptions(int color, float strokeWidth) { + this.color = color; + this.strokeWidth = strokeWidth; + } +} diff --git a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java index e3775de..325f3c8 100644 --- a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java @@ -19,6 +19,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.ImageView; +import android.widget.SeekBar; import android.widget.Toast; import com.simplemobiletools.draw.Config; @@ -46,10 +47,12 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange @BindView(R.id.my_canvas) MyCanvas mMyCanvas; @BindView(R.id.undo) View mUndoBtn; @BindView(R.id.color_picker) View mColorPicker; + @BindView(R.id.stroke_width_bar) SeekBar mStrokeWidthBar; private String curFileName; private int color; + private float strokeWidth; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,15 +60,21 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange setContentView(R.layout.activity_main); ButterKnife.bind(this); mMyCanvas.setListener(this); + mStrokeWidthBar.setOnSeekBarChangeListener(onStrokeWidthBarChangeListener); setBackgroundColor(mConfig.getBackgroundColor()); setColor(mConfig.getBrushColor()); + + float savedStrokeWidth = mConfig.getStrokeWidth(); + mMyCanvas.setStrokeWidth(savedStrokeWidth); + mStrokeWidthBar.setProgress((int) savedStrokeWidth); } @Override protected void onPause() { super.onPause(); mConfig.setBrushColor(color); + mConfig.setStrokeWidth(strokeWidth); } @Override @@ -290,4 +299,18 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange public void pathsChanged(int cnt) { mUndoBtn.setVisibility(cnt > 0 ? View.VISIBLE : View.GONE); } + + SeekBar.OnSeekBarChangeListener onStrokeWidthBarChangeListener = new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + mMyCanvas.setStrokeWidth(progress); + strokeWidth = progress; + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { } + }; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ab8c976..b2ded39 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -26,4 +26,14 @@ android:src="@mipmap/undo_black" android:visibility="gone"/> + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 23c2330..fcef010 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -5,6 +5,7 @@ 8dp 40dp 8dp + 150dp 14sp From 1a6c19b8b534674c7a4209398f042c153f64de41 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Sun, 15 Jan 2017 14:43:39 +0100 Subject: [PATCH 2/6] Hide brush size bar by default, added possibility to show it through settings (saves in prefs) --- .../com/simplemobiletools/draw/Config.java | 8 ++++++ .../com/simplemobiletools/draw/Constants.java | 1 + .../com/simplemobiletools/draw/MyCanvas.java | 18 ++++++++++--- .../draw/activities/MainActivity.java | 8 ++++++ .../draw/activities/SettingsActivity.java | 12 +++++++-- app/src/main/res/layout/activity_main.xml | 3 ++- app/src/main/res/layout/activity_settings.xml | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 70 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/draw/Config.java b/app/src/main/java/com/simplemobiletools/draw/Config.java index 92ce7b0..973047c 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Config.java +++ b/app/src/main/java/com/simplemobiletools/draw/Config.java @@ -31,6 +31,14 @@ public class Config { mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply(); } + public boolean getIsStrokeWidthBarEnabled() { + return mPrefs.getBoolean(Constants.IS_STROKE_WIDTH_BAR_ENABLED, false); + } + + public void setIsStrokeWidthBarEnabled(boolean isStrokeWidthBarEnabled) { + mPrefs.edit().putBoolean(Constants.IS_STROKE_WIDTH_BAR_ENABLED, isStrokeWidthBarEnabled).apply(); + } + public int getBrushColor() { return mPrefs.getInt(Constants.BRUSH_COLOR_KEY, Color.BLACK); } diff --git a/app/src/main/java/com/simplemobiletools/draw/Constants.java b/app/src/main/java/com/simplemobiletools/draw/Constants.java index 306f373..6e3696c 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Constants.java +++ b/app/src/main/java/com/simplemobiletools/draw/Constants.java @@ -8,4 +8,5 @@ public class Constants { public static final String BACKGROUND_COLOR_KEY = "background_color"; public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; + public static final String IS_STROKE_WIDTH_BAR_ENABLED = "is_stroke_width_bar_enabled"; } diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index 707cd84..f8faf97 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -26,6 +26,7 @@ public class MyCanvas extends View { private float mStartX; private float mStartY; private boolean mIsSaving = false; + private boolean mIsStrokeWidthBarEnabled = false; public MyCanvas(Context context, AttributeSet attrs) { super(context, attrs); @@ -65,11 +66,20 @@ public class MyCanvas extends View { public void setColor(int newColor) { mPaintOptions.color = newColor; - invalidate(); + if(mIsStrokeWidthBarEnabled) { + invalidate(); + } } public void setStrokeWidth(float newStrokeWidth){ mPaintOptions.strokeWidth = newStrokeWidth; + if(mIsStrokeWidthBarEnabled) { + invalidate(); + } + } + + public void setIsStrokeWidthBarEnabled(boolean isStrokeWidthBarEnabled) { + mIsStrokeWidthBarEnabled = isStrokeWidthBarEnabled; invalidate(); } @@ -95,7 +105,7 @@ public class MyCanvas extends View { changePaint(mPaintOptions); canvas.drawPath(mPath, mPaint); - if(!mIsSaving) { + if(mIsStrokeWidthBarEnabled && !mIsSaving) { drawPreviewDot(canvas); } } @@ -103,9 +113,9 @@ public class MyCanvas extends View { private void drawPreviewDot(Canvas canvas) { mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color)?Color.WHITE:Color.BLACK); mPaint.setStrokeWidth(100); - canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); + canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint); changePaint(mPaintOptions); - canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); + canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint); } private void changePaint(PaintOptions paintOptions) { diff --git a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java index 325f3c8..71f8667 100644 --- a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java @@ -70,6 +70,14 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange mStrokeWidthBar.setProgress((int) savedStrokeWidth); } + @Override + protected void onResume() { + super.onResume(); + boolean isStrokeWidthBarEnabled = mConfig.getIsStrokeWidthBarEnabled(); + mStrokeWidthBar.setVisibility(isStrokeWidthBarEnabled? View.VISIBLE:View.GONE); + mMyCanvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled); + } + @Override protected void onPause() { super.onPause(); diff --git a/app/src/main/java/com/simplemobiletools/draw/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/draw/activities/SettingsActivity.java index fd9db8d..c4093e5 100644 --- a/app/src/main/java/com/simplemobiletools/draw/activities/SettingsActivity.java +++ b/app/src/main/java/com/simplemobiletools/draw/activities/SettingsActivity.java @@ -13,6 +13,7 @@ import butterknife.OnClick; public class SettingsActivity extends SimpleActivity { @BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch; + @BindView(R.id.settings_brush_size) SwitchCompat mBrushSizeSwitch; private static Config mConfig; @@ -23,11 +24,12 @@ public class SettingsActivity extends SimpleActivity { mConfig = Config.newInstance(getApplicationContext()); ButterKnife.bind(this); - setupDarkTheme(); + setupSwitches(); } - private void setupDarkTheme() { + private void setupSwitches() { mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme()); + mBrushSizeSwitch.setChecked(mConfig.getIsStrokeWidthBarEnabled()); } @OnClick(R.id.settings_dark_theme_holder) @@ -37,6 +39,12 @@ public class SettingsActivity extends SimpleActivity { restartActivity(); } + @OnClick(R.id.settings_brush_size_holder) + public void handleBrushSize() { + mBrushSizeSwitch.setChecked(!mBrushSizeSwitch.isChecked()); + mConfig.setIsStrokeWidthBarEnabled(mBrushSizeSwitch.isChecked()); + } + private void restartActivity() { TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b2ded39..64ab360 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,6 +34,7 @@ android:max="75" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" - android:layout_marginBottom="9dp" /> + android:layout_marginBottom="9dp" + android:visibility="gone"/> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 7c4901f..e9478be 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -36,5 +36,31 @@ android:clickable="false"/> + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eca8301..27afbaf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,6 +16,7 @@ Settings Dark theme + Show brush size tool Clear Change background From ab28e2d2c72b639f637aa7a6bd60b7b15af5d779 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Sun, 15 Jan 2017 14:45:39 +0100 Subject: [PATCH 3/6] Added default strings for brush size label --- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + 7 files changed, 7 insertions(+) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2e137ab..ea7dc1d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -16,6 +16,7 @@ Einstellungen Dunkles Design + Show brush size tool Leeren Change background diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index d44a84d..8e625c0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -16,6 +16,7 @@ Ajustes Tema oscuro + Show brush size tool Limpiar Cambiar fondo diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5122cdb..c5e8e1e 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -16,6 +16,7 @@ Paramètres Thème sombre + Show brush size tool Tout effacer Changer le fond diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e739b75..09e5619 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -16,6 +16,7 @@ Impostazioni Tema scuro + Show brush size tool Clear Change background diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4db33f5..f788bad 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -16,6 +16,7 @@ 設定 ダークテーマ + Show brush size tool クリア Change background diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 5502e4e..8fd34f5 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -16,6 +16,7 @@ Definições Tema escuro + Show brush size tool Limpar Alterar fundo diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index ee2e161..3408baa 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -16,6 +16,7 @@ Inställningar Mörkt tema + Show brush size tool Clear Change background From 5d2c2560fa63b16a316ee9543c532550775a3a40 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Tue, 17 Jan 2017 23:46:20 +0100 Subject: [PATCH 4/6] Dynamic preview dot background + offset numbers converted to constants --- app/src/main/java/com/simplemobiletools/draw/Constants.java | 3 +++ app/src/main/java/com/simplemobiletools/draw/MyCanvas.java | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/draw/Constants.java b/app/src/main/java/com/simplemobiletools/draw/Constants.java index 6e3696c..fd6e4e4 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Constants.java +++ b/app/src/main/java/com/simplemobiletools/draw/Constants.java @@ -9,4 +9,7 @@ public class Constants { public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; public static final String IS_STROKE_WIDTH_BAR_ENABLED = "is_stroke_width_bar_enabled"; + // canvas + public static final int PREVIEW_DOT_STROKE_SIZE = 5; + public static final int PREVIEW_DOT_OFFSET_Y = 120; } diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index f8faf97..0d3a219 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -112,10 +112,10 @@ public class MyCanvas extends View { private void drawPreviewDot(Canvas canvas) { mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color)?Color.WHITE:Color.BLACK); - mPaint.setStrokeWidth(100); - canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint); + mPaint.setStrokeWidth(mPaintOptions.strokeWidth + Constants.PREVIEW_DOT_STROKE_SIZE); + canvas.drawPoint(getWidth()/2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); changePaint(mPaintOptions); - canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint); + canvas.drawPoint(getWidth()/2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); } private void changePaint(PaintOptions paintOptions) { From 7ca648004bb8e9bce040984c9e39de743c8da152 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Tue, 17 Jan 2017 23:57:43 +0100 Subject: [PATCH 5/6] Reformat code --- .../java/com/simplemobiletools/draw/MyCanvas.java | 14 +++++++------- .../draw/activities/MainActivity.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index 0d3a219..b643288 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -66,14 +66,14 @@ public class MyCanvas extends View { public void setColor(int newColor) { mPaintOptions.color = newColor; - if(mIsStrokeWidthBarEnabled) { + if (mIsStrokeWidthBarEnabled) { invalidate(); } } - public void setStrokeWidth(float newStrokeWidth){ + public void setStrokeWidth(float newStrokeWidth) { mPaintOptions.strokeWidth = newStrokeWidth; - if(mIsStrokeWidthBarEnabled) { + if (mIsStrokeWidthBarEnabled) { invalidate(); } } @@ -105,17 +105,17 @@ public class MyCanvas extends View { changePaint(mPaintOptions); canvas.drawPath(mPath, mPaint); - if(mIsStrokeWidthBarEnabled && !mIsSaving) { + if (mIsStrokeWidthBarEnabled && !mIsSaving) { drawPreviewDot(canvas); } } private void drawPreviewDot(Canvas canvas) { - mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color)?Color.WHITE:Color.BLACK); + mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color) ? Color.WHITE : Color.BLACK); mPaint.setStrokeWidth(mPaintOptions.strokeWidth + Constants.PREVIEW_DOT_STROKE_SIZE); - canvas.drawPoint(getWidth()/2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); + canvas.drawPoint(getWidth() / 2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); changePaint(mPaintOptions); - canvas.drawPoint(getWidth()/2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); + canvas.drawPoint(getWidth() / 2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); } private void changePaint(PaintOptions paintOptions) { diff --git a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java index 71f8667..ca4069f 100644 --- a/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/draw/activities/MainActivity.java @@ -74,7 +74,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange protected void onResume() { super.onResume(); boolean isStrokeWidthBarEnabled = mConfig.getIsStrokeWidthBarEnabled(); - mStrokeWidthBar.setVisibility(isStrokeWidthBarEnabled? View.VISIBLE:View.GONE); + mStrokeWidthBar.setVisibility(isStrokeWidthBarEnabled ? View.VISIBLE : View.GONE); mMyCanvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled); } From 17bce7fa9b993e03db3f5cde18ba227a521c3a23 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Wed, 18 Jan 2017 17:48:28 +0100 Subject: [PATCH 6/6] Moved preview dot constants to dimens.xml resource file --- .../main/java/com/simplemobiletools/draw/Constants.java | 3 --- .../main/java/com/simplemobiletools/draw/MyCanvas.java | 8 +++++--- app/src/main/res/values/dimens.xml | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/draw/Constants.java b/app/src/main/java/com/simplemobiletools/draw/Constants.java index fd6e4e4..6e3696c 100644 --- a/app/src/main/java/com/simplemobiletools/draw/Constants.java +++ b/app/src/main/java/com/simplemobiletools/draw/Constants.java @@ -9,7 +9,4 @@ public class Constants { public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; public static final String IS_STROKE_WIDTH_BAR_ENABLED = "is_stroke_width_bar_enabled"; - // canvas - public static final int PREVIEW_DOT_STROKE_SIZE = 5; - public static final int PREVIEW_DOT_OFFSET_Y = 120; } diff --git a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java index b643288..4b1f2bc 100644 --- a/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java +++ b/app/src/main/java/com/simplemobiletools/draw/MyCanvas.java @@ -1,6 +1,7 @@ package com.simplemobiletools.draw; import android.content.Context; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -111,11 +112,12 @@ public class MyCanvas extends View { } private void drawPreviewDot(Canvas canvas) { + Resources res = getResources(); mPaint.setColor(Utils.shouldUseWhite(mPaintOptions.color) ? Color.WHITE : Color.BLACK); - mPaint.setStrokeWidth(mPaintOptions.strokeWidth + Constants.PREVIEW_DOT_STROKE_SIZE); - canvas.drawPoint(getWidth() / 2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); + mPaint.setStrokeWidth(mPaintOptions.strokeWidth + res.getDimension(R.dimen.preview_dot_stroke_size)); + canvas.drawPoint(getWidth() / 2, getHeight() - res.getDimension(R.dimen.preview_dot_offset_y), mPaint); changePaint(mPaintOptions); - canvas.drawPoint(getWidth() / 2, getHeight() - Constants.PREVIEW_DOT_OFFSET_Y, mPaint); + canvas.drawPoint(getWidth() / 2, getHeight() - res.getDimension(R.dimen.preview_dot_offset_y), mPaint); } private void changePaint(PaintOptions paintOptions) { diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index fcef010..c48feeb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -6,6 +6,8 @@ 40dp 8dp 150dp + 2dp + 50dp 14sp