MythTV  master
mythdisplayandroid.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QtAndroidExtras>
3 
4 // MythTV
5 #include "mythlogging.h"
6 #include "mythdisplayandroid.h"
7 
8 #define LOC QString("Display: ")
9 
11  : MythDisplay()
12 {
13  Initialise();
14 }
15 
17 {
18 }
19 
21 {
22  QAndroidJniEnvironment env;
23  QAndroidJniObject activity = QtAndroid::androidActivity();
24  QAndroidJniObject windowManager = activity.callObjectMethod("getWindowManager", "()Landroid/view/WindowManager;");
25  QAndroidJniObject display = windowManager.callObjectMethod("getDefaultDisplay", "()Landroid/view/Display;");
26  QAndroidJniObject displayMetrics("android/util/DisplayMetrics");
27  display.callMethod<void>("getRealMetrics", "(Landroid/util/DisplayMetrics;)V", displayMetrics.object());
28  // check if passed or try a different method
29  if (env->ExceptionCheck())
30  {
31  env->ExceptionClear();
32  display.callMethod<void>("getMetrics", "(Landroid/util/DisplayMetrics;)V", displayMetrics.object());
33  }
34  float xdpi = displayMetrics.getField<jfloat>("xdpi");
35  float ydpi = displayMetrics.getField<jfloat>("ydpi");
36  int height = displayMetrics.getField<jint>("heightPixels");
37  int width = displayMetrics.getField<jint>("widthPixels");
38  float rate = display.callMethod<jfloat>("getRefreshRate");
39  LOG(VB_GENERAL, LOG_INFO, LOC +
40  QString("rate:%1 h:%2 w:%3 xdpi:%4 ydpi:%5")
41  .arg(rate).arg(height).arg(width)
42  .arg(xdpi).arg(ydpi)
43  );
44 
45  m_refreshRate = static_cast<double>(rate);
46  m_resolution = QSize(width, height);
47  m_physicalSize = QSize(width, height);
48  m_modeComplete = true;
49  if (xdpi > 0 && ydpi > 0)
50  {
51  m_physicalSize = QSize(static_cast<int>(width / xdpi * 25.4F),
52  static_cast<int>(height / ydpi * 25.4F));
53  }
54 }
#define LOC
QSize m_resolution
Definition: mythdisplay.h:86
void Initialise(void)
bool m_modeComplete
Definition: mythdisplay.h:83
void UpdateCurrentMode(void) override
Retrieve screen details.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QSize m_physicalSize
Definition: mythdisplay.h:87
double m_refreshRate
Definition: mythdisplay.h:84