/* * 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.Intent; import org.geometerplus.zlibrary.core.options.ZLIntegerOption; import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption; import org.geometerplus.zlibrary.text.view.style.*; import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication; import org.geometerplus.zlibrary.ui.android.view.AndroidFontUtil; import org.geometerplus.fbreader.fbreader.*; import org.geometerplus.fbreader.Paths; import org.geometerplus.fbreader.bookmodel.FBTextKind; public class PreferenceActivity extends ZLPreferenceActivity { public PreferenceActivity() { super("Preferences"); } @Override protected boolean init(Intent intent) { final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance(); //final ZLAndroidApplication androidApp = ZLAndroidApplication.Instance(); //final ColorProfile profile = fbReader.getColorProfile(); final Screen directoriesScreen = createPreferenceScreen("directories"); directoriesScreen.addPreference(new ZLStringOptionPreference( this, Paths.BooksDirectoryOption(), directoriesScreen.Resource, "books" )); if (AndroidFontUtil.areExternalFontsSupported()) { directoriesScreen.addPreference(new ZLStringOptionPreference( this, Paths.FontsDirectoryOption(), directoriesScreen.Resource, "fonts" )); } addPreference(new ZLBooleanPreference( this, ZLAndroidApplication.Instance().NetworkLibraryEnabled, Resource, "networkLibrary" )); /*final Screen appearanceScreen = createPreferenceScreen("appearance"); appearanceScreen.addOption(androidApp.AutoOrientationOption, "autoOrientation"); if (!androidApp.isAlwaysShowStatusBar()) { appearanceScreen.addOption(androidApp.ShowStatusBarOption, "showStatusBar"); }*/ final Screen textScreen = createPreferenceScreen("text"); final ZLTextStyleCollection collection = ZLTextStyleCollection.Instance(); final ZLTextBaseStyle baseStyle = collection.getBaseStyle(); textScreen.addPreference(new FontOption( this, textScreen.Resource, "font", baseStyle.FontFamilyOption, false )); textScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("fontSize"), baseStyle.FontSizeOption )); textScreen.addPreference(new FontStylePreference( this, textScreen.Resource, "fontStyle", baseStyle.BoldOption, baseStyle.ItalicOption )); final ZLIntegerRangeOption spaceOption = baseStyle.LineSpaceOption; final String[] spacings = new String[spaceOption.MaxValue - spaceOption.MinValue + 1]; for (int i = 0; i < spacings.length; ++i) { final int val = spaceOption.MinValue + i; spacings[i] = (char)(val / 10 + '0') + "." + (char)(val % 10 + '0'); } textScreen.addPreference(new ZLChoicePreference( this, textScreen.Resource, "lineSpacing", spaceOption, spacings )); final String[] alignments = { "left", "right", "center", "justify" }; textScreen.addPreference(new ZLChoicePreference( this, textScreen.Resource, "alignment", baseStyle.AlignmentOption, alignments )); textScreen.addPreference(new ZLBooleanPreference( this, baseStyle.AutoHyphenationOption, textScreen.Resource, "autoHyphenations" )); final Screen moreStylesScreen = textScreen.createPreferenceScreen("more"); byte styles[] = { FBTextKind.REGULAR, FBTextKind.TITLE, FBTextKind.SECTION_TITLE, FBTextKind.SUBTITLE, FBTextKind.H1, FBTextKind.H2, FBTextKind.H3, FBTextKind.H4, FBTextKind.H5, FBTextKind.H6, FBTextKind.ANNOTATION, FBTextKind.EPIGRAPH, FBTextKind.AUTHOR, FBTextKind.POEM_TITLE, FBTextKind.STANZA, FBTextKind.VERSE, FBTextKind.CITE, FBTextKind.INTERNAL_HYPERLINK, FBTextKind.EXTERNAL_HYPERLINK, FBTextKind.FOOTNOTE, FBTextKind.ITALIC, FBTextKind.EMPHASIS, FBTextKind.BOLD, FBTextKind.STRONG, FBTextKind.DEFINITION, FBTextKind.DEFINITION_DESCRIPTION, FBTextKind.PREFORMATTED, FBTextKind.CODE }; for (int i = 0; i < styles.length; ++i) { final ZLTextStyleDecoration decoration = collection.getDecoration(styles[i]); if (decoration == null) { continue; } ZLTextFullStyleDecoration fullDecoration = decoration instanceof ZLTextFullStyleDecoration ? (ZLTextFullStyleDecoration)decoration : null; final Screen formatScreen = moreStylesScreen.createPreferenceScreen(decoration.getName()); formatScreen.addPreference(new FontOption( this, textScreen.Resource, "font", decoration.FontFamilyOption, true )); formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("fontSizeDifference"), decoration.FontSizeDeltaOption )); formatScreen.addPreference(new ZLBoolean3Preference( this, textScreen.Resource, "bold", decoration.BoldOption )); formatScreen.addPreference(new ZLBoolean3Preference( this, textScreen.Resource, "italic", decoration.ItalicOption )); if (fullDecoration != null) { final String[] allAlignments = { "unchanged", "left", "right", "center", "justify" }; formatScreen.addPreference(new ZLChoicePreference( this, textScreen.Resource, "alignment", fullDecoration.AlignmentOption, allAlignments )); } formatScreen.addPreference(new ZLBoolean3Preference( this, textScreen.Resource, "allowHyphenations", decoration.AllowHyphenationsOption )); if (fullDecoration != null) { formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("spaceBefore"), fullDecoration.SpaceBeforeOption )); formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("spaceAfter"), fullDecoration.SpaceAfterOption )); formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("leftIndent"), fullDecoration.LeftIndentOption )); formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("rightIndent"), fullDecoration.RightIndentOption )); formatScreen.addPreference(new ZLIntegerRangePreference( this, textScreen.Resource.getResource("firstLineIndent"), fullDecoration.FirstLineIndentDeltaOption )); final ZLIntegerOption spacePercentOption = fullDecoration.LineSpacePercentOption; final int[] spacingValues = new int[17]; final String[] spacingKeys = new String[17]; spacingValues[0] = -1; spacingKeys[0] = "unchanged"; for (int j = 1; j < spacingValues.length; ++j) { final int val = 4 + j; spacingValues[j] = 10 * val; spacingKeys[j] = (char)(val / 10 + '0') + "." + (char)(val % 10 + '0'); } formatScreen.addPreference(new ZLIntegerChoicePreference( this, textScreen.Resource, "lineSpacing", spacePercentOption, spacingValues, spacingKeys )); } } /*final Screen colorsScreen = createPreferenceScreen("colors"); colorsScreen.addPreference(new ZLColorPreference( this, colorsScreen.Resource, "background", profile.BackgroundOption )); /* colorsScreen.addPreference(new ZLColorPreference( this, colorsScreen.Resource, "selectionBackground", profile.SelectionBackgroundOption )); */ /*colorsScreen.addPreference(new ZLColorPreference( this, colorsScreen.Resource, "highlighting", profile.HighlightingOption )); colorsScreen.addPreference(new ZLColorPreference( this, colorsScreen.Resource, "text", profile.RegularTextOption )); colorsScreen.addPreference(new ZLColorPreference( this, colorsScreen.Resource, "hyperlink", profile.HyperlinkTextOption ));*/ final Screen marginsScreen = createPreferenceScreen("margins"); marginsScreen.addPreference(new ZLIntegerRangePreference( this, marginsScreen.Resource.getResource("left"), fbReader.LeftMarginOption )); marginsScreen.addPreference(new ZLIntegerRangePreference( this, marginsScreen.Resource.getResource("right"), fbReader.RightMarginOption )); marginsScreen.addPreference(new ZLIntegerRangePreference( this, marginsScreen.Resource.getResource("top"), fbReader.TopMarginOption )); marginsScreen.addPreference(new ZLIntegerRangePreference( this, marginsScreen.Resource.getResource("bottom"), fbReader.BottomMarginOption )); return true; } }