mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 01:39:18 +02:00
more brightess levels
This commit is contained in:
parent
03d954edfc
commit
0bcf2e2904
12 changed files with 197 additions and 55 deletions
|
@ -6,8 +6,10 @@
|
|||
|
||||
===== 2.6 (??? ??, 2015) =====
|
||||
* Customisable main menu
|
||||
* New (material design style) icon
|
||||
* Simple widgets
|
||||
|
||||
===== 2.5.6 (??? ??, 2015) =====
|
||||
* New (material design style) icon
|
||||
* More brighthess levels in reading mode
|
||||
|
||||
===== 2.5.5 (Aug 14, 2015) =====
|
||||
|
|
|
@ -519,7 +519,7 @@ public final class FBReader extends FBReaderMainActivity implements ZLApplicatio
|
|||
final int brightnessLevel =
|
||||
getZLibrary().ScreenBrightnessLevelOption.getValue();
|
||||
if (brightnessLevel != 0) {
|
||||
setScreenBrightness(brightnessLevel);
|
||||
getViewWidget().setScreenBrightness(brightnessLevel);
|
||||
} else {
|
||||
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() {
|
||||
return (BookCollectionShadow)myFBReaderApp.Collection;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.android.fbreader;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperActivityToast;
|
||||
|
||||
|
@ -60,6 +61,31 @@ public abstract class FBReaderMainActivity extends Activity {
|
|||
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 ++++++ */
|
||||
public boolean isToastShown() {
|
||||
final SuperActivityToast toast = myToast;
|
||||
|
|
67
src/org/geometerplus/zlibrary/ui/android/view/MainView.java
Normal file
67
src/org/geometerplus/zlibrary/ui/android/view/MainView.java
Normal 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();
|
||||
}
|
34
src/org/geometerplus/zlibrary/ui/android/view/ViewUtil.java
Normal file
34
src/org/geometerplus/zlibrary/ui/android/view/ViewUtil.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,10 +38,11 @@ import org.geometerplus.zlibrary.ui.android.view.animation.*;
|
|||
import org.geometerplus.fbreader.Paths;
|
||||
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();
|
||||
|
||||
private final Paint myPaint = new Paint();
|
||||
|
||||
private final BitmapManagerImpl myBitmapManager = new BitmapManagerImpl(this);
|
||||
private Bitmap myFooterBitmap;
|
||||
private final SystemInfo mySystemInfo;
|
||||
|
@ -175,7 +176,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
|||
@Override
|
||||
public void startManualScrolling(int x, int y, ZLView.Direction direction) {
|
||||
final AnimationProvider animator = getAnimationProvider();
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight());
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
|
||||
animator.startManualScrolling(x, y);
|
||||
}
|
||||
|
||||
|
@ -196,7 +197,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
|||
return;
|
||||
}
|
||||
final AnimationProvider animator = getAnimationProvider();
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight());
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
|
||||
animator.startAnimatedScrolling(pageIndex, x, y, speed);
|
||||
if (animator.getMode().Auto) {
|
||||
postInvalidate();
|
||||
|
@ -210,7 +211,7 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
|||
return;
|
||||
}
|
||||
final AnimationProvider animator = getAnimationProvider();
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight());
|
||||
animator.setup(direction, getWidth(), getMainAreaHeight(), myColorLevel);
|
||||
animator.startAnimatedScrolling(pageIndex, null, null, speed);
|
||||
if (animator.getMode().Auto) {
|
||||
postInvalidate();
|
||||
|
@ -546,19 +547,8 @@ public class ZLAndroidWidget extends View implements ZLViewWidget, View.OnLongCl
|
|||
return footer != null ? getHeight() - footer.getHeight() : getHeight();
|
||||
}
|
||||
|
||||
public void setScreenBrightness(int percent) {
|
||||
final Context context = getContext();
|
||||
if (!(context instanceof FBReader)) {
|
||||
return;
|
||||
}
|
||||
((FBReader)context).setScreenBrightness(percent);
|
||||
}
|
||||
|
||||
public int getScreenBrightness() {
|
||||
final Context context = getContext();
|
||||
if (!(context instanceof FBReader)) {
|
||||
return 50;
|
||||
}
|
||||
return ((FBReader)context).getScreenBrightness();
|
||||
@Override
|
||||
protected void updateColorLevel() {
|
||||
ViewUtil.setColorLevel(myPaint, myColorLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ public abstract class AnimationProvider {
|
|||
|
||||
protected int myWidth;
|
||||
protected int myHeight;
|
||||
protected Integer myColorLevel;
|
||||
|
||||
protected AnimationProvider(BitmapManager bitmapManager) {
|
||||
myBitmapManager = bitmapManager;
|
||||
|
@ -209,10 +210,11 @@ public abstract class AnimationProvider {
|
|||
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;
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
myColorLevel = colorLevel;
|
||||
}
|
||||
|
||||
public abstract void doStep();
|
||||
|
@ -240,6 +242,7 @@ public abstract class AnimationProvider {
|
|||
|
||||
public final void draw(Canvas canvas) {
|
||||
final long start = System.currentTimeMillis();
|
||||
setFilter();
|
||||
drawInternal(canvas);
|
||||
myDrawInfos.add(new DrawInfo(myEndX, myEndY, start, System.currentTimeMillis()));
|
||||
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 drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset);
|
||||
|
||||
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) {
|
||||
myBitmapManager.drawBitmap(canvas, x, y, getPageToScrollTo(), paint);
|
||||
}
|
||||
|
||||
public abstract void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ import android.util.FloatMath;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.BitmapUtil;
|
||||
import org.geometerplus.zlibrary.core.view.ZLViewEnums;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.util.ZLAndroidColorUtil;
|
||||
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
|
||||
|
||||
public final class CurlAnimationProvider extends AnimationProvider {
|
||||
private final Paint myPaint = new Paint();
|
||||
|
@ -329,7 +331,14 @@ public final class CurlAnimationProvider extends AnimationProvider {
|
|||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFilter() {
|
||||
ViewUtil.setColorLevel(myPaint, myColorLevel);
|
||||
ViewUtil.setColorLevel(myBackPaint, myColorLevel);
|
||||
ViewUtil.setColorLevel(myEdgePaint, myColorLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.graphics.*;
|
|||
|
||||
import org.geometerplus.zlibrary.core.view.ZLViewEnums;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
|
||||
|
||||
public final class NoneAnimationProvider extends AnimationProvider {
|
||||
private final Paint myPaint = new Paint();
|
||||
|
||||
|
@ -79,7 +81,12 @@ public final class NoneAnimationProvider extends AnimationProvider {
|
|||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFilter() {
|
||||
ViewUtil.setColorLevel(myPaint, myColorLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
|
|||
|
||||
import android.graphics.*;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
|
||||
|
||||
public final class ShiftAnimationProvider extends SimpleAnimationProvider {
|
||||
private final Paint myPaint = new Paint();
|
||||
{
|
||||
|
@ -55,7 +57,7 @@ public final class ShiftAnimationProvider extends SimpleAnimationProvider {
|
|||
}
|
||||
|
||||
@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);
|
||||
if (myDirection.IsHorizontal) {
|
||||
final int dX = myEndX - myStartX;
|
||||
|
@ -66,4 +68,9 @@ public final class ShiftAnimationProvider extends SimpleAnimationProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFilter() {
|
||||
ViewUtil.setColorLevel(myPaint, myColorLevel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
|
|||
import android.graphics.*;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
|
||||
|
||||
public final class SlideAnimationProvider extends SimpleAnimationProvider {
|
||||
private final Paint myDarkPaint = 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) {
|
||||
final int color = 145 + 100 * Math.abs(visible) / full;
|
||||
myDarkPaint.setColorFilter(new PorterDuffColorFilter(
|
||||
Color.rgb(color, color, color), PorterDuff.Mode.MULTIPLY
|
||||
));
|
||||
int darkColorLevel = 145 + 100 * Math.abs(visible) / full;
|
||||
if (myColorLevel != null) {
|
||||
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) {
|
||||
|
@ -79,7 +87,7 @@ public final class SlideAnimationProvider extends SimpleAnimationProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawFooterBitmap(Canvas canvas, Bitmap footerBitmap, int voffset) {
|
||||
protected void drawFooterBitmapInternal(Canvas canvas, Bitmap footerBitmap, int voffset) {
|
||||
if (myDirection.IsHorizontal) {
|
||||
final int dX = myEndX - myStartX;
|
||||
setDarkFilter(dX, myWidth);
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.geometerplus.zlibrary.ui.android.view.animation;
|
|||
|
||||
import android.graphics.*;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.view.ViewUtil;
|
||||
|
||||
public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvider {
|
||||
private final Paint myPaint = new Paint();
|
||||
|
||||
|
@ -52,7 +54,7 @@ public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvide
|
|||
}
|
||||
|
||||
@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);
|
||||
if (myDirection.IsHorizontal) {
|
||||
final int dX = myEndX - myStartX;
|
||||
|
@ -63,4 +65,9 @@ public final class SlideOldStyleAnimationProvider extends SimpleAnimationProvide
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFilter() {
|
||||
ViewUtil.setColorLevel(myPaint, myColorLevel);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue