CameraActivity with Google ML KIT for decoding QR codes
This commit is contained in:
parent
34a268624b
commit
a86e8659f7
9 changed files with 275 additions and 27 deletions
|
|
@ -22,12 +22,10 @@ AndroidVPNActivity::AndroidVPNActivity() {
|
|||
AndroidUtils::runOnAndroidThreadAsync([]() {
|
||||
JNINativeMethod methods[]{
|
||||
{"handleBackButton", "()Z", reinterpret_cast<bool*>(handleBackButton)},
|
||||
{"onServiceMessage", "(ILjava/lang/String;)V",
|
||||
reinterpret_cast<void*>(onServiceMessage)},
|
||||
{"qtOnServiceConnected", "()V",
|
||||
reinterpret_cast<void*>(onServiceConnected)},
|
||||
{"qtOnServiceDisconnected", "()V",
|
||||
reinterpret_cast<void*>(onServiceDisconnected)},
|
||||
{"onServiceMessage", "(ILjava/lang/String;)V", reinterpret_cast<void*>(onServiceMessage)},
|
||||
{"qtOnServiceConnected", "()V", reinterpret_cast<void*>(onServiceConnected)},
|
||||
{"qtOnServiceDisconnected", "()V", reinterpret_cast<void*>(onServiceDisconnected)},
|
||||
{"onActivityMessage", "(ILjava/lang/String;)V", reinterpret_cast<void*>(onAndroidVpnActivityMessage)}
|
||||
};
|
||||
|
||||
QJniObject javaClass(CLASSNAME);
|
||||
|
|
@ -54,6 +52,11 @@ void AndroidVPNActivity::connectService() {
|
|||
QJniObject::callStaticMethod<void>(CLASSNAME, "connectService", "()V");
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::startQrCodeReader()
|
||||
{
|
||||
QJniObject::callStaticMethod<void>(CLASSNAME, "startQrCodeReader", "()V");
|
||||
}
|
||||
|
||||
// static
|
||||
AndroidVPNActivity* AndroidVPNActivity::instance() {
|
||||
if (s_instance == nullptr) {
|
||||
|
|
@ -121,6 +124,19 @@ void AndroidVPNActivity::handleServiceMessage(int code, const QString& data) {
|
|||
}
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::handleActivityMessage(int code, const QString &data)
|
||||
{
|
||||
auto mode = (UIEvents)code;
|
||||
|
||||
switch (mode) {
|
||||
case UIEvents::QR_CODED_DECODED:
|
||||
emit eventQrCodeReceived(data);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::onServiceConnected(JNIEnv* env, jobject thiz) {
|
||||
Q_UNUSED(env);
|
||||
Q_UNUSED(thiz);
|
||||
|
|
@ -134,3 +150,19 @@ void AndroidVPNActivity::onServiceDisconnected(JNIEnv* env, jobject thiz) {
|
|||
|
||||
emit AndroidVPNActivity::instance()->serviceDisconnected();
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::onAndroidVpnActivityMessage(JNIEnv *env, jobject thiz, jint messageType, jstring message)
|
||||
{
|
||||
Q_UNUSED(thiz);
|
||||
const char* buffer = env->GetStringUTFChars(message, nullptr);
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString parcelBody(buffer);
|
||||
env->ReleaseStringUTFChars(message, buffer);
|
||||
|
||||
AndroidUtils::dispatchToMainThread([messageType, parcelBody] {
|
||||
AndroidVPNActivity::instance()->handleActivityMessage(messageType, parcelBody);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ enum ServiceEvents {
|
|||
};
|
||||
typedef enum ServiceEvents ServiceEvents;
|
||||
|
||||
enum UIEvents {
|
||||
QR_CODED_DECODED = 0,
|
||||
};
|
||||
typedef enum UIEvents UIEvents;
|
||||
|
||||
class AndroidVPNActivity : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -69,6 +74,7 @@ public:
|
|||
static bool handleBackButton(JNIEnv* env, jobject thiz);
|
||||
static void sendToService(ServiceAction type, const QString& data);
|
||||
static void connectService();
|
||||
static void startQrCodeReader();
|
||||
|
||||
signals:
|
||||
void serviceConnected();
|
||||
|
|
@ -80,6 +86,7 @@ signals:
|
|||
void eventBackendLogs(const QString& data);
|
||||
void eventActivationError(const QString& data);
|
||||
void eventConfigImport(const QString& data);
|
||||
void eventQrCodeReceived(const QString& data);
|
||||
|
||||
private:
|
||||
AndroidVPNActivity();
|
||||
|
|
@ -87,7 +94,9 @@ private:
|
|||
static void onServiceMessage(JNIEnv* env, jobject thiz, jint messageType, jstring body);
|
||||
static void onServiceConnected(JNIEnv* env, jobject thiz);
|
||||
static void onServiceDisconnected(JNIEnv* env, jobject thiz);
|
||||
static void onAndroidVpnActivityMessage(JNIEnv* env, jobject thiz, jint messageType, jstring message);
|
||||
void handleServiceMessage(int code, const QString& data);
|
||||
void handleActivityMessage(int code, const QString& data);
|
||||
};
|
||||
|
||||
#endif // ANDROIDVPNACTIVITY_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue