Add a check for location services being enabled in BtWiFi setup
This commit is contained in:
parent
e73eb3ed7a
commit
2b15ad34aa
@ -218,3 +218,5 @@ win32 {
|
|||||||
target.path = /usr/bin
|
target.path = /usr/bin
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
|
DISTFILES +=
|
||||||
|
|
||||||
|
|||||||
@ -239,6 +239,11 @@ void PlatformHelper::shareFile(const QString &fileName)
|
|||||||
QDesktopServices::openUrl(QUrl(fileName));
|
QDesktopServices::openUrl(QUrl(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlatformHelper::locationServicesEnabled() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QObject *PlatformHelper::platformHelperProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
QObject *PlatformHelper::platformHelperProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
{
|
{
|
||||||
Q_UNUSED(engine)
|
Q_UNUSED(engine)
|
||||||
|
|||||||
@ -57,6 +57,7 @@ class PlatformHelper : public QObject
|
|||||||
Q_PROPERTY(QColor bottomPanelColor READ bottomPanelColor WRITE setBottomPanelColor NOTIFY bottomPanelColorChanged)
|
Q_PROPERTY(QColor bottomPanelColor READ bottomPanelColor WRITE setBottomPanelColor NOTIFY bottomPanelColorChanged)
|
||||||
Q_PROPERTY(bool darkModeEnabled READ darkModeEnabled NOTIFY darkModeEnabledChanged)
|
Q_PROPERTY(bool darkModeEnabled READ darkModeEnabled NOTIFY darkModeEnabledChanged)
|
||||||
Q_PROPERTY(QVariantList pendingNotificationActions READ pendingNotificationActions NOTIFY pendingNotificationActionsChanged)
|
Q_PROPERTY(QVariantList pendingNotificationActions READ pendingNotificationActions NOTIFY pendingNotificationActionsChanged)
|
||||||
|
Q_PROPERTY(bool locationServicesEnabled READ locationServicesEnabled NOTIFY locationServicesEnabledChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum HapticsFeedback {
|
enum HapticsFeedback {
|
||||||
@ -108,6 +109,8 @@ public:
|
|||||||
|
|
||||||
void notificationActionReceived(const QString &nymeaData);
|
void notificationActionReceived(const QString &nymeaData);
|
||||||
|
|
||||||
|
virtual bool locationServicesEnabled() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void screenTimeoutChanged();
|
void screenTimeoutChanged();
|
||||||
void screenBrightnessChanged();
|
void screenBrightnessChanged();
|
||||||
@ -116,6 +119,7 @@ signals:
|
|||||||
void darkModeEnabledChanged();
|
void darkModeEnabledChanged();
|
||||||
void splashVisibleChanged();
|
void splashVisibleChanged();
|
||||||
void pendingNotificationActionsChanged();
|
void pendingNotificationActionsChanged();
|
||||||
|
void locationServicesEnabledChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PlatformHelper(QObject *parent = nullptr);
|
explicit PlatformHelper(QObject *parent = nullptr);
|
||||||
|
|||||||
@ -13,6 +13,9 @@ import android.os.Vibrator;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.v4.content.FileProvider;
|
import android.support.v4.content.FileProvider;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
|
public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActivity
|
||||||
{
|
{
|
||||||
@ -21,6 +24,17 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
|
|||||||
|
|
||||||
private static native void darkModeEnabledChangedJNI();
|
private static native void darkModeEnabledChangedJNI();
|
||||||
private static native void notificationActionReceivedJNI(String data);
|
private static native void notificationActionReceivedJNI(String data);
|
||||||
|
private static native void locationServicesEnabledChangedJNI();
|
||||||
|
|
||||||
|
private BroadcastReceiver m_gpsSwitchStateReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.i(TAG, "**** Intent received!!!" + intent.getAction());
|
||||||
|
if (LocationManager.MODE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
|
locationServicesEnabledChangedJNI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -37,6 +51,21 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
IntentFilter filter = new IntentFilter(LocationManager.MODE_CHANGED_ACTION);
|
||||||
|
// filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
|
||||||
|
registerReceiver(m_gpsSwitchStateReceiver, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
unregisterReceiver(m_gpsSwitchStateReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
@ -93,4 +122,9 @@ public class NymeaAppActivity extends org.qtproject.qt5.android.bindings.QtActiv
|
|||||||
public boolean darkModeEnabled() {
|
public boolean darkModeEnabled() {
|
||||||
return (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
return (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean locationServicesEnabled() {
|
||||||
|
LocationManager lm = (LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
return lm.isLocationEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
package io.guh.nymeaapp;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
|
||||||
|
|
||||||
|
public class NymeaAppBroadcastReceiver extends BroadcastReceiver
|
||||||
|
{
|
||||||
|
private static final String TAG = "nymea-app: BroadcastReceiver";
|
||||||
|
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
Log.d(TAG, "Broadcast received: " + action);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -34,6 +34,7 @@
|
|||||||
#include <QtAndroid>
|
#include <QtAndroid>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QAndroidIntent>
|
#include <QAndroidIntent>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
|
||||||
// WindowManager.LayoutParams
|
// WindowManager.LayoutParams
|
||||||
@ -49,6 +50,7 @@ static PlatformHelperAndroid *m_instance = nullptr;
|
|||||||
static JNINativeMethod methods[] = {
|
static JNINativeMethod methods[] = {
|
||||||
{ "darkModeEnabledChangedJNI", "()V", (void *)PlatformHelperAndroid::darkModeEnabledChangedJNI },
|
{ "darkModeEnabledChangedJNI", "()V", (void *)PlatformHelperAndroid::darkModeEnabledChangedJNI },
|
||||||
{ "notificationActionReceivedJNI", "(Ljava/lang/String;)V", (void *)PlatformHelperAndroid::notificationActionReceivedJNI },
|
{ "notificationActionReceivedJNI", "(Ljava/lang/String;)V", (void *)PlatformHelperAndroid::notificationActionReceivedJNI },
|
||||||
|
{ "locationServicesEnabledChangedJNI", "()V", (void *)PlatformHelperAndroid::locationServicesEnabledChangedJNI },
|
||||||
};
|
};
|
||||||
|
|
||||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
||||||
@ -82,6 +84,13 @@ PlatformHelperAndroid::PlatformHelperAndroid(QObject *parent) : PlatformHelper(p
|
|||||||
if (!notificationData.isNull()) {
|
if (!notificationData.isNull()) {
|
||||||
notificationActionReceived(notificationData);
|
notificationActionReceived(notificationData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(qApp, &QApplication::applicationStateChanged, this, [this](Qt::ApplicationState state){
|
||||||
|
qCritical() << "******* app state change";
|
||||||
|
if (state == Qt::ApplicationActive) {
|
||||||
|
emit locationServicesEnabledChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformHelperAndroid::hideSplashScreen()
|
void PlatformHelperAndroid::hideSplashScreen()
|
||||||
@ -247,6 +256,12 @@ bool PlatformHelperAndroid::darkModeEnabled() const
|
|||||||
return QtAndroid::androidActivity().callMethod<jboolean>("darkModeEnabled");
|
return QtAndroid::androidActivity().callMethod<jboolean>("darkModeEnabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlatformHelperAndroid::locationServicesEnabled() const
|
||||||
|
{
|
||||||
|
jboolean enabled = QtAndroid::androidActivity().callMethod<jboolean>("locationServicesEnabled", "()Z");
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void PlatformHelperAndroid::shareFile(const QString &fileName)
|
void PlatformHelperAndroid::shareFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QtAndroid::androidActivity().callMethod<void>("shareFile", "(Ljava/lang/String;)V",
|
QtAndroid::androidActivity().callMethod<void>("shareFile", "(Ljava/lang/String;)V",
|
||||||
@ -270,3 +285,11 @@ void PlatformHelperAndroid::notificationActionReceivedJNI(JNIEnv *env, jobject,
|
|||||||
platformHelper->notificationActionReceived(env->GetStringUTFChars(data, nullptr));
|
platformHelper->notificationActionReceived(env->GetStringUTFChars(data, nullptr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformHelperAndroid::locationServicesEnabledChangedJNI()
|
||||||
|
{
|
||||||
|
PlatformHelper* platformHelper = PlatformHelperAndroid::instance(false);
|
||||||
|
if (platformHelper) {
|
||||||
|
emit platformHelper->locationServicesEnabledChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -62,10 +62,13 @@ public:
|
|||||||
|
|
||||||
bool darkModeEnabled() const override;
|
bool darkModeEnabled() const override;
|
||||||
|
|
||||||
|
bool locationServicesEnabled() const override;
|
||||||
|
|
||||||
void shareFile(const QString &fileName) override;
|
void shareFile(const QString &fileName) override;
|
||||||
|
|
||||||
static void darkModeEnabledChangedJNI();
|
static void darkModeEnabledChangedJNI();
|
||||||
static void notificationActionReceivedJNI(JNIEnv *env, jobject /*thiz*/, jstring data);
|
static void notificationActionReceivedJNI(JNIEnv *env, jobject /*thiz*/, jstring data);
|
||||||
|
static void locationServicesEnabledChangedJNI();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void permissionRequestFinished(const QtAndroid::PermissionResultMap &);
|
static void permissionRequestFinished(const QtAndroid::PermissionResultMap &);
|
||||||
|
|||||||
@ -491,7 +491,7 @@ WizardPageBase {
|
|||||||
|
|
||||||
BluetoothDiscovery {
|
BluetoothDiscovery {
|
||||||
id: bluetoothDiscovery
|
id: bluetoothDiscovery
|
||||||
discoveryEnabled: pageStack.currentItem === wirelessBluetoothDiscoveryPage
|
discoveryEnabled: pageStack.currentItem === wirelessBluetoothDiscoveryPage && PlatformHelper.locationServicesEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
content: ListView {
|
content: ListView {
|
||||||
@ -510,7 +510,7 @@ WizardPageBase {
|
|||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0
|
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0 && bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled && PlatformHelper.locationServicesEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: NymeaSwipeDelegate {
|
delegate: NymeaSwipeDelegate {
|
||||||
@ -529,7 +529,7 @@ WizardPageBase {
|
|||||||
width: parent.width - Style.margins * 2
|
width: parent.width - Style.margins * 2
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
spacing: Style.bigMargins
|
spacing: Style.bigMargins
|
||||||
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled
|
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled || !PlatformHelper.locationServicesEnabled
|
||||||
|
|
||||||
ColorIcon {
|
ColorIcon {
|
||||||
name: "/ui/images/connections/bluetooth.svg"
|
name: "/ui/images/connections/bluetooth.svg"
|
||||||
@ -542,10 +542,19 @@ WizardPageBase {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
visible: !bluetoothDiscovery.bluetoothAvailable || !bluetoothDiscovery.bluetoothEnabled
|
||||||
text: !bluetoothDiscovery.bluetoothAvailable
|
text: !bluetoothDiscovery.bluetoothAvailable
|
||||||
? qsTr("Bluetooth doesn't seem to be available on this system.")
|
? qsTr("Bluetooth doesn't seem to be available on this system.")
|
||||||
: qsTr("Bluetooth is turned off. Please enable Bluetooth on this device.")
|
: qsTr("Bluetooth is turned off. Please enable Bluetooth on this device.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
visible: !PlatformHelper.locationServicesEnabled
|
||||||
|
text: qsTr("Location services are disabled. Please enable location services on this device in order to search for nearby nymea:energy gateways.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user