mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
brightness adjustment experiments
This commit is contained in:
parent
0f4f826df9
commit
c0030bb5c0
4 changed files with 56 additions and 0 deletions
|
@ -90,6 +90,8 @@ public final class FBView extends ZLTextView {
|
|||
private int myStartX;
|
||||
private int myStartY;
|
||||
private boolean myIsManualScrollingActive;
|
||||
private boolean myIsBrightnessAdjustmentInProgress;
|
||||
private int myStartBrightness;
|
||||
|
||||
public boolean onStylusPress(int x, int y) {
|
||||
if (super.onStylusPress(x, y)) {
|
||||
|
@ -116,6 +118,14 @@ public final class FBView extends ZLTextView {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (x < 20) {
|
||||
myIsBrightnessAdjustmentInProgress = true;
|
||||
myStartY = y;
|
||||
myStartBrightness = ZLibrary.Instance().getScreenBrightness();
|
||||
System.err.println("starting on level: " + myStartBrightness);
|
||||
return true;
|
||||
}
|
||||
|
||||
final ScrollingPreferences preferences = ScrollingPreferences.Instance();
|
||||
if (preferences.FlickOption.getValue()) {
|
||||
myStartX = x;
|
||||
|
@ -148,6 +158,18 @@ public final class FBView extends ZLTextView {
|
|||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (myIsBrightnessAdjustmentInProgress) {
|
||||
if (x >= 40) {
|
||||
myIsBrightnessAdjustmentInProgress = false;
|
||||
} else {
|
||||
final int delta = (myStartBrightness + 10) * 2 * (myStartY - y) / myContext.getHeight();
|
||||
System.err.println("adjusting to level: " + (myStartBrightness + delta));
|
||||
ZLibrary.Instance().setScreenBrightness(myStartBrightness + delta);
|
||||
System.err.println("adjusted to level: " + ZLibrary.Instance().getScreenBrightness());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isScrollingActive() && myIsManualScrollingActive) {
|
||||
final boolean horizontal = ScrollingPreferences.Instance().HorizontalOption.getValue();
|
||||
final int diff = horizontal ? x - myStartX : y - myStartY;
|
||||
|
@ -183,6 +205,9 @@ public final class FBView extends ZLTextView {
|
|||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (myIsBrightnessAdjustmentInProgress) {
|
||||
myIsBrightnessAdjustmentInProgress = false;
|
||||
}
|
||||
if (isScrollingActive() && myIsManualScrollingActive) {
|
||||
setScrollingActive(false);
|
||||
myIsManualScrollingActive = false;
|
||||
|
|
|
@ -37,5 +37,7 @@ public abstract class ZLibrary {
|
|||
|
||||
abstract public String getVersionName();
|
||||
abstract public String getCurrentTimeString();
|
||||
abstract public void setScreenBrightness(int percent);
|
||||
abstract public int getScreenBrightness();
|
||||
abstract public void openInBrowser(String reference);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,22 @@ public abstract class ZLAndroidActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
final void setScreenBrightness(int percent) {
|
||||
if (percent < 0) {
|
||||
percent = 0;
|
||||
} else if (percent > 100) {
|
||||
percent = 100;
|
||||
}
|
||||
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||
attrs.screenBrightness = percent / 100.0f;
|
||||
getWindow().setAttributes(attrs);
|
||||
}
|
||||
|
||||
final int getScreenBrightness() {
|
||||
final int level = (int)(100 * getWindow().getAttributes().screenBrightness);
|
||||
return (level >= 0) ? level : 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
|
|
@ -110,10 +110,23 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentTimeString() {
|
||||
return DateFormat.getTimeFormat(myApplication.getApplicationContext()).format(new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreenBrightness(int percent) {
|
||||
if (myActivity != null) {
|
||||
myActivity.setScreenBrightness(percent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScreenBrightness() {
|
||||
return (myActivity != null) ? myActivity.getScreenBrightness() : 0;
|
||||
}
|
||||
|
||||
private final class AndroidResourceFile extends ZLResourceFile {
|
||||
private boolean myExists;
|
||||
private int myResourceId;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue