首先,请原谅我糟糕的英语,我正在寻找一些关于如何在Android GITKIT中使用UIManager来为用户身份验证生成自定义UI的示例代码或教程,但我没有找到任何东西。请给我指引谢谢
发布于 2015-12-10 00:15:54
首先,这不是你的错,gitkit的文档也很少。至于实现本身,首先您需要将代码复制粘贴到此处(从the docs):
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的其余部分,按照here描述的接口,您应该在调用这些函数时更改屏幕,并将用户输入与相应的请求一起发送到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);
}https://stackoverflow.com/questions/32923423
复制相似问题