From 1a6c19b8b534674c7a4209398f042c153f64de41 Mon Sep 17 00:00:00 2001 From: Brian Pinsard Date: Sun, 15 Jan 2017 14:43:39 +0100 Subject: [PATCH] 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