1
0
mirror of https://codeberg.org/Starfish/Imagepipe.git synced 2025-10-05 22:52:39 +02:00

remove non-static access to sharedPreferences

This commit is contained in:
Starfish
2024-12-29 14:05:58 +01:00
parent 0b2480b019
commit a5da25aba4
6 changed files with 116 additions and 230 deletions

View File

@@ -3,6 +3,7 @@ Version 0.72
- add support for ACTION_EDIT intent
- fix GET_CONTENT intent never added exif data
- fix GET_CONTENT not working if used immediately after clean app install
- remove non-static access to sharedPreferences
Version 0.71
============

View File

@@ -33,7 +33,6 @@ import android.net.Uri;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
@@ -209,12 +208,6 @@ public class ImageReceiver extends Activity{
private ImageView image_display;
private EditText edit_size;
/*
* Local preferences instance.
*/
private ImagepipePreferences pref;
/*
* Is set true if info bubble is visible.
*/
@@ -539,25 +532,6 @@ public class ImageReceiver extends Activity{
}
};
private final SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals(ImagepipePreferences.PREF_SCALEMAX)){
pref.scalemax = ImagepipePreferences.getScaleMax(context);
} else
if (s.equals(ImagepipePreferences.PREF_COMPRESSFORMAT)){
pref.compressformat = ImagepipePreferences.getImageFileFormat(context);
setQualitybarVisibility();
image_needs_to_be_saved = true;
} else {
readPreferences();
}
if (s.equals(ImagepipePreferences.PREF_NUMBERING)){
image_needs_to_be_saved=true;
}
}
};
private final View.OnLongClickListener cropRatioListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
@@ -937,6 +911,11 @@ public class ImageReceiver extends Activity{
image_needs_to_be_saved = true;
}
}
// check if some preferences were changed that trigger the need to save the image again
if (ImagepipePreferences.imageNeedsToBeSavedFlag(context)){
image_needs_to_be_saved = true;
ImagepipePreferences.setImageNeedsToBeSavedFlag(context,false);
}
// set all the listeners
displayExifTagsIndicator();
// landscape
@@ -1421,7 +1400,7 @@ public class ImageReceiver extends Activity{
if (bitmap_image!=null){
bitmap_visible = bitmap_image.copy(Bitmap.Config.ARGB_8888,true);
image_display.setImageBitmap(bitmap_visible);
if ((pref.previewquality) && (!pref.compressformat.equals(ImagepipePreferences.ImageFileFormat.PNG))){
if ((ImagepipePreferences.previewQuality(context)) && (!ImagepipePreferences.getCompressFormatFileExtension(context).equals(ImagepipePreferences.ImageFileFormat.PNG))){
displayImageQuality();
}
displayExifTagsIndicator();
@@ -1910,7 +1889,7 @@ public class ImageReceiver extends Activity{
public void setQualitybarVisibility(){
TextView textView = (TextView) findViewById(R.id.quality_text);
if (pref.compressformat.equals(ImagepipePreferences.ImageFileFormat.PNG)) {
if (ImagepipePreferences.getCompressFormatFileExtension(context).equals(ImagepipePreferences.ImageFileFormat.PNG)) {
if (seekBar!=null){
seekBar.setVisibility(View.INVISIBLE);
}
@@ -1936,9 +1915,15 @@ public class ImageReceiver extends Activity{
@SuppressLint("ClickableViewAccessibility")
private void imageEditor(){
Log.v("imageEditor() started.");
readPreferences();
selectedColor = pref.lastColor;
pref.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
TextView scale_view = (TextView) findViewById(R.id.editText_size);
scale_view.setText(ImagepipePreferences.getScaleMax(context));
if (seekBar==null){
seekBar = (SeekBar) findViewById(R.id.seekBar_quality);
}
seekBar.setMax(ImagepipePreferences.getQualitymaxvalue(context));
seekBar.setProgress(ImagepipePreferences.getQuality(context));
originalImageContainer = ImagepipePreferences.getOriginalImageContainer(context);
selectedColor = ImagepipePreferences.getLastColor(context);
registerPaintToolButtonListeners();
// Style the actionbar
actionBar = getActionBar();
@@ -2172,11 +2157,13 @@ public class ImageReceiver extends Activity{
if (isSizeEntryValid(editable.toString())){
try {
ImagepipePreferences.setScaleMax(context,Integer.parseInt(editable.toString()));
image_needs_to_be_saved = true;
} catch (NumberFormatException e){
// ignore
}
} else {
ImagepipePreferences.setScaleMax(context,Integer.parseInt(ImagepipePreferences.PREF_SCALEMAX_DEFAULT));
image_needs_to_be_saved = true;
}
}
});
@@ -2246,13 +2233,13 @@ public class ImageReceiver extends Activity{
private void applyChangesOnLoadedImage(Uri source_uri, boolean updateImageInformation, boolean applyQualityLoss, boolean downscale, final Runnable finishedRunnable){
next_quality_update_time = 0;
if (!no_image_loaded){
if ((downscale) && (pref.autoscale)){
if ((downscale) && (ImagepipePreferences.autoScale(context))){
scaleImage(originalImageContainer.originalWidth, originalImageContainer.originalHeight,false);
} else
if (pref.forcedownscale){
if (ImagepipePreferences.forceDownscale(context)){
scaleImage(originalImageContainer.originalWidth, originalImageContainer.originalHeight,true);
}
if (pref.autorotate) {
if (ImagepipePreferences.autoRotate(context)) {
rotateImage(getExifRotationFromUri(source_uri),false);
}
// remove transparent pixels if applicable
@@ -2295,7 +2282,7 @@ public class ImageReceiver extends Activity{
if (readImageBitmapFromUri(source_uri,false)) {
// piping must run after the image has been put to cache async, otherwise it may fail.
Runnable launchAfterImageArrivedInCache = null;
if ((pref.autopipe) && (!piping_was_already_launched)) {
if ((ImagepipePreferences.autopipe(context)) && (!piping_was_already_launched)) {
launchAfterImageArrivedInCache = new Runnable() {
@Override
public void run() {
@@ -2369,9 +2356,6 @@ public class ImageReceiver extends Activity{
if (bitmap_image!=null){
// finally put last image to cache, store last image uri & update displays
ImagepipePreferences.setSavedImageContainer(context,savedImageContainer);
// also update local preferences
pref.savedImage_filesize = savedImageContainer.filesize;
pref.savedImage_uri = savedImageContainer.uri.toString();
try {
bitmap_visible = bitmap_image.copy(Bitmap.Config.ARGB_8888,true);
image_display.setImageBitmap(bitmap_visible);
@@ -2431,9 +2415,6 @@ public class ImageReceiver extends Activity{
PictureCache.clearCacheNotShare(context);
putImageBitmapToCache(null,false);
ImagepipePreferences.setSavedImageContainer(context,savedImageContainer);
// also update local preferences
pref.savedImage_filesize = savedImageContainer.filesize;
pref.savedImage_uri = savedImageContainer.uri.toString();
updateImageDisplay();
updateImagePropertiesText();
}
@@ -2480,6 +2461,8 @@ public class ImageReceiver extends Activity{
startActivity(chooserIntent);
} catch (ActivityNotFoundException e){
displayNoActivityFoundToast(ERROR_NO_BULK_IMAGE_APP);
Log.v("No suitable app found to share multiple images: "+e.getMessage());
Log.printStackTrace(e);
}
}
}
@@ -2487,7 +2470,7 @@ public class ImageReceiver extends Activity{
private void sendGetResultIntentSingle(ArrayList<Uri> source_uris){
// todo: check for read/write permissions
if (readImageBitmapFromUri(source_uris.get(0),false)) {
if (ImagepipePreferences.autopipeEnabled(context)){
if (ImagepipePreferences.autopipe(context)){
applyChangesOnLoadedImage(source_uris.get(0),true, true,true,launchAfterImageArrivedInCache);
} else {
applyChangesOnLoadedImage(source_uris.get(0),true, true,true,null);
@@ -2515,9 +2498,6 @@ public class ImageReceiver extends Activity{
if (bitmap_image!=null){
// finally put last image to cache, store last image uri & update displays
ImagepipePreferences.setSavedImageContainer(context,savedImageContainer);
// also update local preferences
pref.savedImage_filesize = savedImageContainer.filesize;
pref.savedImage_uri = savedImageContainer.uri.toString();
try {
bitmap_visible = bitmap_image.copy(Bitmap.Config.ARGB_8888,true);
image_display.setImageBitmap(bitmap_visible);
@@ -2694,8 +2674,8 @@ public class ImageReceiver extends Activity{
// try to get the scale value directly from the text field
if (edit_size != null) {
try {
maxsize = Integer.parseInt(pref.scalemax);
scaleValueText = pref.scalemax;
maxsize = Integer.parseInt(ImagepipePreferences.getScaleMax(context));
scaleValueText = ImagepipePreferences.getScaleMax(context);
} catch (NumberFormatException e) {
// textfield is invalid, needs a refresh
textFieldChanged = true;
@@ -3292,7 +3272,7 @@ public class ImageReceiver extends Activity{
if ((!no_image_loaded) && (bitmap_image!=null)){
String filesize ="";
String shrinkRatio="";
if ((pref.previewquality) && (originalImageContainer != null)){
if ((ImagepipePreferences.previewQuality(context)) && (originalImageContainer != null)){
filesize = getResources().getString(R.string.size)+" "+getKilobyteString(jpeg_ecoded_filesize);
if ((originalImageContainer.filesize != 0) && (jpeg_ecoded_filesize != 0)){
if (!bidiHelper.isRTL()){
@@ -3441,7 +3421,7 @@ public class ImageReceiver extends Activity{
originalWidth = options.outWidth;
originalHeight = options.outHeight;
Point point;
if ((pref.autoscale) &&(!noShrink)) {
if ((ImagepipePreferences.autoScale(context)) &&(!noShrink)) {
point = getTargetImageResolution(options.outWidth, options.outHeight, false);
} else {
point = getTargetImageResolution(options.outWidth, options.outHeight, true);
@@ -3620,6 +3600,7 @@ public class ImageReceiver extends Activity{
scale_ratio=bundle.getFloat(SIS_SCALE_RATIO,getScaleRatio());
}
/*
private void readPreferences(){
pref = new ImagepipePreferences(this);
pref.readPreferences();
@@ -3633,6 +3614,7 @@ public class ImageReceiver extends Activity{
originalImageContainer = ImagepipePreferences.getOriginalImageContainer(context);
}
*/
private boolean isSizeEntryValid(String s){
int scaleValue = 1024;
boolean result = false;
@@ -4187,10 +4169,10 @@ public class ImageReceiver extends Activity{
}
private String getHintText(){
if (pref.bubblecounter==0){
if (ImagepipePreferences.getBubbleCounter(context)==0){
return getResources().getString(R.string.hint1_line1) + System.getProperty("line.separator") + System.getProperty("line.separator") + getResources().getString(R.string.hint1);
} else {
if (pref.bubblecounter==1){
if (ImagepipePreferences.getBubbleCounter(context)==1){
return getResources().getString(R.string.hint2);
} else
return getResources().getString(R.string.hint3);
@@ -4220,11 +4202,10 @@ public class ImageReceiver extends Activity{
}
});
hintBubbleVisible = true;
pref.bubblecounter = pref.bubblecounter + 1;
if (pref.bubblecounter>HINT_COUNT){
pref.bubblecounter = 0;
ImagepipePreferences.incrementBubbleCounter(context);
if (ImagepipePreferences.getBubbleCounter(context)>HINT_COUNT){
ImagepipePreferences.setBubbleCounter(context,0);
}
pref.savePreferences();
}
public void hideHintBubble(){
@@ -4393,7 +4374,7 @@ public class ImageReceiver extends Activity{
if (!useImageViewSize){
int size = getResizeTextFieldValue();
// force image size to maximum screen resolution if applicable
if ((pref.forcedownscale) && (size>getForceImagesize())){
if ((ImagepipePreferences.forceDownscale(context)) && (size>getForceImagesize())){
size = getForceImagesize();
}
newHeight = size; newWidth = size;

View File

@@ -56,12 +56,13 @@ public class ImageWriter {
}
private static String generateFileNameSkeleton(Context context, ImageContainer originalImageContainer, long i){
ImagepipePreferences pref = new ImagepipePreferences(context);
// ImagepipePreferences pref = new ImagepipePreferences(context);
// skeleton from the settings is default
String skeleton = pref.filename;
String skeleton = ImagepipePreferences.getSkeletonFilename(context);
String numbering = ImagepipePreferences.getNumbering(context);
// take filename if desired and possible. We cannot assume a known filename, e.g. if image is painted
// from scratch.
if ((pref.numbering.equals("5")) || (pref.numbering.equals("6")) || (pref.numbering.equals("7")) || (pref.numbering.equals("8"))){
if ((numbering.equals("5")) || (numbering.equals("6")) || (numbering.equals("7")) || (numbering.equals("8"))){
if (originalImageContainer!=null){
if (originalImageContainer.filename!=null){
skeleton=originalImageContainer.getFileNameSkeleton();
@@ -76,16 +77,16 @@ public class ImageWriter {
}
Calendar calendar = Calendar.getInstance();
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd");
if (pref.numbering.equals("2") || pref.numbering.equals("6")){
if (numbering.equals("2") || numbering.equals("6")){
return String.valueOf(i) + "_" + skeleton;
}
if (pref.numbering.equals("3") || pref.numbering.equals("7")){
if (numbering.equals("3") || numbering.equals("7")){
return date.format(calendar.getTime()) + "_" + skeleton + "_" + String.valueOf(i);
}
if (pref.numbering.equals("4") || pref.numbering.equals("8")){
if (numbering.equals("4") || numbering.equals("8")){
return String.valueOf(i) + "_" + skeleton + "_" + date.format(calendar.getTime());
}
if (pref.numbering.equals("9")){
if (numbering.equals("9")){
return getRandomFileNameSkeleton(); // this ignores the parameter i.
}
// option "1" & "5"

View File

@@ -74,6 +74,7 @@ public class ImagepipePreferences {
public static final String PREF_EXIF_TEMPLATE = "PREF_exif_template";
public static final String PREF_NO_WARN = "PREF_no_warn";
public static final String PREF_WARN_TEMPORARILY_DISABLED = "PREF_no_warn_temporarily";
public static final String PREF_IMAGE_NEEDS_TO_BE_SAVED_FLAG = "PREF_need_to_save_flag";
public static final String PREF_SCALEMAX_DEFAULT = "1024";
private static final int PREF_SCALEMODE_DEFAULT = ImageReceiver.ResizeOptions.MAX;
@@ -112,171 +113,6 @@ public class ImagepipePreferences {
public static final boolean PREF_NO_WARN_DEFAULT = false;
public static final boolean PREF_WARN_TEMPORARILY_DISABLED_DEFAULT = false;
public String scalemax = PREF_SCALEMAX_DEFAULT;
public int scalemode = PREF_SCALEMODE_DEFAULT;
public String filename = PREF_FILENAME_DEFAULT;
public boolean keep_original_name = PREF_KEEP_ORIGINAL_NAME_DEFAULT;
public int quality = PREF_QUALITY_DEFAULT;
public String quality_maxvalue = PREF_MAXQUALITY_DEFAULT;
public String compressformat = PREF_COMPRESSFORMAT_DEFAULT;
public boolean autopipe = PREF_AUTOPIPE_DEFAULT;
public String numbering = PREF_NUMBERING_DEFAULT;
public boolean autoscale = PREF_AUTOSCALE_DEFAULT;
public boolean autorotate = PREF_AUTOROTATE_DEFAULT;
public boolean previewquality = PREF_PREVIEWQUALITY_DEFAULT;
public boolean forcedownscale = PREF_FORCEDOWNSCALE_DEFAULT;
public boolean smartcrop = PREF_SMARTCROP_DEFAULT;
public int bubblecounter = PREF_BUBLLECOUNTER_DEFAULT;
public boolean showHints = PREF_SHOWHINTS_DEFAULT;
public String savedImage_uri = PREF_URI_DEFAULT;
public long savedImage_filesize = PREF_FILESIZE_DEFAULT;
public String originalImage_uri = PREF_URI_DEFAULT;
public long originalImage_filesize = PREF_FILESIZE_DEFAULT;
public String originalImage_filename = PREF_URI_DEFAULT;
public String allowedTags = PREF_ALLOWED_TAGS_DEFAULT;
public boolean bilinear_filtering = PREF_BILINEAR_FILTERING_DEFAULT;
public boolean autosave = PREF_AUTOSAVE_DEFAULT;
public String aspectRatio = PREF_ASPECT_RATIO_DEFAULT;
public int lastVersionCode = PREF_LAST_VERSION_CODE_DEFAULT;
public int lastColor = PREF_LAST_COLOR_DEFAULT;
public int filter = PREF_FILTER_DEFAULT;
public boolean autoApplyFilter = PREF_AUTOAPPLY_FILTER_DEFAULT;
public boolean removeTransparency = PREF_REMOVE_TRANSPARENCY_DEFAULT;
public int replaceColor = PREF_REPLACECOLOR_DEFAULT;
public int colorHistory1 = PREF_COLORHISTORY1_DEFAULT;
public int colorHistory2 = PREF_COLORHISTORY2_DEFAULT;
public long fileNameCounter = PREF_FILENAMECOUNTER_DEFAULT;
public boolean clearAfterShare = PREF_CLEARAFTERSHARE_DEFAULT;
public boolean cropAfterRotation = PREF_CROP_AFTER_ROTATION_DEFAULT;
private Context context;
SharedPreferences sharedPreferences;
public ImagepipePreferences(Context c){
this.context = c;
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
readPreferences();
}
public void readPreferences(){
this.scalemax = readPreference(PREF_SCALEMAX,PREF_SCALEMAX_DEFAULT);
this.scalemode = readPreference(PREF_SCALEMODE,PREF_SCALEMODE_DEFAULT);
this.filename = readPreference(PREF_FILENAME,PREF_FILENAME_DEFAULT);
this.quality = readPreference(PREF_QUALITY,PREF_QUALITY_DEFAULT);
this.quality_maxvalue = readPreference(PREF_MAXQUALITY,PREF_MAXQUALITY_DEFAULT);
this.compressformat = readPreference(PREF_COMPRESSFORMAT,PREF_COMPRESSFORMAT_DEFAULT);
this.autopipe = readPreference(PREF_AUTOPIPE,PREF_AUTOPIPE_DEFAULT);
this.numbering = readPreference(PREF_NUMBERING,PREF_NUMBERING_DEFAULT);
this.autoscale = readPreference(PREF_AUTOSCALE,PREF_AUTOSCALE_DEFAULT);
this.autorotate = readPreference(PREF_AUTOROTATE,PREF_AUTOROTATE_DEFAULT);
this.previewquality = readPreference(PREF_PREVIEWQUALITY,PREF_PREVIEWQUALITY_DEFAULT);
this.forcedownscale = readPreference(PREF_FORCEDOWNSCALE,PREF_FORCEDOWNSCALE_DEFAULT);
this.bubblecounter = readPreference(PREF_BUBLLECOUNTER,PREF_BUBLLECOUNTER_DEFAULT);
this.showHints = readPreference(PREF_SHOWHINTS,PREF_SHOWHINTS_DEFAULT);
this.savedImage_uri = readPreference(PREF_SAVEDIMAGE_URI,PREF_URI_DEFAULT);
this.savedImage_filesize = readPreference(PREF_SAVEDIMAGE_FILESIZE,PREF_FILESIZE_DEFAULT);
this.originalImage_uri = readPreference(PREF_ORIGINALIMAGE_URI,PREF_URI_DEFAULT);
this.originalImage_filesize = readPreference(PREF_ORIGINALIMAGE_FILESIZE,PREF_FILESIZE_DEFAULT);
this.originalImage_filename = readPreference(PREF_ORIGINALIMAGE_FILENAME,PREF_URI_DEFAULT);
this.allowedTags = readPreference(PREF_ALLOWED_TAGS,PREF_ALLOWED_TAGS_DEFAULT);
this.bilinear_filtering = readPreference(PREF_BILINEAR_FILTERING,PREF_BILINEAR_FILTERING_DEFAULT);
this.autosave = readPreference(PREF_AUTOSAVE,PREF_AUTOSAVE_DEFAULT);
this.aspectRatio = readPreference(PREF_ASPECT_RATIO,PREF_ASPECT_RATIO_DEFAULT);
this.lastVersionCode = readPreference(PREF_LAST_VERSION_CODE,PREF_LAST_VERSION_CODE_DEFAULT);
this.lastColor = readPreference(PREF_LAST_COLOR,PREF_LAST_COLOR_DEFAULT);
this.filter = readPreference(PREF_FILTER,PREF_FILTER_DEFAULT);
this.autoApplyFilter = readPreference(PREF_AUTOAPPLY_FILTER,PREF_AUTOAPPLY_FILTER_DEFAULT);
this.removeTransparency = readPreference(PREF_REMOVE_TRANSPARENCY,PREF_REMOVE_TRANSPARENCY_DEFAULT);
this.replaceColor = readPreference(PREF_REPLACECOLOR,PREF_REPLACECOLOR_DEFAULT);
this.colorHistory1 = readPreference(PREF_COLORHISTORY1,PREF_COLORHISTORY1_DEFAULT);
this.colorHistory2 = readPreference(PREF_COLORHISTORY2,PREF_COLORHISTORY2_DEFAULT);
this.fileNameCounter = readPreferenceLong(PREF_FILENAMECOUNTER,PREF_FILENAMECOUNTER_DEFAULT);
this.clearAfterShare = readPreference(PREF_CLEARAFTERSHARE,PREF_CLEARAFTERSHARE_DEFAULT);
this.cropAfterRotation = readPreference(PREF_CROP_AFTER_ROTATION,PREF_CROP_AFTER_ROTATION_DEFAULT);
}
public void savePreferences(){
applyPreference(PREF_SCALEMAX,this.scalemax);
applyPreference(PREF_SCALEMODE,this.scalemode);
applyPreference(PREF_FILENAME,this.filename);
applyPreference(PREF_QUALITY,this.quality);
applyPreference(PREF_MAXQUALITY,this.quality_maxvalue);
applyPreference(PREF_COMPRESSFORMAT,this.compressformat);
applyPreference(PREF_AUTOPIPE,this.autopipe);
applyPreference(PREF_NUMBERING,this.numbering);
applyPreference(PREF_AUTOSCALE,this.autoscale);
applyPreference(PREF_AUTOROTATE,this.autorotate);
applyPreference(PREF_PREVIEWQUALITY,this.previewquality);
applyPreference(PREF_FORCEDOWNSCALE,this.forcedownscale);
applyPreference(PREF_BUBLLECOUNTER,this.bubblecounter);
applyPreference(PREF_SHOWHINTS,this.showHints);
applyPreference(PREF_SAVEDIMAGE_URI,this.savedImage_uri);
applyPreference(PREF_SAVEDIMAGE_FILESIZE,this.savedImage_filesize);
applyPreference(PREF_ORIGINALIMAGE_URI,this.originalImage_uri);
applyPreference(PREF_ORIGINALIMAGE_FILESIZE,this.originalImage_filesize);
applyPreference(PREF_ORIGINALIMAGE_FILENAME,this.originalImage_filename);
applyPreference(PREF_ALLOWED_TAGS,this.allowedTags);
applyPreference(PREF_BILINEAR_FILTERING,this.bilinear_filtering);
applyPreference(PREF_AUTOSAVE,this.autosave);
applyPreference(PREF_ASPECT_RATIO,this.aspectRatio);
applyPreference(PREF_LAST_VERSION_CODE,this.lastVersionCode);
applyPreference(PREF_LAST_COLOR,this.lastColor);
applyPreference(PREF_FILTER,this.filter);
applyPreference(PREF_AUTOAPPLY_FILTER,this.autoApplyFilter);
applyPreference(PREF_REMOVE_TRANSPARENCY,this.removeTransparency);
applyPreference(PREF_REPLACECOLOR,this.replaceColor);
applyPreference(PREF_COLORHISTORY1,this.colorHistory1);
applyPreference(PREF_COLORHISTORY2,this.colorHistory2);
applyPreference(PREF_FILENAMECOUNTER,this.fileNameCounter);
applyPreference(PREF_CLEARAFTERSHARE,this.clearAfterShare);
applyPreference(PREF_CROP_AFTER_ROTATION,this.cropAfterRotation);
}
public String readPreference(String p, String d){
return sharedPreferences.getString(p,d);
}
public Boolean readPreference(String p, Boolean d){
return sharedPreferences.getBoolean(p,d);
}
public int readPreference(String p, int d){
return sharedPreferences.getInt(p,d);
}
public long readPreferenceLong(String p, long d){
return sharedPreferences.getLong(p,d);
}
public long readPreference(String p, long d){
return sharedPreferences.getLong(p,d);
}
public void applyPreference(String pref, String value){
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putString(pref,value);
pref_editor.apply();
}
public void applyPreference(String pref, Boolean value){
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putBoolean(pref,value);
pref_editor.apply();
}
public void applyPreference(String pref, int value){
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putInt(pref,value);
pref_editor.apply();
}
public void applyPreference(String pref, long value){
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putLong(pref,value);
pref_editor.apply();
}
public static int getQualitymaxvalue(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String quality_maxvalue = sharedPreferences.getString(PREF_MAXQUALITY,PREF_MAXQUALITY_DEFAULT);
@@ -371,7 +207,7 @@ public class ImagepipePreferences {
return "jpg";
}
public static boolean autopipeEnabled(Context context){
public static boolean autopipe(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_AUTOPIPE,PREF_AUTOPIPE_DEFAULT);
}
@@ -615,6 +451,11 @@ public class ImagepipePreferences {
return result;
}
public static String getSkeletonFilename(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getString(PREF_FILENAME,PREF_FILENAME_DEFAULT);
}
public static void setLastColor(Context context, int lastColor){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
@@ -622,6 +463,11 @@ public class ImagepipePreferences {
pref_editor.apply();
}
public static int getLastColor(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getInt(PREF_LAST_COLOR, PREF_LAST_COLOR_DEFAULT);
}
public static int getFilter(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getInt(PREF_FILTER, PREF_FILTER_DEFAULT);
@@ -800,5 +646,49 @@ public class ImagepipePreferences {
return sharedPreferences.getBoolean(PREF_WARN_TEMPORARILY_DISABLED,PREF_WARN_TEMPORARILY_DISABLED_DEFAULT);
}
public static boolean autoScale(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_AUTOSCALE,PREF_AUTOSCALE_DEFAULT);
}
public static boolean autoRotate(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_AUTOROTATE,PREF_AUTOROTATE_DEFAULT);
}
public static void setBubbleCounter(Context context, int value){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putInt(PREF_BUBLLECOUNTER, value);
pref_editor.apply();
}
public static int getBubbleCounter(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getInt(PREF_BUBLLECOUNTER,PREF_BUBLLECOUNTER_DEFAULT);
}
public static void incrementBubbleCounter(Context context){
int bubbleCounter = getBubbleCounter(context);
bubbleCounter++;
setBubbleCounter(context,bubbleCounter);
}
public static boolean previewQuality(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_PREVIEWQUALITY,PREF_PREVIEWQUALITY_DEFAULT);
}
public static void setImageNeedsToBeSavedFlag(Context context, boolean value){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putBoolean(PREF_IMAGE_NEEDS_TO_BE_SAVED_FLAG, value);
pref_editor.apply();
}
public static boolean imageNeedsToBeSavedFlag(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_IMAGE_NEEDS_TO_BE_SAVED_FLAG,false);
}
}

View File

@@ -15,4 +15,11 @@ public class Log {
android.util.Log.v("imagepipe",text);
}
}
public static void printStackTrace(Exception e){
StackTraceElement[] stackTraceElements = e.getStackTrace();
for (int j=0; j<stackTraceElements.length; j++){
Log.v(j+" -> "+stackTraceElements[j].getLineNumber()+" "+stackTraceElements[j].getClassName()+" "+stackTraceElements[j].getMethodName()+" "+stackTraceElements[j].getFileName());
}
}
}

View File

@@ -54,8 +54,8 @@ public class Settings extends PreferenceActivity implements SharedPreferences.On
@Override
@SuppressWarnings("deprecation")
protected void onPause(){
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
@SuppressWarnings("deprecation")
@@ -147,10 +147,16 @@ public class Settings extends PreferenceActivity implements SharedPreferences.On
updateValuesDisplay();
if ((id.equals(ImagepipePreferences.PREF_NUMBERING))){
PictureCache.recreateFileNameList(context);
ImagepipePreferences.setImageNeedsToBeSavedFlag(context,true);
}
// reset internal file name counter when file name changes.
if (id.equals(ImagepipePreferences.PREF_FILENAME)){
ImagepipePreferences.setFileNameCounter(context,ImagepipePreferences.PREF_FILENAMECOUNTER_DEFAULT);
ImagepipePreferences.setImageNeedsToBeSavedFlag(context,true);
}
if ((id.equals(ImagepipePreferences.PREF_SCALEMAX)) ||
(id.equals(ImagepipePreferences.PREF_COMPRESSFORMAT))){
ImagepipePreferences.setImageNeedsToBeSavedFlag(context,true);
}
}
}