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

implement custom SeekBarPreference and change the max. quality setting to a SeekBarPreference

This commit is contained in:
Starfish
2024-12-31 19:48:29 +01:00
parent 918f170548
commit e98a94f5da
7 changed files with 362 additions and 11 deletions

View File

@@ -843,6 +843,12 @@ public class ImageReceiver extends Activity{
PictureCache.clearPictureCache(context);
ImagepipePreferences.setCurrentAppVersionFlag(context);
}
// since with version 51 this setting moved from a String (list) to an Integer (seekBar), we need to map
// the old string value to the new integer value.
if (ImagepipePreferences.getLastAppVersion(context)<51){
ImagepipePreferences.setQualitymaxvalue(context,ImagepipePreferences.getQualitymaxvalue_Legacy(context));
ImagepipePreferences.setCurrentAppVersionFlag(context);
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_CLEAR_DATA);
intentFilter.addAction(ACTION_SHOW_PROGRESS);
@@ -974,6 +980,15 @@ public class ImageReceiver extends Activity{
});
button_reloadimage.setOnClickListener(reloadListener);
button_reloadimage.setOnLongClickListener(reloadNoShrinkListener);
// update quality bar, quality display & quality preview since this might have changed when returning from
// the settings.
if (ImagepipePreferences.maxQualityChanged(context)){
int maxQualityValue = ImagepipePreferences.getQualitymaxvalue(context);
seekBar.setMax(maxQualityValue);
ImagepipePreferences.setQuality(context,seekBar.getProgress());
displayImageQuality();
ImagepipePreferences.resetQualitymaxvalueChangedFlag(context);
}
}
@Override

View File

@@ -37,6 +37,8 @@ public class ImagepipePreferences {
public static final String PREF_FILENAME = "PREF_filename";
public static final String PREF_QUALITY = "PREF_quality";
public static final String PREF_MAXQUALITY = "PREF_maxquality";
public static final String PREF_MAXQUALITY2 = "PREF_maxquality2";
public static final String PREF_MAXQUALITY_CHANGED_FLAG = "PREF_maxquality2_changed";
public static final String PREF_COMPRESSFORMAT = "PREF_compressformat";
private static final String PREF_AUTOPIPE = "PREF_autopipe";
public static final String PREF_NUMBERING = "PREF_numbering";
@@ -81,7 +83,7 @@ public class ImagepipePreferences {
private static final String PREF_FILENAME_DEFAULT = "Imagepipe";
private static final boolean PREF_KEEP_ORIGINAL_NAME_DEFAULT = false;
private static final int PREF_QUALITY_DEFAULT = 70;
private static final String PREF_MAXQUALITY_DEFAULT = "80";
private static final int PREF_MAXQUALITY_DEFAULT = 80;
private static final String PREF_COMPRESSFORMAT_DEFAULT = ImageFileFormat.JPEG;
private static final boolean PREF_AUTOPIPE_DEFAULT = true;
private static final String PREF_NUMBERING_DEFAULT = "1";
@@ -113,20 +115,52 @@ public class ImagepipePreferences {
public static final boolean PREF_NO_WARN_DEFAULT = false;
public static final boolean PREF_WARN_TEMPORARILY_DISABLED_DEFAULT = false;
public static int getQualitymaxvalue(Context context) {
public static int getQualitymaxvalue_Legacy(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String quality_maxvalue = sharedPreferences.getString(PREF_MAXQUALITY,PREF_MAXQUALITY_DEFAULT);
String quality_maxvalue = sharedPreferences.getString(PREF_MAXQUALITY,Integer.toString(PREF_MAXQUALITY_DEFAULT));
try {
int i = Integer.valueOf(quality_maxvalue);
return i;
} catch (NumberFormatException e) {
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putString(PREF_MAXQUALITY,PREF_MAXQUALITY_DEFAULT);
pref_editor.putString(PREF_MAXQUALITY,Integer.toString(PREF_MAXQUALITY_DEFAULT));
pref_editor.apply();
return Integer.valueOf(PREF_MAXQUALITY_DEFAULT);
}
}
public static void setQualitymaxvalue(Context context, int value){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putInt(PREF_MAXQUALITY2,value);
pref_editor.apply();
}
public static int getQualitymaxvalue(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
int value = sharedPreferences.getInt(PREF_MAXQUALITY2,PREF_MAXQUALITY_DEFAULT);
return value;
}
public static void setQualitymaxvalueChangedFlag(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putBoolean(PREF_MAXQUALITY_CHANGED_FLAG,true);
pref_editor.apply();
}
public static void resetQualitymaxvalueChangedFlag(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor pref_editor = sharedPreferences.edit();
pref_editor.putBoolean(PREF_MAXQUALITY_CHANGED_FLAG,false);
pref_editor.apply();
}
public static boolean maxQualityChanged(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(PREF_MAXQUALITY_CHANGED_FLAG,false);
}
public static int getResizeMode(Context context){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getInt(PREF_SCALEMODE,PREF_SCALEMODE_DEFAULT);

View File

@@ -0,0 +1,187 @@
/**
* This file is part of Imagepipe.
*
* Copyright (c) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Pawel Dube
*
* Imagepipe is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Imagepipe is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Imagepipe. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kaffeemitkoffein.imagepipe;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;
public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener {
private final static String NAMESPACE = "http://schemas.android.com/apk/res/android";
private Context context;
private int value;
private int min;
private int max;
private int minWarning;
private int maxWarning;
private boolean displayProgressValue = false;
private View preferenceView;
private boolean changeOngoing = false;
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
readAttributes(context,attrs,defStyleAttr);
}
public SeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
readAttributes(context,attrs,0);
}
private void readAttributes(Context context, AttributeSet attrs, int defStyleAttr){
setMax(100);
this.context = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.SeekBarPreference,defStyleAttr,0);
min = attrs.getAttributeIntValue(NAMESPACE,"min",0);
max = attrs.getAttributeIntValue(NAMESPACE,"max",100);
minWarning = min; maxWarning=max;
displayProgressValue = false;
String progressLabel = attrs.getAttributeValue(NAMESPACE,"label");
if (progressLabel!=null){
displayProgressValue = true;
String[] labelIitems = progressLabel.split("\\|");
if (labelIitems.length>1){
minWarning = Integer.parseInt(labelIitems[0]);
maxWarning = Integer.parseInt(labelIitems[1]);
}
}
typedArray.recycle();
}
@Override
protected View onCreateView(ViewGroup parent) {
setLayoutResource(R.layout.seekbarpreference);
View view = super.onCreateView(parent);
preferenceView = view;
TextView textViewValue = (TextView) view.findViewById(R.id.value);
if (!isEnabled()){
TextView textView1 = (TextView) view.findViewById(android.R.id.title);
textView1.setTextColor(Color.GRAY);
TextView textView2 = (TextView) view.findViewById(android.R.id.summary);
textView2.setTextColor(Color.GRAY);
textViewValue.setTextColor(Color.GRAY);
}
if (displayProgressValue){
textViewValue.setVisibility(View.VISIBLE);
} else {
textViewValue.setVisibility(View.GONE);
}
return view;
}
public void setValue(int v){
if (v!=value) {
if (v < min) {
value = min;
} else if (v > max) {
value = max;
} else {
value = v;
}
persistInt(value);
notifyChanged();
}
}
public int getValue(){
return value;
}
public void setMax(int v){
max = v;
notifyChanged();
}
private void setProgress(SeekBar seekBar){
int p = seekBar.getProgress();
if (callChangeListener(p)){
setValue(p);
} else {
seekBar.setProgress(value);
}
}
private void displayValueNumber(int i){
if (displayProgressValue){
TextView textViewValue = (TextView) preferenceView.findViewById(R.id.value);
if ((i<minWarning) || (i>maxWarning)){
textViewValue.setTextColor(context.getResources().getColor(R.color.colorpicker15));
} else {
textViewValue.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
}
textViewValue.setText(Integer.toString(i));
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
SeekBar seekBar = view.findViewById(R.id.seekbar);
TextView textViewValue = view.findViewById(R.id.value);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setMax(max);
seekBar.setProgress(value);
displayValueNumber(seekBar.getProgress());
seekBar.setEnabled(isEnabled());
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue){
if (restoreValue){
if (defaultValue!=null){
value = getPersistedInt((int) defaultValue);
} else {
value = getPersistedInt(0);
}
} else {
value = (int) defaultValue;
}
setValue(value);
}
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {
if (fromUser && !changeOngoing){
setProgress(seekBar);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
changeOngoing = true;
displayValueNumber(seekBar.getProgress());
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
changeOngoing = false;
setProgress(seekBar);
}
}

View File

@@ -94,7 +94,9 @@ public class Settings extends PreferenceActivity implements SharedPreferences.On
p = findPreference(ImagepipePreferences.PREF_NUMBERING);
p.setSummary(getResources().getString(R.string.preference_numbering_summary)+" "+file_ext);
p = findPreference(ImagepipePreferences.PREF_MAXQUALITY);
/*
p.setSummary(getResources().getString(R.string.preference_maxquality_summary)+" "+String.valueOf(sp.getString(ImagepipePreferences.PREF_MAXQUALITY,"80")));
*/
p = findPreference(ImagepipePreferences.PREF_COMPRESSFORMAT);
p.setSummary(getResources().getString(R.string.preference_compressformat_summary)+" "+ImagepipePreferences.getCompressFormatFileExtension(this).toString().toUpperCase(Locale.ROOT));
p= findPreference(ImagepipePreferences.PREF_ALLOWED_TAGS);
@@ -158,5 +160,8 @@ public class Settings extends PreferenceActivity implements SharedPreferences.On
(id.equals(ImagepipePreferences.PREF_COMPRESSFORMAT))){
ImagepipePreferences.setImageNeedsToBeSavedFlag(context,true);
}
if (id.equals(ImagepipePreferences.PREF_MAXQUALITY2)){
ImagepipePreferences.setQualitymaxvalueChangedFlag(context);
}
}
}

View File

@@ -0,0 +1,95 @@
<!--
This file is part of Imagepipe.
Copyright (c) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Pawel Dube
Imagepipe is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Imagepipe is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Imagepipe. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize"
android:paddingEnd="?android:attr/scrollbarSize"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="6dp"
>
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_gravity="start"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/primaryTextColor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/summary"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize"
android:paddingEnd="?android:attr/scrollbarSize"
android:weightSum="10"
android:orientation="horizontal">
<SeekBar
android:id="@+id/seekbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:max="100"
android:layout_weight="9"
android:defaultValue="50"
android:layout_gravity="center"
android:progress="50"/>
<TextView
android:id="@+id/value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="99"
android:textColor="@color/primaryTextColor"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<declare-styleable name="SeekBarPreference">
<attr name="min" format="integer"/>
<attr name="max" format="integer"/>
<attr name="progress" format="integer"/>
<attr name="label" format="string"/>
</declare-styleable>
</resources>

View File

@@ -76,18 +76,22 @@
android:title="@string/preference_previewquality_title"
android:summary="@string/preference_previewquality_summary"
android:defaultValue="true"/>
<ListPreference
android:key="PREF_maxquality"
android:title="@string/preference_maxquality_title"
android:summary="@string/preference_maxquality_summary"
android:entries="@array/maxcompression_text"
android:entryValues="@array/maxcompression_values"
android:defaultValue="80"/>
<de.kaffeemitkoffein.imagepipe.SeekBarPreference
android:key="PREF_maxquality2"
android:title="@string/preference_maxquality_title"
android:summary="@string/preference_maxquality_summary"
android:min="20"
android:max="100"
android:label="50|90"
/>
<CheckBoxPreference
android:key="PREF_bilinear_filtering"
android:title="@string/preference_bilinear_filtering_title"
android:summary="@string/preference_bilinear_filtering_summary"
android:defaultValue="true"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/preference_title_category3">