Hide brush size bar by default, added possibility to show it through settings (saves in prefs)
This commit is contained in:
parent
ffc79f5578
commit
1a6c19b8b5
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -36,5 +36,31 @@
|
|||
android:clickable="false"/>
|
||||
|
||||
</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>
|
||||
</ScrollView>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
<string name="brush_size">Show brush size tool</string>
|
||||
<string name="clear">Clear</string>
|
||||
<string name="change_background">Change background</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue