remember brush and background color when reopening the application (implements #30)
This commit is contained in:
parent
b1170f4406
commit
9ae9edf20c
|
@ -2,6 +2,7 @@ package com.simplemobiletools.draw;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
|
@ -29,4 +30,18 @@ public class Config {
|
||||||
public void setIsDarkTheme(boolean isDarkTheme) {
|
public void setIsDarkTheme(boolean isDarkTheme) {
|
||||||
mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.simplemobiletools.draw;
|
||||||
public class Constants {
|
public class Constants {
|
||||||
// shared preferences
|
// shared preferences
|
||||||
public static final String PREFS_KEY = "Draw";
|
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_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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.Manifest;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -59,7 +58,14 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
mMyCanvas.setListener(this);
|
mMyCanvas.setListener(this);
|
||||||
|
|
||||||
setColor(Color.BLACK);
|
mMyCanvas.setBackgroundColor(mConfig.getBackgroundColor());
|
||||||
|
setColor(mConfig.getBrushColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
mConfig.setBrushColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,6 +111,7 @@ public class MainActivity extends SimpleActivity implements MyCanvas.PathsChange
|
||||||
((ImageView) mUndoBtn).setImageResource(R.mipmap.undo_black);
|
((ImageView) mUndoBtn).setImageResource(R.mipmap.undo_black);
|
||||||
}
|
}
|
||||||
mMyCanvas.setBackgroundColor(pickedColor);
|
mMyCanvas.setBackgroundColor(pickedColor);
|
||||||
|
mConfig.setBackgroundColor(pickedColor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue