From 4ecc7d4acad05275f77fb699f6a9c92235ae919f Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Sun, 14 Nov 2010 12:53:07 +0000 Subject: [PATCH] more options code refactoring --- assets/resources/application/cs.xml | 8 +-- assets/resources/application/de.xml | 8 +-- assets/resources/application/en.xml | 26 +++++--- assets/resources/application/fr.xml | 8 +-- assets/resources/application/hu.xml | 8 +-- assets/resources/application/it.xml | 8 +-- assets/resources/application/ru.xml | 8 +-- assets/resources/application/uk.xml | 8 +-- assets/resources/application/vi.xml | 8 +-- assets/resources/application/zh.xml | 8 +-- .../preferences/PreferenceActivity.java | 28 ++++++-- .../preferences/ZLBoolean3Preference.java | 64 +++++++++++++++++++ .../optionsDialog/FormatOptionsPage.java | 7 -- .../optionsDialog/StyleOptionsPage.java | 21 ------ .../ZLSimpleBoolean3OptionEntry.java | 39 ----------- .../text/view/ZLTextAlignmentOptionEntry.java | 64 ------------------- .../view/style/ZLTextFullStyleDecoration.java | 4 +- 17 files changed, 115 insertions(+), 210 deletions(-) create mode 100644 src/org/geometerplus/android/fbreader/preferences/ZLBoolean3Preference.java delete mode 100644 src/org/geometerplus/zlibrary/core/optionEntries/ZLSimpleBoolean3OptionEntry.java delete mode 100644 src/org/geometerplus/zlibrary/text/view/ZLTextAlignmentOptionEntry.java diff --git a/assets/resources/application/cs.xml b/assets/resources/application/cs.xml index aa99aa549..6d60a0da0 100644 --- a/assets/resources/application/cs.xml +++ b/assets/resources/application/cs.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/de.xml b/assets/resources/application/de.xml index 9e8e4eb83..41849a3ac 100644 --- a/assets/resources/application/de.xml +++ b/assets/resources/application/de.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml index 0ea16a02e..79f60f7ce 100644 --- a/assets/resources/application/en.xml +++ b/assets/resources/application/en.xml @@ -176,17 +176,33 @@ + + + + + + + + + + + + + + + + @@ -396,13 +412,6 @@ - - - - - - - @@ -412,9 +421,6 @@ - - - diff --git a/assets/resources/application/fr.xml b/assets/resources/application/fr.xml index 8e0b1d464..759eb2e97 100644 --- a/assets/resources/application/fr.xml +++ b/assets/resources/application/fr.xml @@ -185,6 +185,7 @@ + @@ -302,13 +303,6 @@ - - - - - - - diff --git a/assets/resources/application/hu.xml b/assets/resources/application/hu.xml index 7a570daa1..05ab7e23e 100644 --- a/assets/resources/application/hu.xml +++ b/assets/resources/application/hu.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/it.xml b/assets/resources/application/it.xml index 6718626f5..faef5b9ff 100644 --- a/assets/resources/application/it.xml +++ b/assets/resources/application/it.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/ru.xml b/assets/resources/application/ru.xml index 25ae497be..1b9bb1a57 100644 --- a/assets/resources/application/ru.xml +++ b/assets/resources/application/ru.xml @@ -181,6 +181,7 @@ + @@ -296,13 +297,6 @@ - - - - - - - diff --git a/assets/resources/application/uk.xml b/assets/resources/application/uk.xml index b6bf7a50e..17c816802 100644 --- a/assets/resources/application/uk.xml +++ b/assets/resources/application/uk.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/vi.xml b/assets/resources/application/vi.xml index 6d6c6f13d..a76e6416a 100644 --- a/assets/resources/application/vi.xml +++ b/assets/resources/application/vi.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/assets/resources/application/zh.xml b/assets/resources/application/zh.xml index 3d92d936c..97d549c55 100644 --- a/assets/resources/application/zh.xml +++ b/assets/resources/application/zh.xml @@ -182,6 +182,7 @@ + @@ -297,13 +298,6 @@ - - - - - - - diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index d98920e99..dc534c268 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -25,9 +25,7 @@ import android.preference.PreferenceScreen; import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption; import org.geometerplus.zlibrary.core.dialogs.ZLOptionsDialog; -import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection; -import org.geometerplus.zlibrary.text.view.style.ZLTextBaseStyle; -import org.geometerplus.zlibrary.text.view.style.ZLTextStyleDecoration; +import org.geometerplus.zlibrary.text.view.style.*; import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication; @@ -122,7 +120,7 @@ public class PreferenceActivity extends ZLPreferenceActivity { this, textCategory.Resource, "lineSpacing", baseStyle.LineSpaceOption, spacings )); - String[] alignments = { "left", "right", "center", "justify" }; + final String[] alignments = { "left", "right", "center", "justify" }; textCategory.addPreference(new ZLChoicePreference( this, textCategory.Resource, "alignment", baseStyle.AlignmentOption, alignments @@ -171,12 +169,34 @@ public class PreferenceActivity extends ZLPreferenceActivity { if (decoration == null) { continue; } + ZLTextFullStyleDecoration fullDecoration = + decoration instanceof ZLTextFullStyleDecoration ? + (ZLTextFullStyleDecoration)decoration : null; final Screen formatScreen = moreStylesCategory.createPreferenceScreen(decoration.getName()); final Category formatCategory = formatScreen.createCategory(null); formatCategory.addPreference(new FontOption( this, textCategory.Resource, "font", decoration.FontFamilyOption, true )); + formatCategory.addPreference(new ZLBoolean3Preference( + this, textCategory.Resource, "bold", + decoration.BoldOption + )); + formatCategory.addPreference(new ZLBoolean3Preference( + this, textCategory.Resource, "italic", + decoration.ItalicOption + )); + if (fullDecoration != null) { + final String[] allAlignments = { "unchanged", "left", "right", "center", "justify" }; + formatCategory.addPreference(new ZLChoicePreference( + this, textCategory.Resource, "alignment", + fullDecoration.AlignmentOption, allAlignments + )); + } + formatCategory.addPreference(new ZLBoolean3Preference( + this, textCategory.Resource, "allowHyphenations", + decoration.AllowHyphenationsOption + )); } final Screen formatScreen = moreStylesCategory.createPreferenceScreen("format"); diff --git a/src/org/geometerplus/android/fbreader/preferences/ZLBoolean3Preference.java b/src/org/geometerplus/android/fbreader/preferences/ZLBoolean3Preference.java new file mode 100644 index 000000000..50cf80d34 --- /dev/null +++ b/src/org/geometerplus/android/fbreader/preferences/ZLBoolean3Preference.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2009-2010 Geometer Plus + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.android.fbreader.preferences; + +import android.content.Context; + +import org.geometerplus.zlibrary.core.util.ZLBoolean3; +import org.geometerplus.zlibrary.core.options.ZLBoolean3Option; +import org.geometerplus.zlibrary.core.resources.ZLResource; + +class ZLBoolean3Preference extends ZLStringListPreference { + private static final String ON = "on"; + private static final String OFF = "off"; + private static final String UNCHANGED = "unchanged"; + + private final ZLBoolean3Option myOption; + + ZLBoolean3Preference(Context context, ZLResource resource, String resourceKey, ZLBoolean3Option option) { + super(context, resource, resourceKey); + + myOption = option; + setList(new String[] { ON, OFF, UNCHANGED }); + + switch (option.getValue()) { + case ZLBoolean3.B3_TRUE: + setInitialValue(ON); + break; + case ZLBoolean3.B3_FALSE: + setInitialValue(OFF); + break; + case ZLBoolean3.B3_UNDEFINED: + setInitialValue(UNCHANGED); + break; + } + } + + public void onAccept() { + final String value = getValue(); + if (ON.equals(value)) { + myOption.setValue(ZLBoolean3.B3_TRUE); + } else if (OFF.equals(value)) { + myOption.setValue(ZLBoolean3.B3_FALSE); + } else { + myOption.setValue(ZLBoolean3.B3_UNDEFINED); + } + } +} diff --git a/src/org/geometerplus/fbreader/optionsDialog/FormatOptionsPage.java b/src/org/geometerplus/fbreader/optionsDialog/FormatOptionsPage.java index 08d3f5f37..4850d746f 100644 --- a/src/org/geometerplus/fbreader/optionsDialog/FormatOptionsPage.java +++ b/src/org/geometerplus/fbreader/optionsDialog/FormatOptionsPage.java @@ -22,7 +22,6 @@ package org.geometerplus.fbreader.optionsDialog; import org.geometerplus.zlibrary.core.dialogs.ZLDialogContent; import org.geometerplus.zlibrary.core.optionEntries.ZLSimpleSpinOptionEntry; import org.geometerplus.zlibrary.core.resources.ZLResource; -import org.geometerplus.zlibrary.text.view.ZLTextAlignmentOptionEntry; import org.geometerplus.zlibrary.text.view.ZLTextLineSpaceOptionEntry; import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection; import org.geometerplus.zlibrary.text.view.style.ZLTextStyleDecoration; @@ -81,12 +80,6 @@ class FormatOptionsPage extends OptionsPage { KEY_FIRSTLINEINDENT, new ZLSimpleSpinOptionEntry(decoration.FirstLineIndentDeltaOption, 1), name ); - - registerEntries(dialogTab, - KEY_ALIGNMENT, new ZLTextAlignmentOptionEntry(decoration.AlignmentOption, dialogTab.getResource(KEY_ALIGNMENT)), - KEY_DUMMY, null, - name - ); } } diff --git a/src/org/geometerplus/fbreader/optionsDialog/StyleOptionsPage.java b/src/org/geometerplus/fbreader/optionsDialog/StyleOptionsPage.java index 55504bbfc..7e09ba04a 100644 --- a/src/org/geometerplus/fbreader/optionsDialog/StyleOptionsPage.java +++ b/src/org/geometerplus/fbreader/optionsDialog/StyleOptionsPage.java @@ -20,7 +20,6 @@ package org.geometerplus.fbreader.optionsDialog; import org.geometerplus.zlibrary.core.dialogs.ZLDialogContent; -import org.geometerplus.zlibrary.core.optionEntries.ZLSimpleBoolean3OptionEntry; import org.geometerplus.zlibrary.core.optionEntries.ZLSimpleSpinOptionEntry; import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.view.ZLPaintContext; @@ -32,12 +31,7 @@ import org.geometerplus.fbreader.bookmodel.FBTextKind; public class StyleOptionsPage extends OptionsPage implements FBTextKind { private final static String KEY_STYLE = "style"; - private final static String KEY_BOLD = "bold"; - private final static String KEY_ITALIC = "italic"; - private final static String KEY_FONTFAMILY = "fontFamily"; - private final static String KEY_FONTSIZE = "fontSize"; private final static String KEY_FONTSIZEDIFFERENCE = "fontSizeDifference"; - private final static String KEY_ALLOWHYPHENATIONS = "allowHyphenations"; public StyleOptionsPage(ZLDialogContent dialogTab, ZLPaintContext context) { final ZLResource styleResource = ZLResource.resource(KEY_STYLE); @@ -63,21 +57,6 @@ public class StyleOptionsPage extends OptionsPage implements FBTextKind { KEY_FONTSIZEDIFFERENCE, new ZLSimpleSpinOptionEntry(decoration.FontSizeDeltaOption, 2), name ); - - registerEntry(dialogTab, - KEY_BOLD, new ZLSimpleBoolean3OptionEntry(decoration.BoldOption), - name - ); - - registerEntry(dialogTab, - KEY_ITALIC, new ZLSimpleBoolean3OptionEntry(decoration.ItalicOption), - name - ); - - registerEntry(dialogTab, - KEY_ALLOWHYPHENATIONS, new ZLSimpleBoolean3OptionEntry(decoration.AllowHyphenationsOption), - name - ); } } diff --git a/src/org/geometerplus/zlibrary/core/optionEntries/ZLSimpleBoolean3OptionEntry.java b/src/org/geometerplus/zlibrary/core/optionEntries/ZLSimpleBoolean3OptionEntry.java deleted file mode 100644 index 68cb32f1e..000000000 --- a/src/org/geometerplus/zlibrary/core/optionEntries/ZLSimpleBoolean3OptionEntry.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2007-2010 Geometer Plus - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -package org.geometerplus.zlibrary.core.optionEntries; - -import org.geometerplus.zlibrary.core.dialogs.ZLBoolean3OptionEntry; -import org.geometerplus.zlibrary.core.options.ZLBoolean3Option; - -public class ZLSimpleBoolean3OptionEntry extends ZLBoolean3OptionEntry { - private final ZLBoolean3Option myOption; - - public ZLSimpleBoolean3OptionEntry(ZLBoolean3Option option) { - myOption = option; - } - - public int initialState() { - return myOption.getValue(); - } - - public void onAccept(int state) { - myOption.setValue(state); - } -} diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextAlignmentOptionEntry.java b/src/org/geometerplus/zlibrary/text/view/ZLTextAlignmentOptionEntry.java deleted file mode 100644 index 7d125aff7..000000000 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextAlignmentOptionEntry.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2007-2010 Geometer Plus - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -package org.geometerplus.zlibrary.text.view; - -import java.util.ArrayList; - -import org.geometerplus.zlibrary.core.dialogs.ZLComboOptionEntry; -import org.geometerplus.zlibrary.core.options.ZLIntegerOption; -import org.geometerplus.zlibrary.core.resources.ZLResource; - -public class ZLTextAlignmentOptionEntry extends ZLComboOptionEntry { - private static final ArrayList ourValues5 = new ArrayList(); - - private final ZLIntegerOption myOption; - - public ZLTextAlignmentOptionEntry(ZLIntegerOption option, final ZLResource resource) { - myOption = option; - if (ourValues5.isEmpty()) { - ourValues5.add(resource.getResource("unchanged").getValue()); - ourValues5.add(resource.getResource("left").getValue()); - ourValues5.add(resource.getResource("rigth").getValue()); - ourValues5.add(resource.getResource("center").getValue()); - ourValues5.add(resource.getResource("justify").getValue()); - } - } - - public ArrayList getValues() { - return ourValues5; - } - - public String initialValue() { - int value = myOption.getValue(); - if ((value < 0) || (value >= 5)) { - value = 0; - } - return (String)ourValues5.get(value); - } - - public void onAccept(String value) { - for (int i = 0; i < 5; ++i) { - if (ourValues5.get(i).equals(value)) { - myOption.setValue(i); - break; - } - } - } -} diff --git a/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullStyleDecoration.java b/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullStyleDecoration.java index 2f422a2b9..1622ba3d1 100644 --- a/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullStyleDecoration.java +++ b/src/org/geometerplus/zlibrary/text/view/style/ZLTextFullStyleDecoration.java @@ -32,7 +32,7 @@ public class ZLTextFullStyleDecoration extends ZLTextStyleDecoration { public final ZLIntegerRangeOption RightIndentOption; public final ZLIntegerRangeOption FirstLineIndentDeltaOption; - public final ZLIntegerOption AlignmentOption; + public final ZLIntegerRangeOption AlignmentOption; public final ZLIntegerOption LineSpacePercentOption; @@ -43,7 +43,7 @@ public class ZLTextFullStyleDecoration extends ZLTextStyleDecoration { LeftIndentOption = new ZLIntegerRangeOption(STYLE, name + ":leftIndent", -300, 300, leftIndent); RightIndentOption = new ZLIntegerRangeOption(STYLE, name + ":rightIndent", -300, 300, rightIndent); FirstLineIndentDeltaOption = new ZLIntegerRangeOption(STYLE, name + ":firstLineIndentDelta", -300, 300, firstLineIndentDelta); - AlignmentOption = new ZLIntegerOption(STYLE, name + ":alignment", alignment); + AlignmentOption = new ZLIntegerRangeOption(STYLE, name + ":alignment", 0, 4, alignment); LineSpacePercentOption = new ZLIntegerOption(STYLE, name + ":lineSpacePercent", lineSpace); }