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

more brightess levels

This commit is contained in:
Nikolay Pultsin 2015-08-14 16:18:35 +02:00
parent 03d954edfc
commit 0bcf2e2904
12 changed files with 197 additions and 55 deletions

View file

@ -6,8 +6,10 @@
===== 2.6 (??? ??, 2015) ===== ===== 2.6 (??? ??, 2015) =====
* Customisable main menu * Customisable main menu
* New (material design style) icon
* Simple widgets * Simple widgets
===== 2.5.6 (??? ??, 2015) =====
* New (material design style) icon
* More brighthess levels in reading mode * More brighthess levels in reading mode
===== 2.5.5 (Aug 14, 2015) ===== ===== 2.5.5 (Aug 14, 2015) =====

View file

@ -519,7 +519,7 @@ public final class FBReader extends FBReaderMainActivity implements ZLApplicatio
final int brightnessLevel = final int brightnessLevel =
getZLibrary().ScreenBrightnessLevelOption.getValue(); getZLibrary().ScreenBrightnessLevelOption.getValue();
if (brightnessLevel != 0) { if (brightnessLevel != 0) {
setScreenBrightness(brightnessLevel); getViewWidget().setScreenBrightness(brightnessLevel);
} else { } else {
setScreenBrightnessAuto(); setScreenBrightnessAuto();
} }
@ -911,29 +911,6 @@ public final class FBReader extends FBReaderMainActivity implements ZLApplicatio
} }
}; };
private void setScreenBrightnessAuto() {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = -1.0f;
getWindow().setAttributes(attrs);
}
public void setScreenBrightness(int percent) {
if (percent < 1) {
percent = 1;
} else if (percent > 100) {
percent = 100;
}
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = percent / 100.0f;
getWindow().setAttributes(attrs);
getZLibrary().ScreenBrightnessLevelOption.setValue(percent);
}
public int getScreenBrightness() {
final int level = (int)(100 * getWindow().getAttributes().screenBrightness);
return (level >= 0) ? level : 50;
}
private BookCollectionShadow getCollection() { private BookCollectionShadow getCollection() {
return (BookCollectionShadow)myFBReaderApp.Collection; return (BookCollectionShadow)myFBReaderApp.Collection;
} }

View file

@ -22,6 +22,7 @@ package org.geometerplus.android.fbreader;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.WindowManager;
import com.github.johnpersano.supertoasts.SuperActivityToast; import com.github.johnpersano.supertoasts.SuperActivityToast;
@ -60,6 +61,31 @@ public abstract class FBReaderMainActivity extends Activity {
return ((ZLAndroidApplication)getApplication()).library(); return ((ZLAndroidApplication)getApplication()).library();
} }
/* ++++++ SCREEN BRIGHTNESS ++++++ */
protected void setScreenBrightnessAuto() {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = -1.0f;
getWindow().setAttributes(attrs);
}
public void setScreenBrightnessSystem(int percent) {
if (percent < 2) {
percent = 2;
} else if (percent > 100) {
percent = 100;
}
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = percent / 100.0f;
getWindow().setAttributes(attrs);
getZLibrary().ScreenBrightnessLevelOption.setValue(percent);
}
public int getScreenBrightnessSystem() {
final int level = (int)(100 * getWindow().getAttributes().screenBrightness);
return level >= 0 ? level : 50;
}
/* ------ SCREEN BRIGHTNESS ------ */
/* ++++++ SUPER TOAST ++++++ */ /* ++++++ SUPER TOAST ++++++ */
public boolean isToastShown() { public boolean isToastShown() {
final SuperActivityToast toast = myToast; final SuperActivityToast toast = myToast;

View file

@ -0,0 +1,67 @@
/*
* Copyright (C) 2007-2015 FBReader.ORG Limited <contact@fbreader.org>
*
* 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.ui.android.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import org.geometerplus.android.fbreader.FBReaderMainActivity;
public abstract class MainView extends View {
protected Integer myColorLevel;
public MainView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MainView(Context context) {
super(context);
}
public final void setScreenBrightness(int percent) {
final Context context = getContext();
if (!(context instanceof FBReaderMainActivity)) {
return;
}
((FBReaderMainActivity)context).setScreenBrightnessSystem(percent);
if (percent >= 50) {
myColorLevel = null;
} else {
myColorLevel = 0x60 + (0xFF - 0x60) * Math.max(percent, 0) / 50;
}
updateColorLevel();
postInvalidate();
}
public final int getScreenBrightness() {
final Context context = getContext();
if (!(context instanceof FBReaderMainActivity)) {
return 50;
}
return ((FBReaderMainActivity)context).getScreenBrightnessSystem();
}
protected abstract void updateColorLevel();
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (C) 2007-2015 FBReader.ORG Limited <contact@fbreader.org>
*
* 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.ui.android.view;
import android.graphics.*;
public abstract class ViewUtil {
public static void setColorLevel(Paint paint, Integer level) {
if (level != null) {
paint.setColorFilter(new PorterDuffColorFilter(
Color.rgb(level, level, level), PorterDuff.Mode.MULTIPLY
));
} else {
paint.setColorFilter(null);
}
}
}

View file

@ -38,10 +38,11 @@ import org.geometerplus.zlibrary.ui.android.view.animation.*;
import org.geometerplus.fbreader.Paths; import org.geometerplus.fbreader.Paths;
import org.geometerplus.android.fbreader.FBReader; import org.geometerplus.android.fbreader.FBReader;
public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongClickListener { public class ZLAndroidWidget extends MainView implements ZLViewWidget, View.OnLongClickListener {
public final ExecutorService PrepareService = Executors.newSingleThreadExecutor(); public final ExecutorService PrepareService = Executors.newSingleThreadExecutor();
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
private final BitmapManagerImpl myBitmapManager = new BitmapManagerImpl(this); private final BitmapManagerImpl myBitmapManager = new BitmapManagerImpl(this);
private Bitmap myFooterBitmap; private Bitmap myFooterBitmap;
private final SystemInfo mySystemInfo; private final SystemInfo mySystemInfo;
@ -175,7 +176,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
@Override @Override
public void startManualScrolling(int x, int y, ZLView.Direction direction) { public void startManualScrolling(int x, int y, ZLView.Direction direction) {
final AnimationProvider animator = getAnimationProvider(); final AnimationProvider animator = getAnimationProvider();
animator.setup(direction, getWidth(), getMainAreaHeight()); animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
animator.startManualScrolling(x, y); animator.startManualScrolling(x, y);
} }
@ -196,7 +197,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
return; return;
} }
final AnimationProvider animator = getAnimationProvider(); final AnimationProvider animator = getAnimationProvider();
animator.setup(direction, getWidth(), getMainAreaHeight()); animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
animator.startAnimatedScrolling(pageIndex, x, y, speed); animator.startAnimatedScrolling(pageIndex, x, y, speed);
if (animator.getMode().Auto) { if (animator.getMode().Auto) {
postInvalidate(); postInvalidate();
@ -210,7 +211,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
return; return;
} }
final AnimationProvider animator = getAnimationProvider(); final AnimationProvider animator = getAnimationProvider();
animator.setup(direction, getWidth(), getMainAreaHeight()); animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
animator.startAnimatedScrolling(pageIndex, null, null, speed); animator.startAnimatedScrolling(pageIndex, null, null, speed);
if (animator.getMode().Auto) { if (animator.getMode().Auto) {
postInvalidate(); postInvalidate();
@ -546,19 +547,8 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
return footer != null ? getHeight() - footer.getHeight() : getHeight(); return footer != null ? getHeight() - footer.getHeight() : getHeight();
} }
public void setScreenBrightness(int percent) { @Override
final Context context = getContext(); protected void updateColorLevel() {
if (!(context instanceof FBReader)) { ViewUtil.setColorLevel(myPaint, myColorLevel);
return;
}
((FBReader)context).setScreenBrightness(percent);
}
public int getScreenBrightness() {
final Context context = getContext();
if (!(context instanceof FBReader)) {
return 50;
}
return ((FBReader)context).getScreenBrightness();
} }
} }

View file

@ -55,6 +55,7 @@ public abstract class AnimationProvider {
protected int myWidth; protected int myWidth;
protected int myHeight; protected int myHeight;
protected Integer myColorLevel;
protected AnimationProvider(BitmapManager bitmapManager) { protected AnimationProvider(BitmapManager bitmapManager) {
myBitmapManager = bitmapManager; myBitmapManager = bitmapManager;
@ -209,10 +210,11 @@ public abstract class AnimationProvider {
return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY; return myDirection.IsHorizontal ? myEndX - myStartX : myEndY - myStartY;
} }
public final void setup(ZLViewEnums.Direction direction, int width, int height) { public final void setup(ZLViewEnums.Direction direction, int width, int height, Integer colorLevel) {
myDirection = direction; myDirection = direction;
myWidth = width; myWidth = width;
myHeight = height; myHeight = height;
myColorLevel = colorLevel;
} }
public abstract void doStep(); public abstract void doStep();
@ -240,6 +242,7 @@ public abstract class AnimationProvider {
public final void draw(Canvas canvas) { public final void draw(Canvas canvas) {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
setFilter();
drawInternal(canvas); drawInternal(canvas);
myDrawInfos.add(new DrawInfo(myEndX, myEndY, start, System.currentTimeMillis())); myDrawInfos.add(new DrawInfo(myEndX, myEndY, start, System.currentTimeMillis()));
if (myDrawInfos.size() > 3) { if (myDrawInfos.size() > 3) {
@ -247,7 +250,14 @@ public abstract class AnimationProvider {
} }
} }
public final void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) {
setFilter();
drawFooterBitmapInternal(canvas, footerBitmap, voffset);
}
protected abstract void setFilter();
protected abstract void drawInternal(Canvas canvas); protected abstract void drawInternal(Canvas canvas);
protected abstract void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset);
public abstract ZLViewEnums.PageIndex getPageToScrollTo(int x, int y); public abstract ZLViewEnums.PageIndex getPageToScrollTo(int x, int y);
@ -270,6 +280,4 @@ public abstract class AnimationProvider {
protected void drawBitmapTo(Canvas canvas, int x, int y, Paint paint) { protected void drawBitmapTo(Canvas canvas, int x, int y, Paint paint) {
myBitmapManager.drawBitmap(canvas, x, y, getPageToScrollTo(), paint); myBitmapManager.drawBitmap(canvas, x, y, getPageToScrollTo(), paint);
} }
public abstract void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset);
} }

View file

@ -24,7 +24,9 @@ import android.util.FloatMath;
import org.geometerplus.zlibrary.core.util.BitmapUtil; import org.geometerplus.zlibrary.core.util.BitmapUtil;
import org.geometerplus.zlibrary.core.view.ZLViewEnums; import org.geometerplus.zlibrary.core.view.ZLViewEnums;
import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil; import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
public final class CurlAnimationProvider extends AnimationProvider { public final class CurlAnimationProvider extends AnimationProvider {
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
@ -329,7 +331,14 @@ public final class CurlAnimationProvider extends AnimationProvider {
} }
@Override @Override
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) { public void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
canvas.drawBitmap(footerBitmap, 0, voffset, myPaint); canvas.drawBitmap(footerBitmap, 0, voffset, myPaint);
} }
@Override
protected void setFilter() {
ViewUtil.setColorLevel(myPaint, myColorLevel);
ViewUtil.setColorLevel(myBackPaint, myColorLevel);
ViewUtil.setColorLevel(myEdgePaint, myColorLevel);
}
} }

View file

@ -23,6 +23,8 @@ import android.graphics.*;
import org.geometerplus.zlibrary.core.view.ZLViewEnums; import org.geometerplus.zlibrary.core.view.ZLViewEnums;
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
public final class NoneAnimationProvider extends AnimationProvider { public final class NoneAnimationProvider extends AnimationProvider {
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
@ -79,7 +81,12 @@ public final class NoneAnimationProvider extends AnimationProvider {
} }
@Override @Override
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) { public void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
canvas.drawBitmap(footerBitmap, 0, voffset, myPaint); canvas.drawBitmap(footerBitmap, 0, voffset, myPaint);
} }
@Override
protected void setFilter() {
ViewUtil.setColorLevel(myPaint, myColorLevel);
}
} }

View file

@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
import android.graphics.*; import android.graphics.*;
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
public final class ShiftAnimationProvider extends SimpleAnimationProvider { public final class ShiftAnimationProvider extends SimpleAnimationProvider {
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
{ {
@ -55,7 +57,7 @@ public final class ShiftAnimationProvider extends SimpleAnimationProvider {
} }
@Override @Override
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) { public void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
canvas.drawBitmap(footerBitmap, 0, voffset, myPaint); canvas.drawBitmap(footerBitmap, 0, voffset, myPaint);
if (myDirection.IsHorizontal) { if (myDirection.IsHorizontal) {
final int dX = myEndX - myStartX; final int dX = myEndX - myStartX;
@ -66,4 +68,9 @@ public final class ShiftAnimationProvider extends SimpleAnimationProvider {
} }
} }
} }
@Override
protected void setFilter() {
ViewUtil.setColorLevel(myPaint, myColorLevel);
}
} }

View file

@ -22,6 +22,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
import android.graphics.*; import android.graphics.*;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
public final class SlideAnimationProvider extends SimpleAnimationProvider { public final class SlideAnimationProvider extends SimpleAnimationProvider {
private final Paint myDarkPaint = new Paint(); private final Paint myDarkPaint = new Paint();
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
@ -31,10 +33,16 @@ public final class SlideAnimationProvider extends SimpleAnimationProvider {
} }
private void setDarkFilter(int visible, int full) { private void setDarkFilter(int visible, int full) {
final int color = 145 + 100 * Math.abs(visible) / full; int darkColorLevel = 145 + 100 * Math.abs(visible) / full;
myDarkPaint.setColorFilter(new PorterDuffColorFilter( if (myColorLevel != null) {
Color.rgb(color, color, color), PorterDuff.Mode.MULTIPLY darkColorLevel = darkColorLevel * myColorLevel / 0xFF;
)); }
ViewUtil.setColorLevel(myDarkPaint, darkColorLevel);
}
@Override
protected void setFilter() {
ViewUtil.setColorLevel(myPaint, myColorLevel);
} }
private void drawShadow(Canvas canvas, int top, int bottom, int dX) { private void drawShadow(Canvas canvas, int top, int bottom, int dX) {
@ -79,7 +87,7 @@ public final class SlideAnimationProvider extends SimpleAnimationProvider {
} }
@Override @Override
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) { protected void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
if (myDirection.IsHorizontal) { if (myDirection.IsHorizontal) {
final int dX = myEndX - myStartX; final int dX = myEndX - myStartX;
setDarkFilter(dX, myWidth); setDarkFilter(dX, myWidth);

View file

@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
import android.graphics.*; import android.graphics.*;
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvider { public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvider {
private final Paint myPaint = new Paint(); private final Paint myPaint = new Paint();
@ -52,7 +54,7 @@ public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvide
} }
@Override @Override
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) { protected void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
canvas.drawBitmap(footerBitmap, 0, voffset, myPaint); canvas.drawBitmap(footerBitmap, 0, voffset, myPaint);
if (myDirection.IsHorizontal) { if (myDirection.IsHorizontal) {
final int dX = myEndX - myStartX; final int dX = myEndX - myStartX;
@ -63,4 +65,9 @@ public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvide
} }
} }
} }
@Override
protected void setFilter() {
ViewUtil.setColorLevel(myPaint, myColorLevel);
}
} }