2015-10-03 2 views
0

сначала извините меня за плохой английский Я ищу пример кода или учебник о том, как использовать UIManager в Android GITKIT для создания пользовательского интерфейса для аутентификации пользователя, но я не нашел что-нибудь. , пожалуйста, назовите меня thanxКак использовать UIManager в Android GITKIT

ответ

0

Прежде всего, это не ваша ошибка и 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. 
     } 

Поскольку это объект, которому вы должны отправить все свои входы пользовательского интерфейса.

Что касается остальной части 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); 
     } 
Смежные вопросы