繁体   English   中英

如何在Android GITKIT中使用UIManager

[英]How to use UIManager in Android GITKIT

首先请问我英文不好,我正在寻找一些示例代码或教程,以了解如何在Android GITKIT中使用UIManager生成用于用户身份验证的自定义UI,但是我什么也没找到。 请指导我

首先,这不是您的错,并且gitkit的文档记录很少。 至于实现本身,首先您需要将代码复制粘贴到此处(来自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的其余部分,应遵循此处描述的界面, 调用这些函数时更改屏幕,并将用户输入与适当的请求一起发送至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);
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM