Android Open Source - kakao-android-sdk-standalone User Profile






From Project

Back to project page kakao-android-sdk-standalone.

License

The source code is released under:

Apache License

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 Minyoung Jeong <kkungkkung@gmail.com>
 * Copyright 2014 Kakao Corp.//from   w  w  w.  j ava2  s. c  o  m
 *
 * 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;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import com.kakao.helper.ServerProtocol;
import com.kakao.helper.SharedPreferencesCache;

import java.util.HashMap;
import java.util.Map;

// {@link com.kakao.helper.ServerProtocol.USER_ID_KEY}
// {@link com.kakao.helper.ServerProtocol.PROPERTIES_KEY}
/**
 * UserManagement API??? ?? ???? ???? id?? ????? ???? ??? ???????? ??.
 */
public class UserProfile implements Parcelable{
    private static final String CACHE_USER_PREFIX = "com.kakao.user.";
    private static final String CACHE_USER_ID = "com.kakao.user.userId";
    private static final String CACHE_NICKNAME = "com.kakao.user.nickname";
    private static final String CACHE_THUMBNAIL_PATH = "com.kakao.user.thumbbnailpath";
    private static final String CACHE_PROFILE_PATH = "com.kakao.user.profilepath";

    private final long id;
    private String nickname;
    private String thumbnailImagePath;
    private String profileImagePath;
    // predefined property? ??? ????? ????? property
    private Map<String, String> properties = new HashMap<String, String>();

    private UserProfile(final long id, final String nickname, final String thumbnailImagePath, final String profileImagePath,
                       final Map<String, String> properties) {
        this.id = id;
        this.nickname = nickname;
        this.thumbnailImagePath = thumbnailImagePath;
        this.profileImagePath = profileImagePath;
        if(properties != null)
            this.properties = properties;
    }

    /**
     * UserManagement API ????? ????? ???? id
     *
     * @return UserManagement API ????? ????? ???? id
     */
    public long getId() {
        return id;
    }

    /**
     * ???? ?????? ?? ??????? ?? ??? key, value? ????? json type?? ??
     * @return ??? ????? ??????? ?? ??
     */
    public Map<String, String> getProperties() {
        return properties;
    }

    /**
     * ? ??? ?? ????? ??????? ?? ? key?? ???? ??
     * @param propertyKey ?? ???? ???? ????? key
     * @return ?? key??? ??
     */
    public String getProperty(final String propertyKey) {
        if(properties != null)
            return properties.get(propertyKey);
        else
            return null;
    }

    /**
     * ???? ??
     * @return ???? ??
     */
    public String getNickname() {
        if (nickname == null)
            return "undefined";
        else
            return nickname;
    }

    /**
     * 110px * 110px(???? ??? ? ??) ??? 160px * 160px(?????? ??? ? ??) ??????? ??????? ??????? ??? ????? ??
     * @return ??????? ??????? ??? ????? ??
     */
    public String getThumbnailImagePath() {
        return thumbnailImagePath;
    }

    /**
     * 480px * 480px ~ 1024px * 1024px ??????? ??????? ??? ????? ??
     * @return ??????? ??? ????? ??
     */
    public String getProfileImagePath() {
        return profileImagePath;
    }

    /**
     * ??????? ??? ??? String?? ????
     * @return ??????? ??? ??? String?? ??? ?
     */
    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("UserProfile{");
        sb.append("nickname='").append(nickname).append('\'');
        sb.append(", thumbnailImagePath='").append(thumbnailImagePath).append('\'');
        sb.append(", profileImagePath='").append(profileImagePath).append('\'');
        sb.append(", properties=").append(properties);
        sb.append('}');
        return sb.toString();
    }

    /**
     * ???? ?? ??????? ??????.
     * @return ?????? ?????? ??????
     */
    public static UserProfile loadFromCache() {
        SharedPreferencesCache cache = Session.getAppCache();
        if(cache == null)
            return null;

        Bundle bundle = cache.load();

        final long userId = bundle.getLong(CACHE_USER_ID);
        bundle.remove(CACHE_USER_ID);
        final String nickname = bundle.getString(CACHE_NICKNAME);
        bundle.remove(CACHE_NICKNAME);
        final String thumbnailPath = bundle.getString(CACHE_THUMBNAIL_PATH);
        bundle.remove(CACHE_THUMBNAIL_PATH);
        final String profilePath = bundle.getString(CACHE_PROFILE_PATH);
        bundle.remove(CACHE_PROFILE_PATH);

        Map<String, String> properties = new HashMap<String, String>();
        if(!bundle.isEmpty()){
            for(String key : bundle.keySet()){
                if(key.startsWith(CACHE_USER_PREFIX))
                    properties.put(key, bundle.getString(key));
            }
        }

        return new UserProfile(userId, nickname, thumbnailPath, profilePath, properties);
    }

    /**
     * ?? ??? ?? UserProfile ???? ???.
     * @param userProfileMap ?????? ???? json?? ?? ???? Map
     * @return ?? ??? ?? ?? UserProfile ???
     */
    public static UserProfile createFromResponse(final Map userProfileMap) {
        final Number userIdNumber = (Number) userProfileMap.get(ServerProtocol.USER_ID_KEY);
        final long userId = userIdNumber.longValue();

        final Map<String, String> properties = (Map<String, String>) userProfileMap.get(ServerProtocol.PROPERTIES_KEY);

        return createFromInput(userId, properties);
    }

    /**
     * ?????? ?? ?? ? ??? ???? ???? id? update? ???? ??? ?? UserProfile ???? ???.
     * @param userId ???? id
     * @param properties update? ???? ??
     * @return input???? ?? UserProfile ???
     */
    private static UserProfile createFromInput(final long userId, final Map<String, String> properties) {
        String nickname = null;
        String thumbnailPath = null;
        String profilePath = null;
        if (properties != null) {
            nickname = properties.remove(ServerProtocol.NICK_NAME_KEY);
            thumbnailPath = properties.remove(ServerProtocol.PROFILE_THUMBNAIL_IMAGE_KEY);
            profilePath = properties.remove(ServerProtocol.PROFILE_IMAGE_KEY);
        }
        return new UserProfile(userId, nickname, thumbnailPath, profilePath, properties);
    }

    /**
     * ??? ??????? update? ???? ??? ?? ????? update? ??? update? ??? ??.
     * @param originUserProfile ??? ?????? ???
     * @param properties update? ???? ??
     * @return input??? merge? ??
     */
    public static UserProfile updateUserProfile(final UserProfile originUserProfile, final Map<String, String> properties) {
        UserProfile userProfile = new UserProfile(originUserProfile.getId(), originUserProfile.getNickname(),
            originUserProfile.getThumbnailImagePath(), originUserProfile.getProfileImagePath(), originUserProfile.getProperties());
        if (properties != null) {
            final String nickname = properties.remove(ServerProtocol.NICK_NAME_KEY);
            if(nickname != null)
                userProfile.nickname = nickname;

            final String thumbnailPath = properties.remove(ServerProtocol.PROFILE_THUMBNAIL_IMAGE_KEY);
            if(thumbnailPath != null)
                userProfile.thumbnailImagePath = thumbnailPath;

            final String profilePath = properties.remove(ServerProtocol.PROFILE_IMAGE_KEY);
            if(profilePath != null)
                 userProfile.profileImagePath = profilePath;

            if(!properties.isEmpty())
                userProfile.properties.putAll(properties);
        }
        return userProfile;
    }

    /**
     * ???? ???? ????? ????.
     */
    public void saveUserToCache() {
        SharedPreferencesCache cache = Session.getAppCache();
        if(cache == null)
            return;

        Bundle bundle = new Bundle();

        bundle.putLong(CACHE_USER_ID, id);
        bundle.putString(CACHE_NICKNAME, nickname);
        bundle.putString(CACHE_THUMBNAIL_PATH, thumbnailImagePath);
        bundle.putString(CACHE_PROFILE_PATH, profileImagePath);

        if(!properties.isEmpty()){
            for(String key : properties.keySet()){
                bundle.putString(CACHE_USER_PREFIX + key, properties.get(key));
            }
        }
        cache.save(bundle);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(id);
        dest.writeString(nickname);
        dest.writeString(thumbnailImagePath);
        dest.writeString(profileImagePath);
        dest.writeMap(properties);
    }

    public UserProfile(Parcel in) {
        id = in.readLong();
        nickname = in.readString();
        thumbnailImagePath = in.readString();
        profileImagePath = in.readString();
        in.readMap(properties, getClass().getClassLoader());
    }

    public static final Parcelable.Creator<UserProfile> CREATOR = new Parcelable.Creator<UserProfile>() {
        public UserProfile createFromParcel(Parcel in) {
            return new UserProfile(in);
        }

        public UserProfile[] newArray(int size) {
            return new UserProfile[size];
        }
    };

}




Java Source Code List

com.kakao.APIErrorResult.java
com.kakao.AppActionBuilder.java
com.kakao.ErrorCode.java
com.kakao.KakaoLinkParseException.java
com.kakao.KakaoLink.java
com.kakao.KakaoStoryHttpResponseHandler.java
com.kakao.KakaoStoryPostParamBuilder.java
com.kakao.KakaoStoryProfile.java
com.kakao.KakaoStoryService.java
com.kakao.KakaoStoryUpload.java
com.kakao.KakaoTalkHttpResponseHandler.java
com.kakao.KakaoTalkLinkMessageBuilder.java
com.kakao.KakaoTalkProfile.java
com.kakao.KakaoTalkService.java
com.kakao.LoginActivity.java
com.kakao.LogoutResponseCallback.java
com.kakao.MeResponseCallback.java
com.kakao.SessionCallback.java
com.kakao.Session.java
com.kakao.SignupResponseCallback.java
com.kakao.UnlinkResponseCallback.java
com.kakao.UpdateProfileResponseCallback.java
com.kakao.UserManagement.java
com.kakao.UserProfileResponseCallback.java
com.kakao.UserProfile.java
com.kakao.UserResponseCallback.java
com.kakao.User.java
com.kakao.authorization.AuthorizationResult.java
com.kakao.authorization.Authorizer.java
com.kakao.authorization.accesstoken.AccessTokenRequest.java
com.kakao.authorization.accesstoken.AccessToken.java
com.kakao.authorization.accesstoken.GetterAccessToken.java
com.kakao.authorization.accesstoken.package-info.java
com.kakao.authorization.authcode.AuthorizationCodeHandler.java
com.kakao.authorization.authcode.AuthorizationCodeRequest.java
com.kakao.authorization.authcode.AuthorizationCode.java
com.kakao.authorization.authcode.GetterAuthorizationCode.java
com.kakao.authorization.authcode.KakaoWebViewDialog.java
com.kakao.authorization.authcode.LoggedInTalkAuthHandler.java
com.kakao.authorization.authcode.LoggedOutTalkAuthHandler.java
com.kakao.authorization.authcode.OnWebViewCompleteListener.java
com.kakao.authorization.authcode.WebViewAuthHandler.java
com.kakao.authorization.authcode.package-info.java
com.kakao.exception.KakaoException.java
com.kakao.exception.KakaoWebviewException.java
com.kakao.exception.package-info.java
com.kakao.helper.Base64.java
com.kakao.helper.JsonHelper.java
com.kakao.helper.Logger.java
com.kakao.helper.ServerProtocol.java
com.kakao.helper.SharedPreferencesCache.java
com.kakao.helper.SystemInfo.java
com.kakao.helper.TalkProtocol.java
com.kakao.helper.Utility.java
com.kakao.helper.package-info.java
com.kakao.http.AsyncHttpClient.java
com.kakao.http.BodyPart.java
com.kakao.http.FilePart.java
com.kakao.http.HttpRequestBuilder.java
com.kakao.http.HttpRequestTask.java
com.kakao.http.HttpResponseHandler.java
com.kakao.http.HttpTaskManager.java
com.kakao.http.KakaoAsyncHandler.java
com.kakao.http.Multipart.java
com.kakao.http.Request.java
com.kakao.http.Response.java
com.kakao.http.package-info.java
com.kakao.internal.ActionInfo.java
com.kakao.internal.Action.java
com.kakao.internal.KakaoTalkLinkProtocol.java
com.kakao.internal.LinkObject.java
com.kakao.internal.package-info.java
com.kakao.rest.APIHttpRequestTask.java
com.kakao.rest.package-info.java
com.kakao.sample.kakaolink.KakaoLinkMainActivity.java
com.kakao.sample.kakaolink.KakaoLinkSplashActivity.java
com.kakao.sample.kakaolink.package-info.java
com.kakao.sample.kakaostory.KakaoStoryLoginActivity.java
com.kakao.sample.kakaostory.KakaoStoryMainActivity.java
com.kakao.sample.kakaostory.KakaoStorySignupActivity.java
com.kakao.sample.kakaostory.package-info.java
com.kakao.sample.kakaotalk.KakaoTalkLoginActivity.java
com.kakao.sample.kakaotalk.KakaoTalkMainActivity.java
com.kakao.sample.kakaotalk.KakaoTalkSignupActivity.java
com.kakao.sample.kakaotalk.package-info.java
com.kakao.sample.usermgmt.ExtraUserPropertyLayout.java
com.kakao.sample.usermgmt.UserMgmtLoginActivity.java
com.kakao.sample.usermgmt.UsermgmtMainActivity.java
com.kakao.sample.usermgmt.UsermgmtSignupActivity.java
com.kakao.sample.usermgmt.package-info.java
com.kakao.template.loginbase.SampleLoginActivity.java
com.kakao.template.loginbase.SampleSignupActivity.java
com.kakao.template.loginbase.package-info.java
com.kakao.template.loginfree.LoginFreeTemplateActivity.java
com.kakao.template.loginfree.package-info.java
com.kakao.widget.LoginButton.java
com.kakao.widget.ProfileLayout.java
com.kakao.widget.package-info.java
com.kakao.package-info.java