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 }
MythDisplay::m_physicalSize
QSize m_physicalSize
Definition: mythdisplay.h:89
MythDisplay::Initialise
void Initialise(void)
Definition: mythdisplay.cpp:504
MythDisplayAndroid::MythDisplayAndroid
MythDisplayAndroid()
Definition: mythdisplayandroid.cpp:10
MythDisplayAndroid::~MythDisplayAndroid
~MythDisplayAndroid() override
Definition: mythdisplayandroid.cpp:16
MythDisplay::m_resolution
QSize m_resolution
Definition: mythdisplay.h:88
arg
arg(title).arg(filename).arg(doDelete))
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
LOC
#define LOC
Definition: mythdisplayandroid.cpp:8
MythDisplayAndroid::UpdateCurrentMode
void UpdateCurrentMode(void) override
Retrieve screen details.
Definition: mythdisplayandroid.cpp:20
MythDisplay::m_modeComplete
bool m_modeComplete
Definition: mythdisplay.h:85
mythlogging.h
MythDisplay
Definition: mythdisplay.h:19
MythDisplay::m_refreshRate
double m_refreshRate
Definition: mythdisplay.h:86
mythdisplayandroid.h