Added signin scope param

This commit is contained in:
FalsinSoft 2019-10-01 23:13:20 +02:00
parent 0e97c4bae5
commit 8be3bd206e
4 changed files with 310 additions and 133 deletions

View File

@ -35,7 +35,9 @@ QAndroidGoogleAccount::QAndroidGoogleAccount() : m_JavaGoogleAccount("com/falsin
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
const JNINativeMethod JniMethod[] = { const JNINativeMethod JniMethod[] = {
{"updateLastSignedInAccountInfo", "(Lcom/falsinsoft/qtandroidtools/AndroidGoogleAccount$AccountInfo;)V", reinterpret_cast<void *>(&QAndroidGoogleAccount::UpdateLastSignedInAccountInfo)} {"updateSignedInAccountInfo", "(Lcom/falsinsoft/qtandroidtools/AndroidGoogleAccount$AccountInfo;)V", reinterpret_cast<void*>(&QAndroidGoogleAccount::UpdateSignedInAccountInfo)},
{"signedIn", "(Z)V", reinterpret_cast<void*>(&QAndroidGoogleAccount::SignedIn)},
{"signedOut", "()V", reinterpret_cast<void*>(&QAndroidGoogleAccount::SignedOut)}
}; };
QAndroidJniEnvironment JniEnv; QAndroidJniEnvironment JniEnv;
jclass ObjectClass; jclass ObjectClass;
@ -51,7 +53,7 @@ QObject* QAndroidGoogleAccount::qmlInstance(QQmlEngine *engine, QJSEngine *scrip
Q_UNUSED(scriptEngine) Q_UNUSED(scriptEngine)
QAndroidGoogleAccount *pAndroidGoogleAccount = new QAndroidGoogleAccount(); QAndroidGoogleAccount *pAndroidGoogleAccount = new QAndroidGoogleAccount();
engine->addImageProvider("LastSignedInAccountPhoto", new AccountPhotoImageProvider(pAndroidGoogleAccount)); engine->addImageProvider("SignedInAccountPhoto", new AccountPhotoImageProvider(pAndroidGoogleAccount));
return pAndroidGoogleAccount; return pAndroidGoogleAccount;
} }
@ -60,123 +62,126 @@ QAndroidGoogleAccount* QAndroidGoogleAccount::instance()
return m_pInstance; return m_pInstance;
} }
bool QAndroidGoogleAccount::signIn() bool QAndroidGoogleAccount::signIn(int scope)
{ {
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
if(m_JavaGoogleAccount.callMethod<jboolean>("loadLastSignedInAccountInfo", "()Z") == false) return m_JavaGoogleAccount.callMethod<jboolean>("signIn", "(I)Z", scope);
{
return signInNewAccount();
} }
return true;
}
return false; return false;
} }
bool QAndroidGoogleAccount::signInNewAccount(int scope) bool QAndroidGoogleAccount::signInSelectAccount(int scope)
{ {
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
const std::function<void (int, int, const QAndroidJniObject &)> ActivityResultFunc = std::bind(&QAndroidGoogleAccount::ActivityResult, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); const QAndroidJniObject SignInIntent = m_JavaGoogleAccount.callObjectMethod("getSignInIntent", "(I)Landroid/content/Intent;", scope);
QtAndroid::startActivity(m_JavaGoogleAccount.callObjectMethod("getSignInIntent", "()Landroid/content/Intent;"), if(SignInIntent.isValid())
m_SignInId, {
ActivityResultFunc QtAndroid::startActivity(SignInIntent, m_SignInId, this);
);
return true; return true;
} }
}
return false; return false;
} }
void QAndroidGoogleAccount::signOut() bool QAndroidGoogleAccount::signOut()
{ {
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
m_JavaGoogleAccount.callMethod<void>("signOut", "()V"); return m_JavaGoogleAccount.callMethod<jboolean>("signOut", "()Z");
} }
return false;
} }
void QAndroidGoogleAccount::revokeAccess() bool QAndroidGoogleAccount::revokeAccess()
{ {
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
m_JavaGoogleAccount.callMethod<void>("revokeAccess", "()V"); return m_JavaGoogleAccount.callMethod<jboolean>("revokeAccess", "()Z");
} }
return false;
} }
void QAndroidGoogleAccount::SetLastSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj) void QAndroidGoogleAccount::SetSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj)
{ {
if(AccountInfoObj.isValid()) if(AccountInfoObj.isValid())
{ {
const QAndroidJniObject PhotoObj = AccountInfoObj.getObjectField("photo", "Landroid/graphics/Bitmap;"); const QAndroidJniObject PhotoObj = AccountInfoObj.getObjectField("photo", "Landroid/graphics/Bitmap;");
m_LastSignedInAccountInfo.Id = AccountInfoObj.getObjectField<jstring>("id").toString(); m_SignedInAccountInfo.Id = AccountInfoObj.getObjectField<jstring>("id").toString();
m_LastSignedInAccountInfo.DisplayName = AccountInfoObj.getObjectField<jstring>("displayName").toString(); m_SignedInAccountInfo.DisplayName = AccountInfoObj.getObjectField<jstring>("displayName").toString();
m_LastSignedInAccountInfo.Email = AccountInfoObj.getObjectField<jstring>("email").toString(); m_SignedInAccountInfo.Email = AccountInfoObj.getObjectField<jstring>("email").toString();
m_LastSignedInAccountInfo.FamilyName = AccountInfoObj.getObjectField<jstring>("familyName").toString(); m_SignedInAccountInfo.FamilyName = AccountInfoObj.getObjectField<jstring>("familyName").toString();
m_LastSignedInAccountInfo.GivenName = AccountInfoObj.getObjectField<jstring>("givenName").toString(); m_SignedInAccountInfo.GivenName = AccountInfoObj.getObjectField<jstring>("givenName").toString();
if(PhotoObj.isValid()) if(PhotoObj.isValid())
m_LastSignedInAccountPhoto = QPixmap::fromImage(AndroidBitmapToImage(PhotoObj)); m_SignedInAccountPhoto = QPixmap::fromImage(AndroidBitmapToImage(PhotoObj));
else else
m_LastSignedInAccountPhoto = QPixmap(); m_SignedInAccountPhoto = QPixmap();
} }
else else
{ {
m_LastSignedInAccountInfo = QAndroidGoogleAccountInfo(); m_SignedInAccountInfo = QAndroidGoogleAccountInfo();
m_LastSignedInAccountPhoto = QPixmap(); m_SignedInAccountPhoto = QPixmap();
} }
emit lastSignedInAccountInfoChanged(); emit signedInAccountInfoChanged();
} }
const QAndroidGoogleAccountInfo& QAndroidGoogleAccount::getLastSignedInAccountInfo() const const QAndroidGoogleAccountInfo& QAndroidGoogleAccount::getSignedInAccountInfo() const
{ {
return m_LastSignedInAccountInfo; return m_SignedInAccountInfo;
} }
QPixmap QAndroidGoogleAccount::GetAccountPhoto() const QPixmap QAndroidGoogleAccount::GetAccountPhoto() const
{ {
return m_LastSignedInAccountPhoto; return m_SignedInAccountPhoto;
} }
void QAndroidGoogleAccount::ActivityResult(int RequestCode, int ResultCode, const QAndroidJniObject &Data) void QAndroidGoogleAccount::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)
{ {
Q_UNUSED(ResultCode) Q_UNUSED(resultCode)
if(RequestCode == m_SignInId) if(receiverRequestCode == m_SignInId)
{ {
if(m_JavaGoogleAccount.isValid()) if(m_JavaGoogleAccount.isValid())
{ {
const bool SignInSuccessfully = m_JavaGoogleAccount.callMethod<jboolean>("signInIntentDataResult", m_JavaGoogleAccount.callMethod<void>("signInIntentDataResult", "(Landroid/content/Intent;)V", data.object<jobject>());
"(Landroid/content/Intent;)Z",
Data.object()
);
if(SignInSuccessfully == false)
{
emit signedIn(false);
}
} }
} }
} }
void QAndroidGoogleAccount::UpdateLastSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo) void QAndroidGoogleAccount::UpdateSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo)
{ {
Q_UNUSED(env) Q_UNUSED(env)
Q_UNUSED(thiz) Q_UNUSED(thiz)
if(m_pInstance != nullptr) if(m_pInstance != nullptr)
{ {
const QAndroidJniObject AccountInfoObj(accountInfo); m_pInstance->SetSignedInAccountInfo(QAndroidJniObject(accountInfo));
}
}
m_pInstance->SetLastSignedInAccountInfo(AccountInfoObj); void QAndroidGoogleAccount::SignedIn(JNIEnv *env, jobject thiz, jboolean signInSuccessfully)
{
Q_UNUSED(env)
Q_UNUSED(thiz)
if(AccountInfoObj.isValid()) if(m_pInstance != nullptr)
emit m_pInstance->signedIn(true); {
else emit m_pInstance->signedIn(signInSuccessfully);
}
}
void QAndroidGoogleAccount::SignedOut(JNIEnv *env, jobject thiz)
{
Q_UNUSED(env)
Q_UNUSED(thiz)
if(m_pInstance != nullptr)
{
emit m_pInstance->signedOut(); emit m_pInstance->signedOut();
} }
} }

View File

@ -46,9 +46,9 @@ public:
}; };
Q_DECLARE_METATYPE(QAndroidGoogleAccountInfo) Q_DECLARE_METATYPE(QAndroidGoogleAccountInfo)
class QAndroidGoogleAccount : public QObject class QAndroidGoogleAccount : public QObject, public QAndroidActivityResultReceiver
{ {
Q_PROPERTY(QAndroidGoogleAccountInfo lastSignedInAccount READ getLastSignedInAccountInfo NOTIFY lastSignedInAccountInfoChanged) Q_PROPERTY(QAndroidGoogleAccountInfo signedInAccount READ getSignedInAccountInfo NOTIFY signedInAccountInfoChanged)
Q_DISABLE_COPY(QAndroidGoogleAccount) Q_DISABLE_COPY(QAndroidGoogleAccount)
Q_ENUMS(SCOPES) Q_ENUMS(SCOPES)
Q_OBJECT Q_OBJECT
@ -60,15 +60,15 @@ class QAndroidGoogleAccount : public QObject
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{ {
const QPixmap LastSignedInAccountPhoto = m_pAccount->GetAccountPhoto(); const QPixmap AccountPhoto = m_pAccount->GetAccountPhoto();
Q_UNUSED(id) Q_UNUSED(id)
if(size) *size = LastSignedInAccountPhoto.size(); if(size) *size = AccountPhoto.size();
if(requestedSize.width() > 0 && requestedSize.height() > 0) if(requestedSize.width() > 0 && requestedSize.height() > 0)
return LastSignedInAccountPhoto.scaled(requestedSize); return AccountPhoto.scaled(requestedSize);
else else
return LastSignedInAccountPhoto; return AccountPhoto;
} }
private: private:
@ -103,15 +103,15 @@ public:
static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine); static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
static QAndroidGoogleAccount* instance(); static QAndroidGoogleAccount* instance();
Q_INVOKABLE bool signIn(); Q_INVOKABLE bool signIn(int scope = SCOPE_NULL);
Q_INVOKABLE bool signInNewAccount(int scope = SCOPE_NULL); Q_INVOKABLE bool signInSelectAccount(int scope = SCOPE_NULL);
Q_INVOKABLE void signOut(); Q_INVOKABLE bool signOut();
Q_INVOKABLE void revokeAccess(); Q_INVOKABLE bool revokeAccess();
const QAndroidGoogleAccountInfo& getLastSignedInAccountInfo() const; const QAndroidGoogleAccountInfo& getSignedInAccountInfo() const;
signals: signals:
void lastSignedInAccountInfoChanged(); void signedInAccountInfoChanged();
void signedIn(bool signInSuccessfully); void signedIn(bool signInSuccessfully);
void signedOut(); void signedOut();
@ -119,13 +119,16 @@ private:
const QAndroidJniObject m_JavaGoogleAccount; const QAndroidJniObject m_JavaGoogleAccount;
static QAndroidGoogleAccount *m_pInstance; static QAndroidGoogleAccount *m_pInstance;
const int m_SignInId = 9001; const int m_SignInId = 9001;
QAndroidGoogleAccountInfo m_LastSignedInAccountInfo; QAndroidGoogleAccountInfo m_SignedInAccountInfo;
QPixmap m_LastSignedInAccountPhoto; QPixmap m_SignedInAccountPhoto;
static void UpdateLastSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo); void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) override;
void ActivityResult(int RequestCode, int ResultCode, const QAndroidJniObject &Data); static void UpdateSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo);
void SetLastSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj); static void SignedIn(JNIEnv *env, jobject thiz, jboolean signInSuccessfully);
static void SignedOut(JNIEnv *env, jobject thiz);
void SetSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj);
QImage AndroidBitmapToImage(const QAndroidJniObject &JniBmp); QImage AndroidBitmapToImage(const QAndroidJniObject &JniBmp);
QPixmap GetAccountPhoto() const; QPixmap GetAccountPhoto() const;
}; };

View File

@ -54,41 +54,43 @@ import java.net.URL;
public class AndroidGoogleAccount public class AndroidGoogleAccount
{ {
private final Activity mActivityInstance; private final Activity mActivityInstance;
private GoogleSignInClient mGoogleSignInClient; private GoogleSignInClient mGoogleSignInClient = null;
public AndroidGoogleAccount(Activity ActivityInstance) public AndroidGoogleAccount(Activity ActivityInstance)
{ {
mActivityInstance = ActivityInstance; mActivityInstance = ActivityInstance;
getSignInClient(ActivityInstance);
} }
private void getSignInClient(Activity ActivityInstance) private GoogleSignInClient getSignInClient(String ScopeValue)
{ {
GoogleSignInOptions SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) GoogleSignInOptions.Builder SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
.requestEmail() if(ScopeValue != null) SignInOptions.requestScopes(new Scope(ScopeValue));
.build(); SignInOptions.requestEmail();
mGoogleSignInClient = GoogleSignIn.getClient(ActivityInstance, SignInOptions); return GoogleSignIn.getClient(mActivityInstance, SignInOptions.build());
} }
public boolean loadLastSignedInAccountInfo() public Intent getSignInIntent(int ScopeId)
{ {
return loadLastSignedInAccountInfo(GoogleSignIn.getLastSignedInAccount(mActivityInstance)); Intent SignInIntent = null;
}
public Intent getSignInIntent() if(mGoogleSignInClient == null)
{ {
return mGoogleSignInClient.getSignInIntent(); mGoogleSignInClient = getSignInClient(ScopeIdToValue(ScopeId));
SignInIntent = mGoogleSignInClient.getSignInIntent();
} }
public boolean signInIntentDataResult(Intent Data) return SignInIntent;
}
public void signInIntentDataResult(Intent Data)
{ {
final Task<GoogleSignInAccount> SignInTask = GoogleSignIn.getSignedInAccountFromIntent(Data); final Task<GoogleSignInAccount> SignInTask = GoogleSignIn.getSignedInAccountFromIntent(Data);
boolean signInSuccessfully = true;
try try
{ {
loadLastSignedInAccountInfo(SignInTask.getResult(ApiException.class)); loadSignedInAccountInfo(SignInTask.getResult(ApiException.class));
return true;
} }
catch(ApiException e) catch(ApiException e)
{ {
@ -96,43 +98,105 @@ public class AndroidGoogleAccount
{ {
Log.d("AndroidGoogleAccount", "DEVELOPER_ERROR -> Have you signed your project on Android console?"); Log.d("AndroidGoogleAccount", "DEVELOPER_ERROR -> Have you signed your project on Android console?");
} }
signInSuccessfully = false;
}
signedIn(signInSuccessfully);
}
public boolean signIn(int ScopeId)
{
if(mGoogleSignInClient == null)
{
Task<GoogleSignInAccount> SignInTask;
mGoogleSignInClient = getSignInClient(ScopeIdToValue(ScopeId));
SignInTask = mGoogleSignInClient.silentSignIn();
if(SignInTask.isSuccessful())
{
loadSignedInAccountInfo(SignInTask.getResult());
signedIn(true);
}
else
{
SignInTask.addOnCompleteListener(mActivityInstance, new SignInAccountListener());
}
return true;
} }
return false; return false;
} }
public void signOut() public boolean signOut()
{ {
mGoogleSignInClient.signOut().addOnCompleteListener(mActivityInstance, new SignOutAccountListener()); if(mGoogleSignInClient != null)
{
final Task<Void> SignOutTask = mGoogleSignInClient.signOut();
if(SignOutTask.isSuccessful())
{
updateSignedInAccountInfo(null);
mGoogleSignInClient = null;
signedOut();
}
else
{
SignOutTask.addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
} }
public void revokeAccess() return true;
{
mGoogleSignInClient.revokeAccess().addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
} }
private boolean loadLastSignedInAccountInfo(final GoogleSignInAccount LastSignedInAccount) return false;
{ }
if(LastSignedInAccount != null)
{
AccountInfo LastSignedInAccountInfo = new AccountInfo();
final Uri PhotoUrl = LastSignedInAccount.getPhotoUrl();
LastSignedInAccountInfo.id = LastSignedInAccount.getId(); public boolean revokeAccess()
LastSignedInAccountInfo.displayName = LastSignedInAccount.getDisplayName(); {
LastSignedInAccountInfo.email = LastSignedInAccount.getEmail(); if(mGoogleSignInClient != null)
LastSignedInAccountInfo.familyName = LastSignedInAccount.getFamilyName(); {
LastSignedInAccountInfo.givenName = LastSignedInAccount.getGivenName(); final Task<Void> SignOutTask = mGoogleSignInClient.revokeAccess();
if(SignOutTask.isSuccessful())
{
updateSignedInAccountInfo(null);
mGoogleSignInClient = null;
signedOut();
}
else
{
SignOutTask.addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
}
return true;
}
return false;
}
private boolean loadSignedInAccountInfo(final GoogleSignInAccount SignedInAccount)
{
if(SignedInAccount != null)
{
AccountInfo SignedInAccountInfo = new AccountInfo();
final Uri PhotoUrl = SignedInAccount.getPhotoUrl();
SignedInAccountInfo.id = SignedInAccount.getId();
SignedInAccountInfo.displayName = SignedInAccount.getDisplayName();
SignedInAccountInfo.email = SignedInAccount.getEmail();
SignedInAccountInfo.familyName = SignedInAccount.getFamilyName();
SignedInAccountInfo.givenName = SignedInAccount.getGivenName();
if(PhotoUrl != null) if(PhotoUrl != null)
{ {
DownloadAccountPhotoTask DownloadAccountPhoto = new DownloadAccountPhotoTask(LastSignedInAccountInfo); DownloadAccountPhotoTask DownloadAccountPhoto = new DownloadAccountPhotoTask(SignedInAccountInfo);
DownloadAccountPhoto.execute(PhotoUrl.toString()); DownloadAccountPhoto.execute(PhotoUrl.toString());
} }
else else
{ {
LastSignedInAccountInfo.photo = null; SignedInAccountInfo.photo = null;
updateLastSignedInAccountInfo(LastSignedInAccountInfo); updateSignedInAccountInfo(SignedInAccountInfo);
} }
return true; return true;
@ -143,11 +207,11 @@ public class AndroidGoogleAccount
private class DownloadAccountPhotoTask extends AsyncTask<String, Void, Bitmap> private class DownloadAccountPhotoTask extends AsyncTask<String, Void, Bitmap>
{ {
private AccountInfo mLastSignedInAccountInfo; private AccountInfo mSignedInAccountInfo;
DownloadAccountPhotoTask(AccountInfo LastSignedInAccountInfo) DownloadAccountPhotoTask(AccountInfo SignedInAccountInfo)
{ {
mLastSignedInAccountInfo = LastSignedInAccountInfo; mSignedInAccountInfo = SignedInAccountInfo;
} }
protected Bitmap doInBackground(String... urls) protected Bitmap doInBackground(String... urls)
@ -169,20 +233,106 @@ public class AndroidGoogleAccount
protected void onPostExecute(Bitmap AccountPhoto) protected void onPostExecute(Bitmap AccountPhoto)
{ {
mLastSignedInAccountInfo.photo = AccountPhoto; mSignedInAccountInfo.photo = AccountPhoto;
updateLastSignedInAccountInfo(mLastSignedInAccountInfo); updateSignedInAccountInfo(mSignedInAccountInfo);
}
}
private class SignInAccountListener implements OnCompleteListener<GoogleSignInAccount>
{
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> SignInTask)
{
boolean signInSuccessfully = true;
try
{
loadSignedInAccountInfo(SignInTask.getResult(ApiException.class));
}
catch(ApiException e)
{
if(e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_REQUIRED)
{
Log.d("AndroidGoogleAccount", "SIGN_IN_REQUIRED -> You have to signin by select account before use this call");
}
signInSuccessfully = false;
mGoogleSignInClient = null;
}
signedIn(signInSuccessfully);
} }
} }
private class SignOutAccountListener implements OnCompleteListener<Void> private class SignOutAccountListener implements OnCompleteListener<Void>
{ {
@Override @Override
public void onComplete(@NonNull Task<Void> task) public void onComplete(@NonNull Task<Void> SignOutTask)
{ {
updateLastSignedInAccountInfo(null); updateSignedInAccountInfo(null);
mGoogleSignInClient = null;
signedOut();
} }
} }
private String ScopeIdToValue(int ScopeId)
{
String ScopeValue = null;
switch(ScopeId)
{
case SCOPE_APP_STATE:
ScopeValue = Scopes.APP_STATE;
break;
case SCOPE_CLOUD_SAVE:
ScopeValue = Scopes.CLOUD_SAVE;
break;
case SCOPE_DRIVE_APPFOLDER:
ScopeValue = Scopes.CLOUD_SAVE;
break;
case SCOPE_DRIVE_FILE:
ScopeValue = Scopes.DRIVE_FILE;
break;
case SCOPE_EMAIL:
ScopeValue = Scopes.EMAIL;
break;
case SCOPE_FITNESS_ACTIVITY_READ:
ScopeValue = Scopes.FITNESS_ACTIVITY_READ;
break;
case SCOPE_FITNESS_ACTIVITY_READ_WRITE:
ScopeValue = Scopes.FITNESS_ACTIVITY_READ_WRITE;
break;
case SCOPE_FITNESS_BODY_READ:
ScopeValue = Scopes.FITNESS_BODY_READ;
break;
case SCOPE_FITNESS_BODY_READ_WRITE:
ScopeValue = Scopes.FITNESS_BODY_READ_WRITE;
break;
case SCOPE_FITNESS_LOCATION_READ:
ScopeValue = Scopes.FITNESS_LOCATION_READ;
break;
case SCOPE_FITNESS_LOCATION_READ_WRITE:
ScopeValue = Scopes.FITNESS_LOCATION_READ_WRITE;
break;
case SCOPE_FITNESS_NUTRITION_READ:
ScopeValue = Scopes.FITNESS_NUTRITION_READ;
break;
case SCOPE_FITNESS_NUTRITION_READ_WRITE:
ScopeValue = Scopes.FITNESS_NUTRITION_READ_WRITE;
break;
case SCOPE_GAMES:
ScopeValue = Scopes.GAMES;
break;
case SCOPE_PLUS_ME:
ScopeValue = Scopes.PLUS_ME;
break;
case SCOPE_PROFILE:
ScopeValue = Scopes.PROFILE;
break;
}
return ScopeValue;
}
public static class AccountInfo public static class AccountInfo
{ {
public String id; public String id;
@ -193,5 +343,24 @@ public class AndroidGoogleAccount
public Bitmap photo; public Bitmap photo;
} }
private static native void updateLastSignedInAccountInfo(AccountInfo accountInfo); private static final int SCOPE_APP_STATE = 1;
private static final int SCOPE_CLOUD_SAVE = 2;
private static final int SCOPE_DRIVE_APPFOLDER = 3;
private static final int SCOPE_DRIVE_FILE = 4;
private static final int SCOPE_EMAIL = 5;
private static final int SCOPE_FITNESS_ACTIVITY_READ = 6;
private static final int SCOPE_FITNESS_ACTIVITY_READ_WRITE = 7;
private static final int SCOPE_FITNESS_BODY_READ = 8;
private static final int SCOPE_FITNESS_BODY_READ_WRITE = 9;
private static final int SCOPE_FITNESS_LOCATION_READ = 10;
private static final int SCOPE_FITNESS_LOCATION_READ_WRITE = 11;
private static final int SCOPE_FITNESS_NUTRITION_READ = 12;
private static final int SCOPE_FITNESS_NUTRITION_READ_WRITE = 13;
private static final int SCOPE_GAMES = 14;
private static final int SCOPE_PLUS_ME = 15;
private static final int SCOPE_PROFILE = 16;
private static native void updateSignedInAccountInfo(AccountInfo accountInfo);
private static native void signedIn(boolean signInSuccessfully);
private static native void signedOut();
} }

View File

@ -10,10 +10,10 @@ Page {
Connections { Connections {
target: QtAndroidGoogleAccount target: QtAndroidGoogleAccount
onSignedInAccountChanged: accountPhoto.source = "image://SignedInAccountPhoto"
onSignedIn: { onSignedIn: {
if(signInSuccessfully === true) if(signInSuccessfully === true)
{ {
accountPhoto.source = "image://LastSignedInAccountPhoto";
} }
} }
onSignedOut: { onSignedOut: {
@ -29,27 +29,27 @@ Page {
Label { Label {
font.pixelSize: 15 font.pixelSize: 15
text: "<b>Id:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.id text: "<b>Id:</b> " + QtAndroidGoogleAccount.signedInAccount.id
} }
Label { Label {
font.pixelSize: 15 font.pixelSize: 15
text: "<b>DisplayName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.displayName text: "<b>DisplayName:</b> " + QtAndroidGoogleAccount.signedInAccount.displayName
} }
Label { Label {
font.pixelSize: 15 font.pixelSize: 15
text: "<b>Email:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.email text: "<b>Email:</b> " + QtAndroidGoogleAccount.signedInAccount.email
} }
Label { Label {
font.pixelSize: 15 font.pixelSize: 15
text: "<b>FamilyName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.familyName text: "<b>FamilyName:</b> " + QtAndroidGoogleAccount.signedInAccount.familyName
} }
Label { Label {
font.pixelSize: 15 font.pixelSize: 15
text: "<b>GivenName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.givenName text: "<b>GivenName:</b> " + QtAndroidGoogleAccount.signedInAccount.givenName
} }
Label { Label {
@ -64,13 +64,13 @@ Page {
Button { Button {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: "sigIn last account" text: "sigIn"
onClicked: QtAndroidGoogleAccount.signIn() onClicked: QtAndroidGoogleAccount.signIn()
} }
Button { Button {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: "sigIn new account" text: "sigIn select account"
onClicked: QtAndroidGoogleAccount.signInNewAccount() onClicked: QtAndroidGoogleAccount.signInSelectAccount()
} }
Button { Button {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter