diff --git a/data/resources/application/cs.xml b/data/resources/application/cs.xml index fcc66d1e4..012ae784f 100644 --- a/data/resources/application/cs.xml +++ b/data/resources/application/cs.xml @@ -167,6 +167,10 @@ + + + + diff --git a/data/resources/application/de.xml b/data/resources/application/de.xml index 23a12691b..fca957151 100644 --- a/data/resources/application/de.xml +++ b/data/resources/application/de.xml @@ -167,6 +167,10 @@ + + + + diff --git a/data/resources/application/en.xml b/data/resources/application/en.xml index f8dd9dc9c..71a5568f4 100644 --- a/data/resources/application/en.xml +++ b/data/resources/application/en.xml @@ -166,6 +166,10 @@ + + + + diff --git a/data/resources/application/fr.xml b/data/resources/application/fr.xml index f95b47ca2..3b8b51b9e 100644 --- a/data/resources/application/fr.xml +++ b/data/resources/application/fr.xml @@ -170,6 +170,10 @@ + + + + diff --git a/data/resources/application/hu.xml b/data/resources/application/hu.xml index 5bfe32a11..cd4525d50 100644 --- a/data/resources/application/hu.xml +++ b/data/resources/application/hu.xml @@ -167,6 +167,10 @@ + + + + diff --git a/data/resources/application/it.xml b/data/resources/application/it.xml index de4453baf..46986c93b 100644 --- a/data/resources/application/it.xml +++ b/data/resources/application/it.xml @@ -167,6 +167,10 @@ + + + + diff --git a/data/resources/application/ru.xml b/data/resources/application/ru.xml index 6d1d7d2c7..aea58cbbf 100644 --- a/data/resources/application/ru.xml +++ b/data/resources/application/ru.xml @@ -166,6 +166,10 @@ + + + + diff --git a/data/resources/application/vi.xml b/data/resources/application/vi.xml index e15a1ff4c..4ef0115c3 100644 --- a/data/resources/application/vi.xml +++ b/data/resources/application/vi.xml @@ -167,6 +167,10 @@ + + + + diff --git a/data/resources/application/zh.xml b/data/resources/application/zh.xml index bf34375cb..afe46fb5f 100644 --- a/data/resources/application/zh.xml +++ b/data/resources/application/zh.xml @@ -167,6 +167,10 @@ + + + + diff --git a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java index b49a39fa2..7bcafa8cf 100644 --- a/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java +++ b/src/org/geometerplus/android/fbreader/preferences/PreferenceActivity.java @@ -75,9 +75,10 @@ public class PreferenceActivity extends ZLPreferenceActivity { final Category lookNFeelCategory = createCategory("LookNFeel"); final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance(); + final ZLAndroidApplication androidApp = ZLAndroidApplication.Instance(); final Screen appearanceScreen = lookNFeelCategory.createPreferenceScreen("appearanceSettings"); - appearanceScreen.setSummary( appearanceScreen.Resource.getResource("summary").getValue() ); + appearanceScreen.setSummary(appearanceScreen.Resource.getResource("summary").getValue()); appearanceScreen.setOnPreferenceClickListener( new PreferenceScreen.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { @@ -113,16 +114,29 @@ public class PreferenceActivity extends ZLPreferenceActivity { statusLineCategory.addOption(fbReader.FooterShowProgress, "showProgress"); statusLineCategory.addOption(fbReader.FooterIsSensitive, "isSensitive"); - lookNFeelCategory.addOption(ZLAndroidApplication.Instance().AutoOrientationOption, "autoOrientation"); - if (!ZLAndroidApplication.Instance().isAlwaysShowStatusBar()) { - lookNFeelCategory.addOption(ZLAndroidApplication.Instance().ShowStatusBarOption, "showStatusBar"); + lookNFeelCategory.addOption(androidApp.AutoOrientationOption, "autoOrientation"); + if (!androidApp.isAlwaysShowStatusBar()) { + lookNFeelCategory.addOption(androidApp.ShowStatusBarOption, "showStatusBar"); } lookNFeelCategory.addPreference(new BatteryLevelToTurnScreenOffPreference( this, - ZLAndroidApplication.Instance().BatteryLevelToTurnScreenOffOption, + androidApp.BatteryLevelToTurnScreenOffOption, lookNFeelCategory.Resource, "dontTurnScreenOff" )); + lookNFeelCategory.addPreference(new ZLBooleanPreference( + this, + fbReader.AllowScreenBrightnessAdjustmentOption, + lookNFeelCategory.Resource, + "allowScreenBrightnessAdjustment" + ) { + public void onAccept() { + super.onAccept(); + if (!isChecked()) { + androidApp.ScreenBrightnessLevelOption.setValue(0); + } + } + }); /* final Screen colorProfileScreen = lookNFeelCategory.createPreferenceScreen("colorProfile"); diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java index a8ab859d8..54604d323 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java +++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java @@ -33,6 +33,8 @@ import org.geometerplus.fbreader.library.Bookmark; import org.geometerplus.fbreader.optionsDialog.OptionsDialog; public final class FBReaderApp extends ZLApplication { + public final ZLBooleanOption AllowScreenBrightnessAdjustmentOption = + new ZLBooleanOption("LookNFeel", "AllowScreenBrightnessAdjustment", true); public final ZLStringOption TextSearchPatternOption = new ZLStringOption("TextSearch", "Pattern", ""); public final ZLStringOption BookmarkSearchPatternOption = diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index 092808fe1..85a8eacd3 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -118,7 +118,7 @@ public final class FBView extends ZLTextView { return true; } - if (x < 20) { + if (myReader.AllowScreenBrightnessAdjustmentOption.getValue() && x < myContext.getWidth() / 10) { myIsBrightnessAdjustmentInProgress = true; myStartY = y; myStartBrightness = ZLibrary.Instance().getScreenBrightness(); @@ -159,10 +159,10 @@ public final class FBView extends ZLTextView { synchronized (this) { if (myIsBrightnessAdjustmentInProgress) { - if (x >= 40) { + if (x >= myContext.getWidth() / 5) { myIsBrightnessAdjustmentInProgress = false; } else { - final int delta = (myStartBrightness + 10) * 2 * (myStartY - y) / myContext.getHeight(); + final int delta = (myStartBrightness + 10) * (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()); @@ -205,9 +205,7 @@ public final class FBView extends ZLTextView { } synchronized (this) { - if (myIsBrightnessAdjustmentInProgress) { - myIsBrightnessAdjustmentInProgress = false; - } + myIsBrightnessAdjustmentInProgress = false; if (isScrollingActive() && myIsManualScrollingActive) { setScrollingActive(false); myIsManualScrollingActive = false; diff --git a/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java b/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java index 3274352f9..65aa8683c 100644 --- a/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java +++ b/src/org/geometerplus/fbreader/fbreader/ScrollingPreferences.java @@ -31,7 +31,7 @@ public class ScrollingPreferences { public final ZLBooleanOption FlickOption = new ZLBooleanOption("Scrolling", "Flick", true); public final ZLBooleanOption VolumeKeysOption = new ZLBooleanOption("Scrolling", "VolumeKeys", true); public final ZLBooleanOption AnimateOption = new ZLBooleanOption("Scrolling", "ShowAnimated", true); - public final ZLBooleanOption HorizontalOption = new ZLBooleanOption("Scrolling", "Horizontal", false); + public final ZLBooleanOption HorizontalOption = new ZLBooleanOption("Scrolling", "Horizontal", true); public final ZLBooleanOption InvertVolumeKeysOption = new ZLBooleanOption("Scrolling", "InvertVolumeKeys", false); private ScrollingPreferences() { diff --git a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidActivity.java b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidActivity.java index 8de45eb8a..c68c8a12d 100644 --- a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidActivity.java +++ b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidActivity.java @@ -60,15 +60,22 @@ public abstract class ZLAndroidActivity extends Activity { } } + private void setScreenBrightnessAuto() { + final WindowManager.LayoutParams attrs = getWindow().getAttributes(); + attrs.screenBrightness = -1.0f; + getWindow().setAttributes(attrs); + } + final void setScreenBrightness(int percent) { - if (percent < 0) { - percent = 0; + 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); + ((ZLAndroidApplication)getApplication()).ScreenBrightnessLevelOption.setValue(percent); } final int getScreenBrightness() { @@ -76,6 +83,19 @@ public abstract class ZLAndroidActivity extends Activity { return (level >= 0) ? level : 50; } + private void disableButtonLight() { + try { + final WindowManager.LayoutParams attrs = getWindow().getAttributes(); + final Class cls = attrs.getClass(); + final Field fld = cls.getField("buttonBrightness"); + if (fld != null && "float".equals(fld.getType().toString())) { + fld.setFloat(attrs, 0); + } + } catch (NoSuchFieldException e) { + } catch (IllegalAccessException e) { + } + } + @Override public void onCreate(Bundle state) { super.onCreate(state); @@ -87,17 +107,7 @@ public abstract class ZLAndroidActivity extends Activity { } requestWindowFeature(Window.FEATURE_NO_TITLE); - try { - final WindowManager.LayoutParams attrs = getWindow().getAttributes(); - final Class cls = attrs.getClass(); - final Field fld = cls.getField("buttonBrightness"); - if (fld != null && "float".equals(fld.getType().toString())) { - fld.setFloat(attrs, 0); - } - } catch (NoSuchFieldException e) { - } catch (IllegalAccessException e) { - } - //getWindow().getAttributes().buttonBrightness = 0; + disableButtonLight(); setContentView(R.layout.main); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); @@ -199,6 +209,13 @@ public abstract class ZLAndroidActivity extends Activity { ZLApplication.Instance().getBatteryLevel() ); myStartTimer = true; + final int brightnessLevel = + ((ZLAndroidApplication)getApplication()).ScreenBrightnessLevelOption.getValue(); + if (brightnessLevel != 0) { + setScreenBrightness(brightnessLevel); + } else { + setScreenBrightnessAuto(); + } registerReceiver(myBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } diff --git a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidApplication.java b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidApplication.java index 34cbc00fa..c65b4de0e 100644 --- a/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidApplication.java +++ b/src/org/geometerplus/zlibrary/ui/android/library/ZLAndroidApplication.java @@ -38,6 +38,7 @@ public class ZLAndroidApplication extends Application { public final ZLBooleanOption AutoOrientationOption = new ZLBooleanOption("LookNFeel", "AutoOrientation", false); public final ZLBooleanOption ShowStatusBarOption = new ZLBooleanOption("LookNFeel", "ShowStatusBar", false); public final ZLIntegerRangeOption BatteryLevelToTurnScreenOffOption = new ZLIntegerRangeOption("LookNFeel", "BatteryLevelToTurnScreenOff", 0, 100, 50); + public final ZLIntegerRangeOption ScreenBrightnessLevelOption = new ZLIntegerRangeOption("LookNFeel", "ScreenBrightnessLevel", 0, 100, 0); public static ZLAndroidApplication Instance() { return ourApplication;