mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
fix example 'wear-os'
This commit is contained in:
parent
2ca4a306a9
commit
5f8e81dfb6
4 changed files with 77 additions and 0 deletions
|
|
@ -6,6 +6,8 @@
|
|||
#include <QtAndroid>
|
||||
#include <QAndroidJniEnvironment>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static int getIntField(const char* name) {
|
||||
QAndroidJniObject activity = QtAndroid::androidActivity();
|
||||
return static_cast<int>(activity.getField<jint>(name));
|
||||
|
|
@ -44,3 +46,5 @@ QVariant QT::heartRate() {
|
|||
QVariant QT::heartRateAccuracy() {
|
||||
return getIntField("_heart_rate_accuracy_");
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
62
examples/wear-os/qt-sensor-hack/git.diff
Normal file
62
examples/wear-os/qt-sensor-hack/git.diff
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
diff --git a/QtActivity.java b/examples/wear-os/qt-sensor-hack/QtActivity.java
|
||||
index 9d8c46f..c068042 100644
|
||||
--- a/QtActivity.java
|
||||
+++ b/examples/wear-os/qt-sensor-hack/QtActivity.java
|
||||
@@ -62,8 +62,56 @@ import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import org.qtproject.qt5.android.QtNative;
|
||||
|
||||
-public class QtActivity extends Activity
|
||||
+// for hack
|
||||
+import android.hardware.Sensor;
|
||||
+import android.hardware.SensorEvent;
|
||||
+import android.hardware.SensorEventListener;
|
||||
+import android.hardware.SensorManager;
|
||||
+import android.util.Log;
|
||||
+
|
||||
+//public class QtActivity extends Activity
|
||||
+public class QtActivity extends Activity implements SensorEventListener
|
||||
{
|
||||
+ // hack
|
||||
+ public int _heart_rate_ = 0;
|
||||
+ public int _heart_rate_accuracy_ = 0;
|
||||
+ private static final String LQML = "[LQML]";
|
||||
+
|
||||
+ // hack
|
||||
+ public void iniSensors()
|
||||
+ {
|
||||
+ try {
|
||||
+ //Log.d(LQML, "ini heart rate sensor...");
|
||||
+ SensorManager mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
|
||||
+ Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
|
||||
+ mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
+ //Log.d(LQML, "ini heart rate sensor OK");
|
||||
+ }
|
||||
+ catch (Exception e) {
|
||||
+ //Log.e(LQML, Log.getStackTraceString(e));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // hack
|
||||
+ @Override
|
||||
+ public void onAccuracyChanged(Sensor sensor, int accuracy)
|
||||
+ {
|
||||
+ if (sensor.getType() == Sensor.TYPE_HEART_RATE) {
|
||||
+ _heart_rate_accuracy_ = accuracy;
|
||||
+ //Log.d(LQML, "BPM accuracy: " + _heart_rate_accuracy_);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // hack
|
||||
+ @Override
|
||||
+ public void onSensorChanged(SensorEvent event)
|
||||
+ {
|
||||
+ if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
|
||||
+ _heart_rate_ = Math.round(event.values[0]);
|
||||
+ //Log.d(LQML, "BPM: " + _heart_rate_);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
public String APPLICATION_PARAMETERS = null; // use this variable to pass any parameters to your application,
|
||||
// the parameters must not contain any white spaces
|
||||
// and must be separated with "\t"
|
||||
1
examples/wear-os/qt-sensor-hack/path.txt
Normal file
1
examples/wear-os/qt-sensor-hack/path.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
~/Qt/5.15.2/android/src/android/java/src/org/qtproject/qt5/android/bindings/
|
||||
10
examples/wear-os/qt-sensor-hack/readme.md
Normal file
10
examples/wear-os/qt-sensor-hack/readme.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
HowTo
|
||||
-----
|
||||
|
||||
Hack to add not yet officially supported sensors to Qt:
|
||||
|
||||
Just copy `QtActivity.java` to path in `path.txt` (for Qt 5.15);
|
||||
alternatively apply patch `git.diff`.
|
||||
|
||||
See also [cpp/qt.cpp](../cpp/qt.cpp).
|
||||
Loading…
Add table
Add a link
Reference in a new issue