// Path: sdk/src/com/kakao/LoginActivity.java
// public class LoginActivity extends Activity {
//     public static final int AUTHORIZATION_CODE_REQUEST = 1;
//     public static final int ACCESS_TOKEN_REQUEST = 2;
//     public static final String CODE_REQUEST_KEY = "authCodeRequest";
//     public static final String TOKEN_REQUEST_KEY = "tokenRequest";
// 
//     private GetterAuthorizationCode getterAuthorizationCode;
//     private GetterAccessToken getterAccessToken;
//     private final Authorizer.BackgroundProcessingListener backgroundProcessingListener = new BackgroundProcessListener();
//     private final Authorizer.OnAuthorizationListener authorizationListener = new AuthorizationCallback();
// 
//     /**
//      * authorize_code 또는 access_token 요청이 들어온다.
//      */
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.kakao_internal_login_activity);
// 
//         AuthorizationCodeRequest authCodeRequest;
//         AccessTokenRequest accessTokenRequest;
//         if (savedInstanceState != null) {
//             authCodeRequest = (AuthorizationCodeRequest) savedInstanceState.getSerializable(CODE_REQUEST_KEY);
//             accessTokenRequest = (AccessTokenRequest) savedInstanceState.getSerializable(TOKEN_REQUEST_KEY);
//         } else {
//             authCodeRequest = (AuthorizationCodeRequest) getIntent().getSerializableExtra(CODE_REQUEST_KEY);
//             accessTokenRequest = (AccessTokenRequest) getIntent().getSerializableExtra(TOKEN_REQUEST_KEY);
//         }
//         if (authCodeRequest != null) {
//             getterAuthorizationCode = new GetterAuthorizationCode(authCodeRequest);
//             initializeAuthorizer(getterAuthorizationCode);
//             getterAuthorizationCode.tryNextHandler();
//         } else if (accessTokenRequest != null) {
//             getterAccessToken = new GetterAccessToken(accessTokenRequest);
//             initializeAuthorizer(getterAccessToken);
//             getterAccessToken.requestAccessToken();
//         } else {
//             Logger.getInstance().d("Error : login activity created without request");
//         }
//     }
// 
//     /**
//      * {@link Authorizer.BackgroundProcessingListener}에게 프로세싱이 끝났다고 알려준다.
//      */
//     @Override
//     protected void onPause() {
//         super.onPause();
//         backgroundProcessingListener.onBackgroundProcessingStopped();
//     }
// 
//     /**
//      * authorize code 또는 access token 요청 중이라면 request를 저장해 둔다.
//      */
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         if(getterAuthorizationCode != null)
//             outState.putSerializable(CODE_REQUEST_KEY, getterAuthorizationCode.getRequest());
//         if(getterAccessToken != null)
//             outState.putSerializable(TOKEN_REQUEST_KEY, getterAccessToken.getRequest());
//     }
// 
//     private void initializeAuthorizer(final Authorizer authorizer) {
//         authorizer.setLoginActivity(this);
//         authorizer.setOnAuthorizationListener(authorizationListener);
//         authorizer.setBackgroundProcessingListener(backgroundProcessingListener);
//     }
// 
//     private class BackgroundProcessListener implements Authorizer.BackgroundProcessingListener {
//         @Override
//         public void onBackgroundProcessingStarted() {
//             findViewById(R.id.kakao_login_activity_progress_bar).setVisibility(View.VISIBLE);
//         }
// 
//         @Override
//         public void onBackgroundProcessingStopped() {
//             findViewById(R.id.kakao_login_activity_progress_bar).setVisibility(View.GONE);
//         }
//     }
// 
//     @Override
//     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//         if (requestCode == AUTHORIZATION_CODE_REQUEST) {
//             getterAuthorizationCode.onActivityResult(requestCode, resultCode, data);
//         }
//     }
// 
//     private class AuthorizationCallback implements Authorizer.OnAuthorizationListener {
//         @Override
//         public void onAuthorizationCompletion(final AuthorizationResult result) {
//             backgroundProcessingListener.onBackgroundProcessingStopped();
// 
//             if (result.isAuthorizationCodeRequest()) {
//                 getterAuthorizationCode = null;
//                 Session.getCurrentSession().onAuthCodeCompleted(result);
//             } else if (result.isAccessTokenRequest()) {
//                 getterAccessToken = null;
//                 Session.getCurrentSession().onAccessTokenCompleted(result);
//             }
//             runOnUiThread(new Runnable() {
//                 @Override
//                 public void run() {
//                     finish();
//                 }
//             });
//         }
//     }
// }


import com.kakao.LoginActivity;
import java.io.Serializable;
/**
 * Copyright 2014 Minyoung Jeong <kkungkkung@gmail.com>
 * Copyright 2014 Kakao Corp.
 *
 * Redistribution and modification in source or binary forms are not permitted without specific prior written permission. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kakao.authorization.authcode;



/**
 * authorization code와 access token을 얻는 base request
 *
 * @author MJ
 */
public class AuthorizationCodeRequest implements Serializable {
    private static final long serialVersionUID = 7078182213563726736L;
    private String appKey;
    private String redirectURI;

    public AuthorizationCodeRequest() {
    }

    public static AuthorizationCodeRequest createNewRequest(final String appKey, final String redirectURI) {
        return new AuthorizationCodeRequest(appKey, redirectURI);
    }

    private AuthorizationCodeRequest(final String appKey, final String redirectURI) {
        this.appKey = appKey;
        this.redirectURI = redirectURI;
    }

    public int getRequestCode() {
// Path: sdk/src/com/kakao/LoginActivity.java
// public class LoginActivity extends Activity {
//     public static final int AUTHORIZATION_CODE_REQUEST = 1;
//     public static final int ACCESS_TOKEN_REQUEST = 2;
//     public static final String CODE_REQUEST_KEY = "authCodeRequest";
//     public static final String TOKEN_REQUEST_KEY = "tokenRequest";
// 
//     private GetterAuthorizationCode getterAuthorizationCode;
//     private GetterAccessToken getterAccessToken;
//     private final Authorizer.BackgroundProcessingListener backgroundProcessingListener = new BackgroundProcessListener();
//     private final Authorizer.OnAuthorizationListener authorizationListener = new AuthorizationCallback();
// 
//     /**
//      * authorize_code 또는 access_token 요청이 들어온다.
//      */
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.kakao_internal_login_activity);
// 
//         AuthorizationCodeRequest authCodeRequest;
//         AccessTokenRequest accessTokenRequest;
//         if (savedInstanceState != null) {
//             authCodeRequest = (AuthorizationCodeRequest) savedInstanceState.getSerializable(CODE_REQUEST_KEY);
//             accessTokenRequest = (AccessTokenRequest) savedInstanceState.getSerializable(TOKEN_REQUEST_KEY);
//         } else {
//             authCodeRequest = (AuthorizationCodeRequest) getIntent().getSerializableExtra(CODE_REQUEST_KEY);
//             accessTokenRequest = (AccessTokenRequest) getIntent().getSerializableExtra(TOKEN_REQUEST_KEY);
//         }
//         if (authCodeRequest != null) {
//             getterAuthorizationCode = new GetterAuthorizationCode(authCodeRequest);
//             initializeAuthorizer(getterAuthorizationCode);
//             getterAuthorizationCode.tryNextHandler();
//         } else if (accessTokenRequest != null) {
//             getterAccessToken = new GetterAccessToken(accessTokenRequest);
//             initializeAuthorizer(getterAccessToken);
//             getterAccessToken.requestAccessToken();
//         } else {
//             Logger.getInstance().d("Error : login activity created without request");
//         }
//     }
// 
//     /**
//      * {@link Authorizer.BackgroundProcessingListener}에게 프로세싱이 끝났다고 알려준다.
//      */
//     @Override
//     protected void onPause() {
//         super.onPause();
//         backgroundProcessingListener.onBackgroundProcessingStopped();
//     }
// 
//     /**
//      * authorize code 또는 access token 요청 중이라면 request를 저장해 둔다.
//      */
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         if(getterAuthorizationCode != null)
//             outState.putSerializable(CODE_REQUEST_KEY, getterAuthorizationCode.getRequest());
//         if(getterAccessToken != null)
//             outState.putSerializable(TOKEN_REQUEST_KEY, getterAccessToken.getRequest());
//     }
// 
//     private void initializeAuthorizer(final Authorizer authorizer) {
//         authorizer.setLoginActivity(this);
//         authorizer.setOnAuthorizationListener(authorizationListener);
//         authorizer.setBackgroundProcessingListener(backgroundProcessingListener);
//     }
// 
//     private class BackgroundProcessListener implements Authorizer.BackgroundProcessingListener {
//         @Override
//         public void onBackgroundProcessingStarted() {
//             findViewById(R.id.kakao_login_activity_progress_bar).setVisibility(View.VISIBLE);
//         }
// 
//         @Override
//         public void onBackgroundProcessingStopped() {
//             findViewById(R.id.kakao_login_activity_progress_bar).setVisibility(View.GONE);
//         }
//     }
// 
//     @Override
//     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//         if (requestCode == AUTHORIZATION_CODE_REQUEST) {
//             getterAuthorizationCode.onActivityResult(requestCode, resultCode, data);
//         }
//     }
// 
//     private class AuthorizationCallback implements Authorizer.OnAuthorizationListener {
//         @Override
//         public void onAuthorizationCompletion(final AuthorizationResult result) {
//             backgroundProcessingListener.onBackgroundProcessingStopped();
// 
//             if (result.isAuthorizationCodeRequest()) {
//                 getterAuthorizationCode = null;
//                 Session.getCurrentSession().onAuthCodeCompleted(result);
//             } else if (result.isAccessTokenRequest()) {
//                 getterAccessToken = null;
//                 Session.getCurrentSession().onAccessTokenCompleted(result);
//             }
//             runOnUiThread(new Runnable() {
//                 @Override
//                 public void run() {
//                     finish();
//                 }
//             });
//         }
//     }
// }


// Path: sdk/src/com/kakao/authorization/authcode/AuthorizationCodeRequest.java
import com.kakao.LoginActivity;
import java.io.Serializable;

/**
 * Copyright 2014 Minyoung Jeong <kkungkkung@gmail.com>
 * Copyright 2014 Kakao Corp.
 *
 * Redistribution and modification in source or binary forms are not permitted without specific prior written permission. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kakao.authorization.authcode;



/**
 * authorization code와 access token을 얻는 base request
 *
 * @author MJ
 */
public class AuthorizationCodeRequest implements Serializable {
    private static final long serialVersionUID = 7078182213563726736L;
    private String appKey;
    private String redirectURI;

    public AuthorizationCodeRequest() {
    }

    public static AuthorizationCodeRequest createNewRequest(final String appKey, final String redirectURI) {
        return new AuthorizationCodeRequest(appKey, redirectURI);
    }

    private AuthorizationCodeRequest(final String appKey, final String redirectURI) {
        this.appKey = appKey;
        this.redirectURI = redirectURI;
    }

    public int getRequestCode() {
        return LoginActivity.AUTHORIZATION_CODE_REQUEST;