1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

more options code refactoring

This commit is contained in:
Nikolay Pultsin 2010-11-14 12:53:07 +00:00
parent d0d4dc3266
commit 4ecc7d4aca
17 changed files with 115 additions and 210 deletions

View file

@ -182,6 +182,7 @@
<node name="right" value="Vpravo"/>
<node name="center" value="Na střed"/>
<node name="justify" value="Do bloku"/>
<node name="unchanged" value="&lt;nezměněno&gt;"/>
</node>
<node name="autoHyphenations" value="Automatické dělení slov">
<node name="summaryOn" value="Dělit slova automaticky"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;nezměněno&gt;"/>
</node>
<node name="firstLineIndent" value="Odsazení prvního řádku"/>
<node name="alignment" value="Zarovnání">
<node name="left" value="Vlevo"/>
<node name="right" value="Vpravo"/>
<node name="center" value="Na střed"/>
<node name="justify" value="Do bloku"/>
<node name="unchanged" value="&lt;nezměněno&gt;"/>
</node>
<node name="spaceBefore" value="Mezera před"/>
<node name="spaceAfter" value="Mezera za"/>
<node name="leftIndent" value="Odsazení vlevo"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="Rechts"/>
<node name="center" value="Zentriert"/>
<node name="justify" value="Blocksatz"/>
<node name="unchanged" value="&lt;unverändert&gt;"/>
</node>
<node name="autoHyphenations" value="Automatisch trennen">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;unverändert&gt;"/>
</node>
<node name="firstLineIndent" value="Einzug erste Zeile"/>
<node name="alignment" value="Ausrichtung">
<node name="left" value="Links"/>
<node name="right" value="Rechts"/>
<node name="center" value="Zentriert"/>
<node name="justify" value="Blocksatz"/>
<node name="unchanged" value="&lt;unverändert&gt;"/>
</node>
<node name="spaceBefore" value="Abstand vor"/>
<node name="spaceAfter" value="Abstand nach"/>
<node name="leftIndent" value="Einzug linke Linie"/>

View file

@ -176,17 +176,33 @@
<node name="italic" value="Italic"/>
<node name="boldItalic" value="Bold Italic"/>
</node>
<node name="bold" value="Bold">
<node name="on" value="bold"/>
<node name="off" value="regular"/>
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="italic" value="Italic">
<node name="on" value="italic"/>
<node name="off" value="regular"/>
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="lineSpacing" value="Line Spacing"/>
<node name="alignment" value="Alignment">
<node name="left" value="Left"/>
<node name="right" value="Right"/>
<node name="center" value="Center"/>
<node name="justify" value="Justify"/>
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="autoHyphenations" value="Auto hyphenations">
<node name="summaryOn" value="Hyphenate words automatically"/>
<node name="summaryOff" value="Do not hyphenate words automatically"/>
</node>
<node name="allowHyphenations" value="Allow Hyphenations">
<node name="on" value="hyphenate words"/>
<node name="off" value="don't hyphenate words"/>
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="more" value="More styles">
<node name="summary" value="Separate settings for titles, epigraphs, etc."/>
<node name="format" value="Format">
@ -396,13 +412,6 @@
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="firstLineIndent" value="First Line Indent"/>
<node name="alignment" value="Alignment">
<node name="left" value="Left"/>
<node name="right" value="Right"/>
<node name="center" value="Center"/>
<node name="justify" value="Justify"/>
<node name="unchanged" value="&lt;unchanged&gt;"/>
</node>
<node name="spaceBefore" value="Space Before"/>
<node name="spaceAfter" value="Space After"/>
<node name="leftIndent" value="Left Indent"/>
@ -412,9 +421,6 @@
<node name="optionsFor" value="Options for"/>
<node name="fontSize" value="Size"/>
<node name="fontSizeDifference" value="Size Difference"/>
<node name="bold" value="Bold"/>
<node name="italic" value="Italic"/>
<node name="allowHyphenations" value="Allow Hyphenations"/>
</node>
<node name="Colors" value="Colors">
<node name="colorFor" value="Color for">

View file

@ -185,6 +185,7 @@
<node name="right" value="Droite"/>
<node name="center" value="Centré"/>
<node name="justify" value="Justifié"/>
<node name="unchanged" value="&lt;inchangé&gt;"/>
</node>
<node name="autoHyphenations" value="Césures automatiques">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -302,13 +303,6 @@
<node name="unchanged" value="&lt;inchangé&gt;"/>
</node>
<node name="firstLineIndent" value="Indentation de la première ligne"/>
<node name="alignment" value="Alignement">
<node name="left" value="Gauche"/>
<node name="right" value="Droite"/>
<node name="center" value="Centré"/>
<node name="justify" value="Justifié"/>
<node name="unchanged" value="&lt;inchangé&gt;"/>
</node>
<node name="spaceBefore" value="Espace avant"/>
<node name="spaceAfter" value="Espace après"/>
<node name="leftIndent" value="Indentation à gauche"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="Jobbra"/>
<node name="center" value="Középre"/>
<node name="justify" value="Sorkizárt"/>
<node name="unchanged" value="&lt;változatlan&gt;"/>
</node>
<node name="autoHyphenations" value="Automatikus elválasztás">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;változatlan&gt;"/>
</node>
<node name="firstLineIndent" value="Első sor behúzása"/>
<node name="alignment" value="Igazítás">
<node name="left" value="Balra"/>
<node name="right" value="Jobbra"/>
<node name="center" value="Középre"/>
<node name="justify" value="Sorkizárt"/>
<node name="unchanged" value="&lt;változatlan&gt;"/>
</node>
<node name="spaceBefore" value="Space Before"/>
<node name="spaceAfter" value="Space After"/>
<node name="leftIndent" value="Left Indent"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="Destra"/>
<node name="center" value="Centrato"/>
<node name="justify" value="Giustificato"/>
<node name="unchanged" value="&lt;non cambiare&gt;"/>
</node>
<node name="autoHyphenations" value="Divisione in sillabe automatica">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;non cambiare&gt;"/>
</node>
<node name="firstLineIndent" value="Rientro alla prima riga"/>
<node name="alignment" value="Allineamento">
<node name="left" value="Sinistra"/>
<node name="right" value="Destra"/>
<node name="center" value="Centrato"/>
<node name="justify" value="Giustificato"/>
<node name="unchanged" value="&lt;non cambiare&gt;"/>
</node>
<node name="spaceBefore" value="Spazio prima"/>
<node name="spaceAfter" value="Spazio dopo"/>
<node name="leftIndent" value="Rientro sinistro"/>

View file

@ -181,6 +181,7 @@
<node name="right" value="правое"/>
<node name="center" value="по центру"/>
<node name="justify" value="по краям"/>
<node name="unchanged" value="&lt;не менять&gt;"/>
</node>
<node name="autoHyphenations" value="Переносы">
<node name="summaryOn" value="Автоматически расставлять переносы"/>
@ -296,13 +297,6 @@
<node name="unchanged" value="&lt;не менять&gt;"/>
</node>
<node name="firstLineIndent" value="Красная строка"/>
<node name="alignment" value="Выравнивание">
<node name="left" value="левое"/>
<node name="right" value="правое"/>
<node name="center" value="по центру"/>
<node name="justify" value="по краям"/>
<node name="unchanged" value="&lt;не менять&gt;"/>
</node>
<node name="spaceBefore" value="Пропуск перед"/>
<node name="spaceAfter" value="Пропуск после"/>
<node name="leftIndent" value="Отступ слева"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="праве"/>
<node name="center" value="по центру"/>
<node name="justify" value="по краях"/>
<node name="unchanged" value="&lt;не міняти&gt;"/>
</node>
<node name="autoHyphenations" value="Перенесення">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;не міняти&gt;"/>
</node>
<node name="firstLineIndent" value="Червона стрічка"/>
<node name="alignment" value="Вирівнювання">
<node name="left" value="ліве"/>
<node name="right" value="праве"/>
<node name="center" value="по центру"/>
<node name="justify" value="по краях"/>
<node name="unchanged" value="&lt;не міняти&gt;"/>
</node>
<node name="spaceBefore" value="Пропуск перед"/>
<node name="spaceAfter" value="Пропуск після"/>
<node name="leftIndent" value="Відступ зліва"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="Phải"/>
<node name="center" value="Giữa"/>
<node name="justify" value="Căn chỉnh"/>
<node name="unchanged" value="&lt;giữ nguyên&gt;"/>
</node>
<node name="autoHyphenations" value="Tự động Tách từ">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;giữ nguyên&gt;"/>
</node>
<node name="firstLineIndent" value="Lùi Dòng Đầu"/>
<node name="alignment" value="Thẳng hàng">
<node name="left" value="Trái"/>
<node name="right" value="Phải"/>
<node name="center" value="Giữa"/>
<node name="justify" value="Căn chỉnh"/>
<node name="unchanged" value="&lt;giữ nguyên&gt;"/>
</node>
<node name="spaceBefore" value="Khoảng trống trước"/>
<node name="spaceAfter" value="Khoảng trống sau"/>
<node name="leftIndent" value="Lùi Trái"/>

View file

@ -182,6 +182,7 @@
<node name="right" value="右" />
<node name="center" value="居中" />
<node name="justify" value="对齐" />
<node name="unchanged" value="&lt;不变&gt;" />
</node>
<node name="autoHyphenations" value="自动断字">
<node name="summaryOn" value="Hyphenate words automatically" toBeTranslated="true"/>
@ -297,13 +298,6 @@
<node name="unchanged" value="&lt;不变&gt;" />
</node>
<node name="firstLineIndent" value="首行缩进" />
<node name="alignment" value="对齐">
<node name="left" value="左" />
<node name="right" value="右" />
<node name="center" value="居中" />
<node name="justify" value="对齐" />
<node name="unchanged" value="&lt;不变&gt;" />
</node>
<node name="spaceBefore" value="段前距" />
<node name="spaceAfter" value="段后距" />
<node name="leftIndent" value="左缩进" />

View file

@ -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");

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2009-2010 Geometer Plus <contact@geometerplus.com>
*
* 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);
}
}
}

View file

@ -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
);
}
}

View file

@ -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
);
}
}

View file

@ -1,39 +0,0 @@
/*
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
*
* 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);
}
}

View file

@ -1,64 +0,0 @@
/*
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
*
* 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<String> ourValues5 = new ArrayList<String>();
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<String> 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;
}
}
}
}

View file

@ -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);
}