Android: Use DisplayListener to detect rotation

Since Activity's onConfigurationChanged is not called
when rotating from landscape to landscape (through 180 degrees),
added display listener to detect the rotation.

DisplayManager.DisplayListener.onDisplayChanged() is called exactly when
Display.getRotation() value is changed.

Task-number: QTBUG-56919
Change-Id: Iabf376adf0a0756dddacaece62e5a2ac604ea947
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Val Doroshchuk 2018-09-11 13:56:12 +02:00 committed by Aapo Keskimolo
parent 02c1f67fc3
commit 1d58d2e987

View File

@ -82,6 +82,7 @@ import android.view.inputmethod.InputMethodManager;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.hardware.display.DisplayManager;
import java.io.BufferedReader;
import java.io.DataOutputStream;
@ -667,6 +668,28 @@ public class QtActivityDelegate
} catch (Exception e) {
e.printStackTrace();
}
DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener() {
@Override
public void onDisplayAdded(int displayId) { }
@Override
public void onDisplayChanged(int displayId) {
m_currentRotation = m_activity.getWindowManager().getDefaultDisplay().getRotation();
QtNative.handleOrientationChanged(m_currentRotation, m_nativeOrientation);
}
@Override
public void onDisplayRemoved(int displayId) { }
};
try {
DisplayManager displayManager = (DisplayManager) m_activity.getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(displayListener, null);
} catch (Exception e) {
e.printStackTrace();
}
m_mainLib = QtNative.loadMainLibrary(m_mainLib, nativeLibsDir);
return m_mainLib != null;
}
@ -856,13 +879,6 @@ public class QtActivityDelegate
} catch (Exception e) {
e.printStackTrace();
}
int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation();
if (rotation != m_currentRotation) {
QtNative.handleOrientationChanged(rotation, m_nativeOrientation);
}
m_currentRotation = rotation;
}
public void onDestroy()