Hide brush size bar by default, added possibility to show it through settings (saves in prefs)

This commit is contained in:
Brian Pinsard 2017-01-15 14:43:39 +01:00
parent ffc79f5578
commit 1a6c19b8b5
8 changed files with 70 additions and 7 deletions

View File

@ -31,6 +31,14 @@ public class Config {
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply(); 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() { public int getBrushColor() {
return mPrefs.getInt(Constants.BRUSH_COLOR_KEY, Color.BLACK); return mPrefs.getInt(Constants.BRUSH_COLOR_KEY, Color.BLACK);
} }

View File

@ -8,4 +8,5 @@ public class Constants {
public static final String BACKGROUND_COLOR_KEY = "background_color"; public static final String BACKGROUND_COLOR_KEY = "background_color";
public static final String IS_FIRST_RUN = "is_first_run"; 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_DARK_THEME = "is_dark_theme";
public static final String IS_STROKE_WIDTH_BAR_ENABLED = "is_stroke_width_bar_enabled";
} }

View File

@ -26,6 +26,7 @@ public class MyCanvas extends View {
private float mStartX; private float mStartX;
private float mStartY; private float mStartY;
private boolean mIsSaving = false; private boolean mIsSaving = false;
private boolean mIsStrokeWidthBarEnabled = false;
public MyCanvas(Context context, AttributeSet attrs) { public MyCanvas(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -65,11 +66,20 @@ public class MyCanvas extends View {
public void setColor(int newColor) { public void setColor(int newColor) {
mPaintOptions.color = newColor; mPaintOptions.color = newColor;
if(mIsStrokeWidthBarEnabled) {
invalidate(); invalidate();
} }
}
public void setStrokeWidth(float newStrokeWidth){ public void setStrokeWidth(float newStrokeWidth){
mPaintOptions.strokeWidth = newStrokeWidth; mPaintOptions.strokeWidth = newStrokeWidth;
if(mIsStrokeWidthBarEnabled) {
invalidate();
}
}
public void setIsStrokeWidthBarEnabled(boolean isStrokeWidthBarEnabled) {
mIsStrokeWidthBarEnabled = isStrokeWidthBarEnabled;
invalidate(); invalidate();
} }
@ -95,7 +105,7 @@ public class MyCanvas extends View {
changePaint(mPaintOptions); changePaint(mPaintOptions);
canvas.drawPath(mPath, mPaint); canvas.drawPath(mPath, mPaint);
if(!mIsSaving) { if(mIsStrokeWidthBarEnabled && !mIsSaving) {
drawPreviewDot(canvas); drawPreviewDot(canvas);
} }
} }
@ -103,9 +113,9 @@ public class MyCanvas extends View {
private void drawPreviewDot(Canvas 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(100); mPaint.setStrokeWidth(100);
canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint);
changePaint(mPaintOptions); changePaint(mPaintOptions);
canvas.drawPoint(getWidth()/2, getHeight() - 100, mPaint); canvas.drawPoint(getWidth()/2, getHeight() - 120, mPaint);
} }
private void changePaint(PaintOptions paintOptions) { private void changePaint(PaintOptions paintOptions) {

View File

@ -70,6 +70,14 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
mStrokeWidthBar.setProgress((int) savedStrokeWidth); 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 @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();

View File

@ -13,6 +13,7 @@ import butterknife.OnClick;
public class SettingsActivity extends SimpleActivity { public class SettingsActivity extends SimpleActivity {
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch; @BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
@BindView(R.id.settings_brush_size) SwitchCompat mBrushSizeSwitch;
private static Config mConfig; private static Config mConfig;
@ -23,11 +24,12 @@ public class SettingsActivity extends SimpleActivity {
mConfig = Config.newInstance(getApplicationContext()); mConfig = Config.newInstance(getApplicationContext());
ButterKnife.bind(this); ButterKnife.bind(this);
setupDarkTheme(); setupSwitches();
} }
private void setupDarkTheme() { private void setupSwitches() {
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme()); mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
mBrushSizeSwitch.setChecked(mConfig.getIsStrokeWidthBarEnabled());
} }
@OnClick(R.id.settings_dark_theme_holder) @OnClick(R.id.settings_dark_theme_holder)
@ -37,6 +39,12 @@ public class SettingsActivity extends SimpleActivity {
restartActivity(); restartActivity();
} }
@OnClick(R.id.settings_brush_size_holder)
public void handleBrushSize() {
mBrushSizeSwitch.setChecked(!mBrushSizeSwitch.isChecked());
mConfig.setIsStrokeWidthBarEnabled(mBrushSizeSwitch.isChecked());
}
private void restartActivity() { private void restartActivity() {
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities(); TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
} }

View File

@ -34,6 +34,7 @@
android:max="75" android:max="75"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginBottom="9dp" /> android:layout_marginBottom="9dp"
android:visibility="gone"/>
</RelativeLayout> </RelativeLayout>

View File

@ -36,5 +36,31 @@
android:clickable="false"/> android:clickable="false"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_brush_size_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_brush_size_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/brush_size"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_brush_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -16,6 +16,7 @@
<!-- Settings --> <!-- Settings -->
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="dark_theme">Dark theme</string> <string name="dark_theme">Dark theme</string>
<string name="brush_size">Show brush size tool</string>
<string name="clear">Clear</string> <string name="clear">Clear</string>
<string name="change_background">Change background</string> <string name="change_background">Change background</string>