Search in sources :

Example 1 with Avatar

use of com.google.samples.apps.topeka.model.Avatar in project android-topeka by googlesamples.

the class PreferencesHelper method getPlayer.

/**
     * Retrieves a {@link com.google.samples.apps.topeka.model.Player} from preferences.
     *
     * @param context The Context which to obtain the SharedPreferences from.
     * @return A previously saved player or <code>null</code> if none was saved previously.
     */
public static Player getPlayer(Context context) {
    SharedPreferences preferences = getSharedPreferences(context);
    final String firstName = preferences.getString(PREFERENCE_FIRST_NAME, null);
    final String lastInitial = preferences.getString(PREFERENCE_LAST_INITIAL, null);
    final String avatarPreference = preferences.getString(PREFERENCE_AVATAR, null);
    final Avatar avatar;
    if (null != avatarPreference) {
        avatar = Avatar.valueOf(avatarPreference);
    } else {
        avatar = null;
    }
    if (null == firstName || null == lastInitial || null == avatar) {
        return null;
    }
    return new Player(firstName, lastInitial, avatar);
}
Also used : Player(com.google.samples.apps.topeka.model.Player) SharedPreferences(android.content.SharedPreferences) Avatar(com.google.samples.apps.topeka.model.Avatar)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Avatar (com.google.samples.apps.topeka.model.Avatar)1 Player (com.google.samples.apps.topeka.model.Player)1