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

fill mode option

This commit is contained in:
Nikolay Pultsin 2014-08-30 15:48:32 +01:00
parent a47e5b1d3a
commit 7e7c4149ba
9 changed files with 54 additions and 17 deletions

View file

@ -622,6 +622,16 @@
<node name="leather" value="Leather"/> <node name="leather" value="Leather"/>
<node name="sepia" value="Sepia"/> <node name="sepia" value="Sepia"/>
<node name="wood" value="Wood"/> <node name="wood" value="Wood"/>
<node name="paper" value="Paper"/>
<node name="papirus" value="Papirus"/>
</node>
<node name="fillMode" value="Fill mode">
<node name="tile" value="Tile"/>
<node name="tileMirror" value="Mirrored tile"/>
<node name="fullscreen" value="Full screen"/>
<node name="stretch" value="Stretch to fill screen"/>
<node name="tileVertically" value="Stretch horizontally, tile vertically"/>
<node name="tileHorizontally" value="Stretch vertically, tile horizontally"/>
</node> </node>
<node name="selectionBackground" value="Selection background"/> <node name="selectionBackground" value="Selection background"/>
<node name="selectionForeground" value="Selected text"/> <node name="selectionForeground" value="Selected text"/>

View file

@ -449,13 +449,27 @@ public class PreferenceActivity extends ZLPreferenceActivity {
final Screen colorsScreen = createPreferenceScreen("colors"); final Screen colorsScreen = createPreferenceScreen("colors");
final PreferenceSet backgroundSet = new PreferenceSet.Enabler() {
@Override
protected Boolean detectState() {
return profile.WallpaperOption.getValue().startsWith("/");
}
};
myBackgroundPreference = new BackgroundPreference( myBackgroundPreference = new BackgroundPreference(
this, this,
profile, profile,
colorsScreen.Resource.getResource("background"), colorsScreen.Resource.getResource("background"),
BACKGROUND_REQUEST_CODE BACKGROUND_REQUEST_CODE
); ) {
@Override
public void update(Intent data) {
super.update(data);
backgroundSet.run();
}
};
colorsScreen.addPreference(myBackgroundPreference); colorsScreen.addPreference(myBackgroundPreference);
backgroundSet.add(colorsScreen.addOption(profile.FillModeOption, "fillMode"));
backgroundSet.run();
colorsScreen.addOption(profile.HighlightingOption, "highlighting"); colorsScreen.addOption(profile.HighlightingOption, "highlighting");
colorsScreen.addOption(profile.RegularTextOption, "text"); colorsScreen.addOption(profile.RegularTextOption, "text");

View file

@ -405,10 +405,10 @@ public final class FBView extends ZLTextView {
} }
@Override @Override
public ZLPaintContext.WallpaperMode getWallpaperMode() { public ZLPaintContext.FillMode getFillMode() {
return getWallpaperFile() instanceof ZLResourceFile return getWallpaperFile() instanceof ZLResourceFile
? ZLPaintContext.WallpaperMode.TILE_MIRROR ? ZLPaintContext.FillMode.tileMirror
: ZLPaintContext.WallpaperMode.TILE; : myViewOptions.getColorProfile().FillModeOption.getValue();
} }
@Override @Override
@ -497,7 +497,7 @@ public final class FBView extends ZLTextView {
public synchronized void paint(ZLPaintContext context) { public synchronized void paint(ZLPaintContext context) {
final ZLFile wallpaper = getWallpaperFile(); final ZLFile wallpaper = getWallpaperFile();
if (wallpaper != null) { if (wallpaper != null) {
context.clear(wallpaper, getWallpaperMode()); context.clear(wallpaper, getFillMode());
} else { } else {
context.clear(getBackgroundColor()); context.clear(getBackgroundColor());
} }

View file

@ -23,6 +23,7 @@ import java.util.*;
import org.geometerplus.zlibrary.core.util.ZLColor; import org.geometerplus.zlibrary.core.util.ZLColor;
import org.geometerplus.zlibrary.core.options.*; import org.geometerplus.zlibrary.core.options.*;
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
public class ColorProfile { public class ColorProfile {
public static final String DAY = "defaultLight"; public static final String DAY = "defaultLight";
@ -56,6 +57,7 @@ public class ColorProfile {
public final String Name; public final String Name;
public final ZLStringOption WallpaperOption; public final ZLStringOption WallpaperOption;
public final ZLEnumOption<ZLPaintContext.FillMode> FillModeOption;
public final ZLColorOption BackgroundOption; public final ZLColorOption BackgroundOption;
public final ZLColorOption SelectionBackgroundOption; public final ZLColorOption SelectionBackgroundOption;
public final ZLColorOption SelectionForegroundOption; public final ZLColorOption SelectionForegroundOption;
@ -67,6 +69,8 @@ public class ColorProfile {
private ColorProfile(String name, ColorProfile base) { private ColorProfile(String name, ColorProfile base) {
this(name); this(name);
WallpaperOption.setValue(base.WallpaperOption.getValue());
FillModeOption.setValue(base.FillModeOption.getValue());
BackgroundOption.setValue(base.BackgroundOption.getValue()); BackgroundOption.setValue(base.BackgroundOption.getValue());
SelectionBackgroundOption.setValue(base.SelectionBackgroundOption.getValue()); SelectionBackgroundOption.setValue(base.SelectionBackgroundOption.getValue());
SelectionForegroundOption.setValue(base.SelectionForegroundOption.getValue()); SelectionForegroundOption.setValue(base.SelectionForegroundOption.getValue());
@ -86,6 +90,8 @@ public class ColorProfile {
if (NIGHT.equals(name)) { if (NIGHT.equals(name)) {
WallpaperOption = WallpaperOption =
new ZLStringOption("Colors", name + ":Wallpaper", ""); new ZLStringOption("Colors", name + ":Wallpaper", "");
FillModeOption =
new ZLEnumOption<ZLPaintContext.FillMode>(name, "FillMode", ZLPaintContext.FillMode.tile);
BackgroundOption = BackgroundOption =
createOption(name, "Background", 0, 0, 0); createOption(name, "Background", 0, 0, 0);
SelectionBackgroundOption = SelectionBackgroundOption =
@ -105,6 +111,8 @@ public class ColorProfile {
} else { } else {
WallpaperOption = WallpaperOption =
new ZLStringOption("Colors", name + ":Wallpaper", "wallpapers/sepia.jpg"); new ZLStringOption("Colors", name + ":Wallpaper", "wallpapers/sepia.jpg");
FillModeOption =
new ZLEnumOption<ZLPaintContext.FillMode>(name, "FillMode", ZLPaintContext.FillMode.tile);
BackgroundOption = BackgroundOption =
createOption(name, "Background", 255, 255, 255); createOption(name, "Background", 255, 255, 255);
SelectionBackgroundOption = SelectionBackgroundOption =

View file

@ -31,7 +31,7 @@ final class DummyPaintContext extends ZLPaintContext {
} }
@Override @Override
public void clear(ZLFile wallpaperFile, WallpaperMode mode) { public void clear(ZLFile wallpaperFile, FillMode mode) {
} }
@Override @Override

View file

@ -32,11 +32,16 @@ abstract public class ZLPaintContext {
protected ZLPaintContext() { protected ZLPaintContext() {
} }
public static enum WallpaperMode { public enum FillMode {
TILE, tile,
TILE_MIRROR tileMirror,
fullscreen,
stretch,
tileVertically,
tileHorizontally
} }
abstract public void clear(ZLFile wallpaperFile, WallpaperMode mode);
abstract public void clear(ZLFile wallpaperFile, FillMode mode);
abstract public void clear(ZLColor color); abstract public void clear(ZLColor color);
abstract public ZLColor getBackgroundColor(); abstract public ZLColor getBackgroundColor();

View file

@ -450,7 +450,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
setContext(context); setContext(context);
final ZLFile wallpaper = getWallpaperFile(); final ZLFile wallpaper = getWallpaperFile();
if (wallpaper != null) { if (wallpaper != null) {
context.clear(wallpaper, getWallpaperMode()); context.clear(wallpaper, getFillMode());
} else { } else {
context.clear(getBackgroundColor()); context.clear(getBackgroundColor());
} }

View file

@ -85,7 +85,7 @@ abstract class ZLTextViewBase extends ZLView {
public abstract boolean twoColumnView(); public abstract boolean twoColumnView();
public abstract ZLFile getWallpaperFile(); public abstract ZLFile getWallpaperFile();
public abstract ZLPaintContext.WallpaperMode getWallpaperMode(); public abstract ZLPaintContext.FillMode getFillMode();
public abstract ZLColor getBackgroundColor(); public abstract ZLColor getBackgroundColor();
public abstract ZLColor getSelectionBackgroundColor(); public abstract ZLColor getSelectionBackgroundColor();
public abstract ZLColor getSelectionForegroundColor(); public abstract ZLColor getSelectionForegroundColor();

View file

@ -81,7 +81,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
private static ZLFile ourWallpaperFile; private static ZLFile ourWallpaperFile;
private static Bitmap ourWallpaper; private static Bitmap ourWallpaper;
@Override @Override
public void clear(ZLFile wallpaperFile, WallpaperMode mode) { public void clear(ZLFile wallpaperFile, FillMode mode) {
if (!wallpaperFile.equals(ourWallpaperFile)) { if (!wallpaperFile.equals(ourWallpaperFile)) {
ourWallpaperFile = wallpaperFile; ourWallpaperFile = wallpaperFile;
ourWallpaper = null; ourWallpaper = null;
@ -89,7 +89,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
final Bitmap fileBitmap = final Bitmap fileBitmap =
BitmapFactory.decodeStream(wallpaperFile.getInputStream()); BitmapFactory.decodeStream(wallpaperFile.getInputStream());
switch (mode) { switch (mode) {
case TILE_MIRROR: case tileMirror:
{ {
final int w = fileBitmap.getWidth(); final int w = fileBitmap.getWidth();
final int h = fileBitmap.getHeight(); final int h = fileBitmap.getHeight();
@ -111,7 +111,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
ourWallpaper = wallpaper; ourWallpaper = wallpaper;
break; break;
} }
case TILE: case tile:
ourWallpaper = fileBitmap; ourWallpaper = fileBitmap;
break; break;
} }
@ -124,7 +124,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
final int w = ourWallpaper.getWidth(); final int w = ourWallpaper.getWidth();
final int h = ourWallpaper.getHeight(); final int h = ourWallpaper.getHeight();
for (int cw = 0, iw = 1; cw < myWidth; cw += w, ++iw) { for (int cw = 0, iw = 1; cw < myWidth; cw += w, ++iw) {
for (int ch = 0, ih = 1; ch < myHeight; ch += h, ++ih) { for (int ch = 0, ih = 1; ch < myHeight + 100; ch += h, ++ih) {
myCanvas.drawBitmap(ourWallpaper, cw, ch, myFillPaint); myCanvas.drawBitmap(ourWallpaper, cw, ch, myFillPaint);
} }
} }
@ -137,7 +137,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
public void clear(ZLColor color) { public void clear(ZLColor color) {
myBackgroundColor = color; myBackgroundColor = color;
myFillPaint.setColor(ZLAndroidColorUtil.rgb(color)); myFillPaint.setColor(ZLAndroidColorUtil.rgb(color));
myCanvas.drawRect(0, 0, myWidth + myScrollbarWidth, myHeight, myFillPaint); myCanvas.drawRect(0, 0, myWidth + myScrollbarWidth, myHeight + 100, myFillPaint);
} }
@Override @Override