Android: use one common getDisplay() method
Use one method getDisplay() which handles different API levels and call it from various code paths instead of doing the same over and over. Task-number: QTBUG-132716 Change-Id: I0b246631b7dd45789f01e6fa6360d8c76c13fee9 Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
This commit is contained in:
parent
495f7cceb2
commit
0abdca8790
@ -154,7 +154,7 @@ class QtActivityDelegate extends QtActivityDelegateBase
|
|||||||
Rect r = new Rect();
|
Rect r = new Rect();
|
||||||
m_activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
m_activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
QtDisplayManager.getDisplay(m_activity).getMetrics(metrics);
|
||||||
final int kbHeight = metrics.heightPixels - r.bottom;
|
final int kbHeight = metrics.heightPixels - r.bottom;
|
||||||
if (kbHeight < 0) {
|
if (kbHeight < 0) {
|
||||||
m_inputDelegate.setKeyboardVisibility(false, System.nanoTime());
|
m_inputDelegate.setKeyboardVisibility(false, System.nanoTime());
|
||||||
|
@ -45,7 +45,7 @@ class QtActivityLoader extends QtLoader {
|
|||||||
int size = m_activity.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
|
int size = m_activity.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
|
||||||
if (size < 36 || size > 512) { // check size sanity
|
if (size < 36 || size > 512) { // check size sanity
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
QtDisplayManager.getDisplay(m_activity).getMetrics(metrics);
|
||||||
size = metrics.densityDpi / 10 * 3;
|
size = metrics.densityDpi / 10 * 3;
|
||||||
if (size < 36)
|
if (size < 36)
|
||||||
size = 36;
|
size = 36;
|
||||||
|
@ -75,20 +75,9 @@ class QtDisplayManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
static void updateRefreshRate(Context context)
|
static void updateRefreshRate(Context context)
|
||||||
{
|
{
|
||||||
Display display;
|
Display display = getDisplay(context);
|
||||||
Activity activity = (Activity) context;
|
|
||||||
if (activity != null) {
|
|
||||||
display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
|
|
||||||
? activity.getWindowManager().getDefaultDisplay()
|
|
||||||
: activity.getDisplay();
|
|
||||||
} else {
|
|
||||||
final DisplayManager dm = context.getSystemService(DisplayManager.class);
|
|
||||||
display = dm.getDisplay(Display.DEFAULT_DISPLAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
float refreshRate = display != null ? display.getRefreshRate() : 60.0f;
|
float refreshRate = display != null ? display.getRefreshRate() : 60.0f;
|
||||||
QtDisplayManager.handleRefreshRateChanged(refreshRate);
|
QtDisplayManager.handleRefreshRateChanged(refreshRate);
|
||||||
}
|
}
|
||||||
@ -104,10 +93,7 @@ class QtDisplayManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int getDisplayRotation(Activity activity) {
|
static int getDisplayRotation(Activity activity) {
|
||||||
Display display = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ?
|
Display display = QtDisplayManager.getDisplay(activity);
|
||||||
activity.getWindowManager().getDefaultDisplay() :
|
|
||||||
activity.getDisplay();
|
|
||||||
|
|
||||||
return display != null ? display.getRotation() : 0;
|
return display != null ? display.getRotation() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,6 +217,20 @@ class QtDisplayManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
static Display getDisplay(Context context)
|
||||||
|
{
|
||||||
|
Activity activity = (Activity) context;
|
||||||
|
if (activity != null) {
|
||||||
|
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
|
||||||
|
? activity.getWindowManager().getDefaultDisplay()
|
||||||
|
: activity.getDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
final DisplayManager dm = context.getSystemService(DisplayManager.class);
|
||||||
|
return dm.getDisplay(Display.DEFAULT_DISPLAY);
|
||||||
|
}
|
||||||
|
|
||||||
@UsedFromNativeCode
|
@UsedFromNativeCode
|
||||||
static Display getDisplay(Context context, int displayId)
|
static Display getDisplay(Context context, int displayId)
|
||||||
{
|
{
|
||||||
@ -279,7 +279,7 @@ class QtDisplayManager {
|
|||||||
|
|
||||||
final WindowInsets rootInsets = activity.getWindow().getDecorView().getRootWindowInsets();
|
final WindowInsets rootInsets = activity.getWindow().getDecorView().getRootWindowInsets();
|
||||||
final WindowManager windowManager = activity.getWindowManager();
|
final WindowManager windowManager = activity.getWindowManager();
|
||||||
Display display;
|
Display display = QtDisplayManager.getDisplay(activity);
|
||||||
|
|
||||||
int insetLeft;
|
int insetLeft;
|
||||||
int insetTop;
|
int insetTop;
|
||||||
@ -288,8 +288,6 @@ class QtDisplayManager {
|
|||||||
int maxHeight;
|
int maxHeight;
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||||
display = windowManager.getDefaultDisplay();
|
|
||||||
|
|
||||||
final DisplayMetrics maxMetrics = new DisplayMetrics();
|
final DisplayMetrics maxMetrics = new DisplayMetrics();
|
||||||
display.getRealMetrics(maxMetrics);
|
display.getRealMetrics(maxMetrics);
|
||||||
maxWidth = maxMetrics.widthPixels;
|
maxWidth = maxMetrics.widthPixels;
|
||||||
@ -298,8 +296,6 @@ class QtDisplayManager {
|
|||||||
insetLeft = rootInsets.getStableInsetLeft();
|
insetLeft = rootInsets.getStableInsetLeft();
|
||||||
insetTop = rootInsets.getStableInsetTop();
|
insetTop = rootInsets.getStableInsetTop();
|
||||||
} else {
|
} else {
|
||||||
display = activity.getDisplay();
|
|
||||||
|
|
||||||
final WindowMetrics maxMetrics = windowManager.getMaximumWindowMetrics();
|
final WindowMetrics maxMetrics = windowManager.getMaximumWindowMetrics();
|
||||||
maxWidth = maxMetrics.getBounds().width();
|
maxWidth = maxMetrics.getBounds().width();
|
||||||
maxHeight = maxMetrics.getBounds().height();
|
maxHeight = maxMetrics.getBounds().height();
|
||||||
|
@ -275,7 +275,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
Rect r = new Rect();
|
Rect r = new Rect();
|
||||||
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
QtDisplayManager.getDisplay(activity).getMetrics(metrics);
|
||||||
int screenHeight = metrics.heightPixels;
|
int screenHeight = metrics.heightPixels;
|
||||||
final int kbHeight = screenHeight - r.bottom;
|
final int kbHeight = screenHeight - r.bottom;
|
||||||
isKeyboardHidden = kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO;
|
isKeyboardHidden = kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO;
|
||||||
@ -359,7 +359,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
private boolean updateSoftInputMode(Activity activity, int height)
|
private boolean updateSoftInputMode(Activity activity, int height)
|
||||||
{
|
{
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
QtDisplayManager.getDisplay(activity).getMetrics(metrics);
|
||||||
|
|
||||||
// If the screen is in portrait mode than we estimate that keyboard height
|
// If the screen is in portrait mode than we estimate that keyboard height
|
||||||
// will not be higher than 2/5 of the screen. Otherwise we estimate that keyboard height
|
// will not be higher than 2/5 of the screen. Otherwise we estimate that keyboard height
|
||||||
@ -401,7 +401,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
if (!m_keyboardIsVisible)
|
if (!m_keyboardIsVisible)
|
||||||
return;
|
return;
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
QtDisplayManager.getDisplay(activity).getMetrics(metrics);
|
||||||
Rect r = new Rect();
|
Rect r = new Rect();
|
||||||
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
|
||||||
if (metrics.heightPixels != r.bottom) {
|
if (metrics.heightPixels != r.bottom) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user