Here, you can see my on click function.
I'm only going to process button clicks
while the Google API client isn't in
the midst of connecting.
So this is just going to
be a big switch statement.
Because the on click
will take in a view v.
And v's ID will be the ID of
the button that was pressed.
So, in this case, when the v.getId
gives me R.id.sign in button,
the sign in button has been pressed.
We just said we want to set
the status to signing in,
and then call this result
sign-in error function.
We'll write that function shortly,
and then just break out
of the switch statement.
And then when we're signing out, we can
clear the default accounts, just so
that the Google services don't
return an unconnected callback,
without any interaction.
And the result, so once you've
signed out, it's good to clear
any of the default information out, so
that you don't have any security issues.
So just going to call
Plus.AccountApi.clearDefaultAccount and
pass it the API client.
We then disconnect the API client and
reconnect it.
And then break out of
the switch statement.
Finally, for
revoking access on the plus account API,
we call the default account for
the same reason.
And then also in the Plus.AccountApi,
we call revokeAccessAndDisconnect and
pass it the GoogleApiClient.
Once we've done that, we'll start the
process of building a new client ,and
getting it ready to connect.
So again, we just say mGoogleApiClient,
and we call the same helper
function that we had earlier.
And then we reconnect that.
So that's all we have to
do in our three run-ins.
So signing in is setting the text and
resolving the errors.
Signing out is clearing the default
account, disconnecting and reconnecting.
And revoking access to
clearing the default account.
Revoking access and disconnecting.
And building a new API client and
connecting that.
تستطيع هنا مشاهدة دالة on click.
سوف أقوم فقط بمعالجة نقرات الزر
عندما لا يكون عميل Google API
في وسط عملية الاتصال.
سوف يكون ذلك
عبارة switch كبيرة.
ونظرًا لأن دالة on click
سوف تأخذ view v،
ويكون معرف v هو معرف
الزر الذي تم الضغط عليه،
ففي هذه الحالة، عندما تقدم v.getId
الزر R.id.sign in،
يكون قد تم الضغط على زر sign in.
كما ذكرنا فورًا فإننا نريد تعيين
الحالة إلى تسجيل الدخول،
ثم نقوم باستدعاء دالة
sign-in error الناتجة.
سوف نكتب الدالة بعد قليل،
ثم نقسم
عبارة switch.
وعندما نقوم بتسجيل الخروج، يمكن
مسح الحسابات الافتراضية، وبذلك
لا ترجع خدمات Google
إعادة استدعاء غير متصل،
بدون أي تفاعل.
والنتيجة هي بمجرد تسجيل
الخروج، يكون من المفيد مسح
أي من المعلومات الافتراضية، لكي لا
تواجه أي مشكلات أمنية.
إذًا فقط نقوم باستدعاء
Plus.AccountApi.clearDefaultAccount و
تمريرها إلى عميل API.
ثم نقوم بقطع اتصال عميل API وإعادة اتصاله.
ثم نقوم بتقسيم عبارة switch.
وأخيرًا، لإبطال الوصول إلى واجهة برمجة تطبيقات
plus account،
نقوم باستدعاء الحساب الافتراضي لنفس السبب.
وفي Plus.AccountApi،
نستدعي revokeAccessAndDisconnect و
نقوم بتمريرها
إلى GoogleApiClient.
بمجرد الانتهاء، سوف نبدأ
في عملية إنشاء عميل جديد و
تجهيزه للاتصال.
إذًا مرة أخرى نقول mGoogleApiClient،
ونستدعي نفس الدالة المساعدة
التي حصلنا عليها مسبقًا.
ثم نقوم بإعادة اتصال ذلك.
هذا هو كل ما نقوم به
مع جميع run-ins الثلاث هذه.
تسجيل الوصول يتضمن إعداد النص وحل الأخطاء.
وتسجيل الخروج يتضمن مسح الحساب
الافتراضي وقطع الاتصال ثم إعادة الاتصال.
ويتم إبطال الوصول لمسح الحساب الافتراضي.
يتم إبطال الوصول ثم قطع الاتصال.
وإنشاء عميل API جديد وتوصيله.
Aqui você pode ver
a minha função onClick.
Processarei os
cliques de botão apenas
enquanto o cliente Google API
não estiver conectando.
Portanto, isso será
uma grande instrução switch.
Porque o onClick
terá um View v.
E a ID de v será a ID do
botão que foi pressionado.
Então, nesse caso, quando v.getId
me dá R.id.sign_in_button,
o botão Entrar
foi pressionado.
Acabamos de dizer que queremos definir
o status como "Signing In"
e chamar de função
resolveSignInError.
Escreveremos essa função em breve
e depois interromperemos
a instrução switch.
E quando estamos desconectando,
podemos limpar as contas padrão,
para que o Google Services
não retorne um callback
desconectado sem nenhuma interação.
E o resultado,
depois de você desconectar,
pode limpar qualquer
informação padrão,
para que não haja
problemas de segurança.
Então, chamarei
Plus.AccountApi.clearDefaultAccount
e passá-lo o cliente API.
Então, desconectamos do cliente API
e o reconectamos.
E, então, interrompemos
a instrução switch.
Por fim, para revoke_access,
em Plus.AccountApi,
chamamos clearDefaultAccount
pelo mesmo motivo.
Também em Plus.AccountApi,
chamamos revokeAccessAndDisconnect
e o passamos o GoogleApiClient.
Após fazer isso,
começaremos o processo
de compilar um novo cliente
e prepará-lo para conectar.
Novamente,
informamos mGoogleApiClient
e chamamos a mesma função auxiliar
que tínhamos anteriormente.
E reconectamos.
Isso é tudo o que temos
que fazer nos nossos três botões.
Então, sign_in está definindo o texto
e resolvendo os erros,
sign_out está limpando
a conta padrão,
desconectando e reconectando
e revoke_access
está limpando a conta padrão,
revogando o acesso, desconectando
compilando um cliente API novo
e conectando-o.
您可以在这看到我的 on click 函数。
我仅在 Google API 客户端
不在正在连接时
处理按钮点击次数。
因此,这是一个
大的 switch 语句。
因为 on click 将
在视图 v 中运行。
v 的 ID 就是所按按钮的 ID。
因此,在本例中,
当 v.getId 指定 R.id.sign in 按钮时,
就会按下登录按钮。
我们刚才说要将状态
设置为正在登录,
然后调用这个结果
登录错误函数。
稍后我们会编写这个函数。
然后就会跳出
这个 switch 语句。
注销之后,
我们可以清除默认帐户,
这样 Google 服务不会
在没有任何交互的情况下
返回一个 onconnected 回调。
然后,在您注销后,
最好清除所有的默认信息,
以避免发生安全问题。
因此我要调用
Plus.AccountApi.clearDefaultAccount,
并将其传递到 API 客户端。
断开 API 客户端的连接,
然后重新连接。
这样就会跳出
这个 switch 语句。
最后,对于 plus account API 中
的撤销访问权,
我们将出于同一原因
调用默认帐户。
然后,继续在 Plus.AccountApi 中调用 revokeAccessAndDisconnect,
并将其传递到 GoogleApiClient。
完成之后,我们会开始
创建新的客户端,
并准备进行连接。
因此,我们会再次利用 mGoogleApiClient,
并调用之前调用过的
同一个辅助函数。
然后便完成了重新连接。
这就是我们在这三个
平行式中的全部操作。
因此,登录就是设置
文字和解决问题。
注销就是清除默认帐户、
断开连接和重新连接。
撤销访问权则是
清除默认帐户、
撤销访问权和断开连接、
以及创建新的 API 客户端
并进行连接。