首先请原谅我的英语很差,我正在寻找一些示例代码或关于如何在 Android GITKIT 中使用 UIManager 为用户身份验证生成自定义 UI 的教程,但我没有找到任何东西。请指导我thanx
问问题
292 次
1 回答
0
首先,这不是你的错,而且 gitkit 的文档记录很差。至于实现本身,首先您需要在此处复制粘贴代码(来自文档):
public class MyLoginActivity extends Activity {
private GitkitClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If there is no signed in user, create a GitkitClient to start sign in flow.
SignInCallbacks callbacks = new SignInCallbacks() {
// Implement the onSignIn method of GitkitClient.SignInCallbacks interface.
@Override
public void onSignIn(IdToken idToken, GitkitUser gitkitUser) {
// Send the idToken to the server. The server should issue a session cookie/token
// for the app if the idToken is verified.
authenticate(idToken.getTokenString());
...
}
// Implement the onSignInFailed method of GitkitClient.SignInCallbacks interface.
@Override
public void onSignInFailed() {
// Handle the sign in failure.
...
}
}
// The example suppose all necessary configurations are set in the AndroidManifest.xml.
// You can also set or overwrite them by calling the corresponding setters on the
// GitkitClientBuilder.
client = GitkitClient.newBuilder(this, callbacks).setUiManager(new MyUiManger()).build();
// Start sign in flow.
client.startSignIn();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (client.handleActivityResult(requestCode, resultCode, data)) {
// result is handled by GitkitClient.
return;
}
// Otherwise, the result is not returned to GitkitClient and should be handled by the
// activity.
...
}
@Override
protected void onNewIntent(Intent intent) {
if (client.handleIntent(intent)) {
// intent is handled by the GitkitClient.
return;
}
// Otherwise, the intent is not for GitkitClient and should be handled by the activity.
...
}
}
然后你应该实现一个 MyUIManger 并注意方法:
@Override
public void setRequestHandler(RequestHandler requestHandler) {
//store requestHandler somewhere accessible.
}
因为这是您应该将所有 UI 输入发送到的对象。
关于 MyUIManager 的其余部分,按照此处描述的界面,您应该在调用这些函数时更改屏幕,并将用户输入与适当的请求一起发送到 requestHandler。
例如,当调用 client.startSignIn() 时,GitKitClient 将调用 MyUIManager.ShowStartSignIn 方法,因此在该方法中您应该显示相关屏幕并将输入发送到之前的 RequestHandler。内容如下:
//in MyUIManager:
@Override
public void showStartSignIn(GitkitUser.UserProfile userProfile) {
//Show start login fragment
}
//some where in the login fragment:
@Override
public void onClick(View view) {
StartSignInRequest request = new StartSignInRequest();
request.setEmail(email);
request.setIdProvider(idProvider);
mRequestHandler.handle(request);
}
于 2015-12-09T16:15:54.063 回答