add easier font size selection dialog
bump version
This commit is contained in:
parent
3d23240bb0
commit
f8a49d8c06
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fox.ttrss"
|
package="org.fox.ttrss"
|
||||||
android:versionCode="224"
|
android:versionCode="225"
|
||||||
android:versionName="1.28" >
|
android:versionName="1.29" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="8"
|
android:minSdkVersion="8"
|
||||||
|
22
res/layout/select_font_size_dialog.xml
Normal file
22
res/layout/select_font_size_dialog.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_progress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dip"
|
||||||
|
android:gravity="center_horizontal" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/seek_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="6dip"
|
||||||
|
android:layout_marginTop="6dip" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -211,4 +211,5 @@
|
|||||||
<string name="synchronize_read_articles_and_go_online">Synchronize read articles and go online</string>
|
<string name="synchronize_read_articles_and_go_online">Synchronize read articles and go online</string>
|
||||||
<string name="prefs_compatible_article_layout">Compatible article layout</string>
|
<string name="prefs_compatible_article_layout">Compatible article layout</string>
|
||||||
<string name="prefs_compatible_layout_summary">Enable if you see glitches in article content</string>
|
<string name="prefs_compatible_layout_summary">Enable if you see glitches in article content</string>
|
||||||
|
<string name="font_size_dialog_suffix">sp</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -103,14 +103,15 @@
|
|||||||
android:summary="@string/pref_headlines_mark_read_scroll_long"
|
android:summary="@string/pref_headlines_mark_read_scroll_long"
|
||||||
android:title="@string/pref_headlines_mark_read_scroll" />
|
android:title="@string/pref_headlines_mark_read_scroll" />
|
||||||
|
|
||||||
<EditTextPreference
|
<org.fox.ttrss.util.FontSizeDialogPreference
|
||||||
android:defaultValue="13"
|
android:defaultValue="13"
|
||||||
android:key="headlines_font_size_sp"
|
android:key="headlines_font_size_sp"
|
||||||
android:inputType="number"
|
android:dialogMessage="@string/pref_headline_font_size"
|
||||||
android:title="@string/pref_headline_font_size" />
|
android:title="@string/pref_headline_font_size" />
|
||||||
</PreferenceCategory>
|
|
||||||
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/reading" >
|
<PreferenceCategory android:title="@string/reading" >
|
||||||
<EditTextPreference
|
<org.fox.ttrss.util.FontSizeDialogPreference
|
||||||
android:defaultValue="16"
|
android:defaultValue="16"
|
||||||
android:key="article_font_size_sp"
|
android:key="article_font_size_sp"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
|
224
src/org/fox/ttrss/util/FontSizeDialogPreference.java
Normal file
224
src/org/fox/ttrss/util/FontSizeDialogPreference.java
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
package org.fox.ttrss.util;
|
||||||
|
|
||||||
|
// http://www.lukehorvat.com/blog/android-seekbardialogpreference/
|
||||||
|
|
||||||
|
import org.fox.ttrss.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.preference.DialogPreference;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link DialogPreference} that provides a user with the means to select an
|
||||||
|
* integer from a {@link SeekBar}, and persist it.
|
||||||
|
*
|
||||||
|
* @author lukehorvat
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class FontSizeDialogPreference extends DialogPreference {
|
||||||
|
private static final int DEFAULT_MIN_PROGRESS = 9;
|
||||||
|
private static final int DEFAULT_MAX_PROGRESS = 24;
|
||||||
|
private static final String DEFAULT_PROGRESS = "0";
|
||||||
|
|
||||||
|
private int mMinProgress = DEFAULT_MIN_PROGRESS;
|
||||||
|
private int mMaxProgress = DEFAULT_MAX_PROGRESS;
|
||||||
|
private int mProgress;
|
||||||
|
private CharSequence mProgressTextSuffix;
|
||||||
|
private TextView mProgressText;
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
|
||||||
|
public FontSizeDialogPreference(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FontSizeDialogPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
|
||||||
|
setProgressTextSuffix(" " + context.getString(R.string.font_size_dialog_suffix));
|
||||||
|
|
||||||
|
// set layout
|
||||||
|
setDialogLayoutResource(R.layout.select_font_size_dialog);
|
||||||
|
setPositiveButtonText(android.R.string.ok);
|
||||||
|
setNegativeButtonText(android.R.string.cancel);
|
||||||
|
setDialogIcon(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetInitialValue(boolean restore, Object defaultValue) {
|
||||||
|
setProgress(restore ? Integer.valueOf(getPersistedString(DEFAULT_PROGRESS))
|
||||||
|
: Integer.valueOf((String)defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||||
|
return a.getString(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBindDialogView(View view) {
|
||||||
|
super.onBindDialogView(view);
|
||||||
|
|
||||||
|
mProgressText = (TextView) view.findViewById(R.id.text_progress);
|
||||||
|
|
||||||
|
mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
|
||||||
|
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress,
|
||||||
|
boolean fromUser) {
|
||||||
|
// update text that displays the current SeekBar progress value
|
||||||
|
// note: this does not persist the progress value. that is only
|
||||||
|
// ever done in setProgress()
|
||||||
|
String progressStr = String.valueOf(progress + mMinProgress);
|
||||||
|
mProgressText.setText(mProgressTextSuffix == null ? progressStr
|
||||||
|
: progressStr.concat(mProgressTextSuffix.toString()));
|
||||||
|
mProgressText.setTextSize(TypedValue.COMPLEX_UNIT_SP, progress + mMinProgress);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mSeekBar.setMax(mMaxProgress - mMinProgress);
|
||||||
|
mSeekBar.setProgress(mProgress - mMinProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinProgress() {
|
||||||
|
return mMinProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinProgress(int minProgress) {
|
||||||
|
mMinProgress = minProgress;
|
||||||
|
setProgress(Math.max(mProgress, mMinProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxProgress() {
|
||||||
|
return mMaxProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxProgress(int maxProgress) {
|
||||||
|
mMaxProgress = maxProgress;
|
||||||
|
setProgress(Math.min(mProgress, mMaxProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProgress() {
|
||||||
|
return mProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(int progress) {
|
||||||
|
progress = Math.max(Math.min(progress, mMaxProgress), mMinProgress);
|
||||||
|
|
||||||
|
if (progress != mProgress) {
|
||||||
|
mProgress = progress;
|
||||||
|
persistString(String.valueOf(progress));
|
||||||
|
notifyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CharSequence getProgressTextSuffix() {
|
||||||
|
return mProgressTextSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgressTextSuffix(CharSequence progressTextSuffix) {
|
||||||
|
mProgressTextSuffix = progressTextSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDialogClosed(boolean positiveResult) {
|
||||||
|
super.onDialogClosed(positiveResult);
|
||||||
|
|
||||||
|
// when the user selects "OK", persist the new value
|
||||||
|
if (positiveResult) {
|
||||||
|
int seekBarProgress = mSeekBar.getProgress() + mMinProgress;
|
||||||
|
if (callChangeListener(seekBarProgress)) {
|
||||||
|
setProgress(seekBarProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Parcelable onSaveInstanceState() {
|
||||||
|
// save the instance state so that it will survive screen orientation
|
||||||
|
// changes and other events that may temporarily destroy it
|
||||||
|
final Parcelable superState = super.onSaveInstanceState();
|
||||||
|
|
||||||
|
// set the state's value with the class member that holds current
|
||||||
|
// setting value
|
||||||
|
final SavedState myState = new SavedState(superState);
|
||||||
|
myState.minProgress = getMinProgress();
|
||||||
|
myState.maxProgress = getMaxProgress();
|
||||||
|
myState.progress = getProgress();
|
||||||
|
|
||||||
|
return myState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Parcelable state) {
|
||||||
|
// check whether we saved the state in onSaveInstanceState()
|
||||||
|
if (state == null || !state.getClass().equals(SavedState.class)) {
|
||||||
|
// didn't save the state, so call superclass
|
||||||
|
super.onRestoreInstanceState(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore the state
|
||||||
|
SavedState myState = (SavedState) state;
|
||||||
|
setMinProgress(myState.minProgress);
|
||||||
|
setMaxProgress(myState.maxProgress);
|
||||||
|
setProgress(myState.progress);
|
||||||
|
|
||||||
|
super.onRestoreInstanceState(myState.getSuperState());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SavedState extends BaseSavedState {
|
||||||
|
int minProgress;
|
||||||
|
int maxProgress;
|
||||||
|
int progress;
|
||||||
|
|
||||||
|
public SavedState(Parcelable superState) {
|
||||||
|
super(superState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
|
minProgress = source.readInt();
|
||||||
|
maxProgress = source.readInt();
|
||||||
|
progress = source.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
|
||||||
|
dest.writeInt(minProgress);
|
||||||
|
dest.writeInt(maxProgress);
|
||||||
|
dest.writeInt(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
|
||||||
|
@Override
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user