【问题标题】:How to use UIManager in Android GITKIT如何在 Android GITKIT 中使用 UIManager
【发布时间】:2015-10-03 13:58:19
【问题描述】:

首先请原谅我的英语不好 我正在寻找一些关于如何在 Android GITKIT 中使用 UIManager 为用户身份验证生成自定义 UI 的示例代码或教程,但我没有找到任何东西。 请指导我 谢谢

【问题讨论】:

    标签: android google-identity-toolkit


    【解决方案1】:

    首先这不是你的错,而且 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);
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多