remember brush and background color when reopening the application (implements #30)

This commit is contained in:
Brian Pinsard 2017-01-03 18:27:57 +01:00
parent b1170f4406
commit 9ae9edf20c
3 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.draw;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
public class Config {
private SharedPreferences mPrefs;
@ -29,4 +30,18 @@ public class Config {
public void setIsDarkTheme(boolean isDarkTheme) {
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
}
public int getBrushColor() {
return mPrefs.getInt(Constants.BRUSH_COLOR_KEY, Color.BLACK);
}
public void setBrushColor(int color){
mPrefs.edit().putInt(Constants.BRUSH_COLOR_KEY, color).apply();
}
public int getBackgroundColor() { return mPrefs.getInt(Constants.BACKGROUND_COLOR_KEY, Color.WHITE); }
public void setBackgroundColor(int color){
mPrefs.edit().putInt(Constants.BACKGROUND_COLOR_KEY, color).apply();
}
}

View File

@ -3,6 +3,8 @@ package com.simplemobiletools.draw;
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 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";
}

View File

@ -4,7 +4,6 @@ import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaScannerConnection;
import android.net.Uri;
@ -59,7 +58,14 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
ButterKnife.bind(this);
mMyCanvas.setListener(this);
setColor(Color.BLACK);
mMyCanvas.setBackgroundColor(mConfig.getBackgroundColor());
setColor(mConfig.getBrushColor());
}
@Override
protected void onPause() {
super.onPause();
mConfig.setBrushColor(color);
}
@Override
@ -105,6 +111,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
((ImageView) mUndoBtn).setImageResource(R.mipmap.undo_black);
}
mMyCanvas.setBackgroundColor(pickedColor);
mConfig.setBackgroundColor(pickedColor);
}
});