Android: set logicalDpi based on DisplayMetrics.scaledDensity
The mathematically correct way would be to set logicalDPi to 160*scaledDensity, but then a 12 pt font would be gigantic. On iOS, we use a factor of 72 to be compatible with the native APIs, but that means that a 12 pt font is very small. A factor of 100 means that desktop apps look reasonable by default. Task-number: QTBUG-29674 Change-Id: I607f110150fb95685a6980b92f6f92f2b489f959 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>bb10
parent
722798a359
commit
439a6fec84
|
|
@ -476,7 +476,7 @@ public class QtActivityDelegate
|
|||
m_activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
QtNative.setApplicationDisplayMetrics(metrics.widthPixels, metrics.heightPixels,
|
||||
metrics.widthPixels, metrics.heightPixels,
|
||||
metrics.xdpi, metrics.ydpi);
|
||||
metrics.xdpi, metrics.ydpi, metrics.scaledDensity);
|
||||
}
|
||||
m_layout = new QtLayout(m_activity);
|
||||
m_surface = new QtSurface(m_activity, 0);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public class QtNative
|
|||
private static int m_displayMetricsDesktopHeightPixels = 0;
|
||||
private static double m_displayMetricsXDpi = .0;
|
||||
private static double m_displayMetricsYDpi = .0;
|
||||
private static double m_displayMetricsScaledDensity = 1.0;
|
||||
private static int m_oldx, m_oldy;
|
||||
private static final int m_moveThreshold = 0;
|
||||
private static ClipboardManager m_clipboardManager = null;
|
||||
|
|
@ -195,7 +196,8 @@ public class QtNative
|
|||
m_displayMetricsDesktopWidthPixels,
|
||||
m_displayMetricsDesktopHeightPixels,
|
||||
m_displayMetricsXDpi,
|
||||
m_displayMetricsYDpi);
|
||||
m_displayMetricsYDpi,
|
||||
m_displayMetricsScaledDensity);
|
||||
if (params.length() > 0)
|
||||
params = "\t" + params;
|
||||
startQtApplication(f.getAbsolutePath() + "\t" + params, environment);
|
||||
|
|
@ -209,7 +211,8 @@ public class QtNative
|
|||
int desktopWidthPixels,
|
||||
int desktopHeightPixels,
|
||||
double XDpi,
|
||||
double YDpi)
|
||||
double YDpi,
|
||||
double scaledDensity)
|
||||
{
|
||||
/* Fix buggy dpi report */
|
||||
if (XDpi < android.util.DisplayMetrics.DENSITY_LOW)
|
||||
|
|
@ -224,7 +227,8 @@ public class QtNative
|
|||
desktopWidthPixels,
|
||||
desktopHeightPixels,
|
||||
XDpi,
|
||||
YDpi);
|
||||
YDpi,
|
||||
scaledDensity);
|
||||
} else {
|
||||
m_displayMetricsScreenWidthPixels = screenWidthPixels;
|
||||
m_displayMetricsScreenHeightPixels = screenHeightPixels;
|
||||
|
|
@ -232,6 +236,7 @@ public class QtNative
|
|||
m_displayMetricsDesktopHeightPixels = desktopHeightPixels;
|
||||
m_displayMetricsXDpi = XDpi;
|
||||
m_displayMetricsYDpi = YDpi;
|
||||
m_displayMetricsScaledDensity = scaledDensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -535,7 +540,8 @@ public class QtNative
|
|||
int desktopWidthPixels,
|
||||
int desktopHeightPixels,
|
||||
double XDpi,
|
||||
double YDpi);
|
||||
double YDpi,
|
||||
double scaledDensity);
|
||||
public static native void handleOrientationChanged(int newOrientation);
|
||||
// screen methods
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
|
|||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
QtNative.setApplicationDisplayMetrics(metrics.widthPixels,
|
||||
metrics.heightPixels, getWidth(), getHeight(), metrics.xdpi, metrics.ydpi);
|
||||
metrics.heightPixels, getWidth(), getHeight(), metrics.xdpi, metrics.ydpi, metrics.scaledDensity);
|
||||
|
||||
if (m_usesGL)
|
||||
holder.setFormat(PixelFormat.RGBA_8888);
|
||||
|
|
@ -136,7 +136,8 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback
|
|||
width,
|
||||
height,
|
||||
metrics.xdpi,
|
||||
metrics.ydpi);
|
||||
metrics.ydpi,
|
||||
metrics.scaledDensity);
|
||||
|
||||
if (!m_started)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ static QAndroidPlatformIntegration *m_androidPlatformIntegration = 0;
|
|||
|
||||
static int m_desktopWidthPixels = 0;
|
||||
static int m_desktopHeightPixels = 0;
|
||||
static double m_scaledDensity = 0;
|
||||
|
||||
static volatile bool m_pauseApplication;
|
||||
|
||||
|
|
@ -287,6 +288,11 @@ namespace QtAndroid
|
|||
return m_desktopHeightPixels;
|
||||
}
|
||||
|
||||
double scaledDensity()
|
||||
{
|
||||
return m_scaledDensity;
|
||||
}
|
||||
|
||||
JavaVM *javaVM()
|
||||
{
|
||||
return m_javaVM;
|
||||
|
|
@ -623,10 +629,11 @@ static void destroySurface(JNIEnv *env, jobject /*thiz*/)
|
|||
static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/,
|
||||
jint /*widthPixels*/, jint /*heightPixels*/,
|
||||
jint desktopWidthPixels, jint desktopHeightPixels,
|
||||
jdouble xdpi, jdouble ydpi)
|
||||
jdouble xdpi, jdouble ydpi, jdouble scaledDensity)
|
||||
{
|
||||
m_desktopWidthPixels = desktopWidthPixels;
|
||||
m_desktopHeightPixels = desktopHeightPixels;
|
||||
m_scaledDensity = scaledDensity;
|
||||
|
||||
if (!m_androidPlatformIntegration) {
|
||||
QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels,desktopHeightPixels,
|
||||
|
|
@ -687,7 +694,7 @@ static JNINativeMethod methods[] = {
|
|||
{"resumeQtApp", "()V", (void *)resumeQtApp},
|
||||
{"quitQtAndroidPlugin", "()V", (void *)quitQtAndroidPlugin},
|
||||
{"terminateQt", "()V", (void *)terminateQt},
|
||||
{"setDisplayMetrics", "(IIIIDD)V", (void *)setDisplayMetrics},
|
||||
{"setDisplayMetrics", "(IIIIDDD)V", (void *)setDisplayMetrics},
|
||||
{"setSurface", "(Ljava/lang/Object;)V", (void *)setSurface},
|
||||
{"destroySurface", "()V", (void *)destroySurface},
|
||||
{"lockSurface", "()V", (void *)lockSurface},
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ namespace QtAndroid
|
|||
QWindow *topLevelWindowAt(const QPoint &globalPos);
|
||||
int desktopWidthPixels();
|
||||
int desktopHeightPixels();
|
||||
double scaledDensity();
|
||||
JavaVM *javaVM();
|
||||
jclass findClass(const QString &className, JNIEnv *env);
|
||||
AAssetManager *assetManager();
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public:
|
|||
EGLNativeDisplayType platformDisplay() const;
|
||||
QSize screenSize() const;
|
||||
QSizeF physicalScreenSize() const;
|
||||
QDpi logicalDpi() const;
|
||||
int screenDepth() const;
|
||||
QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const;
|
||||
EGLNativeWindowType createNativeWindow(const QSize &size, const QSurfaceFormat &format);
|
||||
|
|
@ -86,6 +87,12 @@ QSizeF QEglFSAndroidHooks::physicalScreenSize() const
|
|||
return QSizeF(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth, QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight);
|
||||
}
|
||||
|
||||
QDpi QEglFSAndroidHooks::logicalDpi() const
|
||||
{
|
||||
qreal lDpi = QtAndroid::scaledDensity() * 100;
|
||||
return QDpi(lDpi, lDpi);
|
||||
}
|
||||
|
||||
|
||||
EGLNativeWindowType QEglFSAndroidHooks::createNativeWindow(const QSize &size, const QSurfaceFormat &format)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,3 +69,9 @@ QRegion QAndroidPlatformScreen::doRedraw()
|
|||
QtAndroid::flushImage(mGeometry.topLeft(), *mScreenImage, touched.boundingRect());
|
||||
return touched;
|
||||
}
|
||||
|
||||
QDpi QAndroidPlatformScreen::logicalDpi() const
|
||||
{
|
||||
qreal lDpi = QtAndroid::scaledDensity() * 100;
|
||||
return QDpi(lDpi, lDpi);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class QAndroidPlatformScreen: public QFbScreen
|
|||
public:
|
||||
QAndroidPlatformScreen();
|
||||
void topWindowChanged(QWindow *w);
|
||||
QDpi logicalDpi() const;
|
||||
|
||||
public slots:
|
||||
QRegion doRedraw();
|
||||
|
|
|
|||
Loading…
Reference in New Issue