mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
WakeLock refactoring: see ChangeLog for details
This commit is contained in:
parent
c365690633
commit
66f6de1c3b
4 changed files with 38 additions and 15 deletions
|
@ -1,6 +1,8 @@
|
|||
===== 0.7.9 (??? ??, 2010) =====
|
||||
* List of styles has been fixed in the Options dialog
|
||||
* Monospace font has been included in the fonts list
|
||||
* Wakelock will be acquired during first page repainting, not during screen switching on. That prevents from
|
||||
power comsumption if FBReader works and the screen was switched on accidentally (but not unlocked).
|
||||
|
||||
===== 0.7.8 (Oct 10, 2010) =====
|
||||
* Processing of large OPDS feeds (> 500 books in one file) has been fixed
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.LinkedList;
|
|||
import android.app.SearchManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
@ -154,28 +153,14 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private PowerManager.WakeLock myWakeLock;
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
ControlButtonPanel.restoreVisibilities();
|
||||
if (ZLAndroidApplication.Instance().DontTurnScreenOffOption.getValue()) {
|
||||
myWakeLock =
|
||||
((PowerManager)getSystemService(POWER_SERVICE)).
|
||||
newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "FBReader");
|
||||
myWakeLock.acquire();
|
||||
} else {
|
||||
myWakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (myWakeLock != null) {
|
||||
myWakeLock.release();
|
||||
myWakeLock = null;
|
||||
}
|
||||
ControlButtonPanel.saveVisibilities();
|
||||
super.onPause();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.content.Intent;
|
|||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.*;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
@ -123,8 +124,36 @@ public abstract class ZLAndroidActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
private PowerManager.WakeLock myWakeLock;
|
||||
private boolean myWakeLockToCreate;
|
||||
|
||||
public final void createWakeLock() {
|
||||
if (myWakeLockToCreate) {
|
||||
synchronized (this) {
|
||||
if (myWakeLockToCreate) {
|
||||
myWakeLockToCreate = false;
|
||||
myWakeLock =
|
||||
((PowerManager)getSystemService(POWER_SERVICE)).
|
||||
newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "FBReader");
|
||||
myWakeLock.acquire();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
myWakeLockToCreate = ZLAndroidApplication.Instance().DontTurnScreenOffOption.getValue();
|
||||
myWakeLock = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (myWakeLock != null) {
|
||||
myWakeLock.release();
|
||||
myWakeLock = null;
|
||||
}
|
||||
ZLApplication.Instance().onWindowClosing();
|
||||
super.onPause();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.util.AttributeSet;
|
|||
import org.geometerplus.zlibrary.core.view.ZLView;
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
|
||||
import org.geometerplus.zlibrary.ui.android.util.ZLAndroidKeyUtil;
|
||||
|
||||
public class ZLAndroidWidget extends View {
|
||||
|
@ -72,6 +73,12 @@ public class ZLAndroidWidget extends View {
|
|||
|
||||
@Override
|
||||
protected void onDraw(final Canvas canvas) {
|
||||
final Context context = getContext();
|
||||
if (context instanceof ZLAndroidActivity) {
|
||||
((ZLAndroidActivity)context).createWakeLock();
|
||||
} else {
|
||||
System.err.println("A surprise: view's context is not a ZLAndroidActivity");
|
||||
}
|
||||
super.onDraw(canvas);
|
||||
|
||||
final int w = getWidth();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue