Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public interface Listener {

private Listener listener;

// Some devices report slightly different sizes depending on UI state. Ignore
// such minor fluctuations to avoid spurious capture resets.
private static final int SIZE_EPSILON = 4;

private static boolean approximatelyEquals(Size s1, Size s2) {
if (s1 == null || s2 == null) {
return false;
}
return Math.abs(s1.getWidth() - s2.getWidth()) <= SIZE_EPSILON
&& Math.abs(s1.getHeight() - s2.getHeight()) <= SIZE_EPSILON;
}

public void start(int displayId, Listener listener) {
// Once started, the listener and the displayId must never change
assert listener != null;
Expand Down Expand Up @@ -124,7 +136,7 @@ private void checkDisplaySizeChanged() {
Size sessionDisplaySize = getSessionDisplaySize(); // synchronized

// .equals() also works if sessionDisplaySize == null
if (!size.equals(sessionDisplaySize)) {
if (!approximatelyEquals(size, sessionDisplaySize)) {
// Reset only if the size is different
if (Ln.isEnabled(Ln.Level.VERBOSE)) {
Ln.v("DisplaySizeMonitor: requestReset(): " + sessionDisplaySize + " -> " + size);
Expand Down
Loading