-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseicheckerserviceconfigurator.cpp
37 lines (33 loc) · 1.79 KB
/
seicheckerserviceconfigurator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "seicheckerserviceconfigurator.h"
#include <QtAndroid>
SEICheckerServiceConfigurator::SEICheckerServiceConfigurator(QObject *parent) : QObject(parent)
{
QAndroidJniObject context = QtAndroid::androidContext();
QAndroidJniObject fileKey = QAndroidJniObject::fromString("br.edu.ifba.sei.PREFERENCE_FILE_KEY");
_sharedPreferences = context.callObjectMethod(
"getSharedPreferences",
"(Ljava/lang/String;I)Landroid/content/SharedPreferences;",
fileKey.object<jstring>(),
0 // Context.MODE_PRIVATE
);
}
void SEICheckerServiceConfigurator::setUsername(const QString &username)
{
QAndroidJniObject editor = _sharedPreferences.callObjectMethod("edit", "()Landroid/content/SharedPreferences$Editor;");
editor.callObjectMethod("putString",
"(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;",
QAndroidJniObject::fromString("sei-mobile-login").object<jstring>(),
QAndroidJniObject::fromString(username).object<jstring>()
);
editor.callMethod<jboolean>("commit");
}
void SEICheckerServiceConfigurator::setPassword(const QString &password)
{
QAndroidJniObject editor = _sharedPreferences.callObjectMethod("edit", "()Landroid/content/SharedPreferences$Editor;");
editor.callObjectMethod("putString",
"(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;",
QAndroidJniObject::fromString("sei-mobile-password").object<jstring>(),
QAndroidJniObject::fromString(password).object<jstring>()
);
editor.callMethod<jboolean>("commit");
}