If you think the Android project kakao-android-sdk-standalone listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
* Copyright 2014 Kakao Corp./*www.java2s.com*/
*
* 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;
import android.app.Activity;
import android.content.Intent;
import com.kakao.authorization.AuthorizationResult;
import com.kakao.authorization.Authorizer;
import com.kakao.helper.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* authorization code? ?? ??? ????? ???? ??
* ?????? ???? try?? ???? ???? ???? ????.
*
* @author MJ
*/publicclass GetterAuthorizationCode extends Authorizer {
privatestaticfinallong serialVersionUID = -5915324103491253588L;
privatefinal AuthorizationCodeRequest authorizationCodeRequest;
privatefinal List<AuthorizationCodeHandler> authenticationCodeHandlers = new ArrayList<AuthorizationCodeHandler>();
private AuthorizationCodeHandler currentHandler;
public GetterAuthorizationCode(final AuthorizationCodeRequest authCodeRequest) {
authorizationCodeRequest = authCodeRequest;
authenticationCodeHandlers.add(new LoggedInTalkAuthHandler(this)); // talk?? login???? ?? ????? ?? ??
authenticationCodeHandlers.add(new LoggedOutTalkAuthHandler(this)); // talk?? login???? ?? ????? ?? ??
authenticationCodeHandlers.add(new WebViewAuthHandler(this)); // talk??? install???? ?? ?? ??
}
publicvoid tryNextHandler() {
final Iterator<AuthorizationCodeHandler> iterator = authenticationCodeHandlers.iterator();
while (iterator.hasNext()) {
currentHandler = iterator.next();
iterator.remove();
if (tryCurrentHandler()) {
return;
}
}
// handler? ????? ??????????? authorization code? ?? ???? error
doneOnError("Failed to get Authorization Code.");
}
public AuthorizationCodeRequest getRequest() {
return authorizationCodeRequest;
}
privateboolean tryCurrentHandler() {
if (currentHandler.needsInternetPermission() && !checkInternetPermission()) {
return false;
} else {
return currentHandler.tryAuthorize(authorizationCodeRequest);
}
}
publicvoid cancelCurrentHandler() {
if (currentHandler != null) {
currentHandler.cancel();
}
}
publicboolean onActivityResult(finalint requestCode, finalint resultCode, final Intent data) {
if (requestCode == authorizationCodeRequest.getRequestCode()) {
return currentHandler.onActivityResult(requestCode, resultCode, data);
} else {
return false;
}
}
Activity getCallerActivity() {
return loginActivity;
}
protectedvoid completed(final AuthorizationResult result) {
clear();
if (onAuthorizationListener != null) {
onAuthorizationListener.onAuthorizationCompletion(result);
}
}
protectedvoid doneOnError(final String resultMessage) {
Logger.getInstance().d("GetterAuthorizationCode : " + resultMessage);
clear();
if (onAuthorizationListener != null) {
AuthorizationResult result
= AuthorizationResult.createAuthCodeErrorResult(resultMessage);
onAuthorizationListener.onAuthorizationCompletion(result);
}
}
void clear() {
currentHandler = null;
}
}