mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-27 13:34:31 +00:00
Added signin scope param
This commit is contained in:
parent
0e97c4bae5
commit
8be3bd206e
@ -35,7 +35,9 @@ QAndroidGoogleAccount::QAndroidGoogleAccount() : m_JavaGoogleAccount("com/falsin
|
||||
if(m_JavaGoogleAccount.isValid())
|
||||
{
|
||||
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;
|
||||
jclass ObjectClass;
|
||||
@ -51,7 +53,7 @@ QObject* QAndroidGoogleAccount::qmlInstance(QQmlEngine *engine, QJSEngine *scrip
|
||||
Q_UNUSED(scriptEngine)
|
||||
|
||||
QAndroidGoogleAccount *pAndroidGoogleAccount = new QAndroidGoogleAccount();
|
||||
engine->addImageProvider("LastSignedInAccountPhoto", new AccountPhotoImageProvider(pAndroidGoogleAccount));
|
||||
engine->addImageProvider("SignedInAccountPhoto", new AccountPhotoImageProvider(pAndroidGoogleAccount));
|
||||
return pAndroidGoogleAccount;
|
||||
}
|
||||
|
||||
@ -60,124 +62,127 @@ QAndroidGoogleAccount* QAndroidGoogleAccount::instance()
|
||||
return m_pInstance;
|
||||
}
|
||||
|
||||
bool QAndroidGoogleAccount::signIn()
|
||||
bool QAndroidGoogleAccount::signIn(int scope)
|
||||
{
|
||||
if(m_JavaGoogleAccount.isValid())
|
||||
{
|
||||
if(m_JavaGoogleAccount.callMethod<jboolean>("loadLastSignedInAccountInfo", "()Z") == false)
|
||||
return m_JavaGoogleAccount.callMethod<jboolean>("signIn", "(I)Z", scope);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QAndroidGoogleAccount::signInSelectAccount(int scope)
|
||||
{
|
||||
if(m_JavaGoogleAccount.isValid())
|
||||
{
|
||||
const QAndroidJniObject SignInIntent = m_JavaGoogleAccount.callObjectMethod("getSignInIntent", "(I)Landroid/content/Intent;", scope);
|
||||
|
||||
if(SignInIntent.isValid())
|
||||
{
|
||||
return signInNewAccount();
|
||||
QtAndroid::startActivity(SignInIntent, m_SignInId, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QAndroidGoogleAccount::signInNewAccount(int scope)
|
||||
bool QAndroidGoogleAccount::signOut()
|
||||
{
|
||||
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);
|
||||
|
||||
QtAndroid::startActivity(m_JavaGoogleAccount.callObjectMethod("getSignInIntent", "()Landroid/content/Intent;"),
|
||||
m_SignInId,
|
||||
ActivityResultFunc
|
||||
);
|
||||
return true;
|
||||
return m_JavaGoogleAccount.callMethod<jboolean>("signOut", "()Z");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void QAndroidGoogleAccount::signOut()
|
||||
bool QAndroidGoogleAccount::revokeAccess()
|
||||
{
|
||||
if(m_JavaGoogleAccount.isValid())
|
||||
{
|
||||
m_JavaGoogleAccount.callMethod<void>("signOut", "()V");
|
||||
return m_JavaGoogleAccount.callMethod<jboolean>("revokeAccess", "()Z");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void QAndroidGoogleAccount::revokeAccess()
|
||||
{
|
||||
if(m_JavaGoogleAccount.isValid())
|
||||
{
|
||||
m_JavaGoogleAccount.callMethod<void>("revokeAccess", "()V");
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidGoogleAccount::SetLastSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj)
|
||||
void QAndroidGoogleAccount::SetSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj)
|
||||
{
|
||||
if(AccountInfoObj.isValid())
|
||||
{
|
||||
const QAndroidJniObject PhotoObj = AccountInfoObj.getObjectField("photo", "Landroid/graphics/Bitmap;");
|
||||
|
||||
m_LastSignedInAccountInfo.Id = AccountInfoObj.getObjectField<jstring>("id").toString();
|
||||
m_LastSignedInAccountInfo.DisplayName = AccountInfoObj.getObjectField<jstring>("displayName").toString();
|
||||
m_LastSignedInAccountInfo.Email = AccountInfoObj.getObjectField<jstring>("email").toString();
|
||||
m_LastSignedInAccountInfo.FamilyName = AccountInfoObj.getObjectField<jstring>("familyName").toString();
|
||||
m_LastSignedInAccountInfo.GivenName = AccountInfoObj.getObjectField<jstring>("givenName").toString();
|
||||
m_SignedInAccountInfo.Id = AccountInfoObj.getObjectField<jstring>("id").toString();
|
||||
m_SignedInAccountInfo.DisplayName = AccountInfoObj.getObjectField<jstring>("displayName").toString();
|
||||
m_SignedInAccountInfo.Email = AccountInfoObj.getObjectField<jstring>("email").toString();
|
||||
m_SignedInAccountInfo.FamilyName = AccountInfoObj.getObjectField<jstring>("familyName").toString();
|
||||
m_SignedInAccountInfo.GivenName = AccountInfoObj.getObjectField<jstring>("givenName").toString();
|
||||
|
||||
if(PhotoObj.isValid())
|
||||
m_LastSignedInAccountPhoto = QPixmap::fromImage(AndroidBitmapToImage(PhotoObj));
|
||||
m_SignedInAccountPhoto = QPixmap::fromImage(AndroidBitmapToImage(PhotoObj));
|
||||
else
|
||||
m_LastSignedInAccountPhoto = QPixmap();
|
||||
m_SignedInAccountPhoto = QPixmap();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LastSignedInAccountInfo = QAndroidGoogleAccountInfo();
|
||||
m_LastSignedInAccountPhoto = QPixmap();
|
||||
m_SignedInAccountInfo = QAndroidGoogleAccountInfo();
|
||||
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
|
||||
{
|
||||
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())
|
||||
{
|
||||
const bool SignInSuccessfully = m_JavaGoogleAccount.callMethod<jboolean>("signInIntentDataResult",
|
||||
"(Landroid/content/Intent;)Z",
|
||||
Data.object()
|
||||
);
|
||||
if(SignInSuccessfully == false)
|
||||
{
|
||||
emit signedIn(false);
|
||||
}
|
||||
m_JavaGoogleAccount.callMethod<void>("signInIntentDataResult", "(Landroid/content/Intent;)V", data.object<jobject>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidGoogleAccount::UpdateLastSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo)
|
||||
void QAndroidGoogleAccount::UpdateSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo)
|
||||
{
|
||||
Q_UNUSED(env)
|
||||
Q_UNUSED(thiz)
|
||||
|
||||
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())
|
||||
emit m_pInstance->signedIn(true);
|
||||
else
|
||||
emit m_pInstance->signedOut();
|
||||
if(m_pInstance != nullptr)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ public:
|
||||
};
|
||||
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_ENUMS(SCOPES)
|
||||
Q_OBJECT
|
||||
@ -60,15 +60,15 @@ class QAndroidGoogleAccount : public QObject
|
||||
|
||||
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)
|
||||
|
||||
if(size) *size = LastSignedInAccountPhoto.size();
|
||||
if(size) *size = AccountPhoto.size();
|
||||
|
||||
if(requestedSize.width() > 0 && requestedSize.height() > 0)
|
||||
return LastSignedInAccountPhoto.scaled(requestedSize);
|
||||
return AccountPhoto.scaled(requestedSize);
|
||||
else
|
||||
return LastSignedInAccountPhoto;
|
||||
return AccountPhoto;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -103,15 +103,15 @@ public:
|
||||
static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||
static QAndroidGoogleAccount* instance();
|
||||
|
||||
Q_INVOKABLE bool signIn();
|
||||
Q_INVOKABLE bool signInNewAccount(int scope = SCOPE_NULL);
|
||||
Q_INVOKABLE void signOut();
|
||||
Q_INVOKABLE void revokeAccess();
|
||||
Q_INVOKABLE bool signIn(int scope = SCOPE_NULL);
|
||||
Q_INVOKABLE bool signInSelectAccount(int scope = SCOPE_NULL);
|
||||
Q_INVOKABLE bool signOut();
|
||||
Q_INVOKABLE bool revokeAccess();
|
||||
|
||||
const QAndroidGoogleAccountInfo& getLastSignedInAccountInfo() const;
|
||||
const QAndroidGoogleAccountInfo& getSignedInAccountInfo() const;
|
||||
|
||||
signals:
|
||||
void lastSignedInAccountInfoChanged();
|
||||
void signedInAccountInfoChanged();
|
||||
void signedIn(bool signInSuccessfully);
|
||||
void signedOut();
|
||||
|
||||
@ -119,13 +119,16 @@ private:
|
||||
const QAndroidJniObject m_JavaGoogleAccount;
|
||||
static QAndroidGoogleAccount *m_pInstance;
|
||||
const int m_SignInId = 9001;
|
||||
QAndroidGoogleAccountInfo m_LastSignedInAccountInfo;
|
||||
QPixmap m_LastSignedInAccountPhoto;
|
||||
QAndroidGoogleAccountInfo m_SignedInAccountInfo;
|
||||
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);
|
||||
void SetLastSignedInAccountInfo(const QAndroidJniObject &AccountInfoObj);
|
||||
static void UpdateSignedInAccountInfo(JNIEnv *env, jobject thiz, jobject accountInfo);
|
||||
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);
|
||||
QPixmap GetAccountPhoto() const;
|
||||
};
|
||||
|
@ -54,41 +54,43 @@ import java.net.URL;
|
||||
public class AndroidGoogleAccount
|
||||
{
|
||||
private final Activity mActivityInstance;
|
||||
private GoogleSignInClient mGoogleSignInClient;
|
||||
private GoogleSignInClient mGoogleSignInClient = null;
|
||||
|
||||
public AndroidGoogleAccount(Activity ActivityInstance)
|
||||
{
|
||||
mActivityInstance = ActivityInstance;
|
||||
getSignInClient(ActivityInstance);
|
||||
}
|
||||
|
||||
private void getSignInClient(Activity ActivityInstance)
|
||||
private GoogleSignInClient getSignInClient(String ScopeValue)
|
||||
{
|
||||
GoogleSignInOptions SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.requestEmail()
|
||||
.build();
|
||||
GoogleSignInOptions.Builder SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
|
||||
if(ScopeValue != null) SignInOptions.requestScopes(new Scope(ScopeValue));
|
||||
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;
|
||||
|
||||
if(mGoogleSignInClient == null)
|
||||
{
|
||||
mGoogleSignInClient = getSignInClient(ScopeIdToValue(ScopeId));
|
||||
SignInIntent = mGoogleSignInClient.getSignInIntent();
|
||||
}
|
||||
|
||||
return SignInIntent;
|
||||
}
|
||||
|
||||
public Intent getSignInIntent()
|
||||
{
|
||||
return mGoogleSignInClient.getSignInIntent();
|
||||
}
|
||||
|
||||
public boolean signInIntentDataResult(Intent Data)
|
||||
public void signInIntentDataResult(Intent Data)
|
||||
{
|
||||
final Task<GoogleSignInAccount> SignInTask = GoogleSignIn.getSignedInAccountFromIntent(Data);
|
||||
boolean signInSuccessfully = true;
|
||||
|
||||
try
|
||||
{
|
||||
loadLastSignedInAccountInfo(SignInTask.getResult(ApiException.class));
|
||||
return true;
|
||||
loadSignedInAccountInfo(SignInTask.getResult(ApiException.class));
|
||||
}
|
||||
catch(ApiException e)
|
||||
{
|
||||
@ -96,43 +98,105 @@ public class AndroidGoogleAccount
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public void signOut()
|
||||
public boolean signOut()
|
||||
{
|
||||
mGoogleSignInClient.signOut().addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
|
||||
}
|
||||
|
||||
public void revokeAccess()
|
||||
{
|
||||
mGoogleSignInClient.revokeAccess().addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
|
||||
}
|
||||
|
||||
private boolean loadLastSignedInAccountInfo(final GoogleSignInAccount LastSignedInAccount)
|
||||
{
|
||||
if(LastSignedInAccount != null)
|
||||
if(mGoogleSignInClient != null)
|
||||
{
|
||||
AccountInfo LastSignedInAccountInfo = new AccountInfo();
|
||||
final Uri PhotoUrl = LastSignedInAccount.getPhotoUrl();
|
||||
final Task<Void> SignOutTask = mGoogleSignInClient.signOut();
|
||||
|
||||
LastSignedInAccountInfo.id = LastSignedInAccount.getId();
|
||||
LastSignedInAccountInfo.displayName = LastSignedInAccount.getDisplayName();
|
||||
LastSignedInAccountInfo.email = LastSignedInAccount.getEmail();
|
||||
LastSignedInAccountInfo.familyName = LastSignedInAccount.getFamilyName();
|
||||
LastSignedInAccountInfo.givenName = LastSignedInAccount.getGivenName();
|
||||
if(SignOutTask.isSuccessful())
|
||||
{
|
||||
updateSignedInAccountInfo(null);
|
||||
mGoogleSignInClient = null;
|
||||
signedOut();
|
||||
}
|
||||
else
|
||||
{
|
||||
SignOutTask.addOnCompleteListener(mActivityInstance, new SignOutAccountListener());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean revokeAccess()
|
||||
{
|
||||
if(mGoogleSignInClient != null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
DownloadAccountPhotoTask DownloadAccountPhoto = new DownloadAccountPhotoTask(LastSignedInAccountInfo);
|
||||
DownloadAccountPhotoTask DownloadAccountPhoto = new DownloadAccountPhotoTask(SignedInAccountInfo);
|
||||
DownloadAccountPhoto.execute(PhotoUrl.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
LastSignedInAccountInfo.photo = null;
|
||||
updateLastSignedInAccountInfo(LastSignedInAccountInfo);
|
||||
SignedInAccountInfo.photo = null;
|
||||
updateSignedInAccountInfo(SignedInAccountInfo);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -143,11 +207,11 @@ public class AndroidGoogleAccount
|
||||
|
||||
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)
|
||||
@ -169,20 +233,106 @@ public class AndroidGoogleAccount
|
||||
|
||||
protected void onPostExecute(Bitmap AccountPhoto)
|
||||
{
|
||||
mLastSignedInAccountInfo.photo = AccountPhoto;
|
||||
updateLastSignedInAccountInfo(mLastSignedInAccountInfo);
|
||||
mSignedInAccountInfo.photo = AccountPhoto;
|
||||
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>
|
||||
{
|
||||
@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 String id;
|
||||
@ -193,5 +343,24 @@ public class AndroidGoogleAccount
|
||||
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();
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ Page {
|
||||
|
||||
Connections {
|
||||
target: QtAndroidGoogleAccount
|
||||
onSignedInAccountChanged: accountPhoto.source = "image://SignedInAccountPhoto"
|
||||
onSignedIn: {
|
||||
if(signInSuccessfully === true)
|
||||
{
|
||||
accountPhoto.source = "image://LastSignedInAccountPhoto";
|
||||
{
|
||||
}
|
||||
}
|
||||
onSignedOut: {
|
||||
@ -29,27 +29,27 @@ Page {
|
||||
|
||||
Label {
|
||||
font.pixelSize: 15
|
||||
text: "<b>Id:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.id
|
||||
text: "<b>Id:</b> " + QtAndroidGoogleAccount.signedInAccount.id
|
||||
}
|
||||
|
||||
Label {
|
||||
font.pixelSize: 15
|
||||
text: "<b>DisplayName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.displayName
|
||||
text: "<b>DisplayName:</b> " + QtAndroidGoogleAccount.signedInAccount.displayName
|
||||
}
|
||||
|
||||
Label {
|
||||
font.pixelSize: 15
|
||||
text: "<b>Email:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.email
|
||||
text: "<b>Email:</b> " + QtAndroidGoogleAccount.signedInAccount.email
|
||||
}
|
||||
|
||||
Label {
|
||||
font.pixelSize: 15
|
||||
text: "<b>FamilyName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.familyName
|
||||
text: "<b>FamilyName:</b> " + QtAndroidGoogleAccount.signedInAccount.familyName
|
||||
}
|
||||
|
||||
Label {
|
||||
font.pixelSize: 15
|
||||
text: "<b>GivenName:</b> " + QtAndroidGoogleAccount.lastSignedInAccount.givenName
|
||||
text: "<b>GivenName:</b> " + QtAndroidGoogleAccount.signedInAccount.givenName
|
||||
}
|
||||
|
||||
Label {
|
||||
@ -64,13 +64,13 @@ Page {
|
||||
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "sigIn last account"
|
||||
text: "sigIn"
|
||||
onClicked: QtAndroidGoogleAccount.signIn()
|
||||
}
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "sigIn new account"
|
||||
onClicked: QtAndroidGoogleAccount.signInNewAccount()
|
||||
text: "sigIn select account"
|
||||
onClicked: QtAndroidGoogleAccount.signInSelectAccount()
|
||||
}
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
Loading…
x
Reference in New Issue
Block a user